aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/angular
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-05-23 11:07:42 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-05-23 11:07:42 +0200
commitcf20596c107eb0833259fa1098cc784267298a19 (patch)
tree094044145bdae9a840ff1fa5ceb56751528d3826 /client/angular
parent8140a704bbbecd149c68267545e4215579c9785c (diff)
downloadPeerTube-cf20596c107eb0833259fa1098cc784267298a19.tar.gz
PeerTube-cf20596c107eb0833259fa1098cc784267298a19.tar.zst
PeerTube-cf20596c107eb0833259fa1098cc784267298a19.zip
Add trivial sort for the client
Diffstat (limited to 'client/angular')
-rw-r--r--client/angular/app/app.component.ts1
-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
-rw-r--r--client/angular/videos/videos.service.ts11
7 files changed, 74 insertions, 8 deletions
diff --git a/client/angular/app/app.component.ts b/client/angular/app/app.component.ts
index 513830d6b..bfd5adaee 100644
--- a/client/angular/app/app.component.ts
+++ b/client/angular/app/app.component.ts
@@ -68,7 +68,6 @@ export class AppComponent {
68 } 68 }
69 69
70 onSearch(search: Search) { 70 onSearch(search: Search) {
71 console.log(search);
72 if (search.value !== '') { 71 if (search.value !== '') {
73 this._router.navigate(['VideosList', { search: search.value, field: search.field }]); 72 this._router.navigate(['VideosList', { search: search.value, field: search.field }]);
74 } else { 73 } else {
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}
diff --git a/client/angular/videos/videos.service.ts b/client/angular/videos/videos.service.ts
index 1329ead49..43e3346aa 100644
--- a/client/angular/videos/videos.service.ts
+++ b/client/angular/videos/videos.service.ts
@@ -6,6 +6,7 @@ import { Pagination } from './pagination';
6import { Video } from './video'; 6import { Video } from './video';
7import { AuthService } from '../users/services/auth.service'; 7import { AuthService } from '../users/services/auth.service';
8import { Search } from '../app/search'; 8import { Search } from '../app/search';
9import { SortField } from './components/list/sort';
9 10
10@Injectable() 11@Injectable()
11export class VideosService { 12export class VideosService {
@@ -13,8 +14,11 @@ export class VideosService {
13 14
14 constructor (private http: Http, private _authService: AuthService) {} 15 constructor (private http: Http, private _authService: AuthService) {}
15 16
16 getVideos(pagination: Pagination) { 17 getVideos(pagination: Pagination, sort: SortField) {
17 const params = this.createPaginationParams(pagination); 18 const params = this.createPaginationParams(pagination);
19
20 if (sort) params.set('sort', sort)
21
18 return this.http.get(this._baseVideoUrl, { search: params }) 22 return this.http.get(this._baseVideoUrl, { search: params })
19 .map(res => res.json()) 23 .map(res => res.json())
20 .map(this.extractVideos) 24 .map(this.extractVideos)
@@ -34,9 +38,12 @@ export class VideosService {
34 .catch(this.handleError); 38 .catch(this.handleError);
35 } 39 }
36 40
37 searchVideos(search: Search, pagination: Pagination) { 41 searchVideos(search: Search, pagination: Pagination, sort: SortField) {
38 const params = this.createPaginationParams(pagination); 42 const params = this.createPaginationParams(pagination);
43
39 if (search.field) params.set('field', search.field); 44 if (search.field) params.set('field', search.field);
45 if (sort) params.set('sort', sort)
46
40 return this.http.get(this._baseVideoUrl + 'search/' + encodeURIComponent(search.value), { search: params }) 47 return this.http.get(this._baseVideoUrl + 'search/' + encodeURIComponent(search.value), { search: params })
41 .map(res => res.json()) 48 .map(res => res.json())
42 .map(this.extractVideos) 49 .map(this.extractVideos)