forked from MapComplete/MapComplete
Studio: add delete button for layers
This commit is contained in:
parent
22095f4640
commit
eb5cc4d78c
4 changed files with 39 additions and 17 deletions
|
@ -9,7 +9,7 @@
|
||||||
import { Utils } from "../../Utils"
|
import { Utils } from "../../Utils"
|
||||||
import type { ConversionMessage } from "../../Models/ThemeConfig/Conversion/Conversion"
|
import type { ConversionMessage } from "../../Models/ThemeConfig/Conversion/Conversion"
|
||||||
import ErrorIndicatorForRegion from "./ErrorIndicatorForRegion.svelte"
|
import ErrorIndicatorForRegion from "./ErrorIndicatorForRegion.svelte"
|
||||||
import { ChevronRightIcon } from "@rgossiaux/svelte-heroicons/solid"
|
import { ChevronRightIcon, TrashIcon } from "@rgossiaux/svelte-heroicons/solid"
|
||||||
import SchemaBasedInput from "./SchemaBasedInput.svelte"
|
import SchemaBasedInput from "./SchemaBasedInput.svelte"
|
||||||
import FloatOver from "../Base/FloatOver.svelte"
|
import FloatOver from "../Base/FloatOver.svelte"
|
||||||
import TagRenderingInput from "./TagRenderingInput.svelte"
|
import TagRenderingInput from "./TagRenderingInput.svelte"
|
||||||
|
@ -21,6 +21,7 @@
|
||||||
const layerSchema: ConfigMeta[] = <any>layerSchemaRaw
|
const layerSchema: ConfigMeta[] = <any>layerSchemaRaw
|
||||||
|
|
||||||
export let state: EditLayerState
|
export let state: EditLayerState
|
||||||
|
export let backToStudio: () => void
|
||||||
let messages = state.messages
|
let messages = state.messages
|
||||||
let hasErrors = messages.mapD(
|
let hasErrors = messages.mapD(
|
||||||
(m: ConversionMessage[]) => m.filter((m) => m.level === "error").length
|
(m: ConversionMessage[]) => m.filter((m) => m.level === "error").length
|
||||||
|
@ -72,6 +73,10 @@
|
||||||
})
|
})
|
||||||
|
|
||||||
let highlightedItem: UIEventSource<HighlightedTagRendering> = state.highlightedItem
|
let highlightedItem: UIEventSource<HighlightedTagRendering> = state.highlightedItem
|
||||||
|
function deleteLayer() {
|
||||||
|
state.delete()
|
||||||
|
backToStudio()
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex h-screen flex-col">
|
<div class="flex h-screen flex-col">
|
||||||
|
@ -113,6 +118,12 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col" slot="content0">
|
<div class="flex flex-col" slot="content0">
|
||||||
<Region {state} configs={perRegion["Basic"]} />
|
<Region {state} configs={perRegion["Basic"]} />
|
||||||
|
<div class="mt-12">
|
||||||
|
|
||||||
|
<button on:click={() => deleteLayer()} class="small" >
|
||||||
|
<TrashIcon class="h-6 w-6"/> Delete this layer
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div slot="title1" class="flex">
|
<div slot="title1" class="flex">
|
||||||
|
|
|
@ -107,6 +107,9 @@ export abstract class EditJsonState<T> {
|
||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async delete(){
|
||||||
|
await this.server.delete(this.getId().data, this.category)
|
||||||
|
}
|
||||||
public getStoreFor<T>(path: ReadonlyArray<string | number>): UIEventSource<T | undefined> {
|
public getStoreFor<T>(path: ReadonlyArray<string | number>): UIEventSource<T | undefined> {
|
||||||
const key = path.join(".")
|
const key = path.join(".")
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,14 @@ export default class StudioServer {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async delete(id: string, category: "layers" | "themes") {
|
||||||
|
if (id === undefined || id === "") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await fetch(this.urlFor(id, category), {
|
||||||
|
method: "DELETE"
|
||||||
|
})
|
||||||
|
}
|
||||||
async update(id: string, config: string, category: "layers" | "themes") {
|
async update(id: string, config: string, category: "layers" | "themes") {
|
||||||
if (id === undefined || id === "") {
|
if (id === undefined || id === "") {
|
||||||
return
|
return
|
||||||
|
|
|
@ -260,7 +260,7 @@
|
||||||
<Loading />
|
<Loading />
|
||||||
</div>
|
</div>
|
||||||
{:else if state === "editing_layer"}
|
{:else if state === "editing_layer"}
|
||||||
<EditLayer state={editLayerState}>
|
<EditLayer state={editLayerState} backToStudio={() => {state = undefined}}>
|
||||||
<BackButton
|
<BackButton
|
||||||
clss="small p-1"
|
clss="small p-1"
|
||||||
imageClass="w-8 h-8"
|
imageClass="w-8 h-8"
|
||||||
|
@ -284,22 +284,23 @@
|
||||||
</BackButton>
|
</BackButton>
|
||||||
</EditTheme>
|
</EditTheme>
|
||||||
{/if}
|
{/if}
|
||||||
</LoginToggle>
|
|
||||||
</If>
|
|
||||||
|
|
||||||
{#if { intro, tagrenderings: intro_tagrenderings }[$showIntro]?.sections}
|
{#if { intro, tagrenderings: intro_tagrenderings }[$showIntro]?.sections}
|
||||||
<FloatOver
|
<FloatOver
|
||||||
on:close={() => {
|
on:close={() => {
|
||||||
showIntro.setData("no")
|
showIntro.setData("no")
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div class="flex h-full p-4 pr-12">
|
<div class="flex h-full p-4 pr-12">
|
||||||
<Walkthrough
|
<Walkthrough
|
||||||
pages={{ intro, tagrenderings: intro_tagrenderings }[$showIntro]?.sections}
|
pages={{ intro, tagrenderings: intro_tagrenderings }[$showIntro]?.sections}
|
||||||
on:done={() => {
|
on:done={() => {
|
||||||
showIntro.setData("no")
|
showIntro.setData("no")
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</FloatOver>
|
</FloatOver>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
</LoginToggle>
|
||||||
|
</If>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue