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";
|
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";
|
2021-10-01 03:14:36 +02:00
|
|
|
import Lazy from "../Base/Lazy";
|
2022-01-30 18:29:00 +01:00
|
|
|
import {FixedUiElement} from "../Base/FixedUiElement";
|
2022-06-06 20:12:04 +02:00
|
|
|
import FeaturePipelineState from "../../Logic/State/FeaturePipelineState";
|
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 [],
|
2022-01-19 20:34:04 +01:00
|
|
|
state,
|
2021-11-07 16:34:51 +01:00
|
|
|
options: {
|
|
|
|
editMode?: UIEventSource<boolean>,
|
|
|
|
innerElementClasses?: string
|
2021-10-28 00:53:09 +02:00
|
|
|
}
|
2021-09-09 00:05:51 +02:00
|
|
|
) {
|
2021-10-02 15:16:41 +02:00
|
|
|
|
|
|
|
// The tagrendering is hidden if:
|
2022-01-17 21:33:03 +01:00
|
|
|
// - The answer is unknown. The questionbox will then show the question
|
|
|
|
// - There is a condition hiding the answer
|
2021-10-02 15:16:41 +02:00
|
|
|
const renderingIsShown = tags.map(tags =>
|
|
|
|
configuration.IsKnown(tags) &&
|
|
|
|
(configuration?.condition?.matchesProperties(tags) ?? true))
|
2021-11-07 16:34:51 +01:00
|
|
|
|
2021-10-02 15:16:41 +02:00
|
|
|
super(
|
2021-10-28 00:53:09 +02:00
|
|
|
new Lazy(() => {
|
|
|
|
const editMode = options.editMode ?? new UIEventSource<boolean>(false)
|
2022-01-30 18:29:00 +01:00
|
|
|
let rendering = EditableTagRendering.CreateRendering(state, tags, configuration, units, editMode);
|
2021-10-28 00:53:09 +02:00
|
|
|
rendering.SetClass(options.innerElementClasses)
|
2022-02-10 23:16:14 +01:00
|
|
|
if(state.featureSwitchIsDebugging.data || state.featureSwitchIsTesting.data){
|
2022-01-30 18:29:00 +01:00
|
|
|
rendering = new Combine([
|
|
|
|
new FixedUiElement(configuration.id).SetClass("self-end subtle"),
|
|
|
|
rendering
|
|
|
|
]).SetClass("flex flex-col")
|
|
|
|
}
|
2021-10-28 00:53:09 +02:00
|
|
|
return rendering
|
|
|
|
}),
|
2021-10-02 15:16:41 +02:00
|
|
|
undefined,
|
|
|
|
renderingIsShown
|
|
|
|
)
|
|
|
|
}
|
2021-11-07 16:34:51 +01:00
|
|
|
|
2022-06-06 20:12:04 +02:00
|
|
|
private static CreateRendering(state: FeaturePipelineState, tags: UIEventSource<any>, configuration: TagRenderingConfig, units: Unit[], editMode: UIEventSource<boolean>): BaseUIElement {
|
2022-01-19 20:34:04 +01:00
|
|
|
const answer: BaseUIElement = new TagRenderingAnswer(tags, configuration, state)
|
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
|
|
|
|
2022-01-19 20:34:04 +01:00
|
|
|
if (configuration.question !== undefined && state?.featureSwitchUserbadge?.data) {
|
2021-06-14 02:39:23 +02:00
|
|
|
// We have a question and editing is enabled
|
|
|
|
const answerWithEditButton = new Combine([answer,
|
2021-10-02 15:16:41 +02:00
|
|
|
new Toggle(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);
|
|
|
|
}),
|
2021-09-26 17:36:39 +02:00
|
|
|
undefined,
|
2022-01-19 20:34:04 +01:00
|
|
|
state.osmConnection.isLoggedIn)
|
2021-09-26 17:36:39 +02:00
|
|
|
]).SetClass("flex justify-between w-full")
|
2021-06-14 02:39:23 +02:00
|
|
|
|
2021-01-06 01:11:07 +01:00
|
|
|
|
2021-10-03 21:44:43 +02:00
|
|
|
const question = new Lazy(() =>
|
2022-01-26 21:40:38 +01:00
|
|
|
new TagRenderingQuestion(tags, configuration, state,
|
2021-10-02 15:16:41 +02:00
|
|
|
{
|
|
|
|
units: units,
|
|
|
|
cancelButton: Translations.t.general.cancel.Clone()
|
2022-02-04 00:45:22 +01:00
|
|
|
.SetClass("btn btn-secondary")
|
2021-10-02 15:16:41 +02:00
|
|
|
.onClick(() => {
|
|
|
|
editMode.setData(false)
|
|
|
|
}),
|
|
|
|
afterSave: () => {
|
|
|
|
editMode.setData(false)
|
|
|
|
}
|
2021-10-03 21:44:43 +02:00
|
|
|
}))
|
2021-06-14 02:39:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
rendering = new Toggle(
|
|
|
|
question,
|
|
|
|
answerWithEditButton,
|
|
|
|
editMode
|
|
|
|
)
|
2020-10-27 01:01:34 +01:00
|
|
|
}
|
2021-10-02 15:16:41 +02:00
|
|
|
return rendering;
|
2020-10-27 01:01:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|