From 7b87d2d5141d0eb48db2a3fd162208d6a79b2035 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 17 Apr 2018 10:56:27 +0200 Subject: Handle sort in rss --- client/src/app/shared/video/abstract-video-list.ts | 8 ++--- client/src/app/shared/video/sort-field.type.ts | 2 +- client/src/app/shared/video/video.service.ts | 39 +++++++++------------- 3 files changed, 20 insertions(+), 29 deletions(-) (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/video/abstract-video-list.ts b/client/src/app/shared/video/abstract-video-list.ts index c1c07e628..7f2cf2d7e 100644 --- a/client/src/app/shared/video/abstract-video-list.ts +++ b/client/src/app/shared/video/abstract-video-list.ts @@ -9,7 +9,7 @@ import { fromEvent } from 'rxjs/observable/fromEvent' import { Subscription } from 'rxjs/Subscription' import { AuthService } from '../../core/auth' import { ComponentPagination } from '../rest/component-pagination.model' -import { SortField } from './sort-field.type' +import { VideoSortField } from './sort-field.type' import { Video } from './video.model' export abstract class AbstractVideoList implements OnInit, OnDestroy { @@ -23,8 +23,8 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy { itemsPerPage: 10, totalItems: null } - sort: SortField = '-createdAt' - defaultSort: SortField = '-createdAt' + sort: VideoSortField = '-createdAt' + defaultSort: VideoSortField = '-createdAt' syndicationItems = [] loadOnInit = true @@ -154,7 +154,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy { } protected loadRouteParams (routeParams: { [ key: string ]: any }) { - this.sort = routeParams['sort'] as SortField || this.defaultSort + this.sort = routeParams['sort'] as VideoSortField || this.defaultSort if (routeParams['page'] !== undefined) { this.pagination.currentPage = parseInt(routeParams['page'], 10) diff --git a/client/src/app/shared/video/sort-field.type.ts b/client/src/app/shared/video/sort-field.type.ts index 776f360f8..2a3ae4ddd 100644 --- a/client/src/app/shared/video/sort-field.type.ts +++ b/client/src/app/shared/video/sort-field.type.ts @@ -1,4 +1,4 @@ -export type SortField = 'name' | '-name' +export type VideoSortField = 'name' | '-name' | 'duration' | '-duration' | 'createdAt' | '-createdAt' | 'views' | '-views' diff --git a/client/src/app/shared/video/video.service.ts b/client/src/app/shared/video/video.service.ts index 4c19c3765..ef8babd55 100644 --- a/client/src/app/shared/video/video.service.ts +++ b/client/src/app/shared/video/video.service.ts @@ -16,7 +16,7 @@ import { ComponentPagination } from '../rest/component-pagination.model' import { RestExtractor } from '../rest/rest-extractor.service' import { RestService } from '../rest/rest.service' import { UserService } from '../users/user.service' -import { SortField } from './sort-field.type' +import { VideoSortField } from './sort-field.type' import { VideoDetails } from './video-details.model' import { VideoEdit } from './video-edit.model' import { Video } from './video.model' @@ -86,7 +86,7 @@ export class VideoService { .catch(this.restExtractor.handleError) } - getMyVideos (videoPagination: ComponentPagination, sort: SortField): Observable<{ videos: Video[], totalVideos: number}> { + getMyVideos (videoPagination: ComponentPagination, sort: VideoSortField): Observable<{ videos: Video[], totalVideos: number}> { const pagination = this.restService.componentPaginationToRestPagination(videoPagination) let params = new HttpParams() @@ -99,7 +99,7 @@ export class VideoService { getVideos ( videoPagination: ComponentPagination, - sort: SortField, + sort: VideoSortField, filter?: VideoFilter ): Observable<{ videos: Video[], totalVideos: number}> { const pagination = this.restService.componentPaginationToRestPagination(videoPagination) @@ -117,7 +117,7 @@ export class VideoService { .catch((res) => this.restExtractor.handleError(res)) } - buildBaseFeedUrls () { + buildBaseFeedUrls (params: HttpParams) { const feeds = [ { label: 'rss 2.0', @@ -133,43 +133,34 @@ export class VideoService { } ] + if (params && params.keys().length !== 0) { + for (const feed of feeds) { + feed.url += '?' + params.toString() + } + } + return feeds } - getVideoFeedUrls (filter?: VideoFilter) { - let params = this.restService.addRestGetParams(new HttpParams()) - const feeds = this.buildBaseFeedUrls() + getVideoFeedUrls (sort: VideoSortField, filter?: VideoFilter) { + let params = this.restService.addRestGetParams(new HttpParams(), undefined, sort) if (filter) params = params.set('filter', filter) - if (params.keys().length !== 0) { - for (let item of feeds) { - item.url += `?${params.toString()}` - } - } - - return feeds + return this.buildBaseFeedUrls(params) } getAccountFeedUrls (accountId: number) { let params = this.restService.addRestGetParams(new HttpParams()) - const feeds = this.buildBaseFeedUrls() - params = params.set('accountId', accountId.toString()) - if (params.keys().length !== 0) { - for (let item of feeds) { - item.url += `?${params.toString()}` - } - } - - return feeds + return this.buildBaseFeedUrls(params) } searchVideos ( search: string, videoPagination: ComponentPagination, - sort: SortField + sort: VideoSortField ): Observable<{ videos: Video[], totalVideos: number}> { const url = VideoService.BASE_VIDEO_URL + 'search' -- cgit v1.2.3