[UI] Better parsing of the parameter types in getUrlArgs and setUrlArgs.

This commit is contained in:
Fabio Manganiello 2024-08-25 00:15:20 +02:00
parent db34a607e4
commit 818f60a468
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -15,8 +15,22 @@ export default {
.split(/[&;]/)
.reduce((acc, obj) => {
const tokens = obj.split('=')
if (tokens[0]?.length)
acc[tokens[0]] = decodeURIComponent(tokens[1])
let key = tokens[0]
let value = tokens.slice(1).join('=')
if (value === 'true')
value = true
else if (value === 'false')
value = false
else if (value.match(/^-?\d+$/))
value = parseInt(value)
else if (value.match(/^-?\d+\.\d+$/))
value = parseFloat(value)
else
value = decodeURIComponent(value)
if (key?.length)
acc[key] = value
return acc
}, {})
},
@ -29,10 +43,24 @@ export default {
acc[key] = value
else if (curArgs[key] != null)
delete curArgs[key]
return acc
}, {})
args = Object.entries({...curArgs, ...args})
.reduce((acc, [key, value]) => {
// Serialize boolean values
if (typeof value === 'boolean')
value = value.toString()
// Serialize numbers
if (typeof value === 'number')
value = value.toString()
acc[key] = value
return acc
}, {})
args = {...curArgs, ...args}
let location = `${window.location.pathname}#${this.parseUrlFragment()}`
if (Object.keys(args).length)
location += `?${this.fragmentFromArgs(args)}`