aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-10 11:02:42 +0100
committerChocobozzz <me@florianbigard.com>2021-12-10 11:02:42 +0100
commit8cf43a6524d354fbfa0f0eaf789e8d4756bd25d6 (patch)
tree3f33a5e36a89eedf7e4ebfa4d08336262e9604c2 /client/src/app/shared
parent90701ec1d8d27d0072d6b0d2b19362d471484f9a (diff)
downloadPeerTube-8cf43a6524d354fbfa0f0eaf789e8d4756bd25d6.tar.gz
PeerTube-8cf43a6524d354fbfa0f0eaf789e8d4756bd25d6.tar.zst
PeerTube-8cf43a6524d354fbfa0f0eaf789e8d4756bd25d6.zip
Add filter on search results
Diffstat (limited to 'client/src/app/shared')
-rw-r--r--client/src/app/shared/shared-search/advanced-search.model.ts30
-rw-r--r--client/src/app/shared/shared-search/search.service.ts14
2 files changed, 42 insertions, 2 deletions
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 {
8 VideosSearchQuery 8 VideosSearchQuery
9} from '@shared/models' 9} from '@shared/models'
10 10
11export type AdvancedSearchResultType = 'videos' | 'playlists' | 'channels'
12
11export class AdvancedSearch { 13export class AdvancedSearch {
12 startDate: string // ISO 8601 14 startDate: string // ISO 8601
13 endDate: string // ISO 8601 15 endDate: string // ISO 8601
@@ -36,6 +38,7 @@ export class AdvancedSearch {
36 sort: string 38 sort: string
37 39
38 searchTarget: SearchTargetType 40 searchTarget: SearchTargetType
41 resultType: AdvancedSearchResultType
39 42
40 // Filters we don't want to count, because they are mandatory 43 // Filters we don't want to count, because they are mandatory
41 private silentFilters = new Set([ 'sort', 'searchTarget' ]) 44 private silentFilters = new Set([ 'sort', 'searchTarget' ])
@@ -61,6 +64,7 @@ export class AdvancedSearch {
61 durationMax?: string 64 durationMax?: string
62 sort?: string 65 sort?: string
63 searchTarget?: SearchTargetType 66 searchTarget?: SearchTargetType
67 resultType?: AdvancedSearchResultType
64 }) { 68 }) {
65 if (!options) return 69 if (!options) return
66 70
@@ -84,6 +88,12 @@ export class AdvancedSearch {
84 88
85 this.searchTarget = options.searchTarget || undefined 89 this.searchTarget = options.searchTarget || undefined
86 90
91 this.resultType = options.resultType || undefined
92
93 if (!this.resultType && this.hasVideoFilter()) {
94 this.resultType = 'videos'
95 }
96
87 if (isNaN(this.durationMin)) this.durationMin = undefined 97 if (isNaN(this.durationMin)) this.durationMin = undefined
88 if (isNaN(this.durationMax)) this.durationMax = undefined 98 if (isNaN(this.durationMax)) this.durationMax = undefined
89 99
@@ -137,7 +147,8 @@ export class AdvancedSearch {
137 isLive: this.isLive, 147 isLive: this.isLive,
138 host: this.host, 148 host: this.host,
139 sort: this.sort, 149 sort: this.sort,
140 searchTarget: this.searchTarget 150 searchTarget: this.searchTarget,
151 resultType: this.resultType
141 } 152 }
142 } 153 }
143 154
@@ -199,4 +210,21 @@ export class AdvancedSearch {
199 210
200 return true 211 return true
201 } 212 }
213
214 private hasVideoFilter () {
215 return this.startDate !== undefined ||
216 this.endDate !== undefined ||
217 this.originallyPublishedStartDate !== undefined ||
218 this.originallyPublishedEndDate !== undefined ||
219 this.nsfw !== undefined !== undefined ||
220 this.categoryOneOf !== undefined ||
221 this.licenceOneOf !== undefined ||
222 this.languageOneOf !== undefined ||
223 this.tagsOneOf !== undefined ||
224 this.tagsAllOf !== undefined ||
225 this.durationMin !== undefined ||
226 this.durationMax !== undefined ||
227 this.host !== undefined ||
228 this.isLive !== undefined
229 }
202} 230}
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 @@
1import { Observable } from 'rxjs' 1import { Observable, of } from 'rxjs'
2import { catchError, map, switchMap } from 'rxjs/operators' 2import { catchError, map, switchMap } from 'rxjs/operators'
3import { HttpClient, HttpParams } from '@angular/common/http' 3import { HttpClient, HttpParams } from '@angular/common/http'
4import { Injectable } from '@angular/core' 4import { Injectable } from '@angular/core'
@@ -39,6 +39,10 @@ export class SearchService {
39 }): Observable<ResultList<Video>> { 39 }): Observable<ResultList<Video>> {
40 const { search, uuids, componentPagination, advancedSearch } = parameters 40 const { search, uuids, componentPagination, advancedSearch } = parameters
41 41
42 if (advancedSearch.resultType !== undefined && advancedSearch.resultType !== 'videos') {
43 return of({ total: 0, data: [] })
44 }
45
42 const url = SearchService.BASE_SEARCH_URL + 'videos' 46 const url = SearchService.BASE_SEARCH_URL + 'videos'
43 let pagination: RestPagination 47 let pagination: RestPagination
44 48
@@ -73,6 +77,10 @@ export class SearchService {
73 }): Observable<ResultList<VideoChannel>> { 77 }): Observable<ResultList<VideoChannel>> {
74 const { search, advancedSearch, componentPagination, handles } = parameters 78 const { search, advancedSearch, componentPagination, handles } = parameters
75 79
80 if (advancedSearch.resultType !== undefined && advancedSearch.resultType !== 'channels') {
81 return of({ total: 0, data: [] })
82 }
83
76 const url = SearchService.BASE_SEARCH_URL + 'video-channels' 84 const url = SearchService.BASE_SEARCH_URL + 'video-channels'
77 85
78 let pagination: RestPagination 86 let pagination: RestPagination
@@ -107,6 +115,10 @@ export class SearchService {
107 }): Observable<ResultList<VideoPlaylist>> { 115 }): Observable<ResultList<VideoPlaylist>> {
108 const { search, advancedSearch, componentPagination, uuids } = parameters 116 const { search, advancedSearch, componentPagination, uuids } = parameters
109 117
118 if (advancedSearch.resultType !== undefined && advancedSearch.resultType !== 'playlists') {
119 return of({ total: 0, data: [] })
120 }
121
110 const url = SearchService.BASE_SEARCH_URL + 'video-playlists' 122 const url = SearchService.BASE_SEARCH_URL + 'video-playlists'
111 123
112 let pagination: RestPagination 124 let pagination: RestPagination