-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.component.ts
86 lines (65 loc) · 2.26 KB
/
web.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import {Component, OnInit, OnDestroy} from '@angular/core';
import {Router, ActivatedRoute} from '@angular/router';
import {User} from '../models/user';
import {Category} from '../models/category';
import {AuthService} from '../services/auth.service';
import {VideosService} from '../services/videos.service';
import {CategoriesService} from '../services/categories.service';
import {Page} from '../helpers/page';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import {TypeaheadMatch} from 'ngx-bootstrap/typeahead';
@Component({
selector: 'app-web',
templateUrl: './web.component.html',
styleUrls: ['./web.component.css']
})
export class WebComponent implements OnInit {
public categoriesPage = new Page();
public categories = new Array();
public currentUser: User = new User();
public searchInputExpanded = false;
public asyncSelected: string;
public typeaheadLoading: boolean;
public typeaheadNoResults: boolean;
public dataSource: Observable<any>;
constructor(private _auth: AuthService,
private _categories: CategoriesService,
private _videos: VideosService,
private router: Router,
private route: ActivatedRoute) {
this.dataSource = Observable
.create((observer: any) => {
observer.next(this.asyncSelected);
}).mergeMap((token: string) => this.getResultAsObservable(token));
this.categoriesPage.pageNumber = 0;
this.categoriesPage.size = 10;
this._auth.currentUser.subscribe((user: User) => {
this.currentUser = user;
if (this.currentUser.logged) {
this._categories.list(this.categoriesPage).subscribe(pagedData => {
this.categories = pagedData.data;
});
}
});
}
public ngOnInit() {
}
toggleSearchInput() {
this.searchInputExpanded = !this.searchInputExpanded;
}
public getResultAsObservable(token: string): Observable<any> {
return Observable.of(
this._videos.search(token)
);
}
public changeTypeaheadLoading(e: boolean): void {
this.typeaheadLoading = e;
}
public changeTypeaheadNoResults(e: boolean): void {
this.typeaheadNoResults = e;
}
public typeaheadOnSelect(e: TypeaheadMatch): void {
console.log('Selected value: ', e.value);
}
}