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 {
28 pagination: Pagination = {
34 loading: boolean = false;
36 private search: Search;
39 private _authService: AuthService,
40 private _videoService: VideoService,
41 private _routeParams: RouteParams,
42 private _router: Router
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;
82 onRemoved(video: Video): void {
83 this.videos.splice(this.videos.indexOf(video), 1);
86 onSort(sort: SortField) {
93 if (this.search.value) {
94 params.search = this.search.value;
95 params.field = this.search.field;
98 this._router.navigate(['VideosList', params]);