mapcomplete/UI/Popup/FeatureInfoBox.ts

80 lines
3 KiB
TypeScript
Raw Normal View History

2020-10-14 12:15:09 +02:00
import {UIElement} from "../UIElement";
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";
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-09 13:10:48 +01:00
import {Utils} from "../../Utils";
2021-03-22 03:05:08 +01:00
import {Tag} from "../../Logic/Tag";
export default class FeatureInfoBox extends ScrollableFullScreen {
private constructor(
2020-10-27 01:01:34 +01:00
tags: UIEventSource<any>,
layerConfig: LayerConfig
) {
super(() => FeatureInfoBox.GenerateTitleBar(tags, layerConfig),
() => FeatureInfoBox.GenerateContent(tags, layerConfig),
tags.data.id);
2021-03-12 13:48:49 +01:00
2020-11-17 16:29:51 +01:00
if (layerConfig === undefined) {
throw "Undefined layerconfig";
2020-11-02 18:59:21 +01:00
}
2021-01-25 03:12:09 +01:00
}
static construct(tags: UIEventSource<any>, layer: LayerConfig): FeatureInfoBox {
return new FeatureInfoBox(tags, layer)
2021-01-25 04:21:22 +01:00
}
private static GenerateTitleBar(tags: UIEventSource<any>,
layerConfig: LayerConfig): UIElement {
const title = new TagRenderingAnswer(tags, layerConfig.title ?? new TagRenderingConfig("POI", undefined))
.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(
layerConfig.titleIcons.map(icon => new TagRenderingAnswer(tags, icon,
"block w-8 h-8 align-baseline box-content sm:p-0.5", "width: 2rem !important;")
.HideOnEmpty(true)
))
.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([
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>,
layerConfig: LayerConfig): UIElement {
let questionBox: UIElement = undefined;
if (State.state.featureSwitchUserbadge.data) {
2020-12-08 23:44:34 +01:00
questionBox = new QuestionBox(tags, layerConfig.tagRenderings);
}
2020-12-08 23:44:34 +01:00
let questionBoxIsUsed = false;
const renderings = layerConfig.tagRenderings.map(tr => {
if (tr.question === null) {
2020-12-08 23:44:34 +01:00
// This is the question box!
questionBoxIsUsed = true;
2020-12-08 23:44:34 +01:00
return questionBox;
}
return new EditableTagRendering(tags, tr);
2020-12-08 23:44:34 +01:00
});
if (!questionBoxIsUsed) {
2021-01-08 02:13:44 +01:00
renderings.push(questionBox);
}
if(State.state.featureSwitchIsDebugging.data){
const config: TagRenderingConfig = new TagRenderingConfig({render:"{all_tags()}"}, new Tag("id",""), "");
renderings.push(new TagRenderingAnswer(tags,config ))
}
2021-01-08 02:13:44 +01:00
return new Combine(renderings).SetClass("block")
}
2020-07-20 15:54:50 +02:00
}