From af7fd04a6706fb781e4622167b08dc6c9376f06a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 29 Jul 2021 15:19:22 +0200 Subject: Add ability to filter by host in search page --- .../shared/shared-search/advanced-search.model.ts | 34 ++++++++++++++++++++-- .../src/app/shared/shared-search/search.service.ts | 29 +++++++++--------- 2 files changed, 47 insertions(+), 16 deletions(-) (limited to 'client/src/app/shared/shared-search') diff --git a/client/src/app/shared/shared-search/advanced-search.model.ts b/client/src/app/shared/shared-search/advanced-search.model.ts index 2c83f53b6..9c55f6cd8 100644 --- a/client/src/app/shared/shared-search/advanced-search.model.ts +++ b/client/src/app/shared/shared-search/advanced-search.model.ts @@ -1,4 +1,11 @@ -import { BooleanBothQuery, BooleanQuery, SearchTargetType, VideosSearchQuery } from '@shared/models' +import { + BooleanBothQuery, + BooleanQuery, + SearchTargetType, + VideoChannelsSearchQuery, + VideoPlaylistsSearchQuery, + VideosSearchQuery +} from '@shared/models' export class AdvancedSearch { startDate: string // ISO 8601 @@ -23,6 +30,8 @@ export class AdvancedSearch { isLive: BooleanQuery + host: string + sort: string searchTarget: SearchTargetType @@ -45,6 +54,8 @@ export class AdvancedSearch { isLive?: BooleanQuery + host?: string + durationMin?: string durationMax?: string sort?: string @@ -68,6 +79,8 @@ export class AdvancedSearch { this.durationMin = parseInt(options.durationMin, 10) this.durationMax = parseInt(options.durationMax, 10) + this.host = options.host || undefined + this.searchTarget = options.searchTarget || undefined if (isNaN(this.durationMin)) this.durationMin = undefined @@ -101,6 +114,7 @@ export class AdvancedSearch { this.durationMin = undefined this.durationMax = undefined this.isLive = undefined + this.host = undefined this.sort = '-match' } @@ -120,12 +134,13 @@ export class AdvancedSearch { durationMin: this.durationMin, durationMax: this.durationMax, isLive: this.isLive, + host: this.host, sort: this.sort, searchTarget: this.searchTarget } } - toAPIObject (): VideosSearchQuery { + toVideosAPIObject (): VideosSearchQuery { let isLive: boolean if (this.isLive) isLive = this.isLive === 'true' @@ -142,12 +157,27 @@ export class AdvancedSearch { tagsAllOf: this.tagsAllOf, durationMin: this.durationMin, durationMax: this.durationMax, + host: this.host, isLive, sort: this.sort, searchTarget: this.searchTarget } } + toPlaylistAPIObject (): VideoPlaylistsSearchQuery { + return { + host: this.host, + searchTarget: this.searchTarget + } + } + + toChannelAPIObject (): VideoChannelsSearchQuery { + return { + host: this.host, + searchTarget: this.searchTarget + } + } + size () { let acc = 0 diff --git a/client/src/app/shared/shared-search/search.service.ts b/client/src/app/shared/shared-search/search.service.ts index ad258f5e5..2c26eb2e5 100644 --- a/client/src/app/shared/shared-search/search.service.ts +++ b/client/src/app/shared/shared-search/search.service.ts @@ -7,7 +7,6 @@ import { Video, VideoChannel, VideoChannelService, VideoService } from '@app/sha import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' import { ResultList, - SearchTargetType, Video as VideoServerModel, VideoChannel as VideoChannelServerModel, VideoPlaylist as VideoPlaylistServerModel @@ -33,8 +32,8 @@ export class SearchService { } searchVideos (parameters: { - search: string, - componentPagination?: ComponentPaginationLight, + search: string + componentPagination?: ComponentPaginationLight advancedSearch?: AdvancedSearch }): Observable> { const { search, componentPagination, advancedSearch } = parameters @@ -52,7 +51,7 @@ export class SearchService { if (search) params = params.append('search', search) if (advancedSearch) { - const advancedSearchObject = advancedSearch.toAPIObject() + const advancedSearchObject = advancedSearch.toVideosAPIObject() params = this.restService.addObjectParams(params, advancedSearchObject) } @@ -65,11 +64,11 @@ export class SearchService { } searchVideoChannels (parameters: { - search: string, - searchTarget?: SearchTargetType, + search: string + advancedSearch?: AdvancedSearch componentPagination?: ComponentPaginationLight }): Observable> { - const { search, componentPagination, searchTarget } = parameters + const { search, advancedSearch, componentPagination } = parameters const url = SearchService.BASE_SEARCH_URL + 'video-channels' @@ -82,8 +81,9 @@ export class SearchService { params = this.restService.addRestGetParams(params, pagination) params = params.append('search', search) - if (searchTarget) { - params = params.append('searchTarget', searchTarget as string) + if (advancedSearch) { + const advancedSearchObject = advancedSearch.toChannelAPIObject() + params = this.restService.addObjectParams(params, advancedSearchObject) } return this.authHttp @@ -95,11 +95,11 @@ export class SearchService { } searchVideoPlaylists (parameters: { - search: string, - searchTarget?: SearchTargetType, + search: string + advancedSearch?: AdvancedSearch componentPagination?: ComponentPaginationLight }): Observable> { - const { search, componentPagination, searchTarget } = parameters + const { search, advancedSearch, componentPagination } = parameters const url = SearchService.BASE_SEARCH_URL + 'video-playlists' @@ -112,8 +112,9 @@ export class SearchService { params = this.restService.addRestGetParams(params, pagination) params = params.append('search', search) - if (searchTarget) { - params = params.append('searchTarget', searchTarget as string) + if (advancedSearch) { + const advancedSearchObject = advancedSearch.toPlaylistAPIObject() + params = this.restService.addObjectParams(params, advancedSearchObject) } return this.authHttp -- cgit v1.2.3