2023-03-08 01:36:27 +01:00
|
|
|
import { Store, 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"
|
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"
|
2022-11-08 14:37:48 +01: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"
|
2022-11-08 14:37:48 +01:00
|
|
|
import { Utils } from "../../Utils"
|
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"
|
2022-01-19 20:34:04 +01:00
|
|
|
import Lazy from "../Base/Lazy"
|
2022-05-01 04:17:40 +02:00
|
|
|
import FeaturePipelineState from "../../Logic/State/FeaturePipelineState"
|
2022-11-08 14:37:48 +01:00
|
|
|
import { Tag } from "../../Logic/Tags/Tag"
|
|
|
|
import Svg from "../../Svg"
|
|
|
|
import Translations from "../i18n/Translations"
|
2020-06-27 03:06:51 +02:00
|
|
|
|
2021-02-25 02:23:26 +01:00
|
|
|
export default class FeatureInfoBox extends ScrollableFullScreen {
|
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,
|
2022-05-01 04:17:40 +02:00
|
|
|
state: FeaturePipelineState,
|
2022-07-08 03:14:55 +02:00
|
|
|
options?: {
|
|
|
|
hashToShow?: string
|
|
|
|
isShown?: UIEventSource<boolean>
|
|
|
|
setHash?: true | boolean
|
|
|
|
}
|
2020-06-27 03:06:51 +02:00
|
|
|
) {
|
2022-01-19 20:34:04 +01:00
|
|
|
if (state === undefined) {
|
|
|
|
throw "State is undefined!"
|
|
|
|
}
|
2023-03-08 01:36:27 +01:00
|
|
|
const showAllQuestions = state.featureSwitchShowAllQuestions.map(
|
|
|
|
(fsShow) => fsShow || state.showAllQuestionsAtOnce.data,
|
|
|
|
[state.showAllQuestionsAtOnce]
|
|
|
|
)
|
2022-01-19 20:34:04 +01:00
|
|
|
super(
|
|
|
|
() => FeatureInfoBox.GenerateTitleBar(tags, layerConfig, state),
|
2023-03-08 01:36:27 +01:00
|
|
|
() => FeatureInfoBox.GenerateContent(tags, layerConfig, state, showAllQuestions),
|
2022-07-08 03:14:55 +02:00
|
|
|
options?.hashToShow ?? tags.data.id ?? "item",
|
|
|
|
options?.isShown,
|
|
|
|
options
|
2022-09-08 21:40:48 +02:00
|
|
|
)
|
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-01-25 03:12:09 +01:00
|
|
|
}
|
2021-02-20 02:25:29 +01:00
|
|
|
|
2022-07-13 17:58:01 +02:00
|
|
|
public static GenerateTitleBar(
|
|
|
|
tags: UIEventSource<any>,
|
2022-01-19 20:34:04 +01:00
|
|
|
layerConfig: LayerConfig,
|
|
|
|
state: {}
|
|
|
|
): BaseUIElement {
|
|
|
|
const title = new TagRenderingAnswer(
|
|
|
|
tags,
|
|
|
|
layerConfig.title ?? new TagRenderingConfig("POI"),
|
|
|
|
state
|
2022-02-01 04:14:54 +01:00
|
|
|
).SetClass("break-words font-bold sm:p-0.5 md:p-1 sm:p-1.5 md:p-2 text-2xl")
|
2021-01-08 02:13:44 +01:00
|
|
|
const titleIcons = new Combine(
|
2022-04-06 19:16:55 +02:00
|
|
|
layerConfig.titleIcons.map((icon) => {
|
|
|
|
return new TagRenderingAnswer(
|
|
|
|
tags,
|
|
|
|
icon,
|
|
|
|
state,
|
2022-07-09 20:35:59 +02:00
|
|
|
"block h-8 max-h-8 align-baseline box-content sm:p-0.5 titleicon"
|
2021-02-21 01:36:31 +01:00
|
|
|
)
|
2022-09-08 21:40:48 +02:00
|
|
|
})
|
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"
|
2022-09-08 21:40:48 +02:00
|
|
|
),
|
2021-01-25 03:12:09 +01:00
|
|
|
])
|
|
|
|
}
|
|
|
|
|
2022-07-13 17:58:01 +02:00
|
|
|
public static GenerateContent(
|
2022-12-16 01:09:18 +01:00
|
|
|
tags: UIEventSource<any>,
|
|
|
|
layerConfig: LayerConfig,
|
2023-03-08 01:36:27 +01:00
|
|
|
state: FeaturePipelineState,
|
|
|
|
showAllQuestions?: Store<boolean>
|
2022-12-16 13:45:07 +01:00
|
|
|
): BaseUIElement {
|
2022-12-16 01:09:18 +01:00
|
|
|
return new Toggle(
|
2022-12-16 13:45:07 +01:00
|
|
|
new Combine([
|
|
|
|
Svg.delete_icon_svg().SetClass("w-8 h-8"),
|
|
|
|
Translations.t.delete.isDeleted,
|
|
|
|
]).SetClass("flex justify-center font-bold items-center"),
|
2023-03-08 01:36:27 +01:00
|
|
|
FeatureInfoBox.GenerateMainContent(tags, layerConfig, state, showAllQuestions),
|
2022-12-16 13:45:07 +01:00
|
|
|
tags.map((t) => t["_deleted"] == "yes")
|
2022-12-16 01:09:18 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
private static GenerateMainContent(
|
2022-07-13 17:58:01 +02:00
|
|
|
tags: UIEventSource<any>,
|
2022-01-19 20:34:04 +01:00
|
|
|
layerConfig: LayerConfig,
|
2023-03-08 01:36:27 +01:00
|
|
|
state: FeaturePipelineState,
|
|
|
|
showAllQuestions?: Store<boolean>
|
2022-05-01 04:17:40 +02:00
|
|
|
): BaseUIElement {
|
2021-11-10 18:42:31 +01:00
|
|
|
let questionBoxes: Map<string, QuestionBox> = new Map<string, QuestionBox>()
|
2022-11-07 23:12:31 +01:00
|
|
|
const t = Translations.t.general
|
2021-10-23 00:31:41 +02:00
|
|
|
const allGroupNames = Utils.Dedup(layerConfig.tagRenderings.map((tr) => tr.group))
|
2022-01-19 20:34:04 +01:00
|
|
|
if (state?.featureSwitchUserbadge?.data ?? true) {
|
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]
|
2022-01-19 20:34:04 +01:00
|
|
|
const questionBox = new QuestionBox(state, {
|
2021-11-12 01:44:13 +01:00
|
|
|
tagsSource: tags,
|
|
|
|
tagRenderings: questions,
|
|
|
|
units: layerConfig.units,
|
2022-01-19 20:34:04 +01:00
|
|
|
showAllQuestionsAtOnce:
|
2023-03-08 01:36:27 +01:00
|
|
|
questionSpec?.freeform?.helperArgs["showAllQuestions"] ?? showAllQuestions,
|
2021-11-12 01:44:13 +01:00
|
|
|
})
|
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
|
|
|
|
2022-11-08 14:37:48 +01:00
|
|
|
const withQuestion = layerConfig.tagRenderings.filter(
|
|
|
|
(tr) => tr.question !== undefined
|
|
|
|
).length
|
2022-11-07 23:12:31 +01:00
|
|
|
|
|
|
|
const allRenderings: BaseUIElement[] = [
|
|
|
|
new VariableUiElement(
|
2022-11-08 14:37:48 +01:00
|
|
|
tags
|
|
|
|
.map((data) => data[Tag.newlyCreated.key])
|
|
|
|
.map((isCreated) => {
|
2023-01-09 20:56:39 +01:00
|
|
|
if (isCreated === undefined) {
|
2022-11-08 14:37:48 +01:00
|
|
|
return undefined
|
|
|
|
}
|
2023-01-09 20:56:39 +01:00
|
|
|
const createdDate = new Date(isCreated)
|
|
|
|
const secondsSinceCreation = (Date.now() - createdDate.getTime()) / 1000
|
|
|
|
if (secondsSinceCreation >= 60 * 5) {
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
|
2022-11-08 14:37:48 +01:00
|
|
|
const els = []
|
|
|
|
const thanks = new Combine([
|
|
|
|
Svg.party_svg().SetClass(
|
|
|
|
"w-12 h-12 shrink-0 p-1 m-1 bg-white rounded-full block"
|
|
|
|
),
|
|
|
|
t.newlyCreated,
|
2022-11-07 23:12:31 +01:00
|
|
|
]).SetClass("flex w-full thanks content-center")
|
2022-11-08 14:37:48 +01:00
|
|
|
els.push(thanks)
|
|
|
|
if (withQuestion > 0) {
|
|
|
|
els.push(t.feelFreeToSkip)
|
|
|
|
}
|
2022-11-07 23:12:31 +01:00
|
|
|
|
2022-11-08 14:37:48 +01:00
|
|
|
return new Combine(els).SetClass("pb-4 mb-4 border-b block border-black")
|
|
|
|
})
|
|
|
|
),
|
2022-11-07 23:12:31 +01:00
|
|
|
]
|
2021-10-23 00:31:41 +02:00
|
|
|
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")
|
2022-01-19 20:34:04 +01:00
|
|
|
const renderedQuestion = new TagRenderingAnswer(
|
|
|
|
tags,
|
|
|
|
tr,
|
|
|
|
state,
|
2021-12-21 18:35:31 +01:00
|
|
|
tr.group + " questions",
|
|
|
|
"",
|
|
|
|
{
|
2022-01-19 20:34:04 +01:00
|
|
|
specialViz: new Map<string, BaseUIElement>([
|
|
|
|
["questions", questionBox],
|
|
|
|
]),
|
|
|
|
}
|
|
|
|
)
|
2021-11-10 18:42:31 +01:00
|
|
|
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-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
|
|
|
|
2022-01-19 20:34:04 +01:00
|
|
|
const etr = new EditableTagRendering(tags, tr, layerConfig.units, state, {
|
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)
|
|
|
|
}
|
2022-01-19 20:34:04 +01:00
|
|
|
allRenderings.push(
|
|
|
|
new Toggle(
|
|
|
|
new Lazy(() =>
|
|
|
|
FeatureInfoBox.createEditElements(questionBoxes, layerConfig, tags, state)
|
|
|
|
),
|
|
|
|
undefined,
|
|
|
|
state.featureSwitchUserbadge
|
|
|
|
)
|
2022-09-08 21:40:48 +02:00
|
|
|
)
|
2021-10-23 00:31:41 +02:00
|
|
|
|
2022-01-19 20:34:04 +01:00
|
|
|
return new Combine(allRenderings).SetClass("block")
|
|
|
|
}
|
2021-09-09 00:05:51 +02:00
|
|
|
|
2022-01-19 20:34:04 +01:00
|
|
|
/**
|
|
|
|
* All the edit elements, together (note that the question boxes are passed though)
|
|
|
|
* @param questionBoxes
|
|
|
|
* @param layerConfig
|
|
|
|
* @param tags
|
|
|
|
* @param state
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
private static createEditElements(
|
|
|
|
questionBoxes: Map<string, QuestionBox>,
|
|
|
|
layerConfig: LayerConfig,
|
|
|
|
tags: UIEventSource<any>,
|
2022-05-01 04:17:40 +02:00
|
|
|
state: FeaturePipelineState
|
2022-01-19 20:34:04 +01:00
|
|
|
): BaseUIElement {
|
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) => {
|
2022-01-19 20:34:04 +01:00
|
|
|
const feature = state.allElements.ContainingFeatures.get(id)
|
|
|
|
if (feature === undefined) {
|
|
|
|
return "This feature is not register in the state.allElements and cannot be moved"
|
|
|
|
}
|
2021-10-14 03:46:09 +02:00
|
|
|
return new MoveWizard(feature, 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, state, layerConfig.deletion))
|
2021-10-26 02:09:04 +02:00
|
|
|
).SetClass("text-base")
|
2022-09-08 21:40:48 +02:00
|
|
|
)
|
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, state))
|
2021-10-26 02:09:04 +02:00
|
|
|
).SetClass("text-base")
|
2022-09-08 21:40:48 +02:00
|
|
|
)
|
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(
|
2022-01-19 20:34:04 +01:00
|
|
|
state.osmConnection.userDetails
|
2021-07-03 14:35:44 +02:00
|
|
|
.map((ud) => ud.csCount)
|
|
|
|
.map(
|
|
|
|
(csCount) => {
|
|
|
|
if (
|
|
|
|
csCount <= Constants.userJourney.historyLinkVisible &&
|
2022-01-19 20:34:04 +01:00
|
|
|
state.featureSwitchIsDebugging.data == false &&
|
|
|
|
state.featureSwitchIsTesting.data === false
|
|
|
|
) {
|
2021-07-03 14:35:44 +02:00
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
|
2022-01-19 20:34:04 +01:00
|
|
|
return new TagRenderingAnswer(
|
|
|
|
tags,
|
|
|
|
SharedTagRenderings.SharedTagRendering.get("last_edit"),
|
|
|
|
state
|
|
|
|
)
|
|
|
|
},
|
|
|
|
[state.featureSwitchIsDebugging, state.featureSwitchIsTesting]
|
2022-09-08 21:40:48 +02:00
|
|
|
)
|
2021-06-27 20:52:25 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2021-07-28 15:14:13 +02:00
|
|
|
editElements.push(
|
2022-10-27 01:50:41 +02:00
|
|
|
Toggle.If(state.featureSwitchIsDebugging, () => {
|
|
|
|
const config_all_tags: TagRenderingConfig = new TagRenderingConfig(
|
2022-11-08 14:37:48 +01:00
|
|
|
{ render: "{all_tags()}" },
|
2022-10-27 01:50:41 +02:00
|
|
|
""
|
2022-09-27 18:48:02 +02:00
|
|
|
)
|
2022-10-27 01:50:41 +02:00
|
|
|
const config_download: TagRenderingConfig = new TagRenderingConfig(
|
2022-11-08 14:37:48 +01:00
|
|
|
{ render: "{export_as_geojson()}" },
|
2022-10-27 01:50:41 +02:00
|
|
|
""
|
|
|
|
)
|
|
|
|
const config_id: TagRenderingConfig = new TagRenderingConfig(
|
2022-11-08 14:37:48 +01:00
|
|
|
{ render: "{open_in_iD()}" },
|
2022-10-27 01:50:41 +02:00
|
|
|
""
|
|
|
|
)
|
|
|
|
|
|
|
|
return new Combine([
|
|
|
|
new TagRenderingAnswer(tags, config_all_tags, state),
|
|
|
|
new TagRenderingAnswer(tags, config_download, state),
|
|
|
|
new TagRenderingAnswer(tags, config_id, state),
|
|
|
|
"This is layer " + layerConfig.id,
|
|
|
|
])
|
|
|
|
})
|
2021-06-27 20:52:25 +02:00
|
|
|
)
|
2021-09-09 00:05:51 +02:00
|
|
|
|
2022-01-19 20:34:04 +01:00
|
|
|
return new Combine(editElements).SetClass("flex flex-col")
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|
|
|
|
}
|