]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/angular/videos/components/list/videos-list.component.ts
Add typescript (and angular2) linter
[github/Chocobozzz/PeerTube.git] / client / angular / videos / components / list / videos-list.component.ts
CommitLineData
98b01bac
C
1import { Component, OnInit } from 'angular2/core';
2import { ROUTER_DIRECTIVES, RouteParams } from 'angular2/router';
dc8bc31b 3
98b01bac
C
4import { VideosService } from '../../services/videos.service';
5import { Video } from '../../models/video';
dc8bc31b
C
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
14export class VideosListComponent implements OnInit {
15 videos: Video[];
16
98b01bac
C
17 private search: string;
18
dc8bc31b 19 constructor(
98b01bac
C
20 private _videosService: VideosService,
21 routeParams: RouteParams
22 ) {
23 this.search = routeParams.get('search');
24 }
dc8bc31b
C
25
26 ngOnInit() {
27 this.getVideos();
28 }
29
30 getVideos() {
98b01bac
C
31 let observable = null;
32
33 if (this.search !== null) {
34 observable = this._videosService.searchVideos(this.search);
35 } else {
44124980 36 observable = this._videosService.getVideos();
98b01bac
C
37 }
38
39 observable.subscribe(
dc8bc31b
C
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)
44124980 49 );
dc8bc31b
C
50 }
51
52}