Implement user requests autorizations in the client side
[oweals/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 { AuthService } from '../../../users/services/auth.service';
5 import { User } from '../../../users/models/user';
6 import { VideosService } from '../../services/videos.service';
7 import { Video } from '../../models/video';
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 {
17   user: User = null;
18   videos: Video[];
19
20   private search: string;
21
22   constructor(
23     private _authService: AuthService,
24     private _videosService: VideosService,
25     routeParams: RouteParams
26   ) {
27     this.search = routeParams.get('search');
28   }
29
30   ngOnInit() {
31     if (this._authService.isLoggedIn()) {
32       this.user = User.load();
33     }
34
35     this.getVideos();
36   }
37
38   getVideos() {
39     let observable = null;
40
41     if (this.search !== null) {""
42       observable = this._videosService.searchVideos(this.search);
43     } else {
44       observable = this._videosService.getVideos();
45     }
46
47     observable.subscribe(
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)
57     );
58   }
59
60 }