forked from MapComplete/MapComplete
Fix rendering of multianswers, other small bug fixes
This commit is contained in:
parent
46254434db
commit
ad08a55517
13 changed files with 68 additions and 62 deletions
|
@ -53,13 +53,8 @@ export default class EditableTagRendering extends UIElement {
|
|||
if (this._editMode.data) {
|
||||
return this._question.Render();
|
||||
}
|
||||
if (this._configuration.multiAnswer) {
|
||||
const atLeastOneMatch = this._configuration.mappings.some(mp =>TagUtils.MatchesMultiAnswer(mp.if, this._tags.data));
|
||||
if (!atLeastOneMatch) {
|
||||
return "";
|
||||
}
|
||||
} else if (this._configuration.GetRenderValue(this._tags.data) === undefined) {
|
||||
return "";
|
||||
if(!this._configuration.IsKnown(this._tags.data)){
|
||||
return ""
|
||||
}
|
||||
|
||||
return new Combine([this._answer,
|
||||
|
|
|
@ -56,24 +56,19 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
|
|||
}
|
||||
|
||||
let questionBoxIsUsed = false;
|
||||
const renderings = layerConfig.tagRenderings.map(tr => {
|
||||
const renderings = layerConfig.tagRenderings.map((tr,i) => {
|
||||
if (tr.question === null) {
|
||||
// This is the question box!
|
||||
questionBoxIsUsed = true;
|
||||
return questionBox;
|
||||
}
|
||||
return new EditableTagRendering(tags, tr);
|
||||
return new EditableTagRendering(tags, tr);
|
||||
});
|
||||
if (!questionBoxIsUsed) {
|
||||
renderings.push(questionBox);
|
||||
}
|
||||
const tail = new Combine([]).SetClass("only-on-mobile");
|
||||
|
||||
return new Combine([
|
||||
...renderings,
|
||||
tail.SetClass("featureinfobox-tail")
|
||||
]
|
||||
).SetClass("block")
|
||||
return new Combine(renderings).SetClass("block")
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -46,37 +46,11 @@ export default class QuestionBox extends UIElement {
|
|||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if it is known or not shown, false if the question should be asked
|
||||
* @constructor
|
||||
*/
|
||||
IsKnown(tagRendering: TagRenderingConfig): boolean {
|
||||
if (tagRendering.condition &&
|
||||
!tagRendering.condition.matchesProperties(this._tags.data)) {
|
||||
// Filtered away by the condition
|
||||
return true;
|
||||
}
|
||||
if(tagRendering.multiAnswer){
|
||||
for (const m of tagRendering.mappings) {
|
||||
if(TagUtils.MatchesMultiAnswer(m.if, this._tags.data)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tagRendering.GetRenderValue(this._tags.data) !== undefined) {
|
||||
// This value is known and can be rendered
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
InnerRender(): string {
|
||||
for (let i = 0; i < this._tagRenderingQuestions.length; i++) {
|
||||
let tagRendering = this._tagRenderings[i];
|
||||
|
||||
if(this.IsKnown(tagRendering)){
|
||||
if(tagRendering.IsKnown(this._tags.data)){
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import {Utils} from "../../Utils";
|
|||
import Combine from "../Base/Combine";
|
||||
import {TagUtils} from "../../Logic/Tags";
|
||||
import {SubstitutedTranslation} from "../SubstitutedTranslation";
|
||||
import {Translation} from "../i18n/Translation";
|
||||
|
||||
/***
|
||||
* Displays the correct value for a known tagrendering
|
||||
|
@ -43,7 +44,7 @@ export default class TagRenderingAnswer extends UIElement {
|
|||
|
||||
// The render value doesn't work well with multi-answers (checkboxes), so we have to check for them manually
|
||||
if (this._configuration.multiAnswer) {
|
||||
const applicableThens = Utils.NoNull(this._configuration.mappings.map(mapping => {
|
||||
const applicableThens: Translation[] = Utils.NoNull(this._configuration.mappings.map(mapping => {
|
||||
if (mapping.if === undefined) {
|
||||
return mapping.then;
|
||||
}
|
||||
|
@ -52,12 +53,20 @@ export default class TagRenderingAnswer extends UIElement {
|
|||
}
|
||||
return undefined;
|
||||
}))
|
||||
if (applicableThens.length >= 0) {
|
||||
if (applicableThens.length === 1) {
|
||||
this._content = applicableThens[0];
|
||||
|
||||
if (this._configuration.freeform !== undefined && tags[this._configuration.freeform.key] !== undefined) {
|
||||
applicableThens.push(this._configuration.render)
|
||||
}
|
||||
|
||||
const self = this
|
||||
const valuesToRender: UIElement[] = applicableThens.map(tr => SubstitutedTranslation.construct(tr, self._tags))
|
||||
|
||||
if (valuesToRender.length >= 0) {
|
||||
if (valuesToRender.length === 1) {
|
||||
this._content = valuesToRender[0];
|
||||
} else {
|
||||
this._content = new Combine(["<ul>",
|
||||
...applicableThens.map(tr => new Combine(["<li>", tr, "</li>"]))
|
||||
...valuesToRender.map(tr => new Combine(["<li>", tr, "</li>"]))
|
||||
,
|
||||
"</ul>"
|
||||
])
|
||||
|
@ -66,13 +75,13 @@ export default class TagRenderingAnswer extends UIElement {
|
|||
return this._content.SetClass(this._contentClass).SetStyle(this._contentStyle).Render();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const tr = this._configuration.GetRenderValue(tags);
|
||||
if (tr !== undefined) {
|
||||
this._content = SubstitutedTranslation.construct(tr, this._tags);
|
||||
return this._content.SetClass(this._contentClass).SetStyle(this._contentStyle).Render();
|
||||
}
|
||||
|
||||
|
||||
return "";
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue