20979a3950ede88993ee7e54c8e0629d5d31bbe4
[oweals/peertube.git] / client / src / app / videos / video-list / video-sort.component.ts
1 import { Component, EventEmitter, Input, Output } from '@angular/core';
2
3 import { SortField } from '../shared';
4
5 @Component({
6   selector: 'my-video-sort',
7   templateUrl: './video-sort.component.html'
8 })
9
10 export class VideoSortComponent {
11   @Output() sort = new EventEmitter<any>();
12
13   @Input() currentSort: SortField;
14
15   sortChoices: { [ P in SortField ]: string } = {
16     'name': 'Name - Asc',
17     '-name': 'Name - Desc',
18     'duration': 'Duration - Asc',
19     '-duration': 'Duration - Desc',
20     'createdAt': 'Created Date - Asc',
21     '-createdAt': 'Created Date - Desc',
22     'views': 'Views - Asc',
23     '-views': 'Views - Desc',
24     'likes': 'Likes - Asc',
25     '-likes': 'Likes - Desc'
26   };
27
28   get choiceKeys() {
29     return Object.keys(this.sortChoices);
30   }
31
32   getStringChoice(choiceKey: SortField) {
33     return this.sortChoices[choiceKey];
34   }
35
36   onSortChange() {
37     this.sort.emit(this.currentSort);
38   }
39 }