diff options
Diffstat (limited to 'client/angular/videos/components/list/videos-list.component.ts')
-rw-r--r-- | client/angular/videos/components/list/videos-list.component.ts | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/client/angular/videos/components/list/videos-list.component.ts b/client/angular/videos/components/list/videos-list.component.ts index a17b06cd9..98fe7b153 100644 --- a/client/angular/videos/components/list/videos-list.component.ts +++ b/client/angular/videos/components/list/videos-list.component.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component, OnInit } from '@angular/core'; |
2 | import { ROUTER_DIRECTIVES, RouteParams } from '@angular/router-deprecated'; | 2 | import { ROUTER_DIRECTIVES, RouteParams, Router } from '@angular/router-deprecated'; |
3 | 3 | ||
4 | import { PAGINATION_DIRECTIVES } from 'ng2-bootstrap/components/pagination'; | 4 | import { PAGINATION_DIRECTIVES } from 'ng2-bootstrap/components/pagination'; |
5 | 5 | ||
@@ -10,12 +10,14 @@ import { VideosService } from '../../videos.service'; | |||
10 | import { Video } from '../../video'; | 10 | import { Video } from '../../video'; |
11 | import { VideoMiniatureComponent } from './video-miniature.component'; | 11 | import { VideoMiniatureComponent } from './video-miniature.component'; |
12 | import { Search, SearchField } from '../../../app/search'; | 12 | import { Search, SearchField } from '../../../app/search'; |
13 | import { VideoSortComponent } from './video-sort.component'; | ||
14 | import { SortField } from './sort'; | ||
13 | 15 | ||
14 | @Component({ | 16 | @Component({ |
15 | selector: 'my-videos-list', | 17 | selector: 'my-videos-list', |
16 | styleUrls: [ 'app/angular/videos/components/list/videos-list.component.css' ], | 18 | styleUrls: [ 'app/angular/videos/components/list/videos-list.component.css' ], |
17 | templateUrl: 'app/angular/videos/components/list/videos-list.component.html', | 19 | templateUrl: 'app/angular/videos/components/list/videos-list.component.html', |
18 | directives: [ ROUTER_DIRECTIVES, PAGINATION_DIRECTIVES, VideoMiniatureComponent ] | 20 | directives: [ ROUTER_DIRECTIVES, PAGINATION_DIRECTIVES, VideoMiniatureComponent, VideoSortComponent ] |
19 | }) | 21 | }) |
20 | 22 | ||
21 | export class VideosListComponent implements OnInit { | 23 | export class VideosListComponent implements OnInit { |
@@ -26,18 +28,22 @@ export class VideosListComponent implements OnInit { | |||
26 | itemsPerPage: 9, | 28 | itemsPerPage: 9, |
27 | total: 0 | 29 | total: 0 |
28 | } | 30 | } |
31 | sort: SortField; | ||
29 | 32 | ||
30 | private search: Search; | 33 | private search: Search; |
31 | 34 | ||
32 | constructor( | 35 | constructor( |
33 | private _authService: AuthService, | 36 | private _authService: AuthService, |
34 | private _videosService: VideosService, | 37 | private _videosService: VideosService, |
35 | private _routeParams: RouteParams | 38 | private _routeParams: RouteParams, |
39 | private _router: Router | ||
36 | ) { | 40 | ) { |
37 | this.search = { | 41 | this.search = { |
38 | value: this._routeParams.get('search'), | 42 | value: this._routeParams.get('search'), |
39 | field: <SearchField>this._routeParams.get('field') | 43 | field: <SearchField>this._routeParams.get('field') |
40 | } | 44 | } |
45 | |||
46 | this.sort = <SortField>this._routeParams.get('sort') || '-createdDate'; | ||
41 | } | 47 | } |
42 | 48 | ||
43 | ngOnInit() { | 49 | ngOnInit() { |
@@ -52,9 +58,9 @@ export class VideosListComponent implements OnInit { | |||
52 | let observable = null; | 58 | let observable = null; |
53 | 59 | ||
54 | if (this.search.value !== null) { | 60 | if (this.search.value !== null) { |
55 | observable = this._videosService.searchVideos(this.search, this.pagination); | 61 | observable = this._videosService.searchVideos(this.search, this.pagination, this.sort); |
56 | } else { | 62 | } else { |
57 | observable = this._videosService.getVideos(this.pagination); | 63 | observable = this._videosService.getVideos(this.pagination, this.sort); |
58 | } | 64 | } |
59 | 65 | ||
60 | observable.subscribe( | 66 | observable.subscribe( |
@@ -70,4 +76,9 @@ export class VideosListComponent implements OnInit { | |||
70 | this.videos.splice(this.videos.indexOf(video), 1); | 76 | this.videos.splice(this.videos.indexOf(video), 1); |
71 | } | 77 | } |
72 | 78 | ||
79 | onSort(sort: SortField) { | ||
80 | this.sort = sort; | ||
81 | this._router.navigate(['VideosList', { sort: this.sort }]); | ||
82 | this.getVideos(); | ||
83 | } | ||
73 | } | 84 | } |