1 import { Component, OnInit } from '@angular/core';
2 import { Router, ROUTER_DIRECTIVES, RouteParams } from '@angular/router-deprecated';
4 import { PAGINATION_DIRECTIVES } from 'ng2-bootstrap/components/pagination';
12 } from '../shared/index';
13 import { AuthService, Search, SearchField, User } from '../../shared/index';
14 import { VideoMiniatureComponent } from './video-miniature.component';
15 import { VideoSortComponent } from './video-sort.component';
18 selector: 'my-videos-list',
19 styleUrls: [ 'client/app/videos/video-list/video-list.component.css' ],
20 templateUrl: 'client/app/videos/video-list/video-list.component.html',
21 directives: [ LoaderComponent, PAGINATION_DIRECTIVES, ROUTER_DIRECTIVES, VideoMiniatureComponent, VideoSortComponent ]
24 export class VideoListComponent implements OnInit {
26 pagination: Pagination = {
35 private search: Search;
38 private authService: AuthService,
39 private router: Router,
40 private routeParams: RouteParams,
41 private videoService: VideoService
44 value: this.routeParams.get('search'),
45 field: <SearchField>this.routeParams.get('field')
48 this.sort = <SortField>this.routeParams.get('sort') || '-createdDate';
52 if (this.authService.isLoggedIn()) {
53 this.user = User.load();
63 let observable = null;
65 if (this.search.value !== null) {
66 observable = this.videoService.searchVideos(this.search, this.pagination, this.sort);
68 observable = this.videoService.getVideos(this.pagination, this.sort);
72 ({ videos, totalVideos }) => {
74 this.pagination.total = totalVideos;
83 return !this.loading && this.videos.length === 0;
86 onRemoved(video: Video) {
87 this.videos.splice(this.videos.indexOf(video), 1);
90 onSort(sort: SortField) {
97 if (this.search.value) {
98 params.field = this.search.field;
99 params.search = this.search.value;
102 this.router.navigate(['VideosList', params]);