chore: refactor FeatureMixin.matchFacets

This commit is contained in:
Yohan Boniface 2024-04-17 18:26:35 +02:00
parent 9c326d09e1
commit 91f0f29d5e

View file

@ -493,30 +493,25 @@ U.FeatureMixin = {
}, },
matchFacets: function () { matchFacets: function () {
const facets = this.map.facets.selected const selected = this.map.facets.selected
for (const [property, criteria] of Object.entries(facets)) { for (let [name, { type, min, max, choices }] of Object.entries(selected)) {
let value = this.properties[property] let value = this.properties[name]
const type = criteria["type"] switch (type) {
if (["date", "datetime", "number"].includes(type)) { case 'date':
let min = criteria["min"] case 'datetime':
let max = criteria["max"] case 'number':
value = (value != null ? value : undefined) const caster = type === 'number' ? parseFloat : (v) => new Date(v)
if (["date", "datetime"].includes(type)) { value = value != null ? value : undefined
min = new Date(min) min = caster(min)
max = new Date(max) max = caster(max)
value = new Date(value) value = caster(value)
}
if (["number"].includes(type)) {
min = parseFloat(min)
max = parseFloat(max)
value = parseFloat(value)
}
if (!isNaN(min) && !isNaN(value) && min > value) return false if (!isNaN(min) && !isNaN(value) && min > value) return false
if (!isNaN(max) && !isNaN(value) && max < value) return false if (!isNaN(max) && !isNaN(value) && max < value) return false
} else { break
const choices = criteria["choices"] default:
value = String(value || '') || L._("<empty value>") value = String(value || '') || L._('<empty value>')
if (choices?.length && (!value || !choices.includes(value))) return false if (choices?.length && (!value || !choices.includes(value))) return false
break
} }
} }
return true return true