forked from MapComplete/MapComplete
First working version of the notes-layer, add filtering
This commit is contained in:
parent
ebb510da04
commit
91d2272861
19 changed files with 282 additions and 109 deletions
|
@ -162,7 +162,7 @@ class AutomationPanel extends Combine{
|
|||
return true;
|
||||
}
|
||||
stateToShow.setData("Applying metatags")
|
||||
pipeline.updateAllMetaTagging()
|
||||
pipeline.updateAllMetaTagging("triggered by automaton")
|
||||
stateToShow.setData("Gathering applicable elements")
|
||||
|
||||
let handled = 0
|
||||
|
|
|
@ -14,6 +14,9 @@ import FilteredLayer from "../../Models/FilteredLayer";
|
|||
import BackgroundSelector from "./BackgroundSelector";
|
||||
import FilterConfig from "../../Models/ThemeConfig/FilterConfig";
|
||||
import TilesourceConfig from "../../Models/ThemeConfig/TilesourceConfig";
|
||||
import {SubstitutedTranslation} from "../SubstitutedTranslation";
|
||||
import ValidatedTextField from "../Input/ValidatedTextField";
|
||||
import {QueryParameters} from "../../Logic/Web/QueryParameters";
|
||||
|
||||
export default class FilterView extends VariableUiElement {
|
||||
constructor(filteredLayer: UIEventSource<FilteredLayer[]>, tileLayers: { config: TilesourceConfig, isDisplayed: UIEventSource<boolean> }[]) {
|
||||
|
@ -144,7 +147,7 @@ export default class FilterView extends VariableUiElement {
|
|||
layer.filters.forEach((f, i) => filterIndexes.set(f.id, i))
|
||||
|
||||
let listFilterElements: [BaseUIElement, UIEventSource<{ filter: FilterConfig, selected: number }>][] = layer.filters.map(
|
||||
FilterView.createFilter
|
||||
filter => FilterView.createFilter(filter)
|
||||
);
|
||||
|
||||
listFilterElements.forEach((inputElement, i) =>
|
||||
|
@ -193,6 +196,71 @@ export default class FilterView extends VariableUiElement {
|
|||
}
|
||||
|
||||
private static createFilter(filterConfig: FilterConfig): [BaseUIElement, UIEventSource<{ filter: FilterConfig, selected: number }>] {
|
||||
|
||||
if (filterConfig.options[0].fields.length > 0) {
|
||||
|
||||
// Filter which uses one or more textfields
|
||||
const filter = filterConfig.options[0]
|
||||
const mappings = new Map<string, BaseUIElement>()
|
||||
let allValid = new UIEventSource(true)
|
||||
const properties = new UIEventSource<any>({})
|
||||
for (const {name, type} of filter.fields) {
|
||||
const value = QueryParameters.GetQueryParameter("filter-" + filterConfig.id + "-" + name, "", "Value for filter " + filterConfig.id)
|
||||
const field = ValidatedTextField.InputForType(type, {
|
||||
value
|
||||
}).SetClass("inline-block")
|
||||
mappings.set(name, field)
|
||||
const stable = value.stabilized(250)
|
||||
stable.addCallbackAndRunD(v => {
|
||||
properties.data[name] = v.toLowerCase();
|
||||
properties.ping()
|
||||
})
|
||||
allValid = allValid.map(previous => previous && field.IsValid(stable.data) && stable.data !== "", [stable])
|
||||
}
|
||||
const tr = new SubstitutedTranslation(filter.question, new UIEventSource<any>({id: filterConfig.id}), State.state, mappings)
|
||||
const neutral = {
|
||||
filter: new FilterConfig({
|
||||
id: filterConfig.id,
|
||||
options: [
|
||||
{
|
||||
question: "--",
|
||||
}
|
||||
]
|
||||
}, "While dynamically constructing a filterconfig"),
|
||||
selected: 0
|
||||
}
|
||||
const trigger = allValid.map(isValid => {
|
||||
if (!isValid) {
|
||||
return neutral
|
||||
}
|
||||
|
||||
// Replace all the field occurences in the tags...
|
||||
const osmTags = Utils.WalkJson(filter.originalTagsSpec,
|
||||
v => {
|
||||
if (typeof v !== "string") {
|
||||
return v
|
||||
}
|
||||
return Utils.SubstituteKeys(v, properties.data)
|
||||
}
|
||||
)
|
||||
// ... which we use below to construct a filter!
|
||||
return {
|
||||
filter: new FilterConfig({
|
||||
id: filterConfig.id,
|
||||
options: [
|
||||
{
|
||||
question: "--",
|
||||
osmTags
|
||||
}
|
||||
]
|
||||
}, "While dynamically constructing a filterconfig"),
|
||||
selected: 0
|
||||
}
|
||||
}, [properties])
|
||||
return [tr, trigger];
|
||||
}
|
||||
|
||||
|
||||
if (filterConfig.options.length === 1) {
|
||||
let option = filterConfig.options[0];
|
||||
|
||||
|
|
|
@ -436,7 +436,7 @@ export default class ValidatedTextField {
|
|||
/**
|
||||
* {string (typename) --> TextFieldDef}
|
||||
*/
|
||||
public static AllTypes = ValidatedTextField.allTypesDict();
|
||||
public static AllTypes: Map<string, TextFieldDef> = ValidatedTextField.allTypesDict();
|
||||
|
||||
public static InputForType(type: string, options?: {
|
||||
placeholder?: string | BaseUIElement,
|
||||
|
@ -455,7 +455,7 @@ export default class ValidatedTextField {
|
|||
}): InputElement<string> {
|
||||
options = options ?? {};
|
||||
options.placeholder = options.placeholder ?? type;
|
||||
const tp: TextFieldDef = ValidatedTextField.AllTypes[type]
|
||||
const tp: TextFieldDef = ValidatedTextField.AllTypes.get(type)
|
||||
const isValidTp = tp.isValid;
|
||||
let isValid;
|
||||
options.textArea = options.textArea ?? type === "text";
|
||||
|
@ -615,10 +615,11 @@ export default class ValidatedTextField {
|
|||
}
|
||||
|
||||
|
||||
private static allTypesDict() {
|
||||
const types = {};
|
||||
private static allTypesDict(): Map<string, TextFieldDef> {
|
||||
const types = new Map<string, TextFieldDef>();
|
||||
for (const tp of ValidatedTextField.tpList) {
|
||||
types[tp.name] = tp;
|
||||
types.set(tp.name, tp);
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
|
|
@ -43,8 +43,8 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
|
|||
const title = new TagRenderingAnswer(tags, layerConfig.title ?? new TagRenderingConfig("POI"), State.state)
|
||||
.SetClass("break-words font-bold sm:p-0.5 md:p-1 sm:p-1.5 md:p-2");
|
||||
const titleIcons = new Combine(
|
||||
layerConfig.titleIcons.map(icon => new TagRenderingAnswer(tags, icon,
|
||||
"block w-8 h-8 max-h-8 align-baseline box-content sm:p-0.5", "width: 2rem;")
|
||||
layerConfig.titleIcons.map(icon => new TagRenderingAnswer(tags, icon, State.state,
|
||||
"block w-8 h-8 max-h-8 align-baseline box-content sm:p-0.5 w-10",)
|
||||
))
|
||||
.SetClass("flex flex-row flex-wrap pt-0.5 sm:pt-1 items-center mr-2")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue