]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/angular/videos/components/list/videos-list.component.ts
Extends the search feature by customizing the search field (name,
[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';
501bc6c2
C
6import { VideosService } from '../../videos.service';
7import { Video } from '../../video';
8import { VideoMiniatureComponent } from './video-miniature.component';
dc8bc31b
C
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',
501bc6c2 14 directives: [ ROUTER_DIRECTIVES, VideoMiniatureComponent ]
dc8bc31b
C
15})
16
17export class VideosListComponent implements OnInit {
1553e15d 18 user: User = null;
d908a155 19 videos: Video[] = [];
dc8bc31b 20
98b01bac
C
21 private search: string;
22
dc8bc31b 23 constructor(
1553e15d 24 private _authService: AuthService,
98b01bac
C
25 private _videosService: VideosService,
26 routeParams: RouteParams
27 ) {
28 this.search = routeParams.get('search');
29 }
dc8bc31b
C
30
31 ngOnInit() {
1553e15d
C
32 if (this._authService.isLoggedIn()) {
33 this.user = User.load();
34 }
35
dc8bc31b
C
36 this.getVideos();
37 }
38
39 getVideos() {
98b01bac
C
40 let observable = null;
41
2e2bef6f 42 if (this.search !== null) {
98b01bac
C
43 observable = this._videosService.searchVideos(this.search);
44 } else {
44124980 45 observable = this._videosService.getVideos();
98b01bac
C
46 }
47
48 observable.subscribe(
dc8bc31b
C
49 videos => this.videos = videos,
50 error => alert(error)
51 );
52 }
53
501bc6c2
C
54 onRemoved(video: Video): void {
55 this.videos.splice(this.videos.indexOf(video), 1);
dc8bc31b
C
56 }
57
58}