2020-10-14 12:15:09 +02:00
|
|
|
import {UIEventSource} from "../../Logic/UIEventSource";
|
2020-10-27 01:01:34 +01:00
|
|
|
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-08 02:13:44 +01:00
|
|
|
import ScrollableFullScreen from "../Base/ScrollableFullScreen";
|
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";
|
2021-07-03 14:35:44 +02:00
|
|
|
import DeleteWizard from "./DeleteWizard";
|
2021-07-15 20:47:28 +02:00
|
|
|
import SplitRoadWizard from "./SplitRoadWizard";
|
2021-08-07 23:11:34 +02:00
|
|
|
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
|
|
|
|
import LayerConfig from "../../Models/ThemeConfig/LayerConfig";
|
|
|
|
import {Translation} from "../i18n/Translation";
|
|
|
|
import {Utils} from "../../Utils";
|
|
|
|
import {SubstitutedTranslation} from "../SubstitutedTranslation";
|
2021-10-14 03:46:09 +02:00
|
|
|
import MoveWizard from "./MoveWizard";
|
2021-11-10 18:42:31 +01:00
|
|
|
import Toggle from "../Input/Toggle";
|
2021-11-12 01:44:13 +01:00
|
|
|
import {FixedUiElement} from "../Base/FixedUiElement";
|
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),
|
2021-10-25 20:50:59 +02:00
|
|
|
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-10-19 03:00:57 +02:00
|
|
|
const title = new TagRenderingAnswer(tags, layerConfig.title ?? new TagRenderingConfig("POI"))
|
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-07-16 02:13:41 +02:00
|
|
|
"block w-8 h-8 align-baseline box-content sm:p-0.5", "width: 2rem;")
|
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-11-10 18:42:31 +01:00
|
|
|
let questionBoxes: Map<string, QuestionBox> = new Map<string, QuestionBox>();
|
2021-04-21 01:26:36 +02:00
|
|
|
|
2021-10-23 00:31:41 +02:00
|
|
|
const allGroupNames = Utils.Dedup(layerConfig.tagRenderings.map(tr => tr.group))
|
2020-11-12 12:21:34 +01:00
|
|
|
if (State.state.featureSwitchUserbadge.data) {
|
2021-11-12 01:44:13 +01:00
|
|
|
const questionSpecs = layerConfig.tagRenderings.filter(tr => tr.id === "questions")
|
2021-10-22 18:53:07 +02:00
|
|
|
for (const groupName of allGroupNames) {
|
|
|
|
const questions = layerConfig.tagRenderings.filter(tr => tr.group === groupName)
|
2021-11-12 01:44:13 +01:00
|
|
|
const questionSpec = questionSpecs.filter(tr => tr.group === groupName)[0]
|
|
|
|
const questionBox = new QuestionBox({
|
|
|
|
tagsSource: tags,
|
|
|
|
tagRenderings: questions,
|
|
|
|
units: layerConfig.units,
|
|
|
|
showAllQuestionsAtOnce: questionSpec?.freeform?.helperArgs["showAllQuestions"] ?? State.state.featureSwitchShowAllQuestions
|
|
|
|
});
|
2021-10-22 18:53:07 +02:00
|
|
|
questionBoxes.set(groupName, questionBox)
|
|
|
|
}
|
2020-11-12 12:21:34 +01:00
|
|
|
}
|
2021-01-04 04:06:21 +01:00
|
|
|
|
2021-10-23 00:31:41 +02:00
|
|
|
const allRenderings = []
|
|
|
|
for (let i = 0; i < allGroupNames.length; i++) {
|
|
|
|
const groupName = allGroupNames[i];
|
|
|
|
|
|
|
|
const trs = layerConfig.tagRenderings.filter(tr => tr.group === groupName)
|
2021-10-28 00:53:09 +02:00
|
|
|
const renderingsForGroup: (EditableTagRendering | BaseUIElement)[] = []
|
|
|
|
const innerClasses = "block w-full break-word text-default m-1 p-1 border-b border-gray-200 mb-2 pb-2";
|
2021-10-23 00:31:41 +02:00
|
|
|
for (const tr of trs) {
|
|
|
|
if (tr.question === null || tr.id === "questions") {
|
|
|
|
// This is a question box!
|
|
|
|
const questionBox = questionBoxes.get(tr.group)
|
|
|
|
questionBoxes.delete(tr.group)
|
2021-11-12 01:44:13 +01:00
|
|
|
|
|
|
|
if (tr.render !== undefined) {
|
|
|
|
questionBox.SetClass("text-sm")
|
2021-11-10 18:42:31 +01:00
|
|
|
const renderedQuestion = new TagRenderingAnswer(tags, tr, tr.group + " questions", "", {
|
|
|
|
specialViz: new Map<string, BaseUIElement>([["questions", questionBox]])
|
|
|
|
})
|
|
|
|
const possiblyHidden = new Toggle(
|
|
|
|
renderedQuestion,
|
|
|
|
undefined,
|
2021-11-12 01:44:13 +01:00
|
|
|
questionBox.restingQuestions.map(ls => ls?.length > 0)
|
2021-11-10 18:42:31 +01:00
|
|
|
)
|
|
|
|
renderingsForGroup.push(possiblyHidden)
|
2021-11-12 01:44:13 +01:00
|
|
|
} else {
|
2021-11-10 18:42:31 +01:00
|
|
|
renderingsForGroup.push(questionBox)
|
|
|
|
}
|
2021-11-12 01:44:13 +01:00
|
|
|
|
2021-10-23 00:31:41 +02:00
|
|
|
} else {
|
2021-10-28 00:53:09 +02:00
|
|
|
let classes = innerClasses
|
2021-11-07 16:34:51 +01:00
|
|
|
let isHeader = renderingsForGroup.length === 0 && i > 0
|
|
|
|
if (isHeader) {
|
2021-10-28 00:53:09 +02:00
|
|
|
// This is the first element of a group!
|
|
|
|
// It should act as header and be sticky
|
2021-11-07 16:34:51 +01:00
|
|
|
classes = ""
|
2021-10-28 00:53:09 +02:00
|
|
|
}
|
2021-11-07 16:34:51 +01:00
|
|
|
|
|
|
|
const etr = new EditableTagRendering(tags, tr, layerConfig.units, {
|
2021-10-28 00:53:09 +02:00
|
|
|
innerElementClasses: innerClasses
|
|
|
|
})
|
2021-11-07 16:34:51 +01:00
|
|
|
if (isHeader) {
|
2021-10-28 01:26:35 +02:00
|
|
|
etr.SetClass("sticky top-0")
|
|
|
|
}
|
2021-10-23 00:31:41 +02:00
|
|
|
renderingsForGroup.push(etr)
|
|
|
|
}
|
|
|
|
}
|
2021-11-07 16:34:51 +01:00
|
|
|
|
2021-10-23 00:31:41 +02:00
|
|
|
allRenderings.push(...renderingsForGroup)
|
|
|
|
}
|
|
|
|
|
2021-09-09 00:05:51 +02:00
|
|
|
|
|
|
|
let editElements: BaseUIElement[] = []
|
2021-10-22 18:53:07 +02:00
|
|
|
questionBoxes.forEach(questionBox => {
|
2021-07-28 15:14:13 +02:00
|
|
|
editElements.push(questionBox);
|
2021-10-22 18:53:07 +02:00
|
|
|
})
|
2021-06-27 20:52:25 +02:00
|
|
|
|
2021-10-23 00:31:41 +02:00
|
|
|
if (layerConfig.allowMove) {
|
2021-10-14 03:46:09 +02:00
|
|
|
editElements.push(
|
|
|
|
new VariableUiElement(tags.map(tags => tags.id).map(id => {
|
|
|
|
const feature = State.state.allElements.ContainingFeatures.get(id)
|
|
|
|
return new MoveWizard(
|
|
|
|
feature,
|
|
|
|
State.state,
|
|
|
|
layerConfig.allowMove
|
|
|
|
);
|
|
|
|
})
|
2021-10-26 02:09:04 +02:00
|
|
|
).SetClass("text-base")
|
2021-10-14 03:46:09 +02:00
|
|
|
);
|
|
|
|
}
|
2021-06-27 20:52:25 +02:00
|
|
|
|
2021-07-03 14:35:44 +02:00
|
|
|
if (layerConfig.deletion) {
|
2021-07-28 15:14:13 +02:00
|
|
|
editElements.push(
|
2021-07-03 14:35:44 +02:00
|
|
|
new VariableUiElement(tags.map(tags => tags.id).map(id =>
|
|
|
|
new DeleteWizard(
|
|
|
|
id,
|
|
|
|
layerConfig.deletion
|
|
|
|
))
|
2021-10-26 02:09:04 +02:00
|
|
|
).SetClass("text-base"))
|
2021-07-03 14:35:44 +02:00
|
|
|
}
|
2021-06-27 20:52:25 +02:00
|
|
|
|
2021-07-15 20:47:28 +02:00
|
|
|
if (layerConfig.allowSplit) {
|
2021-07-28 15:14:13 +02:00
|
|
|
editElements.push(
|
2021-07-15 20:47:28 +02:00
|
|
|
new VariableUiElement(tags.map(tags => tags.id).map(id =>
|
|
|
|
new SplitRoadWizard(id))
|
2021-10-26 02:09:04 +02:00
|
|
|
).SetClass("text-base"))
|
2021-07-15 20:47:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-07 23:11:34 +02:00
|
|
|
const hasMinimap = layerConfig.tagRenderings.some(tr => FeatureInfoBox.hasMinimap(tr))
|
2021-07-15 20:47:28 +02:00
|
|
|
if (!hasMinimap) {
|
2021-10-23 00:31:41 +02:00
|
|
|
allRenderings.push(new TagRenderingAnswer(tags, SharedTagRenderings.SharedTagRendering.get("minimap")))
|
2021-07-15 20:47:28 +02:00
|
|
|
}
|
|
|
|
|
2021-07-28 15:14:13 +02:00
|
|
|
editElements.push(
|
2021-07-03 14:35:44 +02:00
|
|
|
new VariableUiElement(
|
|
|
|
State.state.osmConnection.userDetails
|
|
|
|
.map(ud => ud.csCount)
|
|
|
|
.map(csCount => {
|
|
|
|
if (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, State.state.featureSwitchIsTesting])
|
2021-06-27 20:52:25 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-07-28 15:14:13 +02:00
|
|
|
editElements.push(
|
2021-06-27 20:52:25 +02:00
|
|
|
new VariableUiElement(
|
|
|
|
State.state.featureSwitchIsDebugging.map(isDebugging => {
|
|
|
|
if (isDebugging) {
|
2021-10-23 00:31:41 +02:00
|
|
|
const config: TagRenderingConfig = new TagRenderingConfig({render: "{all_tags()}"}, "");
|
2021-10-15 00:52:31 +02:00
|
|
|
return new TagRenderingAnswer(tags, config, "all_tags")
|
2021-06-27 20:52:25 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
2021-09-09 00:05:51 +02:00
|
|
|
|
2021-07-28 15:14:13 +02:00
|
|
|
const editors = new VariableUiElement(State.state.featureSwitchUserbadge.map(
|
|
|
|
userbadge => {
|
2021-09-09 00:05:51 +02:00
|
|
|
if (!userbadge) {
|
2021-07-28 15:14:13 +02:00
|
|
|
return undefined
|
|
|
|
}
|
2021-09-22 05:02:09 +02:00
|
|
|
return new Combine(editElements).SetClass("flex flex-col")
|
2021-07-28 15:14:13 +02:00
|
|
|
}
|
|
|
|
))
|
2021-10-23 00:31:41 +02:00
|
|
|
allRenderings.push(editors)
|
2021-01-08 02:13:44 +01:00
|
|
|
|
2021-10-23 00:31:41 +02:00
|
|
|
return new Combine(allRenderings).SetClass("block")
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|
2020-07-20 15:54:50 +02:00
|
|
|
|
2021-08-07 23:11:34 +02:00
|
|
|
/**
|
|
|
|
* Returns true if this tag rendering has a minimap in some language.
|
|
|
|
* Note: this might be hidden by conditions
|
|
|
|
*/
|
|
|
|
private static hasMinimap(renderingConfig: TagRenderingConfig): boolean {
|
|
|
|
const translations: Translation[] = Utils.NoNull([renderingConfig.render, ...(renderingConfig.mappings ?? []).map(m => m.then)]);
|
|
|
|
for (const translation of translations) {
|
|
|
|
for (const key in translation.translations) {
|
|
|
|
if (!translation.translations.hasOwnProperty(key)) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
const template = translation.translations[key]
|
|
|
|
const parts = SubstitutedTranslation.ExtractSpecialComponents(template)
|
|
|
|
const hasMiniMap = parts.filter(part => part.special !== undefined).some(special => special.special.func.funcName === "minimap")
|
|
|
|
if (hasMiniMap) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|