2020-10-27 01:01:34 +01:00
|
|
|
import {UIEventSource} from "../../Logic/UIEventSource";
|
|
|
|
import TagRenderingQuestion from "./TagRenderingQuestion";
|
|
|
|
import Translations from "../i18n/Translations";
|
|
|
|
import Combine from "../Base/Combine";
|
|
|
|
import TagRenderingAnswer from "./TagRenderingAnswer";
|
|
|
|
import State from "../../State";
|
2020-11-06 01:58:26 +01:00
|
|
|
import Svg from "../../Svg";
|
2021-06-14 02:39:23 +02:00
|
|
|
import Toggle from "../Input/Toggle";
|
|
|
|
import BaseUIElement from "../BaseUIElement";
|
2021-08-07 23:11:34 +02:00
|
|
|
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
|
|
|
|
import {Unit} from "../../Models/Unit";
|
2020-10-27 01:01:34 +01:00
|
|
|
|
2021-06-14 02:39:23 +02:00
|
|
|
export default class EditableTagRendering extends Toggle {
|
2020-10-27 01:01:34 +01:00
|
|
|
|
|
|
|
constructor(tags: UIEventSource<any>,
|
2021-06-16 21:23:03 +02:00
|
|
|
configuration: TagRenderingConfig,
|
2021-06-22 03:16:45 +02:00
|
|
|
units: Unit [],
|
2021-06-16 21:23:03 +02:00
|
|
|
editMode = new UIEventSource<boolean>(false)
|
2021-09-09 00:05:51 +02:00
|
|
|
) {
|
2021-06-14 02:39:23 +02:00
|
|
|
const answer: BaseUIElement = new TagRenderingAnswer(tags, configuration)
|
2021-06-16 14:23:53 +02:00
|
|
|
answer.SetClass("w-full")
|
2021-06-14 02:39:23 +02:00
|
|
|
let rendering = answer;
|
2020-10-27 01:01:34 +01:00
|
|
|
|
2021-06-14 02:39:23 +02:00
|
|
|
if (configuration.question !== undefined && State.state?.featureSwitchUserbadge?.data) {
|
|
|
|
// We have a question and editing is enabled
|
|
|
|
const editButton =
|
|
|
|
new Combine([Svg.pencil_ui()]).SetClass("block relative h-10 w-10 p-2 float-right").SetStyle("border: 1px solid black; border-radius: 0.7em")
|
|
|
|
.onClick(() => {
|
|
|
|
editMode.setData(true);
|
|
|
|
});
|
2020-10-27 01:01:34 +01:00
|
|
|
|
2021-01-06 01:11:07 +01:00
|
|
|
|
2021-06-14 02:39:23 +02:00
|
|
|
const answerWithEditButton = new Combine([answer,
|
2021-06-14 17:28:11 +02:00
|
|
|
new Toggle(editButton, undefined, State.state.osmConnection.isLoggedIn)])
|
|
|
|
.SetClass("flex justify-between w-full")
|
2021-06-14 02:39:23 +02:00
|
|
|
|
2021-01-06 01:11:07 +01:00
|
|
|
|
2020-10-27 01:01:34 +01:00
|
|
|
const cancelbutton =
|
|
|
|
Translations.t.general.cancel.Clone()
|
2021-01-24 22:20:40 +01:00
|
|
|
.SetClass("btn btn-secondary mr-3")
|
2020-10-27 01:01:34 +01:00
|
|
|
.onClick(() => {
|
2021-06-14 02:39:23 +02:00
|
|
|
editMode.setData(false)
|
2020-10-27 01:01:34 +01:00
|
|
|
});
|
|
|
|
|
2021-07-01 02:26:45 +02:00
|
|
|
const question = new TagRenderingQuestion(tags, configuration,
|
|
|
|
{
|
|
|
|
units: units,
|
|
|
|
cancelButton: cancelbutton,
|
2021-09-09 00:05:51 +02:00
|
|
|
afterSave: () => {
|
2021-07-01 02:26:45 +02:00
|
|
|
editMode.setData(false)
|
|
|
|
}
|
|
|
|
})
|
2021-06-14 02:39:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
rendering = new Toggle(
|
|
|
|
question,
|
|
|
|
answerWithEditButton,
|
|
|
|
editMode
|
|
|
|
)
|
2020-10-27 01:01:34 +01:00
|
|
|
}
|
2021-06-14 17:28:11 +02:00
|
|
|
rendering.SetClass("block w-full break-word text-default m-1 p-1 border-b border-gray-200 mb-2 pb-2")
|
2021-06-14 02:39:23 +02:00
|
|
|
// The tagrendering is hidden if:
|
|
|
|
// The answer is unknown. The questionbox will then show the question
|
|
|
|
// There is a condition hiding the answer
|
|
|
|
const renderingIsShown = tags.map(tags =>
|
2021-06-14 17:28:11 +02:00
|
|
|
configuration.IsKnown(tags) &&
|
2021-06-14 02:39:23 +02:00
|
|
|
(configuration?.condition?.matchesProperties(tags) ?? true))
|
|
|
|
super(
|
|
|
|
rendering,
|
|
|
|
undefined,
|
|
|
|
renderingIsShown
|
|
|
|
)
|
2020-10-27 01:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|