2020-10-14 12:15:09 +02:00
|
|
|
import {UIEventSource} from "../../Logic/UIEventSource";
|
2020-10-27 01:01:34 +01:00
|
|
|
import LayerConfig from "../../Customizations/JSON/LayerConfig";
|
|
|
|
import EditableTagRendering from "./EditableTagRendering";
|
|
|
|
import QuestionBox from "./QuestionBox";
|
|
|
|
import Combine from "../Base/Combine";
|
|
|
|
import TagRenderingAnswer from "./TagRenderingAnswer";
|
2020-11-12 12:18:02 +01:00
|
|
|
import State from "../../State";
|
2021-01-07 04:50:12 +01:00
|
|
|
import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig";
|
2021-01-08 02:13:44 +01:00
|
|
|
import ScrollableFullScreen from "../Base/ScrollableFullScreen";
|
2021-03-29 02:04:42 +02:00
|
|
|
import {Tag} from "../../Logic/Tags/Tag";
|
2021-04-21 01:26:36 +02:00
|
|
|
import Constants from "../../Models/Constants";
|
|
|
|
import SharedTagRenderings from "../../Customizations/SharedTagRenderings";
|
2021-06-14 02:39:23 +02:00
|
|
|
import BaseUIElement from "../BaseUIElement";
|
2021-06-27 20:52:25 +02:00
|
|
|
import {VariableUiElement} from "../Base/VariableUIElement";
|
2020-06-27 03:06:51 +02:00
|
|
|
|
2021-02-25 02:23:26 +01:00
|
|
|
export default class FeatureInfoBox extends ScrollableFullScreen {
|
2021-01-20 23:00:11 +01:00
|
|
|
|
2021-06-14 02:39:23 +02:00
|
|
|
public constructor(
|
2020-10-27 01:01:34 +01:00
|
|
|
tags: UIEventSource<any>,
|
2021-06-22 03:16:45 +02:00
|
|
|
layerConfig: LayerConfig,
|
2020-06-27 03:06:51 +02:00
|
|
|
) {
|
2021-03-12 14:52:34 +01:00
|
|
|
super(() => FeatureInfoBox.GenerateTitleBar(tags, layerConfig),
|
|
|
|
() => FeatureInfoBox.GenerateContent(tags, layerConfig),
|
|
|
|
tags.data.id);
|
2021-04-17 23:36:46 +02:00
|
|
|
|
2020-11-17 16:29:51 +01:00
|
|
|
if (layerConfig === undefined) {
|
2021-02-25 02:23:26 +01:00
|
|
|
throw "Undefined layerconfig";
|
2020-11-02 18:59:21 +01:00
|
|
|
}
|
2021-02-20 02:25:29 +01:00
|
|
|
|
2021-01-25 03:12:09 +01:00
|
|
|
}
|
2021-02-20 02:25:29 +01:00
|
|
|
|
2021-01-25 04:21:22 +01:00
|
|
|
private static GenerateTitleBar(tags: UIEventSource<any>,
|
2021-06-14 02:39:23 +02:00
|
|
|
layerConfig: LayerConfig): BaseUIElement {
|
2021-01-08 03:57:18 +01:00
|
|
|
const title = new TagRenderingAnswer(tags, layerConfig.title ?? new TagRenderingConfig("POI", undefined))
|
2021-02-21 01:36:31 +01:00
|
|
|
.SetClass("break-words font-bold sm:p-0.5 md:p-1 sm:p-1.5 md:p-2");
|
2021-01-08 02:13:44 +01:00
|
|
|
const titleIcons = new Combine(
|
2021-02-25 02:23:26 +01:00
|
|
|
layerConfig.titleIcons.map(icon => new TagRenderingAnswer(tags, icon,
|
2021-06-22 03:16:45 +02:00
|
|
|
"block w-8 h-8 align-baseline box-content sm:p-0.5")
|
2021-02-21 01:36:31 +01:00
|
|
|
))
|
|
|
|
.SetClass("flex flex-row flex-wrap pt-0.5 sm:pt-1 items-center mr-2")
|
2021-01-25 03:12:09 +01:00
|
|
|
|
2021-01-25 04:21:22 +01:00
|
|
|
return new Combine([
|
2021-02-21 01:36:31 +01:00
|
|
|
new Combine([title, titleIcons]).SetClass("flex flex-col sm:flex-row flex-grow justify-between")
|
2021-01-25 03:12:09 +01:00
|
|
|
])
|
|
|
|
}
|
|
|
|
|
2021-01-25 04:21:22 +01:00
|
|
|
private static GenerateContent(tags: UIEventSource<any>,
|
2021-06-14 02:39:23 +02:00
|
|
|
layerConfig: LayerConfig): BaseUIElement {
|
2021-06-28 00:45:49 +02:00
|
|
|
let questionBox: BaseUIElement = undefined;
|
2021-04-21 01:26:36 +02:00
|
|
|
|
2020-11-12 12:21:34 +01:00
|
|
|
if (State.state.featureSwitchUserbadge.data) {
|
2021-06-22 03:16:45 +02:00
|
|
|
questionBox = new QuestionBox(tags, layerConfig.tagRenderings, layerConfig.units);
|
2020-11-12 12:21:34 +01:00
|
|
|
}
|
2021-01-04 04:06:21 +01:00
|
|
|
|
2020-12-08 23:44:34 +01:00
|
|
|
let questionBoxIsUsed = false;
|
2021-06-27 20:52:25 +02:00
|
|
|
const renderings: BaseUIElement[] = layerConfig.tagRenderings.map(tr => {
|
2021-01-04 04:06:21 +01:00
|
|
|
if (tr.question === null) {
|
2020-12-08 23:44:34 +01:00
|
|
|
// This is the question box!
|
2021-02-20 02:25:29 +01:00
|
|
|
questionBoxIsUsed = true;
|
2020-12-08 23:44:34 +01:00
|
|
|
return questionBox;
|
|
|
|
}
|
2021-06-22 03:16:45 +02:00
|
|
|
return new EditableTagRendering(tags, tr, layerConfig.units);
|
2020-12-08 23:44:34 +01:00
|
|
|
});
|
2021-01-04 04:06:21 +01:00
|
|
|
if (!questionBoxIsUsed) {
|
2021-01-08 02:13:44 +01:00
|
|
|
renderings.push(questionBox);
|
2021-01-04 04:06:21 +01:00
|
|
|
}
|
2021-06-27 20:52:25 +02:00
|
|
|
|
2021-06-27 19:21:31 +02:00
|
|
|
const hasMinimap = layerConfig.tagRenderings.some(tr => tr.hasMinimap())
|
2021-06-27 20:52:25 +02:00
|
|
|
if (!hasMinimap) {
|
2021-06-27 19:21:31 +02:00
|
|
|
renderings.push(new TagRenderingAnswer(tags, SharedTagRenderings.SharedTagRendering.get("minimap")))
|
|
|
|
}
|
2021-06-30 18:48:23 +02:00
|
|
|
|
2021-06-27 20:52:25 +02:00
|
|
|
renderings.push(
|
|
|
|
new VariableUiElement(
|
|
|
|
State.state.osmConnection.userDetails.map(userdetails => {
|
|
|
|
if (userdetails.csCount <= Constants.userJourney.historyLinkVisible
|
|
|
|
&& State.state.featureSwitchIsDebugging.data == false
|
|
|
|
&& State.state.featureSwitchIsTesting.data === false) {
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
return new TagRenderingAnswer(tags, SharedTagRenderings.SharedTagRendering.get("last_edit"));
|
|
|
|
|
|
|
|
}, [State.state.featureSwitchIsDebugging])
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
renderings.push(
|
|
|
|
new VariableUiElement(
|
|
|
|
State.state.featureSwitchIsDebugging.map(isDebugging => {
|
|
|
|
if (isDebugging) {
|
|
|
|
const config: TagRenderingConfig = new TagRenderingConfig({render: "{all_tags()}"}, new Tag("id", ""), "");
|
|
|
|
return new TagRenderingAnswer(tags, config)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
2021-01-08 02:13:44 +01:00
|
|
|
|
2021-03-13 17:25:44 +01:00
|
|
|
return new Combine(renderings).SetClass("block")
|
2020-06-27 03:06:51 +02:00
|
|
|
|
|
|
|
}
|
2020-07-20 15:54:50 +02:00
|
|
|
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|