diff options
author | Chocobozzz <me@florianbigard.com> | 2022-06-10 09:40:20 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-06-10 09:40:20 +0200 |
commit | 55269c0460207ebd924fedeeb88fc0bca973b96d (patch) | |
tree | 67d2361281daaf18105b44419fe25ab367d8a932 | |
parent | 462a833e4c14b84224182adbe9e963535c165ad1 (diff) | |
download | PeerTube-55269c0460207ebd924fedeeb88fc0bca973b96d.tar.gz PeerTube-55269c0460207ebd924fedeeb88fc0bca973b96d.tar.zst PeerTube-55269c0460207ebd924fedeeb88fc0bca973b96d.zip |
Fix search filters count
-rw-r--r-- | client/src/app/+search/search-filters.component.ts | 8 | ||||
-rw-r--r-- | client/src/app/shared/shared-search/advanced-search.model.ts | 31 |
2 files changed, 18 insertions, 21 deletions
diff --git a/client/src/app/+search/search-filters.component.ts b/client/src/app/+search/search-filters.component.ts index aaa4ecc5a..f9de04706 100644 --- a/client/src/app/+search/search-filters.component.ts +++ b/client/src/app/+search/search-filters.component.ts | |||
@@ -138,11 +138,11 @@ export class SearchFiltersComponent implements OnInit { | |||
138 | private loadOriginallyPublishedAtYears () { | 138 | private loadOriginallyPublishedAtYears () { |
139 | this.originallyPublishedStartYear = this.advancedSearch.originallyPublishedStartDate | 139 | this.originallyPublishedStartYear = this.advancedSearch.originallyPublishedStartDate |
140 | ? new Date(this.advancedSearch.originallyPublishedStartDate).getFullYear().toString() | 140 | ? new Date(this.advancedSearch.originallyPublishedStartDate).getFullYear().toString() |
141 | : null | 141 | : undefined |
142 | 142 | ||
143 | this.originallyPublishedEndYear = this.advancedSearch.originallyPublishedEndDate | 143 | this.originallyPublishedEndYear = this.advancedSearch.originallyPublishedEndDate |
144 | ? new Date(this.advancedSearch.originallyPublishedEndDate).getFullYear().toString() | 144 | ? new Date(this.advancedSearch.originallyPublishedEndDate).getFullYear().toString() |
145 | : null | 145 | : undefined |
146 | } | 146 | } |
147 | 147 | ||
148 | private loadFromDurationRange () { | 148 | private loadFromDurationRange () { |
@@ -189,7 +189,7 @@ export class SearchFiltersComponent implements OnInit { | |||
189 | 189 | ||
190 | this.advancedSearch.originallyPublishedStartDate = start.toISOString() | 190 | this.advancedSearch.originallyPublishedStartDate = start.toISOString() |
191 | } else { | 191 | } else { |
192 | this.advancedSearch.originallyPublishedStartDate = null | 192 | this.advancedSearch.originallyPublishedStartDate = undefined |
193 | } | 193 | } |
194 | 194 | ||
195 | if (this.originallyPublishedEndYear) { | 195 | if (this.originallyPublishedEndYear) { |
@@ -199,7 +199,7 @@ export class SearchFiltersComponent implements OnInit { | |||
199 | 199 | ||
200 | this.advancedSearch.originallyPublishedEndDate = end.toISOString() | 200 | this.advancedSearch.originallyPublishedEndDate = end.toISOString() |
201 | } else { | 201 | } else { |
202 | this.advancedSearch.originallyPublishedEndDate = null | 202 | this.advancedSearch.originallyPublishedEndDate = undefined |
203 | } | 203 | } |
204 | } | 204 | } |
205 | 205 | ||
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 e40fd2e66..1375820da 100644 --- a/client/src/app/shared/shared-search/advanced-search.model.ts +++ b/client/src/app/shared/shared-search/advanced-search.model.ts | |||
@@ -40,9 +40,6 @@ export class AdvancedSearch { | |||
40 | searchTarget: SearchTargetType | 40 | searchTarget: SearchTargetType |
41 | resultType: AdvancedSearchResultType | 41 | resultType: AdvancedSearchResultType |
42 | 42 | ||
43 | // Filters we don't want to count, because they are mandatory | ||
44 | private silentFilters = new Set([ 'sort', 'searchTarget' ]) | ||
45 | |||
46 | constructor (options?: { | 43 | constructor (options?: { |
47 | startDate?: string | 44 | startDate?: string |
48 | endDate?: string | 45 | endDate?: string |
@@ -101,14 +98,7 @@ export class AdvancedSearch { | |||
101 | } | 98 | } |
102 | 99 | ||
103 | containsValues () { | 100 | containsValues () { |
104 | const obj = this.toUrlObject() | 101 | return this.size() !== 0 |
105 | for (const k of Object.keys(obj)) { | ||
106 | if (this.silentFilters.has(k)) continue | ||
107 | |||
108 | if (this.isValidValue(obj[k])) return true | ||
109 | } | ||
110 | |||
111 | return false | ||
112 | } | 102 | } |
113 | 103 | ||
114 | reset () { | 104 | reset () { |
@@ -193,12 +183,19 @@ export class AdvancedSearch { | |||
193 | size () { | 183 | size () { |
194 | let acc = 0 | 184 | let acc = 0 |
195 | 185 | ||
196 | const obj = this.toUrlObject() | 186 | if (this.isValidValue(this.startDate) || this.isValidValue(this.endDate)) acc++ |
197 | for (const k of Object.keys(obj)) { | 187 | if (this.isValidValue(this.originallyPublishedStartDate) || this.isValidValue(this.originallyPublishedEndDate)) acc++ |
198 | if (this.silentFilters.has(k)) continue | 188 | |
199 | 189 | if (this.isValidValue(this.nsfw)) acc++ | |
200 | if (this.isValidValue(obj[k])) acc++ | 190 | if (this.isValidValue(this.categoryOneOf)) acc++ |
201 | } | 191 | if (this.isValidValue(this.licenceOneOf)) acc++ |
192 | if (this.isValidValue(this.languageOneOf)) acc++ | ||
193 | if (this.isValidValue(this.tagsOneOf)) acc++ | ||
194 | if (this.isValidValue(this.tagsAllOf)) acc++ | ||
195 | if (this.isValidValue(this.durationMin) || this.isValidValue(this.durationMax)) acc++ | ||
196 | if (this.isValidValue(this.isLive)) acc++ | ||
197 | if (this.isValidValue(this.host)) acc++ | ||
198 | if (this.isValidValue(this.resultType)) acc++ | ||
202 | 199 | ||
203 | return acc | 200 | return acc |
204 | } | 201 | } |