diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-05-03 23:01:57 +0200 |
---|---|---|
committer | Rigel Kent <par@rigelk.eu> | 2020-05-04 15:01:44 +0200 |
commit | 25a42e293be90d35afad2096e9db2fa3d617d855 (patch) | |
tree | 5739da8e2aed75447cf0fd608089cc8849c0da33 /server/models/utils.ts | |
parent | 801d957155d574bda984206021cdd1fe58ef56b9 (diff) | |
download | PeerTube-25a42e293be90d35afad2096e9db2fa3d617d855.tar.gz PeerTube-25a42e293be90d35afad2096e9db2fa3d617d855.tar.zst PeerTube-25a42e293be90d35afad2096e9db2fa3d617d855.zip |
Fix rowsPerPage change, add filter clear button, update video-abuse-list search query param dynamically
Diffstat (limited to 'server/models/utils.ts')
-rw-r--r-- | server/models/utils.ts | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/server/models/utils.ts b/server/models/utils.ts index 3e3825b32..956562e70 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts | |||
@@ -223,9 +223,12 @@ interface QueryStringFilterPrefixes { | |||
223 | [key: string]: string | { prefix: string, handler: Function, multiple?: boolean } | 223 | [key: string]: string | { prefix: string, handler: Function, multiple?: boolean } |
224 | } | 224 | } |
225 | 225 | ||
226 | function parseQueryStringFilter (q: string, prefixes: QueryStringFilterPrefixes) { | 226 | function parseQueryStringFilter (q: string, prefixes: QueryStringFilterPrefixes): { |
227 | search: string | ||
228 | [key: string]: string | number | string[] | number[] | ||
229 | } { | ||
227 | const tokens = q // tokenize only if we have a querystring | 230 | const tokens = q // tokenize only if we have a querystring |
228 | ? [].concat.apply([], q.split('"').map((v, i) => i % 2 ? v : v.split(' '))).filter(Boolean) | 231 | ? [].concat.apply([], q.split('"').map((v, i) => i % 2 ? v : v.split(' '))).filter(Boolean) // split by space unless using double quotes |
229 | : [] | 232 | : [] |
230 | 233 | ||
231 | // TODO: when Typescript supports Object.fromEntries, replace with the Object method | 234 | // TODO: when Typescript supports Object.fromEntries, replace with the Object method |
@@ -252,16 +255,18 @@ function parseQueryStringFilter (q: string, prefixes: QueryStringFilterPrefixes) | |||
252 | } | 255 | } |
253 | })).join(' '), | 256 | })).join(' '), |
254 | // filters defined in prefixes are added under their own name | 257 | // filters defined in prefixes are added under their own name |
255 | ...objectMap(prefixes, v => { | 258 | ...objectMap(prefixes, p => { |
256 | if (typeof v === "string") { | 259 | if (typeof p === "string") { |
257 | return tokens.filter(e => e.startsWith(v)).map(e => e.slice(v.length)) | 260 | return tokens.filter(e => e.startsWith(p)).map(e => e.slice(p.length)) // we keep the matched item, and remove its prefix |
258 | } else { | 261 | } else { |
259 | const _tokens = tokens.filter(e => e.startsWith(v.prefix)).map(e => e.slice(v.prefix.length)).map(v.handler) | 262 | const _tokens = tokens.filter(e => e.startsWith(p.prefix)).map(e => e.slice(p.prefix.length)).map(p.handler) |
260 | return !v.multiple | 263 | // multiple is false by default, meaning we usually just keep the first occurence of a given prefix |
261 | ? _tokens.length > 0 | 264 | if (!p.multiple && _tokens.length > 0) { |
262 | ? _tokens[0] | 265 | return _tokens[0] |
263 | : '' | 266 | } else if (!p.multiple) { |
264 | : _tokens | 267 | return '' |
268 | } | ||
269 | return _tokens | ||
265 | } | 270 | } |
266 | }) | 271 | }) |
267 | } | 272 | } |