1 import { Component, OnInit } from '@angular/core';
2 import { ROUTER_DIRECTIVES, RouteParams, Router } from '@angular/router-deprecated';
4 import { PAGINATION_DIRECTIVES } from 'ng2-bootstrap/components/pagination';
6 import { AuthService } from '../../../users/services/auth.service';
7 import { Pagination } from '../../pagination';
8 import { User } from '../../../users/models/user';
9 import { VideosService } from '../../videos.service';
10 import { Video } from '../../video';
11 import { VideoMiniatureComponent } from './video-miniature.component';
12 import { Search, SearchField } from '../../../app/search';
13 import { VideoSortComponent } from './video-sort.component';
14 import { SortField } from './sort';
15 import { LoaderComponent } from '../../loader.component';
18 selector: 'my-videos-list',
19 styleUrls: [ 'app/angular/videos/components/list/videos-list.component.css' ],
20 templateUrl: 'app/angular/videos/components/list/videos-list.component.html',
21 directives: [ ROUTER_DIRECTIVES, PAGINATION_DIRECTIVES, VideoMiniatureComponent, VideoSortComponent, LoaderComponent ]
24 export class VideosListComponent implements OnInit {
27 pagination: Pagination = {
33 loading: boolean = false;
35 private search: Search;
38 private _authService: AuthService,
39 private _videosService: VideosService,
40 private _routeParams: RouteParams,
41 private _router: Router
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._videosService.searchVideos(this.search, this.pagination, this.sort);
68 observable = this._videosService.getVideos(this.pagination, this.sort);
72 ({ videos, totalVideos }) => {
74 this.pagination.total = totalVideos;
81 onRemoved(video: Video): void {
82 this.videos.splice(this.videos.indexOf(video), 1);
85 onSort(sort: SortField) {
92 if (this.search.value) {
93 params.search = this.search.value;
94 params.field = this.search.field;
97 this._router.navigate(['VideosList', params]);