PeerTube/client/angular/videos/components/list/videos-list.component.ts

61 lines
1.5 KiB
TypeScript
Raw Normal View History

2016-03-14 21:16:43 +00:00
import { Component, OnInit } from 'angular2/core';
import { ROUTER_DIRECTIVES, RouteParams } from 'angular2/router';
2016-03-14 12:50:19 +00:00
import { AuthService } from '../../../users/services/auth.service';
import { User } from '../../../users/models/user';
2016-03-14 21:16:43 +00:00
import { VideosService } from '../../services/videos.service';
import { Video } from '../../models/video';
2016-03-14 12:50:19 +00:00
@Component({
selector: 'my-videos-list',
styleUrls: [ 'app/angular/videos/components/list/videos-list.component.css' ],
templateUrl: 'app/angular/videos/components/list/videos-list.component.html',
directives: [ ROUTER_DIRECTIVES ]
})
export class VideosListComponent implements OnInit {
user: User = null;
2016-04-28 17:42:57 +00:00
videos: Video[] = [];
2016-03-14 12:50:19 +00:00
2016-03-14 21:16:43 +00:00
private search: string;
2016-03-14 12:50:19 +00:00
constructor(
private _authService: AuthService,
2016-03-14 21:16:43 +00:00
private _videosService: VideosService,
routeParams: RouteParams
) {
this.search = routeParams.get('search');
}
2016-03-14 12:50:19 +00:00
ngOnInit() {
if (this._authService.isLoggedIn()) {
this.user = User.load();
}
2016-03-14 12:50:19 +00:00
this.getVideos();
}
getVideos() {
2016-03-14 21:16:43 +00:00
let observable = null;
2016-04-14 20:12:03 +00:00
if (this.search !== null) {
2016-03-14 21:16:43 +00:00
observable = this._videosService.searchVideos(this.search);
} else {
2016-04-08 18:58:07 +00:00
observable = this._videosService.getVideos();
2016-03-14 21:16:43 +00:00
}
observable.subscribe(
2016-03-14 12:50:19 +00:00
videos => this.videos = videos,
error => alert(error)
);
}
removeVideo(id: string) {
this._videosService.removeVideo(id).subscribe(
status => this.getVideos(),
error => alert(error)
2016-04-08 18:58:07 +00:00
);
2016-03-14 12:50:19 +00:00
}
}