translation capability and small cleanups

This commit is contained in:
flammermann 2024-03-03 13:28:03 +00:00 committed by Yohan Boniface
parent 10b1bc6265
commit f4413a8a74
4 changed files with 28 additions and 21 deletions

View file

@ -710,7 +710,7 @@ const ControlsMixin = {
}
} else {
value = String(value)
value = (value.length ? value : "empty string")
value = (value.length ? value : L._("empty string"))
if (!!value && !facetCriteria[key]["choices"].includes(value)) {
facetCriteria[key]["choices"].push(value)
}
@ -729,15 +729,20 @@ const ControlsMixin = {
if (!found)
this.ui.alert({ content: L._('No results for these facets'), level: 'info' })
}
const fields = keys.map((key) => [
const fields = keys.map((key) => {
let criteria = facetCriteria[key]
let handler = ["date", "datetime-local", "number"].includes(criteria["inputType"]) ? 'FacetSearchMinMax' : 'FacetSearchChoices'
let label = facetKeys[key]["label"]
return [
`facets.${key}`,
{
handler: ["date", "datetime-local", "number"].includes(facetCriteria[key]["inputType"]) ? 'FacetSearchMinMax' : 'FacetSearchChoices',
criteria: facetCriteria[key],
label: facetKeys[key]["label"]
criteria: criteria,
handler: handler,
label: label
},
])
const builder = new U.FormBuilder(this, fields, {
]
})
const builder = new L.U.FormBuilder(this, fields, {
makeDirty: false,
callback: filterFeatures,
callbackContext: this,

View file

@ -67,6 +67,13 @@ L.Util.setNullableBooleanFromQueryString = function (options, name) {
}
}
L.Util.calculateStepFromNumber = function (n) {
// calculate step for number input field from significant digits of number
let step = String(n).replace(/^\d+?(0*)((\.)(\d*?)0*|)$/, "1$1$3$4").split('.')
step = parseFloat((step[1] || "").replace(/\d/g, "0").replace(/^0/, "0.0").replace(/0$/, "1") || (step[0] || "").replace(/0$/, "") || "1")
return step
}
L.DomUtil.add = (tagName, className, container, content) => {
const el = L.DomUtil.create(tagName, className, container)
if (content) {

View file

@ -516,7 +516,7 @@ U.FeatureMixin = {
} else {
const choices = criteria["choices"]
value = String(value)
value = (value.length ? value : "empty string")
value = (value.length ? value : L._("empty string"))
if (choices.length && (!value || !choices.includes(value))) return false
}
}

View file

@ -796,7 +796,7 @@ L.FormBuilder.FacetSearchMinMax = L.FormBuilder.Element.extend({
this.minTdLabel = L.DomUtil.create('td', '', this.minTr)
this.minLabel = L.DomUtil.create('label', '', this.minTdLabel)
this.minLabel.innerHTML = 'Min'
this.minLabel.innerHTML = L._('Min')
this.minLabel.htmlFor = `${this.inputType}_${this.name}_min`
this.minTdInput = L.DomUtil.create('td', '', this.minTr)
@ -813,7 +813,7 @@ L.FormBuilder.FacetSearchMinMax = L.FormBuilder.Element.extend({
this.maxTdLabel = L.DomUtil.create('td', '', this.maxTr)
this.maxLabel = L.DomUtil.create('label', '', this.maxTdLabel)
this.maxLabel.innerHTML = 'Max'
this.maxLabel.innerHTML = L._('Max')
this.maxLabel.htmlFor = `${this.inputType}_${this.name}_max`
this.maxTdInput = L.DomUtil.create('td', '', this.maxTr)
@ -827,8 +827,8 @@ L.FormBuilder.FacetSearchMinMax = L.FormBuilder.Element.extend({
}
if (["date", "datetime-local"].includes(this.inputType)) {
this.minLabel.innerHTML = 'From'
this.maxLabel.innerHTML = 'Until'
this.minLabel.innerHTML = L._('From')
this.maxLabel.innerHTML = L._('Until')
if (min != null) {
this.minInput.valueAsNumber = (min.valueOf() - min.getTimezoneOffset() * 60000)
}
@ -845,12 +845,7 @@ L.FormBuilder.FacetSearchMinMax = L.FormBuilder.Element.extend({
if (["number"].includes(this.inputType)) {
if (min != null && max != null) {
// calculate step from significant digits of min and max values
let minStep = String(min).replace(/^\d+?(0*)((\.)(\d*?)0*|)$/, "1$1$3$4").split('.')
let maxStep = String(max).replace(/^\d+?(0*)((\.)(\d*?)0*|)$/, "1$1$3$4").split('.')
minStep = parseFloat((minStep[1] || "").replace(/\d/g, "0").replace(/^0/, "0.0").replace(/0$/, "1") || (minStep[0] || "").replace(/0$/, "") || "1")
maxStep = parseFloat((maxStep[1] || "").replace(/\d/g, "0").replace(/^0/, "0.0").replace(/0$/, "1") || (maxStep[0] || "").replace(/0$/, "") || "1")
const step = Math.min(minStep, maxStep)
const step = Math.min(L.Util.calculateStepFromNumber(min), L.Util.calculateStepFromNumber(max))
this.minInput.step = String(step)
this.maxInput.step = String(step)
}