From 7520c44059269536df20079c153d43484cce11b1 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Thu, 26 Oct 2023 13:58:45 +0200 Subject: [PATCH] Studio: WIP: add theme edit possibility --- src/UI/Studio/ChooseLayerToEdit.svelte | 33 +-- src/UI/Studio/EditLayer.svelte | 25 +- src/UI/Studio/EditLayerState.ts | 258 +++++++++++--------- src/UI/Studio/EditTheme.svelte | 64 +++++ src/UI/Studio/ShowConversionMessages.svelte | 23 ++ src/UI/Studio/StudioServer.ts | 24 +- 6 files changed, 275 insertions(+), 152 deletions(-) diff --git a/src/UI/Studio/ChooseLayerToEdit.svelte b/src/UI/Studio/ChooseLayerToEdit.svelte index 14c0267aa..cb1fffca8 100644 --- a/src/UI/Studio/ChooseLayerToEdit.svelte +++ b/src/UI/Studio/ChooseLayerToEdit.svelte @@ -3,26 +3,31 @@ import NextButton from "../Base/NextButton.svelte"; import { createEventDispatcher } from "svelte"; import { AllSharedLayers } from "../../Customizations/AllSharedLayers"; + import { AllKnownLayouts, AllKnownLayoutsLazy } from "../../Customizations/AllKnownLayouts"; - export let layerIds : { id: string }[] - const dispatch = createEventDispatcher<{layerSelected: string}>() + export let layerIds: { id: string }[]; + export let category: "layers" | "themes" = "layers"; + const dispatch = createEventDispatcher<{ layerSelected: string }>(); function fetchIconDescription(layerId): any { + if(category === "themes"){ + return AllKnownLayouts.allKnownLayouts.get(layerId).icon + } return AllSharedLayers.getSharedLayersConfigs().get(layerId)?._layerIcon; } {#if layerIds.length > 0} - -
- {#each Array.from(layerIds) as layer} - dispatch("layerSelected", layer.id)}> -
- -
- {layer.id} -
- {/each} -
- {/if} + +
+ {#each Array.from(layerIds) as layer} + dispatch("layerSelected", layer.id)}> +
+ +
+ {layer.id} +
+ {/each} +
+{/if} diff --git a/src/UI/Studio/EditLayer.svelte b/src/UI/Studio/EditLayer.svelte index 93160b730..93de221dc 100644 --- a/src/UI/Studio/EditLayer.svelte +++ b/src/UI/Studio/EditLayer.svelte @@ -1,13 +1,12 @@ + +
+ +

Editing theme {$title}

+ {#if $hasErrors > 0} +
{$hasErrors} errors detected
+ {:else} + + Try it out + + + {/if} +
+ +
+ {Object.keys(perRegion).join(";")} + +
Basic properties
+
+ + +
+
Feature switches
+
+ +
+
Configuration file
+
+
+ {JSON.stringify($config)} +
+ + + +
+
+
+ diff --git a/src/UI/Studio/ShowConversionMessages.svelte b/src/UI/Studio/ShowConversionMessages.svelte index e69de29bb..33915e991 100644 --- a/src/UI/Studio/ShowConversionMessages.svelte +++ b/src/UI/Studio/ShowConversionMessages.svelte @@ -0,0 +1,23 @@ + + +{#if messages.length === 0} +
+ No errors, warnings or messages +
+ {/if} + +{#each messages as message} +
  • + {message.level} + {message.context.path.join(".")} + {message.message} + + {message.context.operation.join(".")} + +
  • +{/each} diff --git a/src/UI/Studio/StudioServer.ts b/src/UI/Studio/StudioServer.ts index e074dbeff..7d1ef4688 100644 --- a/src/UI/Studio/StudioServer.ts +++ b/src/UI/Studio/StudioServer.ts @@ -12,10 +12,11 @@ export default class StudioServer { this._userId = userId } - public async fetchLayerOverview(): Promise< + public async fetchOverview(): Promise< { id: string owner: number + category: "layers" | "themes" }[] > { const uid = this._userId.data @@ -29,6 +30,7 @@ export default class StudioServer { const layerOverview: { id: string owner: number | undefined + category: "layers" | "themes" }[] = [] for (let file of allFiles) { let owner = undefined @@ -36,31 +38,29 @@ export default class StudioServer { owner = uid file = file.substring(file.indexOf("/") + 1) } - if (!file.startsWith("layers/")) { - continue - } + const category = <"layers" | "themes">file.substring(0, file.indexOf("/")) const id = file.substring(file.lastIndexOf("/") + 1, file.length - ".json".length) if (Constants.priviliged_layers.indexOf(id) > 0) { continue } - layerOverview.push({ id, owner }) + layerOverview.push({ id, owner, category }) } return layerOverview } - async fetchLayer(layerId: string): Promise { + async fetch(layerId: string, category: "layers" | "themes"): Promise { try { - return await Utils.downloadJson(this.layerUrl(layerId)) + return await Utils.downloadJson(this.urlFor(layerId, category)) } catch (e) { return undefined } } - async updateLayer(id: string, config: string) { + async update(id: string, config: string, category: "layers" | "themes") { if (id === undefined || id === "") { return } - await fetch(this.layerUrl(id), { + await fetch(this.urlFor(id, category), { method: "POST", headers: { "Content-Type": "application/json;charset=utf-8", @@ -70,8 +70,12 @@ export default class StudioServer { } public layerUrl(id: string) { + return this.urlFor(id, "layers") + } + + public urlFor(id: string, category: "layers" | "themes") { const uid = this._userId.data const uidStr = uid !== undefined ? "/" + uid : "" - return `${this.url}${uidStr}/layers/${id}/${id}.json` + return `${this.url}${uidStr}/${category}/${id}/${id}.json` } }