aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/angular/videos/components/list
diff options
context:
space:
mode:
Diffstat (limited to 'client/angular/videos/components/list')
-rw-r--r--client/angular/videos/components/list/sort.ts3
-rw-r--r--client/angular/videos/components/list/video-sort.component.html5
-rw-r--r--client/angular/videos/components/list/video-sort.component.ts36
-rw-r--r--client/angular/videos/components/list/videos-list.component.html5
-rw-r--r--client/angular/videos/components/list/videos-list.component.ts21
5 files changed, 65 insertions, 5 deletions
diff --git a/client/angular/videos/components/list/sort.ts b/client/angular/videos/components/list/sort.ts
new file mode 100644
index 000000000..6e8cc7936
--- /dev/null
+++ b/client/angular/videos/components/list/sort.ts
@@ -0,0 +1,3 @@
1export type SortField = "name" | "-name"
2 | "duration" | "-duration"
3 | "createdDate" | "-createdDate";
diff --git a/client/angular/videos/components/list/video-sort.component.html b/client/angular/videos/components/list/video-sort.component.html
new file mode 100644
index 000000000..b1392ccca
--- /dev/null
+++ b/client/angular/videos/components/list/video-sort.component.html
@@ -0,0 +1,5 @@
1<select [(ngModel)]="currentSort" (ngModelChange)="onSortChange()">
2 <option *ngFor="let choice of choiceKeys" [value]="choice">
3 {{ getStringChoice(choice) }}
4 </option>
5</select>
diff --git a/client/angular/videos/components/list/video-sort.component.ts b/client/angular/videos/components/list/video-sort.component.ts
new file mode 100644
index 000000000..e63a70e9e
--- /dev/null
+++ b/client/angular/videos/components/list/video-sort.component.ts
@@ -0,0 +1,36 @@
1import { Component, Input, Output, EventEmitter } from '@angular/core';
2
3import { SortField } from './sort';
4
5@Component({
6 selector: 'my-video-sort',
7 // styleUrls: [ 'app/angular/videos/components/list/video-sort.component.css' ],
8 templateUrl: 'app/angular/videos/components/list/video-sort.component.html'
9})
10
11export class VideoSortComponent {
12 @Output() sort = new EventEmitter<any>();
13
14 @Input() currentSort: SortField;
15
16 sortChoices = {
17 'name': 'Name - Asc',
18 '-name': "Name - Desc",
19 'duration': "Duration - Asc",
20 '-duration': "Duration - Desc",
21 'createdDate': "Created Date - Asc",
22 '-createdDate': "Created Date - Desc"
23 }
24
25 get choiceKeys() {
26 return Object.keys(this.sortChoices);
27 }
28
29 getStringChoice(choiceKey: SortField): string {
30 return this.sortChoices[choiceKey];
31 }
32
33 onSortChange() {
34 this.sort.emit(this.currentSort);
35 }
36}
diff --git a/client/angular/videos/components/list/videos-list.component.html b/client/angular/videos/components/list/videos-list.component.html
index 39cdf29ba..5524ab546 100644
--- a/client/angular/videos/components/list/videos-list.component.html
+++ b/client/angular/videos/components/list/videos-list.component.html
@@ -1,3 +1,8 @@
1<div class="videos-info">
2 <span class="videos-total-results"> {{ pagination.total }}</span>
3 <my-video-sort [currentSort]="sort" (sort)="onSort($event)"></my-video-sort>
4</div>
5
1<div class="videos-miniatures"> 6<div class="videos-miniatures">
2 <div *ngIf="videos.length === 0">There is no video.</div> 7 <div *ngIf="videos.length === 0">There is no video.</div>
3 8
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 @@
1import { Component, OnInit } from '@angular/core'; 1import { Component, OnInit } from '@angular/core';
2import { ROUTER_DIRECTIVES, RouteParams } from '@angular/router-deprecated'; 2import { ROUTER_DIRECTIVES, RouteParams, Router } from '@angular/router-deprecated';
3 3
4import { PAGINATION_DIRECTIVES } from 'ng2-bootstrap/components/pagination'; 4import { PAGINATION_DIRECTIVES } from 'ng2-bootstrap/components/pagination';
5 5
@@ -10,12 +10,14 @@ import { VideosService } from '../../videos.service';
10import { Video } from '../../video'; 10import { Video } from '../../video';
11import { VideoMiniatureComponent } from './video-miniature.component'; 11import { VideoMiniatureComponent } from './video-miniature.component';
12import { Search, SearchField } from '../../../app/search'; 12import { Search, SearchField } from '../../../app/search';
13import { VideoSortComponent } from './video-sort.component';
14import { 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
21export class VideosListComponent implements OnInit { 23export 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}