From 8cf43a6524d354fbfa0f0eaf789e8d4756bd25d6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Dec 2021 11:02:42 +0100 Subject: Add filter on search results --- .../shared/shared-search/advanced-search.model.ts | 30 +++++++++++++++++++++- .../src/app/shared/shared-search/search.service.ts | 14 +++++++++- 2 files changed, 42 insertions(+), 2 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 2675c6135..724c4d834 100644 --- a/client/src/app/shared/shared-search/advanced-search.model.ts +++ b/client/src/app/shared/shared-search/advanced-search.model.ts @@ -8,6 +8,8 @@ import { VideosSearchQuery } from '@shared/models' +export type AdvancedSearchResultType = 'videos' | 'playlists' | 'channels' + export class AdvancedSearch { startDate: string // ISO 8601 endDate: string // ISO 8601 @@ -36,6 +38,7 @@ export class AdvancedSearch { sort: string searchTarget: SearchTargetType + resultType: AdvancedSearchResultType // Filters we don't want to count, because they are mandatory private silentFilters = new Set([ 'sort', 'searchTarget' ]) @@ -61,6 +64,7 @@ export class AdvancedSearch { durationMax?: string sort?: string searchTarget?: SearchTargetType + resultType?: AdvancedSearchResultType }) { if (!options) return @@ -84,6 +88,12 @@ export class AdvancedSearch { this.searchTarget = options.searchTarget || undefined + this.resultType = options.resultType || undefined + + if (!this.resultType && this.hasVideoFilter()) { + this.resultType = 'videos' + } + if (isNaN(this.durationMin)) this.durationMin = undefined if (isNaN(this.durationMax)) this.durationMax = undefined @@ -137,7 +147,8 @@ export class AdvancedSearch { isLive: this.isLive, host: this.host, sort: this.sort, - searchTarget: this.searchTarget + searchTarget: this.searchTarget, + resultType: this.resultType } } @@ -199,4 +210,21 @@ export class AdvancedSearch { return true } + + private hasVideoFilter () { + return this.startDate !== undefined || + this.endDate !== undefined || + this.originallyPublishedStartDate !== undefined || + this.originallyPublishedEndDate !== undefined || + this.nsfw !== undefined !== undefined || + this.categoryOneOf !== undefined || + this.licenceOneOf !== undefined || + this.languageOneOf !== undefined || + this.tagsOneOf !== undefined || + this.tagsAllOf !== undefined || + this.durationMin !== undefined || + this.durationMax !== undefined || + this.host !== undefined || + this.isLive !== undefined + } } diff --git a/client/src/app/shared/shared-search/search.service.ts b/client/src/app/shared/shared-search/search.service.ts index 71350c733..415bf083c 100644 --- a/client/src/app/shared/shared-search/search.service.ts +++ b/client/src/app/shared/shared-search/search.service.ts @@ -1,4 +1,4 @@ -import { Observable } from 'rxjs' +import { Observable, of } from 'rxjs' import { catchError, map, switchMap } from 'rxjs/operators' import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' @@ -39,6 +39,10 @@ export class SearchService { }): Observable> { const { search, uuids, componentPagination, advancedSearch } = parameters + if (advancedSearch.resultType !== undefined && advancedSearch.resultType !== 'videos') { + return of({ total: 0, data: [] }) + } + const url = SearchService.BASE_SEARCH_URL + 'videos' let pagination: RestPagination @@ -73,6 +77,10 @@ export class SearchService { }): Observable> { const { search, advancedSearch, componentPagination, handles } = parameters + if (advancedSearch.resultType !== undefined && advancedSearch.resultType !== 'channels') { + return of({ total: 0, data: [] }) + } + const url = SearchService.BASE_SEARCH_URL + 'video-channels' let pagination: RestPagination @@ -107,6 +115,10 @@ export class SearchService { }): Observable> { const { search, advancedSearch, componentPagination, uuids } = parameters + if (advancedSearch.resultType !== undefined && advancedSearch.resultType !== 'playlists') { + return of({ total: 0, data: [] }) + } + const url = SearchService.BASE_SEARCH_URL + 'video-playlists' let pagination: RestPagination -- cgit v1.2.3