2023-10-25 00:03:51 +02:00
|
|
|
<script lang="ts">
|
|
|
|
import type { ConfigMeta } from "./configMeta";
|
|
|
|
import EditLayerState from "./EditLayerState";
|
|
|
|
import * as questions from "../../assets/generated/layers/questions.json";
|
|
|
|
import { ImmutableStore, Store } from "../../Logic/UIEventSource";
|
|
|
|
import TagRenderingEditable from "../Popup/TagRendering/TagRenderingEditable.svelte";
|
|
|
|
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
|
2023-11-02 04:35:32 +01:00
|
|
|
import nmd from "nano-markdown";
|
2023-10-25 00:03:51 +02:00
|
|
|
import type {
|
|
|
|
QuestionableTagRenderingConfigJson
|
|
|
|
} from "../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson.js";
|
|
|
|
import type { TagRenderingConfigJson } from "../../Models/ThemeConfig/Json/TagRenderingConfigJson";
|
|
|
|
import FromHtml from "../Base/FromHtml.svelte";
|
2023-11-03 02:04:42 +01:00
|
|
|
import ShowConversionMessage from "./ShowConversionMessage.svelte";
|
|
|
|
import NextButton from "../Base/NextButton.svelte";
|
2023-10-25 00:03:51 +02:00
|
|
|
|
|
|
|
export let state: EditLayerState;
|
|
|
|
export let path: ReadonlyArray<string | number>;
|
|
|
|
export let schema: ConfigMeta;
|
|
|
|
let value = state.getStoreFor(path);
|
|
|
|
|
|
|
|
let perId: Record<string, TagRenderingConfigJson[]> = {};
|
2023-11-05 12:05:00 +01:00
|
|
|
for (let tagRendering of questions.tagRenderings) {
|
2023-10-25 00:03:51 +02:00
|
|
|
if (tagRendering.labels) {
|
2023-11-05 12:05:00 +01:00
|
|
|
for (let label of tagRendering.labels) {
|
2023-10-25 00:03:51 +02:00
|
|
|
perId[label] = (perId[label] ?? []).concat(tagRendering);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
perId[tagRendering.id] = [tagRendering];
|
|
|
|
}
|
|
|
|
|
|
|
|
let configJson: Store<QuestionableTagRenderingConfigJson[]> = value.map(x => {
|
|
|
|
if (typeof x === "string") {
|
|
|
|
return perId[x];
|
|
|
|
} else {
|
|
|
|
return [x];
|
|
|
|
}
|
|
|
|
});
|
2023-11-05 12:05:00 +01:00
|
|
|
let configs: Store<TagRenderingConfig[]> = configJson.map(configs => {
|
|
|
|
if (!configs) {
|
|
|
|
return [{ error: "No configuartions found" }];
|
2023-11-02 04:35:32 +01:00
|
|
|
}
|
2023-11-05 12:05:00 +01:00
|
|
|
console.log("Regenerating configs");
|
|
|
|
return configs.map(config => {
|
|
|
|
try {
|
|
|
|
return new TagRenderingConfig(config);
|
|
|
|
} catch (e) {
|
|
|
|
return { error: e };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2023-10-25 00:03:51 +02:00
|
|
|
let id: Store<string> = value.mapD(c => {
|
2023-11-02 04:35:32 +01:00
|
|
|
if (c?.id) {
|
2023-10-25 00:03:51 +02:00
|
|
|
return c.id;
|
|
|
|
}
|
|
|
|
if (typeof c === "string") {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
});
|
|
|
|
|
|
|
|
let tags = state.testTags;
|
|
|
|
|
|
|
|
let messages = state.messagesFor(path);
|
|
|
|
|
2023-11-05 12:05:00 +01:00
|
|
|
let description = schema.description;
|
|
|
|
if (description) {
|
|
|
|
try {
|
|
|
|
description = nmd(description);
|
|
|
|
} catch (e) {
|
|
|
|
console.error("Could not convert description to markdown", { description });
|
2023-11-02 04:35:32 +01:00
|
|
|
}
|
|
|
|
}
|
2023-10-25 00:03:51 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="flex">
|
|
|
|
|
|
|
|
<div class="flex flex-col interactive border-interactive m-4 w-full">
|
|
|
|
|
|
|
|
{#if $id}
|
|
|
|
TagRendering {$id}
|
|
|
|
{/if}
|
2023-11-03 02:04:42 +01:00
|
|
|
<NextButton clss="primary" on:click={() => state.highlightedItem.setData({path, schema})}>
|
2023-10-25 00:03:51 +02:00
|
|
|
{#if schema.hints.question}
|
|
|
|
{schema.hints.question}
|
|
|
|
{/if}
|
2023-11-03 02:04:42 +01:00
|
|
|
</NextButton>
|
2023-11-02 04:35:32 +01:00
|
|
|
{#if description}
|
|
|
|
<FromHtml src={description} />
|
2023-10-25 00:03:51 +02:00
|
|
|
{/if}
|
|
|
|
{#each $messages as message}
|
2023-11-05 12:05:00 +01:00
|
|
|
<ShowConversionMessage {message} />
|
2023-10-25 00:03:51 +02:00
|
|
|
{/each}
|
|
|
|
|
|
|
|
<slot class="self-end my-4"></slot>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="flex flex-col w-full m-4">
|
2023-11-03 02:04:42 +01:00
|
|
|
<h3>Preview of this question</h3>
|
2023-10-25 00:03:51 +02:00
|
|
|
{#each $configs as config}
|
2023-11-05 12:05:00 +01:00
|
|
|
{#if config.error !== undefined}
|
|
|
|
<div class="alert">Could not create a preview of this tagRendering: {config.error}</div>
|
|
|
|
{:else}
|
|
|
|
{#if config.condition && !config.condition.matchesProperties($tags)}
|
|
|
|
This tagRendering is currently not shown. It will appear if the feature matches the condition
|
|
|
|
<b>
|
|
|
|
<FromHtml src={config.condition.asHumanString(true, false, {})} />
|
|
|
|
</b>
|
|
|
|
|
|
|
|
Try to answer the relevant question above
|
|
|
|
{:else if config.metacondition && !config.metacondition.matchesProperties($tags)}
|
|
|
|
This tagRendering is currently not shown. It will appear if the feature matches the metacondition
|
|
|
|
<b>
|
|
|
|
<FromHtml src={config.metacondition.asHumanString(true, false, {})} />
|
|
|
|
</b>
|
|
|
|
For a breakdown of usable meta conditions, go to a mapcomplete theme > settings and enable debug-data. The meta-tags will appear at the bottom
|
|
|
|
{:else}
|
|
|
|
<TagRenderingEditable
|
|
|
|
selectedElement={state.exampleFeature}
|
|
|
|
config={config} editingEnabled={new ImmutableStore(true)} showQuestionIfUnknown={true}
|
|
|
|
{state}
|
|
|
|
{tags}></TagRenderingEditable>
|
|
|
|
{/if}
|
|
|
|
{/if}
|
2023-10-25 00:03:51 +02:00
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|