]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/angular/videos/components/list/videos-list.component.ts
Update to Angular RC 1
[github/Chocobozzz/PeerTube.git] / client / angular / videos / components / list / videos-list.component.ts
CommitLineData
230809ef
C
1import { Component, OnInit } from '@angular/core';
2import { ROUTER_DIRECTIVES, RouteParams } from '@angular/router-deprecated';
dc8bc31b 3
1553e15d
C
4import { AuthService } from '../../../users/services/auth.service';
5import { User } from '../../../users/models/user';
98b01bac
C
6import { VideosService } from '../../services/videos.service';
7import { 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
16export class VideosListComponent implements OnInit {
1553e15d 17 user: User = null;
d908a155 18 videos: Video[] = [];
dc8bc31b 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}