]>
Commit | Line | Data |
---|---|---|
98b01bac C |
1 | import { Component, OnInit } from 'angular2/core'; |
2 | import { ROUTER_DIRECTIVES, RouteParams } from 'angular2/router'; | |
dc8bc31b | 3 | |
1553e15d C |
4 | import { AuthService } from '../../../users/services/auth.service'; |
5 | import { User } from '../../../users/models/user'; | |
98b01bac C |
6 | import { VideosService } from '../../services/videos.service'; |
7 | import { Video } from '../../models/video'; | |
dc8bc31b C |
8 | |
9 | @Component({ | |
10 | selector: 'my-videos-list', | |
11 | styleUrls: [ 'app/angular/videos/components/list/videos-list.component.css' ], | |
12 | templateUrl: 'app/angular/videos/components/list/videos-list.component.html', | |
13 | directives: [ ROUTER_DIRECTIVES ] | |
14 | }) | |
15 | ||
16 | export class VideosListComponent implements OnInit { | |
1553e15d | 17 | user: User = null; |
dc8bc31b C |
18 | videos: Video[]; |
19 | ||
98b01bac C |
20 | private search: string; |
21 | ||
dc8bc31b | 22 | constructor( |
1553e15d | 23 | private _authService: AuthService, |
98b01bac C |
24 | private _videosService: VideosService, |
25 | routeParams: RouteParams | |
26 | ) { | |
27 | this.search = routeParams.get('search'); | |
28 | } | |
dc8bc31b C |
29 | |
30 | ngOnInit() { | |
1553e15d C |
31 | if (this._authService.isLoggedIn()) { |
32 | this.user = User.load(); | |
33 | } | |
34 | ||
dc8bc31b C |
35 | this.getVideos(); |
36 | } | |
37 | ||
38 | getVideos() { | |
98b01bac C |
39 | let observable = null; |
40 | ||
2e2bef6f | 41 | if (this.search !== null) { |
98b01bac C |
42 | observable = this._videosService.searchVideos(this.search); |
43 | } else { | |
44124980 | 44 | observable = this._videosService.getVideos(); |
98b01bac C |
45 | } |
46 | ||
47 | observable.subscribe( | |
dc8bc31b C |
48 | videos => this.videos = videos, |
49 | error => alert(error) | |
50 | ); | |
51 | } | |
52 | ||
53 | removeVideo(id: string) { | |
54 | this._videosService.removeVideo(id).subscribe( | |
55 | status => this.getVideos(), | |
56 | error => alert(error) | |
44124980 | 57 | ); |
dc8bc31b C |
58 | } |
59 | ||
60 | } |