]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/angular/videos/components/list/videos-list.component.ts
ae58f4d7e8abf27a4b1330aac1c8d6ff26c11186
[github/Chocobozzz/PeerTube.git] / client / angular / videos / components / list / videos-list.component.ts
1 import { Component, OnInit } from 'angular2/core';
2 import { ROUTER_DIRECTIVES, RouteParams } from 'angular2/router';
3
4 import { VideosService } from '../../services/videos.service';
5 import { Video } from '../../models/video';
6
7 @Component({
8 selector: 'my-videos-list',
9 styleUrls: [ 'app/angular/videos/components/list/videos-list.component.css' ],
10 templateUrl: 'app/angular/videos/components/list/videos-list.component.html',
11 directives: [ ROUTER_DIRECTIVES ]
12 })
13
14 export class VideosListComponent implements OnInit {
15 videos: Video[];
16
17 private search: string;
18
19 constructor(
20 private _videosService: VideosService,
21 routeParams: RouteParams
22 ) {
23 this.search = routeParams.get('search');
24 }
25
26 ngOnInit() {
27 this.getVideos();
28 }
29
30 getVideos() {
31 let observable = null;
32
33 if (this.search !== null) {
34 observable = this._videosService.searchVideos(this.search);
35 } else {
36 observable = this._videosService.getVideos();
37 }
38
39 observable.subscribe(
40 videos => this.videos = videos,
41 error => alert(error)
42 );
43 }
44
45 removeVideo(id: string) {
46 this._videosService.removeVideo(id).subscribe(
47 status => this.getVideos(),
48 error => alert(error)
49 );
50 }
51
52 }