]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/angular/videos/components/list/videos-list.component.ts
6fc0c1f04b290f2f79ec271bace64ca04c59c082
[github/Chocobozzz/PeerTube.git] / client / angular / videos / components / list / videos-list.component.ts
1 import { Component, OnInit } from '@angular/core';
2 import { ROUTER_DIRECTIVES, RouteParams } from '@angular/router-deprecated';
3
4 import { AuthService } from '../../../users/services/auth.service';
5 import { User } from '../../../users/models/user';
6 import { VideosService } from '../../videos.service';
7 import { Video } from '../../video';
8 import { VideoMiniatureComponent } from './video-miniature.component';
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',
14 directives: [ ROUTER_DIRECTIVES, VideoMiniatureComponent ]
15 })
16
17 export class VideosListComponent implements OnInit {
18 user: User = null;
19 videos: Video[] = [];
20
21 private search: string;
22
23 constructor(
24 private _authService: AuthService,
25 private _videosService: VideosService,
26 routeParams: RouteParams
27 ) {
28 this.search = routeParams.get('search');
29 }
30
31 ngOnInit() {
32 if (this._authService.isLoggedIn()) {
33 this.user = User.load();
34 }
35
36 this.getVideos();
37 }
38
39 getVideos() {
40 let observable = null;
41
42 if (this.search !== null) {
43 observable = this._videosService.searchVideos(this.search);
44 } else {
45 observable = this._videosService.getVideos();
46 }
47
48 observable.subscribe(
49 videos => this.videos = videos,
50 error => alert(error)
51 );
52 }
53
54 onRemoved(video: Video): void {
55 this.videos.splice(this.videos.indexOf(video), 1);
56 }
57
58 }