forked from MapComplete/MapComplete
Fix rendering of multianswers without explicit 'render'-field
This commit is contained in:
parent
52d9b2f452
commit
a35b80afbb
11 changed files with 195 additions and 97 deletions
|
@ -7,6 +7,7 @@ import Combine from "../Base/Combine";
|
|||
import TagRenderingAnswer from "./TagRenderingAnswer";
|
||||
import State from "../../State";
|
||||
import Svg from "../../Svg";
|
||||
import {TagUtils} from "../../Logic/Tags";
|
||||
|
||||
export default class EditableTagRendering extends UIElement {
|
||||
private readonly _tags: UIEventSource<any>;
|
||||
|
@ -45,6 +46,29 @@ export default class EditableTagRendering extends UIElement {
|
|||
}
|
||||
}
|
||||
|
||||
InnerRender(): string {
|
||||
if (!this._configuration?.condition?.matchesProperties(this._tags.data)) {
|
||||
return "";
|
||||
}
|
||||
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));
|
||||
console.log("SOME MATCH?", atLeastOneMatch)
|
||||
if (!atLeastOneMatch) {
|
||||
return "";
|
||||
}
|
||||
} else if (this._configuration.GetRenderValue(this._tags.data) === undefined) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return new Combine([this._answer,
|
||||
(State.state?.osmConnection?.userDetails?.data?.loggedIn ?? true) ? this._editButton : undefined
|
||||
]).SetClass("answer")
|
||||
.Render();
|
||||
}
|
||||
|
||||
private GenerateQuestion() {
|
||||
const self = this;
|
||||
if (this._configuration.question !== undefined) {
|
||||
|
@ -64,25 +88,4 @@ export default class EditableTagRendering extends UIElement {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
InnerRender(): string {
|
||||
|
||||
if (this._editMode.data) {
|
||||
return this._question.Render();
|
||||
}
|
||||
|
||||
if(this._configuration.GetRenderValue(this._tags.data)=== undefined){
|
||||
return "";
|
||||
}
|
||||
|
||||
if(!this._configuration?.condition?.matchesProperties(this._tags.data)){
|
||||
return "";
|
||||
}
|
||||
|
||||
return new Combine([this._answer,
|
||||
(State.state?.osmConnection?.userDetails?.data?.loggedIn ?? true) ? this._editButton : undefined
|
||||
]).SetClass("answer")
|
||||
.Render();
|
||||
}
|
||||
|
||||
}
|
|
@ -3,6 +3,7 @@ import {UIEventSource} from "../../Logic/UIEventSource";
|
|||
import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig";
|
||||
import TagRenderingQuestion from "./TagRenderingQuestion";
|
||||
import Translations from "../i18n/Translations";
|
||||
import {TagUtils} from "../../Logic/Tags";
|
||||
|
||||
|
||||
/**
|
||||
|
@ -46,20 +47,39 @@ 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(tagRendering.condition &&
|
||||
!tagRendering.condition.matchesProperties(this._tags.data)){
|
||||
// Filtered away by the condition
|
||||
|
||||
if(this.IsKnown(tagRendering)){
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tagRendering.GetRenderValue(this._tags.data) !== undefined) {
|
||||
// This value is known
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (this._skippedQuestions.data.indexOf(i) >= 0) {
|
||||
continue;
|
||||
|
|
|
@ -2,6 +2,9 @@ import {UIEventSource} from "../../Logic/UIEventSource";
|
|||
import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig";
|
||||
import {UIElement} from "../UIElement";
|
||||
import {SubstitutedTranslation} from "../SpecialVisualizations";
|
||||
import {Utils} from "../../Utils";
|
||||
import Combine from "../Base/Combine";
|
||||
import {TagUtils} from "../../Logic/Tags";
|
||||
|
||||
/***
|
||||
* Displays the correct value for a known tagrendering
|
||||
|
@ -15,7 +18,7 @@ export default class TagRenderingAnswer extends UIElement {
|
|||
super(tags);
|
||||
this._tags = tags;
|
||||
this._configuration = configuration;
|
||||
if(configuration === undefined){
|
||||
if (configuration === undefined) {
|
||||
throw "Trying to generate a tagRenderingAnswer without configuration..."
|
||||
}
|
||||
}
|
||||
|
@ -32,12 +35,38 @@ export default class TagRenderingAnswer extends UIElement {
|
|||
return "";
|
||||
}
|
||||
const tr = this._configuration.GetRenderValue(tags);
|
||||
if (tr === undefined) {
|
||||
return "";
|
||||
if (tr !== undefined) {
|
||||
this._content = new SubstitutedTranslation(tr, this._tags);
|
||||
return this._content.Render();
|
||||
}
|
||||
// Bit of a hack; remember that the fields are updated
|
||||
this._content = new SubstitutedTranslation(tr, this._tags);
|
||||
return this._content.Render();
|
||||
|
||||
// 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 => {
|
||||
if (mapping.if === undefined) {
|
||||
return mapping.then;
|
||||
}
|
||||
if (TagUtils.MatchesMultiAnswer(mapping.if, tags)) {
|
||||
return mapping.then;
|
||||
}
|
||||
return undefined;
|
||||
}))
|
||||
if (applicableThens.length >= 0) {
|
||||
if (applicableThens.length === 1) {
|
||||
this._content = applicableThens[0];
|
||||
} else {
|
||||
this._content = new Combine(["<ul>",
|
||||
...applicableThens.map(tr => new Combine(["<li>", tr, "</li>"]))
|
||||
,
|
||||
"</ul>"
|
||||
])
|
||||
|
||||
}
|
||||
return this._content.Render();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -53,7 +53,9 @@ export default class TagRenderingQuestion extends UIElement {
|
|||
this._inputElement = this.GenerateInputElement()
|
||||
const self = this;
|
||||
const save = () => {
|
||||
console.log("Save clicked!")
|
||||
const selection = self._inputElement.GetValue().data;
|
||||
console.log("Selection is", selection)
|
||||
if (selection) {
|
||||
(State.state?.changes ?? new Changes())
|
||||
.addTag(tags.data.id, selection, tags);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue