Fix small issue: wrong format for addExtraTags in some layers

This commit is contained in:
pietervdvn 2021-03-31 15:50:29 +02:00
parent edd10d52fd
commit e47accbab1
4 changed files with 53 additions and 51 deletions

View file

@ -18,7 +18,7 @@ export default class TagRenderingConfig {
readonly question?: Translation; readonly question?: Translation;
readonly condition?: TagsFilter; readonly condition?: TagsFilter;
readonly configuration_warnings : string[] = [] readonly configuration_warnings: string[] = []
readonly freeform?: { readonly freeform?: {
readonly key: string, readonly key: string,
@ -49,13 +49,13 @@ export default class TagRenderingConfig {
throw "Initing a TagRenderingConfig with undefined in " + context; throw "Initing a TagRenderingConfig with undefined in " + context;
} }
if (typeof json === "string") { if (typeof json === "string") {
this.render = Translations.T(json, context+".render"); this.render = Translations.T(json, context + ".render");
this.multiAnswer = false; this.multiAnswer = false;
return; return;
} }
this.render = Translations.T(json.render, context+".render"); this.render = Translations.T(json.render, context + ".render");
this.question = Translations.T(json.question, context+".question"); this.question = Translations.T(json.question, context + ".question");
this.roaming = json.roaming ?? false; this.roaming = json.roaming ?? false;
const condition = FromJSON.Tag(json.condition ?? {"and": []}, `${context}.condition`); const condition = FromJSON.Tag(json.condition ?? {"and": []}, `${context}.condition`);
if (this.roaming && conditionIfRoaming !== undefined) { if (this.roaming && conditionIfRoaming !== undefined) {
@ -70,15 +70,18 @@ export default class TagRenderingConfig {
addExtraTags: json.freeform.addExtraTags?.map((tg, i) => addExtraTags: json.freeform.addExtraTags?.map((tg, i) =>
FromJSON.Tag(tg, `${context}.extratag[${i}]`)) ?? [] FromJSON.Tag(tg, `${context}.extratag[${i}]`)) ?? []
} }
if(this.freeform.key === undefined || this.freeform.key === ""){ if(json.freeform["extraTags"] !== undefined){
throw `Freeform.extraTags is defined. This should probably be 'freeform.addExtraTag' (at ${context})`
}
if (this.freeform.key === undefined || this.freeform.key === "") {
throw `Freeform.key is undefined or the empty string - this is not allowed; either fill out something or remove the freeform block alltogether. Error in ${context}` throw `Freeform.key is undefined or the empty string - this is not allowed; either fill out something or remove the freeform block alltogether. Error in ${context}`
} }
if (ValidatedTextField.AllTypes[this.freeform.type] === undefined) { if (ValidatedTextField.AllTypes[this.freeform.type] === undefined) {
throw `Freeform.key ${this.freeform.key} is an invalid type` throw `Freeform.key ${this.freeform.key} is an invalid type`
} }
if(this.freeform.addExtraTags){ if (this.freeform.addExtraTags) {
const usedKeys = new And(this.freeform.addExtraTags).usedKeys(); const usedKeys = new And(this.freeform.addExtraTags).usedKeys();
if(usedKeys.indexOf(this.freeform.key) >= 0){ if (usedKeys.indexOf(this.freeform.key) >= 0) {
throw `The freeform key ${this.freeform.key} will be overwritten by one of the extra tags, as they use the same key too. This is in ${context}`; throw `The freeform key ${this.freeform.key} will be overwritten by one of the extra tags, as they use the same key too. This is in ${context}`;
} }
} }
@ -132,29 +135,29 @@ export default class TagRenderingConfig {
throw `${context}: Detected a freeform key without rendering... Key: ${this.freeform.key} in ${context}` throw `${context}: Detected a freeform key without rendering... Key: ${this.freeform.key} in ${context}`
} }
if(this.render && this.question && this.freeform === undefined){ if (this.render && this.question && this.freeform === undefined) {
throw `${context}: Detected a tagrendering which takes input without freeform key in ${context}; the question is ${this.question.txt}` throw `${context}: Detected a tagrendering which takes input without freeform key in ${context}; the question is ${this.question.txt}`
} }
if(!json.multiAnswer && this.mappings !== undefined && this.question !== undefined){ if (!json.multiAnswer && this.mappings !== undefined && this.question !== undefined) {
let keys = [] let keys = []
for (let i = 0; i < this.mappings.length; i++){ for (let i = 0; i < this.mappings.length; i++) {
const mapping = this.mappings[i]; const mapping = this.mappings[i];
if(mapping.if === undefined){ if (mapping.if === undefined) {
throw `${context}.mappings[${i}].if is undefined` throw `${context}.mappings[${i}].if is undefined`
} }
keys.push(...mapping.if.usedKeys()) keys.push(...mapping.if.usedKeys())
} }
keys = Utils.Dedup(keys) keys = Utils.Dedup(keys)
for (let i = 0; i < this.mappings.length; i++){ for (let i = 0; i < this.mappings.length; i++) {
const mapping = this.mappings[i]; const mapping = this.mappings[i];
if(mapping.hideInAnswer){ if (mapping.hideInAnswer) {
continue continue
} }
const usedKeys = mapping.if.usedKeys(); const usedKeys = mapping.if.usedKeys();
for (const expectedKey of keys) { for (const expectedKey of keys) {
if(usedKeys.indexOf(expectedKey) < 0){ if (usedKeys.indexOf(expectedKey) < 0) {
const msg = `${context}.mappings[${i}]: This mapping only defines values for ${usedKeys.join(', ')}, but it should also give a value for ${expectedKey}` const msg = `${context}.mappings[${i}]: This mapping only defines values for ${usedKeys.join(', ')}, but it should also give a value for ${expectedKey}`
this.configuration_warnings.push(msg) this.configuration_warnings.push(msg)
} }
@ -197,15 +200,15 @@ export default class TagRenderingConfig {
// Filtered away by the condition // Filtered away by the condition
return true; return true;
} }
if(this.multiAnswer){ if (this.multiAnswer) {
for (const m of this.mappings) { for (const m of this.mappings) {
if(TagUtils.MatchesMultiAnswer(m.if, tags)){ if (TagUtils.MatchesMultiAnswer(m.if, tags)) {
return true; return true;
} }
} }
const free = this.freeform?.key const free = this.freeform?.key
if(free !== undefined){ if (free !== undefined) {
return tags[free] !== undefined return tags[free] !== undefined
} }
return false return false
@ -220,7 +223,7 @@ export default class TagRenderingConfig {
return false; return false;
} }
public IsQuestionBoxElement(): boolean{ public IsQuestionBoxElement(): boolean {
return this.question === null && this.condition === null; return this.question === null && this.condition === null;
} }

View file

@ -94,6 +94,18 @@ export default class TagRenderingQuestion extends UIElement {
).SetClass("block") ).SetClass("block")
} }
InnerRender(): string {
return new Combine([
this._question,
this._inputElement,
this._cancelButton,
this._saveButton,
this._appliedTags]
)
.SetClass("question")
.Render()
}
private GenerateInputElement(): InputElement<TagsFilter> { private GenerateInputElement(): InputElement<TagsFilter> {
const ff = this.GenerateFreeform(); const ff = this.GenerateFreeform();
const self = this; const self = this;
@ -105,7 +117,7 @@ export default class TagRenderingQuestion extends UIElement {
return ff; return ff;
} }
if(ff){ if (ff) {
mappings.push(ff); mappings.push(ff);
} }
@ -131,11 +143,11 @@ export default class TagRenderingQuestion extends UIElement {
const tags: TagsFilter[] = indices.map(i => elements[i].GetValue().data); const tags: TagsFilter[] = indices.map(i => elements[i].GetValue().data);
const oppositeTags: TagsFilter[] = []; const oppositeTags: TagsFilter[] = [];
for (let i = 0; i < ifNotSelected.length; i++) { for (let i = 0; i < ifNotSelected.length; i++) {
if(indices.indexOf(i) >= 0){ if (indices.indexOf(i) >= 0) {
continue; continue;
} }
const notSelected = ifNotSelected[i]; const notSelected = ifNotSelected[i];
if(notSelected === undefined){ if (notSelected === undefined) {
continue; continue;
} }
oppositeTags.push(notSelected); oppositeTags.push(notSelected);
@ -223,7 +235,7 @@ export default class TagRenderingQuestion extends UIElement {
if (mapping.hideInAnswer === true) { if (mapping.hideInAnswer === true) {
return undefined; return undefined;
} }
if(typeof(mapping.hideInAnswer) !== "boolean" && mapping.hideInAnswer.matchesProperties(this._tags.data)){ if (typeof (mapping.hideInAnswer) !== "boolean" && mapping.hideInAnswer.matchesProperties(this._tags.data)) {
return undefined; return undefined;
} }
return new FixedInputElement( return new FixedInputElement(
@ -232,7 +244,6 @@ export default class TagRenderingQuestion extends UIElement {
(t0, t1) => t1.isEquivalent(t0)); (t0, t1) => t1.isEquivalent(t0));
} }
private GenerateFreeform(): InputElement<TagsFilter> { private GenerateFreeform(): InputElement<TagsFilter> {
const freeform = this._configuration.freeform; const freeform = this._configuration.freeform;
if (freeform === undefined) { if (freeform === undefined) {
@ -287,16 +298,4 @@ export default class TagRenderingQuestion extends UIElement {
} }
InnerRender(): string {
return new Combine([
this._question,
this._inputElement,
this._cancelButton,
this._saveButton,
this._appliedTags]
)
.SetClass("question")
.Render()
}
} }

View file

@ -65,7 +65,7 @@
}, },
"freeform": { "freeform": {
"key": "charge", "key": "charge",
"extraTags": ["fee=yes"] "addExtraTags": ["fee=yes"]
}, },
"mappings": [ "mappings": [
{ {

View file

@ -67,7 +67,7 @@
}, },
"freeform": { "freeform": {
"key": "bicycle_parking", "key": "bicycle_parking",
"extraTags": [ "addExtraTags": [
"fixme=Freeform used on 'bicycle_parking'-tag: possibly a wrong value" "fixme=Freeform used on 'bicycle_parking'-tag: possibly a wrong value"
] ]
}, },
@ -260,7 +260,7 @@
}, },
"freeform": { "freeform": {
"key": "access", "key": "access",
"extraTags": [ "addExtraTags": [
"fixme=Freeform used on 'access'-tag: possibly a wrong value" "fixme=Freeform used on 'access'-tag: possibly a wrong value"
] ]
}, },