forked from MapComplete/MapComplete
Feature: Properly fix postfixdistinguished
This commit is contained in:
parent
7268e2290f
commit
7d8d4fa074
1 changed files with 42 additions and 21 deletions
|
|
@ -5,10 +5,7 @@ import { TagUtils } from "../../Logic/Tags/TagUtils"
|
||||||
import { And } from "../../Logic/Tags/And"
|
import { And } from "../../Logic/Tags/And"
|
||||||
import { Utils } from "../../Utils"
|
import { Utils } from "../../Utils"
|
||||||
import { Tag } from "../../Logic/Tags/Tag"
|
import { Tag } from "../../Logic/Tags/Tag"
|
||||||
import {
|
import { MappingConfigJson, QuestionableTagRenderingConfigJson } from "./Json/QuestionableTagRenderingConfigJson"
|
||||||
MappingConfigJson,
|
|
||||||
QuestionableTagRenderingConfigJson,
|
|
||||||
} from "./Json/QuestionableTagRenderingConfigJson"
|
|
||||||
import Validators, { ValidatorType } from "../../UI/InputElement/Validators"
|
import Validators, { ValidatorType } from "../../UI/InputElement/Validators"
|
||||||
import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson"
|
import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson"
|
||||||
import { RegexTag } from "../../Logic/Tags/RegexTag"
|
import { RegexTag } from "../../Logic/Tags/RegexTag"
|
||||||
|
|
@ -688,6 +685,43 @@ export default class TagRenderingConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* TagRenderingConfig.splitPostfixDistinguished("€10") // => {value: "€10", denomination: ""}
|
||||||
|
* TagRenderingConfig.splitPostfixDistinguished(" €10 / day ") // => {value: "€10", denomination: "day"}
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static splitPostfixDistinguished(part: string): { value: string, denomination: string } {
|
||||||
|
const i = part.indexOf("/")
|
||||||
|
if (i < 0) {
|
||||||
|
return { value: part, denomination: "" }
|
||||||
|
}
|
||||||
|
const value = part.substring(0, i).trim()
|
||||||
|
const denomination = part.substring(i + 1).trim()
|
||||||
|
return { value, denomination }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the freeform value into a postfix-table, e.g.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* const charge = "€5/student;€6/citizen;€7/adult;€4/disabled;€10"
|
||||||
|
* TagRenderingConfig.buildPostfixTable(charge) // => {"student": "€5", "citizen": "€6", "adult": "€7", "disabled": "€4", "":"€10"}
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static buildPostfixTable(v: string): Record<string, string> {
|
||||||
|
const allValues = v.split(";").map((s) => s.trim())
|
||||||
|
const perPostfix: Record<string, string> = {}
|
||||||
|
for (const part of allValues) {
|
||||||
|
const { denomination, value } = TagRenderingConfig.splitPostfixDistinguished(part)
|
||||||
|
if (value === "") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
perPostfix[denomination] = value.trim()
|
||||||
|
}
|
||||||
|
return perPostfix
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a value for the freeform key and an overview of the selected mappings, construct the correct tagsFilter to apply.
|
* Given a value for the freeform key and an overview of the selected mappings, construct the correct tagsFilter to apply.
|
||||||
* Result should be interpreted as "and"
|
* Result should be interpreted as "and"
|
||||||
|
|
@ -753,12 +787,8 @@ export default class TagRenderingConfig {
|
||||||
const pf = this.freeform?.postfixDistinguished
|
const pf = this.freeform?.postfixDistinguished
|
||||||
if (pf) {
|
if (pf) {
|
||||||
const v = currentProperties[this.freeform.key] ?? ""
|
const v = currentProperties[this.freeform.key] ?? ""
|
||||||
const allValues = v.split(";").map((s) => s.trim())
|
const perPostfix = TagRenderingConfig.buildPostfixTable(v)
|
||||||
const perPostfix: Record<string, string> = {}
|
|
||||||
for (const value of allValues) {
|
|
||||||
const [v, postfix] = value.split("/").map((s) => s.trim())
|
|
||||||
perPostfix[postfix ?? pf] = v.trim()
|
|
||||||
}
|
|
||||||
if (freeformValue === "" || freeformValue === undefined) {
|
if (freeformValue === "" || freeformValue === undefined) {
|
||||||
delete perPostfix[this.freeform.postfixDistinguished]
|
delete perPostfix[this.freeform.postfixDistinguished]
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -981,17 +1011,8 @@ export default class TagRenderingConfig {
|
||||||
if (!distinguish) {
|
if (!distinguish) {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
const parts = value.split(";")
|
const perPostfix = TagRenderingConfig.buildPostfixTable(value)
|
||||||
for (const part of parts) {
|
return perPostfix[distinguish] ?? ""
|
||||||
if (part.indexOf("/") < 0) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
const [v, denom] = part.split("/").map((s) => s.trim())
|
|
||||||
if (denom === distinguish) {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue