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 { Search, SearchField } from '../../shared/index';
14 import { AuthService, User } from '../../users/index';
15 import { VideoMiniatureComponent } from './video-miniature.component';
16 import { VideoSortComponent } from './video-sort.component';
19 selector: 'my-videos-list',
20 styleUrls: [ 'client/app/videos/video-list/video-list.component.css' ],
21 templateUrl: 'client/app/videos/video-list/video-list.component.html',
22 directives: [ ROUTER_DIRECTIVES, PAGINATION_DIRECTIVES, VideoMiniatureComponent, VideoSortComponent, LoaderComponent ]
25 export class VideoListComponent implements OnInit {
27 pagination: Pagination = {
36 private search: Search;
39 private authService: AuthService,
40 private router: Router,
41 private routeParams: RouteParams,
42 private videoService: VideoService
45 value: this.routeParams.get('search'),
46 field: <SearchField>this.routeParams.get('field')
49 this.sort = <SortField>this.routeParams.get('sort') || '-createdDate';
53 if (this.authService.isLoggedIn()) {
54 this.user = User.load();
64 let observable = null;
66 if (this.search.value !== null) {
67 observable = this.videoService.searchVideos(this.search, this.pagination, this.sort);
69 observable = this.videoService.getVideos(this.pagination, this.sort);
73 ({ videos, totalVideos }) => {
75 this.pagination.total = totalVideos;
83 onRemoved(video: Video) {
84 this.videos.splice(this.videos.indexOf(video), 1);
87 onSort(sort: SortField) {
94 if (this.search.value) {
95 params.field = this.search.field;
96 params.search = this.search.value;
99 this.router.navigate(['VideosList', params]);