Rework units to allow picking different default units in different locations, fixes #1011

This commit is contained in:
Pieter Vander Vennet 2022-08-18 19:17:15 +02:00
parent e981abd2aa
commit 5da76b9418
17 changed files with 149 additions and 100 deletions

View file

@ -20,6 +20,7 @@ import {QueryParameters} from "../../Logic/Web/QueryParameters";
import {TagUtils} from "../../Logic/Tags/TagUtils";
import {InputElement} from "../Input/InputElement";
import {DropDown} from "../Input/DropDown";
import {FixedUiElement} from "../Base/FixedUiElement";
export default class FilterView extends VariableUiElement {
constructor(filteredLayer: UIEventSource<FilteredLayer[]>,
@ -91,7 +92,7 @@ export default class FilterView extends VariableUiElement {
if (filteredLayer.layerDef.name === undefined) {
// Name is not defined: we hide this one
return new Toggle(
filteredLayer?.layerDef?.description?.Clone()?.SetClass("subtle") ,
new FixedUiElement(filteredLayer?.layerDef?.id ).SetClass("block") ,
undefined,
state?.featureSwitchIsDebugging
);

View file

@ -90,7 +90,7 @@ export class TextFieldDef {
if (options.unit !== undefined) {
// Reformatting is handled by the unit in this case
options["isValid"] = str => {
const denom = options.unit.findDenomination(str);
const denom = options.unit.findDenomination(str, options?.country);
if (denom === undefined) {
return false;
}
@ -153,7 +153,7 @@ export class TextFieldDef {
}
})
)
unitDropDown.GetValue().setData(unit.defaultDenom)
unitDropDown.GetValue().setData(unit.getDefaultInput(options.country))
unitDropDown.SetClass("w-min")
const fixedDenom = unit.denominations.length === 1 ? unit.denominations[0] : undefined
@ -169,7 +169,7 @@ export class TextFieldDef {
},
(valueWithDenom: string) => {
// Take the value from OSM and feed it into the textfield and the dropdown
const withDenom = unit.findDenomination(valueWithDenom);
const withDenom = unit.findDenomination(valueWithDenom, options?.country);
if (withDenom === undefined) {
// Not a valid value at all - we give it undefined and leave the details up to the other elements (but we keep the previous denomination)
return [undefined, fixedDenom]

View file

@ -617,6 +617,7 @@ export default class TagRenderingQuestion extends Combine {
const tagsData = tags.data;
const feature = state?.allElements?.ContainingFeatures?.get(tagsData.id)
const center = feature != undefined ? GeoOperations.centerpointCoordinates(feature) : [0, 0]
console.log("Creating a tr-question with applicableUnit", applicableUnit)
const input: InputElement<string> = ValidatedTextField.ForType(configuration.freeform.type)?.ConstructInputElement({
country: () => tagsData._country,
location: [center[1], center[0]],

View file

@ -1273,6 +1273,9 @@ export default class SpecialVisualizations {
const tagRendering = layer.tagRenderings.find(tr => tr.id === tagRenderingId)
tagRenderings.push([layer, tagRendering])
}
if(tagRenderings.length === 0){
throw "Could not create stolen tagrenddering: tagRenderings not found"
}
return new VariableUiElement(featureTags.map(tags => {
const featureId = tags[featureIdKey]
if (featureId === undefined) {