| 
									
										
										
										
											2023-10-25 00:03:51 +02:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |   import type { ConfigMeta } from "./configMeta" | 
					
						
							| 
									
										
										
										
											2024-08-02 19:06:14 +02:00
										 |  |  |   import EditLayerState, { EditJsonState } from "./EditLayerState" | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |   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" | 
					
						
							| 
									
										
										
										
											2024-08-14 13:53:56 +02:00
										 |  |  |   import type { QuestionableTagRenderingConfigJson } from "../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson.js" | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |   import type { TagRenderingConfigJson } from "../../Models/ThemeConfig/Json/TagRenderingConfigJson" | 
					
						
							|  |  |  |   import FromHtml from "../Base/FromHtml.svelte" | 
					
						
							|  |  |  |   import ShowConversionMessage from "./ShowConversionMessage.svelte" | 
					
						
							|  |  |  |   import NextButton from "../Base/NextButton.svelte" | 
					
						
							| 
									
										
										
										
											2024-04-27 23:44:54 +02:00
										 |  |  |   import Markdown from "../Base/Markdown.svelte" | 
					
						
							| 
									
										
										
										
											2023-10-25 00:03:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |   export let state: EditLayerState | 
					
						
							|  |  |  |   export let path: ReadonlyArray<string | number> | 
					
						
							|  |  |  |   export let schema: ConfigMeta | 
					
						
							|  |  |  |   let value = state.getStoreFor(path) | 
					
						
							| 
									
										
										
										
											2023-10-25 00:03:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |   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-11-09 16:30:26 +01:00
										 |  |  |         perId[label] = (perId[label] ?? []).concat(tagRendering) | 
					
						
							| 
									
										
										
										
											2023-10-25 00:03:51 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |     perId[tagRendering.id] = [tagRendering] | 
					
						
							| 
									
										
										
										
											2023-10-25 00:03:51 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |   let configJson: Store<QuestionableTagRenderingConfigJson[]> = value.map((x) => { | 
					
						
							| 
									
										
										
										
											2024-08-24 23:41:09 +02:00
										 |  |  |     if(x === undefined){ | 
					
						
							|  |  |  |       console.log("No config found for ",path) | 
					
						
							|  |  |  |       return [] | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-10-25 00:03:51 +02:00
										 |  |  |     if (typeof x === "string") { | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |       return perId[x] | 
					
						
							| 
									
										
										
										
											2023-10-25 00:03:51 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2024-08-02 19:06:14 +02:00
										 |  |  |       return <any>[x] | 
					
						
							| 
									
										
										
										
											2023-10-25 00:03:51 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |   }) | 
					
						
							|  |  |  |   let configs: Store<TagRenderingConfig[]> = configJson.map((configs) => { | 
					
						
							| 
									
										
										
										
											2023-11-05 12:05:00 +01:00
										 |  |  |     if (!configs) { | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |       return [{ error: "No configuartions found" }] | 
					
						
							| 
									
										
										
										
											2023-11-02 04:35:32 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-08-24 23:41:09 +02:00
										 |  |  |     console.log("Configs are", configs) | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |     return configs.map((config) => { | 
					
						
							| 
									
										
										
										
											2024-08-02 19:06:14 +02:00
										 |  |  |       if (config["builtin"]) { | 
					
						
							|  |  |  |         let override = "" | 
					
						
							|  |  |  |         if (config["override"]) { | 
					
						
							| 
									
										
										
										
											2024-08-14 13:53:56 +02:00
										 |  |  |           override = | 
					
						
							|  |  |  |             ". Some items are changed with an override. Editing this is not yet supported with Studio." | 
					
						
							| 
									
										
										
										
											2024-08-02 19:06:14 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         return new TagRenderingConfig({ | 
					
						
							|  |  |  |           render: { | 
					
						
							| 
									
										
										
										
											2024-08-14 13:53:56 +02:00
										 |  |  |             en: "This question reuses <b>" + JSON.stringify(config["builtin"]) + "</b>" + override, | 
					
						
							| 
									
										
										
										
											2024-08-02 19:06:14 +02:00
										 |  |  |           }, | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2023-11-05 12:05:00 +01:00
										 |  |  |       try { | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |         return new TagRenderingConfig(config) | 
					
						
							| 
									
										
										
										
											2023-11-05 12:05:00 +01:00
										 |  |  |       } catch (e) { | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |         return { error: e } | 
					
						
							| 
									
										
										
										
											2023-11-05 12:05:00 +01:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							| 
									
										
										
										
											2023-10-25 00:03:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |   let tags = state.testTags | 
					
						
							| 
									
										
										
										
											2023-10-25 00:03:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |   let messages = state.messagesFor(path) | 
					
						
							| 
									
										
										
										
											2023-10-25 00:03:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |   let description = schema.description | 
					
						
							| 
									
										
										
										
											2023-10-25 00:03:51 +02:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <div class="flex"> | 
					
						
							| 
									
										
										
										
											2024-06-26 11:57:18 +02:00
										 |  |  |   <div class="m-4 flex w-full flex-col"> | 
					
						
							| 
									
										
										
										
											2024-08-14 13:53:56 +02:00
										 |  |  |     {#if $configJson.some((config) => config["builtin"] !== undefined)} | 
					
						
							|  |  |  |       <div class="interactive rounded-2xl p-2"> | 
					
						
							|  |  |  |         This question uses an advanced 'builtin'+'override' construction in the source code. Editing | 
					
						
							|  |  |  |         this with Studio is not supported. | 
					
						
							| 
									
										
										
										
											2024-08-02 19:06:14 +02:00
										 |  |  |       </div> | 
					
						
							|  |  |  |     {:else} | 
					
						
							|  |  |  |       <NextButton clss="primary" on:click={() => state.highlightedItem.setData({ path, schema })}> | 
					
						
							|  |  |  |         {#if schema.hints.question} | 
					
						
							|  |  |  |           {schema.hints.question} | 
					
						
							|  |  |  |         {/if} | 
					
						
							|  |  |  |       </NextButton> | 
					
						
							|  |  |  |     {/if} | 
					
						
							| 
									
										
										
										
											2023-11-02 04:35:32 +01:00
										 |  |  |     {#if description} | 
					
						
							| 
									
										
										
										
											2024-06-16 16:06:26 +02:00
										 |  |  |       <Markdown 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} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |     <slot class="my-4 self-end" /> | 
					
						
							| 
									
										
										
										
											2023-10-25 00:03:51 +02:00
										 |  |  |   </div> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |   <div class="m-4 flex w-full flex-col"> | 
					
						
							| 
									
										
										
										
											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> | 
					
						
							| 
									
										
										
										
											2024-08-02 19:06:14 +02:00
										 |  |  |         {JSON.stringify($value)} | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |       {: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 | 
					
						
							| 
									
										
										
										
											2023-11-05 12:05:00 +01:00
										 |  |  |       {:else} | 
					
						
							| 
									
										
										
										
											2023-11-09 16:30:26 +01:00
										 |  |  |         <TagRenderingEditable | 
					
						
							|  |  |  |           selectedElement={state.exampleFeature} | 
					
						
							|  |  |  |           {config} | 
					
						
							|  |  |  |           editingEnabled={new ImmutableStore(true)} | 
					
						
							|  |  |  |           {state} | 
					
						
							|  |  |  |           {tags} | 
					
						
							|  |  |  |         /> | 
					
						
							| 
									
										
										
										
											2023-11-05 12:05:00 +01:00
										 |  |  |       {/if} | 
					
						
							| 
									
										
										
										
											2023-10-25 00:03:51 +02:00
										 |  |  |     {/each} | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | </div> |