Merge and bugfixes

This commit is contained in:
Pieter Vander Vennet 2020-07-08 16:11:40 +02:00
commit c3664ce82f
9 changed files with 87 additions and 44 deletions

View file

@ -72,7 +72,7 @@ export class TagRenderingOptions {
const tagsKV = TagUtils.proprtiesToKV(tags);
for (const oneOnOneElement of this.options.mappings) {
if (oneOnOneElement.k.matches(tagsKV)) {
if (oneOnOneElement.k === null || oneOnOneElement.k.matches(tagsKV)) {
return false;
}
}
@ -147,10 +147,9 @@ export class TagRendering extends UIElement {
this.elementPriority = options.priority ?? 0;
// Prepare the choices for the Radio buttons
let i = 0;
const choices: UIElement[] = [];
const alreadyUsedTexts: string[] = [];
const usedChoices: string [] = [];
for (const choice of options.mappings ?? []) {
if (choice.k === null) {
this._mapping.push(choice);
@ -167,15 +166,16 @@ export class TagRendering extends UIElement {
}
}
const txt = choiceSubbed.txt;
if (alreadyUsedTexts.indexOf(txt) < 0) {
const txt = choiceSubbed.txt
// Choices is what is shown in the radio buttons
if (usedChoices.indexOf(txt) < 0) {
choices.push(new FixedUiElement(txt));
alreadyUsedTexts.push(txt);
usedChoices.push(txt);
// This is used to convert the radio button index into tags needed to add
this._mapping.push(choiceSubbed);
}
this._mapping.push(choiceSubbed);
i++;
}
// Map radiobutton choice and textfield answer onto tagfilter. That tagfilter will be pushed into the changes later on
@ -205,6 +205,7 @@ export class TagRendering extends UIElement {
// Prepare the actual input element -> pick an appropriate implementation
let inputElement: UIInputElement<TagsFilter>;
if (this._freeform !== undefined && this._mapping !== undefined) {
// Radio buttons with 'other'
inputElement = new UIRadioButtonWithOther(
@ -215,14 +216,15 @@ export class TagRendering extends UIElement {
pickString
);
this._questionElement = inputElement;
} else if (this._mapping !== undefined) {
} else if (this._mapping !== [] && this._mapping.length > 0) {
// This is a classic radio selection element
inputElement = new UIRadioButton(new UIEventSource(choices), pickChoice)
inputElement = new UIRadioButton(new UIEventSource(choices), pickChoice, false)
this._questionElement = inputElement;
} else if (this._freeform !== undefined) {
this._textField = new TextField(new UIEventSource<string>(this._freeform.placeholder), pickString);
inputElement = this._textField;
this._questionElement = new FixedUiElement(this._freeform.template.replace("$$$", inputElement.Render()))
this._questionElement = new FixedUiElement(
"<div>" + this._freeform.template.replace("$$$", inputElement.Render()) + "</div>")
} else {
throw "Invalid questionRendering, expected at least choices or a freeform"
}
@ -239,6 +241,7 @@ export class TagRendering extends UIElement {
const cancel = () => {
self._questionSkipped.setData(true);
self._editMode.setData(false);
self._source.ping(); // Send a ping upstream to render the next question
}
// Setup the save button and it's action
@ -357,7 +360,7 @@ export class TagRendering extends UIElement {
return "<div class='question'>" +
this._question +
"<span class='question-text'>" + this._question + "</span>" +
(this._question !== "" ? "<br/>" : "") +
this._questionElement.Render() +
this._skipButton.Render() +