Skip to content

Commit cbd32c6

Browse files
committed
1.x - Added functionality for settings and for search click videos
1 parent 380c703 commit cbd32c6

File tree

6 files changed

+104
-63
lines changed

6 files changed

+104
-63
lines changed

src/app/app.component.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,21 @@ export class AppComponent implements OnInit {
3636

3737
videoCurVolume = -1;
3838

39-
loading: boolean = true;
39+
loading = true;
4040

41-
constructor(private youtube: YoutubeGetVideo, private ref: ChangeDetectorRef, private shared:SharedService) {
41+
constructor(
42+
private youtube: YoutubeGetVideo,
43+
private ref: ChangeDetectorRef,
44+
private shared: SharedService
45+
) {
4246
this._ref = ref;
4347
this._shared = shared;
4448
}
4549

4650
ngOnInit() {
4751
console.log('app comp');
4852
this.getFeedVideos();
53+
this.getSettings();
4954
}
5055

5156
onClickRelated(event: Event, i: number) {
@@ -70,9 +75,17 @@ export class AppComponent implements OnInit {
7075
return playerVars;
7176
}
7277

78+
getSettings() {
79+
this._shared.getSettings().subscribe(data => {
80+
if (data) {
81+
this.debuggingInfo = data[0].selected;
82+
}
83+
});
84+
}
85+
7386
getFeedVideos() {
7487
this._shared.getFeed().subscribe(data => {
75-
if(data) {
88+
if (data) {
7689
this.feedVideos = data;
7790
this.setDefaultPlayer();
7891
}
@@ -98,10 +111,10 @@ export class AppComponent implements OnInit {
98111
this.getRelatedVideos();
99112
}
100113
}
101-
114+
102115
setSettings(data: any, from: number) {
103-
if(from === 1) {
104-
console.log(data);
116+
if (from === 0) {
117+
this.debuggingInfo = data[from].selected;
105118
}
106119
}
107120

src/app/components/youtube-search.component.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
11
import { Component, OnInit } from '@angular/core';
22
import { YoutubeGetVideo } from '../config/youtube.config';
3+
import { AppComponent } from '../app.component';
34
import { SharedService } from '../config/shared.module';
45
import { FormControl, FormGroup, Validators } from '@angular/forms';
56
import 'rxjs/add/operator/map';
67

78
@Component({
89
selector: 'app-search',
9-
templateUrl: 'youtube-search.component.html',
10+
templateUrl: 'youtube-search.component.html'
1011
})
1112

1213
export class SearchComponent implements OnInit {
1314

1415
searchForm: FormGroup;
1516

16-
debuggingInfo = false;
1717
searchVideoImage = false;
1818

1919
videos: any;
2020
feedVideos: any;
2121

2222
_shared: any;
23+
_app: any;
2324

24-
constructor(private youtube: YoutubeGetVideo, shared: SharedService) {
25+
constructor(
26+
private youtube: YoutubeGetVideo,
27+
private shared: SharedService,
28+
private app: AppComponent
29+
) {
2530
this._shared = shared;
31+
this._app = app;
2632
}
2733

2834
ngOnInit() {
2935
console.log('search');
3036
this.searchFunction();
3137
this.getFeedVideos();
38+
this.getSettings();
3239
}
3340

3441
searchFunction() {
@@ -52,9 +59,17 @@ export class SearchComponent implements OnInit {
5259
});
5360
}
5461

62+
getSettings() {
63+
this._shared.getSettings().subscribe(data => {
64+
if (data) {
65+
this.searchVideoImage = data[1].selected;
66+
}
67+
});
68+
}
69+
5570
getFeedVideos() {
5671
this._shared.getFeed().subscribe(data => {
57-
if(data) {
72+
if (data) {
5873
this.feedVideos = data;
5974
}
6075
});
@@ -70,31 +85,21 @@ export class SearchComponent implements OnInit {
7085
}
7186

7287
onClickVideo(event: Event, i: any, list: number) {
73-
console.log(i, list);
7488
if (list === 1) {
7589
const videoID = this.videos[i].id.videoId;
7690
const videoName = this.videos[i].snippet.title;
77-
//this._app.getVideo(videoID, videoName);
91+
this._app.getVideo(videoID, videoName);
92+
this.clearSearch();
7893
} else if (list === 3) {
7994
const videoID = this.feedVideos[i].id;
8095
const videoName = this.feedVideos[i].snippet.title;
81-
//this._app.getVideo(videoID, videoName);
96+
this._app.getVideo(videoID, videoName);
8297
}
83-
this.clearSearch();
8498
}
8599

86-
changeStates(event) {
87-
// Trigger from youtube-settings.component
88-
if (event.settings[0].selected != null) {
89-
this.debuggingInfo = event.settings[0].selected;
90-
} else {
91-
this.debuggingInfo = event.settings[0];
92-
}
93-
94-
if (event.settings[1].selected != null) {
95-
this.searchVideoImage = event.settings[1].selected;
96-
} else {
97-
this.searchVideoImage = event.settings[1];
100+
setSettings(data: any, from: number) {
101+
if (from === 0) {
102+
this.searchVideoImage = data[from].selected;
98103
}
99104
}
100105

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,47 @@
11
import { Component, OnInit } from '@angular/core';
22
import { FormControl, FormArray, FormGroup, FormBuilder, ReactiveFormsModule } from '@angular/forms';
3+
import { AppComponent } from '../app.component';
4+
import { SearchComponent } from './youtube-search.component';
35
import { SharedService } from '../config/shared.module';
46
import { Http } from '@angular/http';
57

68
@Component({
79
selector: 'app-settings',
8-
templateUrl: 'youtube-settings.component.html'
10+
templateUrl: 'youtube-settings.component.html',
11+
providers: [ SearchComponent ]
912
})
1013

1114
export class SettingsComponent implements OnInit {
1215

1316
private finished = false;
1417

15-
_fb: any;
1618
_shared: any;
19+
_fb: any;
20+
_app: any;
21+
_search: any;
1722

1823
settingsForm: FormGroup;
1924

2025
playerAttr = {
2126
settings: []
2227
};
2328

24-
constructor(private fb: FormBuilder, private http: Http, private shared: SharedService) {
25-
this._fb = fb;
29+
constructor(
30+
private fb: FormBuilder,
31+
private http: Http,
32+
private shared: SharedService,
33+
private app: AppComponent,
34+
private search: SearchComponent
35+
) {
2636
this._shared = shared;
37+
this._fb = fb;
38+
this._app = app;
39+
this._search = search;
2740
}
2841

2942
ngOnInit() {
3043
console.log('settings');
31-
this._shared.getSettings().subscribe(data => {
32-
if(data) {
33-
this.playerAttr.settings = data;
34-
this.finished = true;
35-
this.setForm();
36-
}
37-
});
44+
this.getDefaultSettings();
3845
}
3946

4047
setForm() {
@@ -50,12 +57,12 @@ export class SettingsComponent implements OnInit {
5057

5158
checkInputs() {
5259
this._shared.settings = this.playerAttr.settings;
53-
//this._app.setSettings(this.playerAttr.settings, 1);
5460
this.settingsForm.valueChanges.subscribe((data) => {
5561
Object.keys(data.settings).map(i => {
5662
this.playerAttr.settings[i].selected = data.settings[i];
5763
});
58-
console.log('se schimba ceva prin settings');
64+
this._app.setSettings(this.playerAttr.settings, 0);
65+
this._search.setSettings(this.playerAttr.settings, 1);
5966
});
6067
}
6168

@@ -66,4 +73,14 @@ export class SettingsComponent implements OnInit {
6673
return this.fb.array(arr);
6774
}
6875

76+
getDefaultSettings() {
77+
this._shared.getSettings().subscribe(data => {
78+
if (data) {
79+
this.playerAttr.settings = data;
80+
this.finished = true;
81+
this.setForm();
82+
}
83+
});
84+
}
85+
6986
}

src/app/config/shared.module.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import 'rxjs/add/operator/map';
77
@Injectable()
88
export class SharedService {
99

10-
videoID: string;
1110
feedVideos: Array<Object>;
1211
settings: Array<Object>;
1312

14-
constructor(private youtube: YoutubeGetVideo, private http: Http) {
13+
constructor(
14+
private youtube: YoutubeGetVideo,
15+
private http: Http
16+
) {
1517

1618
}
1719

@@ -20,17 +22,18 @@ export class SharedService {
2022
if (this.feedVideos) {
2123
observer.next(this.feedVideos);
2224
return observer.complete();
25+
} else {
26+
this.youtube.feedVideos().subscribe(
27+
result => {
28+
this.feedVideos = result.items;
29+
observer.next(this.feedVideos);
30+
observer.complete();
31+
},
32+
error => {
33+
console.log('error on feed videos' + error);
34+
}
35+
);
2336
}
24-
this.youtube.feedVideos().subscribe(
25-
result => {
26-
this.feedVideos = result.items;
27-
observer.next(this.feedVideos);
28-
observer.complete();
29-
},
30-
error => {
31-
console.log('error on feed videos');
32-
}
33-
);
3437
});
3538
}
3639

@@ -39,19 +42,20 @@ export class SharedService {
3942
if (this.settings) {
4043
observer.next(this.settings);
4144
return observer.complete();
45+
} else {
46+
this.http.get('assets/settings.json')
47+
.map(res => res.json())
48+
.subscribe(
49+
data => {
50+
this.settings = data;
51+
observer.next(this.settings);
52+
observer.complete();
53+
},
54+
error => {
55+
console.log('error on get settings ' + error);
56+
}
57+
);
4258
}
43-
this.http.get('assets/settings.json')
44-
.map(res => res.json())
45-
.subscribe(
46-
data => {
47-
this.settings = data;
48-
observer.next(this.settings);
49-
observer.complete();
50-
},
51-
err => {
52-
console.log('JSON Settings ' + err);
53-
}
54-
);
5559
});
5660
}
5761
}

src/assets/css/main.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ a:active {
197197

198198
.debugging-info {
199199
display: none;
200+
color: #ffffff;
200201
}
201202

202203
.debugging-info.active {

src/assets/scss/_common.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
.debugging-info {
4747
display: none;
48+
color: $c-white;
4849
&.active {
4950
display: block;
5051
}

0 commit comments

Comments
 (0)