From 61b909b9bf849516f30dab2bf5977acfbbddc5c6 Mon Sep 17 00:00:00 2001 From: PhieF Date: Wed, 27 Jun 2018 14:24:49 +0200 Subject: Filter by category (#720) * get videos with specific category (api) * update api doc with category * add url parameter to filter by category * fix lint issues --- client/src/app/shared/video/abstract-video-list.ts | 3 ++- client/src/app/shared/video/video.service.ts | 11 +++++++++-- client/src/app/videos/video-list/video-local.component.ts | 4 ++-- .../app/videos/video-list/video-recently-added.component.ts | 4 ++-- client/src/app/videos/video-list/video-trending.component.ts | 4 ++-- 5 files changed, 17 insertions(+), 9 deletions(-) (limited to 'client') diff --git a/client/src/app/shared/video/abstract-video-list.ts b/client/src/app/shared/video/abstract-video-list.ts index a468d3231..d60536e20 100644 --- a/client/src/app/shared/video/abstract-video-list.ts +++ b/client/src/app/shared/video/abstract-video-list.ts @@ -24,6 +24,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy { totalItems: null } sort: VideoSortField = '-publishedAt' + category?: number defaultSort: VideoSortField = '-publishedAt' syndicationItems = [] @@ -167,7 +168,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy { protected loadRouteParams (routeParams: { [ key: string ]: any }) { this.sort = routeParams['sort'] as VideoSortField || this.defaultSort - + this.category = routeParams['category'] if (routeParams['page'] !== undefined) { this.pagination.currentPage = parseInt(routeParams['page'], 10) } else { diff --git a/client/src/app/shared/video/video.service.ts b/client/src/app/shared/video/video.service.ts index 2da36ff1b..4783adf42 100644 --- a/client/src/app/shared/video/video.service.ts +++ b/client/src/app/shared/video/video.service.ts @@ -158,7 +158,8 @@ export class VideoService { getVideos ( videoPagination: ComponentPagination, sort: VideoSortField, - filter?: VideoFilter + filter?: VideoFilter, + category?: number ): Observable<{ videos: Video[], totalVideos: number }> { const pagination = this.restService.componentPaginationToRestPagination(videoPagination) @@ -169,6 +170,10 @@ export class VideoService { params = params.set('filter', filter) } + if (category) { + params = params.set('category', category + '') + } + return this.authHttp .get>(VideoService.BASE_VIDEO_URL, { params }) .pipe( @@ -202,11 +207,13 @@ export class VideoService { return feeds } - getVideoFeedUrls (sort: VideoSortField, filter?: VideoFilter) { + getVideoFeedUrls (sort: VideoSortField, filter?: VideoFilter, category?: number) { let params = this.restService.addRestGetParams(new HttpParams(), undefined, sort) if (filter) params = params.set('filter', filter) + if (category) params = params.set('category', category + '') + return this.buildBaseFeedUrls(params) } diff --git a/client/src/app/videos/video-list/video-local.component.ts b/client/src/app/videos/video-list/video-local.component.ts index dbe1d937d..de460ea60 100644 --- a/client/src/app/videos/video-list/video-local.component.ts +++ b/client/src/app/videos/video-list/video-local.component.ts @@ -50,10 +50,10 @@ export class VideoLocalComponent extends AbstractVideoList implements OnInit, On getVideosObservable (page: number) { const newPagination = immutableAssign(this.pagination, { currentPage: page }) - return this.videoService.getVideos(newPagination, this.sort, this.filter) + return this.videoService.getVideos(newPagination, this.sort, this.filter, this.category) } generateSyndicationList () { - this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, this.filter) + this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, this.filter, this.category) } } diff --git a/client/src/app/videos/video-list/video-recently-added.component.ts b/client/src/app/videos/video-list/video-recently-added.component.ts index 004a49168..75688731d 100644 --- a/client/src/app/videos/video-list/video-recently-added.component.ts +++ b/client/src/app/videos/video-list/video-recently-added.component.ts @@ -48,10 +48,10 @@ export class VideoRecentlyAddedComponent extends AbstractVideoList implements On getVideosObservable (page: number) { const newPagination = immutableAssign(this.pagination, { currentPage: page }) - return this.videoService.getVideos(newPagination, this.sort) + return this.videoService.getVideos(newPagination, this.sort, undefined, this.category) } generateSyndicationList () { - this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort) + this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.category) } } diff --git a/client/src/app/videos/video-list/video-trending.component.ts b/client/src/app/videos/video-list/video-trending.component.ts index f2174aa14..3738b95b1 100644 --- a/client/src/app/videos/video-list/video-trending.component.ts +++ b/client/src/app/videos/video-list/video-trending.component.ts @@ -47,10 +47,10 @@ export class VideoTrendingComponent extends AbstractVideoList implements OnInit, getVideosObservable (page: number) { const newPagination = immutableAssign(this.pagination, { currentPage: page }) - return this.videoService.getVideos(newPagination, this.sort) + return this.videoService.getVideos(newPagination, this.sort, undefined, this.category) } generateSyndicationList () { - this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort) + this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.category) } } -- cgit v1.2.3