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

View file

@ -516,7 +516,7 @@ U.FeatureMixin = {
} else { } else {
const choices = criteria["choices"] const choices = criteria["choices"]
value = String(value) 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 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.minTdLabel = L.DomUtil.create('td', '', this.minTr)
this.minLabel = L.DomUtil.create('label', '', this.minTdLabel) 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.minLabel.htmlFor = `${this.inputType}_${this.name}_min`
this.minTdInput = L.DomUtil.create('td', '', this.minTr) 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.maxTdLabel = L.DomUtil.create('td', '', this.maxTr)
this.maxLabel = L.DomUtil.create('label', '', this.maxTdLabel) 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.maxLabel.htmlFor = `${this.inputType}_${this.name}_max`
this.maxTdInput = L.DomUtil.create('td', '', this.maxTr) 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)) { if (["date", "datetime-local"].includes(this.inputType)) {
this.minLabel.innerHTML = 'From' this.minLabel.innerHTML = L._('From')
this.maxLabel.innerHTML = 'Until' this.maxLabel.innerHTML = L._('Until')
if (min != null) { if (min != null) {
this.minInput.valueAsNumber = (min.valueOf() - min.getTimezoneOffset() * 60000) 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 (["number"].includes(this.inputType)) {
if (min != null && max != null) { if (min != null && max != null) {
// calculate step from significant digits of min and max values // calculate step from significant digits of min and max values
let minStep = String(min).replace(/^\d+?(0*)((\.)(\d*?)0*|)$/, "1$1$3$4").split('.') const step = Math.min(L.Util.calculateStepFromNumber(min), L.Util.calculateStepFromNumber(max))
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)
this.minInput.step = String(step) this.minInput.step = String(step)
this.maxInput.step = String(step) this.maxInput.step = String(step)
} }