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