forked from MapComplete/MapComplete
Better tag rewriting, add icons, add bicycle rental theme
This commit is contained in:
parent
1dcb3897e4
commit
9594868e83
23 changed files with 389 additions and 117 deletions
|
@ -5,6 +5,8 @@ import {VariableUiElement} from "../Base/VariableUIElement";
|
|||
import List from "../Base/List";
|
||||
import {SubstitutedTranslation} from "../SubstitutedTranslation";
|
||||
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
|
||||
import Combine from "../Base/Combine";
|
||||
import Img from "../Base/Img";
|
||||
|
||||
/***
|
||||
* Displays the correct value for a known tagrendering
|
||||
|
@ -38,11 +40,17 @@ export default class TagRenderingAnswer extends VariableUiElement {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
const valuesToRender: BaseUIElement[] = trs.map(tr => new SubstitutedTranslation(tr, tagsSource, state, options?.specialViz))
|
||||
const valuesToRender: BaseUIElement[] = trs.map(tr => {
|
||||
const text = new SubstitutedTranslation(tr.then, tagsSource, state, options?.specialViz);
|
||||
if(tr.icon === undefined){
|
||||
return text
|
||||
}
|
||||
return new Combine([new Img(tr.icon).SetClass("w-6 max-h-6 pr-2"), text]).SetClass("flex")
|
||||
})
|
||||
if (valuesToRender.length === 1) {
|
||||
return valuesToRender[0];
|
||||
} else if (valuesToRender.length > 1) {
|
||||
return new List(valuesToRender)
|
||||
return new Combine(valuesToRender).SetClass("flex flex-col")
|
||||
}
|
||||
return undefined;
|
||||
}).map((element: BaseUIElement) => element?.SetClass(contentClasses)?.SetStyle(contentStyle)))
|
||||
|
|
|
@ -26,6 +26,10 @@ import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
|
|||
import {Unit} from "../../Models/Unit";
|
||||
import VariableInputElement from "../Input/VariableInputElement";
|
||||
import Toggle from "../Input/Toggle";
|
||||
import Img from "../Base/Img";
|
||||
import {flattenEach, tag} from "@turf/turf";
|
||||
import FeaturePipeline from "../../Logic/FeatureSource/FeaturePipeline";
|
||||
import FeaturePipelineState from "../../Logic/State/FeaturePipelineState";
|
||||
|
||||
/**
|
||||
* Shows the question element.
|
||||
|
@ -343,7 +347,8 @@ export default class TagRenderingQuestion extends Combine {
|
|||
mapping: {
|
||||
if: TagsFilter,
|
||||
then: Translation,
|
||||
addExtraTags: Tag[]
|
||||
addExtraTags: Tag[],
|
||||
img?: string
|
||||
}, ifNot?: TagsFilter[]): InputElement<TagsFilter> {
|
||||
|
||||
let tagging: TagsFilter = mapping.if;
|
||||
|
@ -354,11 +359,23 @@ export default class TagRenderingQuestion extends Combine {
|
|||
tagging = new And([tagging, ...mapping.addExtraTags])
|
||||
}
|
||||
|
||||
|
||||
return new FixedInputElement(
|
||||
new SubstitutedTranslation(mapping.then, tagsSource, state),
|
||||
TagRenderingQuestion.GenerateMappingContent(mapping, tagsSource, state) ,
|
||||
tagging,
|
||||
(t0, t1) => t1.isEquivalent(t0));
|
||||
}
|
||||
|
||||
private static GenerateMappingContent( mapping: {
|
||||
then: Translation,
|
||||
icon?: string
|
||||
}, tagsSource: UIEventSource<any>, state: FeaturePipelineState): BaseUIElement{
|
||||
const text = new SubstitutedTranslation(mapping.then, tagsSource, state)
|
||||
if (mapping.icon === undefined) {
|
||||
return text;
|
||||
}
|
||||
return new Combine([new Img(mapping.icon).SetClass("w-6 max-h-6 pr-2"), text]).SetClass("flex")
|
||||
}
|
||||
|
||||
private static GenerateFreeform(state, configuration: TagRenderingConfig, applicableUnit: Unit, tags: UIEventSource<any>): InputElement<TagsFilter> {
|
||||
const freeform = configuration.freeform;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue