2023-06-16 02:36:11 +02:00
|
|
|
<script lang="ts">
|
2023-10-07 03:07:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
import NextButton from "./Base/NextButton.svelte";
|
|
|
|
import { UIEventSource } from "../Logic/UIEventSource";
|
|
|
|
import ValidatedInput from "./InputElement/ValidatedInput.svelte";
|
|
|
|
import EditLayerState from "./Studio/EditLayerState";
|
|
|
|
import EditLayer from "./Studio/EditLayer.svelte";
|
|
|
|
import Loading from "../assets/svg/Loading.svelte";
|
2023-10-11 04:16:52 +02:00
|
|
|
import Marker from "./Map/Marker.svelte";
|
|
|
|
import { AllSharedLayers } from "../Customizations/AllSharedLayers";
|
|
|
|
import StudioServer from "./Studio/StudioServer";
|
|
|
|
import LoginToggle from "./Base/LoginToggle.svelte";
|
|
|
|
import { OsmConnection } from "../Logic/Osm/OsmConnection";
|
|
|
|
import { QueryParameters } from "../Logic/Web/QueryParameters";
|
2023-10-07 03:07:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
export let studioUrl = "http://127.0.0.1:1235";
|
2023-10-11 04:16:52 +02:00
|
|
|
const studio = new StudioServer(studioUrl);
|
|
|
|
let layers = UIEventSource.FromPromise(studio.fetchLayerOverview());
|
2023-10-07 03:07:32 +02:00
|
|
|
let state: undefined | "edit_layer" | "new_layer" | "edit_theme" | "new_theme" | "editing_layer" | "loading" = undefined;
|
|
|
|
|
2023-10-11 04:16:52 +02:00
|
|
|
let initialLayerConfig: { id: string };
|
2023-10-07 03:07:32 +02:00
|
|
|
let newLayerId = new UIEventSource<string>("");
|
|
|
|
let layerIdFeedback = new UIEventSource<string>(undefined);
|
|
|
|
newLayerId.addCallbackD(layerId => {
|
|
|
|
if (layerId === "") {
|
|
|
|
return;
|
|
|
|
}
|
2023-10-11 04:16:52 +02:00
|
|
|
if (layers.data.has(layerId)) {
|
2023-10-07 03:07:32 +02:00
|
|
|
layerIdFeedback.setData("This id is already used");
|
|
|
|
}
|
|
|
|
}, [layers]);
|
|
|
|
|
|
|
|
|
|
|
|
let editLayerState = new EditLayerState();
|
|
|
|
|
2023-10-11 04:16:52 +02:00
|
|
|
function fetchIconDescription(layerId): any {
|
|
|
|
const icon = AllSharedLayers.getSharedLayersConfigs().get(layerId)?._layerIcon;
|
|
|
|
console.log(icon);
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
let osmConnection = new OsmConnection( new OsmConnection({
|
|
|
|
oauth_token: QueryParameters.GetQueryParameter(
|
|
|
|
"oauth_token",
|
|
|
|
undefined,
|
|
|
|
"Used to complete the login"
|
|
|
|
),
|
|
|
|
}))
|
|
|
|
|
2023-06-16 02:36:11 +02:00
|
|
|
</script>
|
2023-10-11 04:16:52 +02:00
|
|
|
|
|
|
|
<LoginToggle state={{osmConnection}}>
|
|
|
|
<div slot="not-logged-in" >
|
|
|
|
<NextButton clss="primary">
|
|
|
|
Please log in to use MapComplete Studio
|
|
|
|
</NextButton>
|
|
|
|
</div>
|
2023-10-07 03:07:32 +02:00
|
|
|
{#if state === undefined}
|
|
|
|
<h1>MapComplete Studio</h1>
|
|
|
|
<div class="w-full flex flex-col">
|
2023-06-16 02:36:11 +02:00
|
|
|
|
2023-10-07 03:07:32 +02:00
|
|
|
<NextButton on:click={() => state = "edit_layer"}>
|
|
|
|
Edit an existing layer
|
|
|
|
</NextButton>
|
|
|
|
<NextButton on:click={() => state = "new_layer"}>
|
|
|
|
Create a new layer
|
|
|
|
</NextButton>
|
|
|
|
<NextButton on:click={() => state = "edit_theme"}>
|
|
|
|
Edit a theme
|
|
|
|
</NextButton>
|
|
|
|
<NextButton on:click={() => state = "new_theme"}>
|
|
|
|
Create a new theme
|
|
|
|
</NextButton>
|
|
|
|
</div>
|
|
|
|
{:else if state === "edit_layer"}
|
|
|
|
<div class="flex flex-wrap">
|
2023-10-11 04:16:52 +02:00
|
|
|
{#each Array.from($layers) as layerId}
|
2023-10-07 03:07:32 +02:00
|
|
|
<NextButton clss="small" on:click={async () => {
|
|
|
|
console.log("Editing layer",layerId)
|
|
|
|
state = "loading"
|
2023-10-11 04:16:52 +02:00
|
|
|
initialLayerConfig = await studio.fetchLayer(layerId)
|
2023-10-07 03:07:32 +02:00
|
|
|
state = "editing_layer"
|
|
|
|
}}>
|
2023-10-11 04:16:52 +02:00
|
|
|
<div class="w-4 h-4 mr-1">
|
|
|
|
<Marker icons={fetchIconDescription(layerId)} />
|
|
|
|
</div>
|
2023-10-07 03:07:32 +02:00
|
|
|
{layerId}
|
|
|
|
</NextButton>
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
{:else if state === "new_layer"}
|
|
|
|
<ValidatedInput type="id" value={newLayerId} feedback={layerIdFeedback} />
|
|
|
|
{#if $layerIdFeedback !== undefined}
|
|
|
|
<div class="alert">
|
|
|
|
{$layerIdFeedback}
|
|
|
|
</div>
|
|
|
|
{:else }
|
2023-10-11 04:16:52 +02:00
|
|
|
<NextButton on:click={async () => {
|
|
|
|
state = "loading"
|
|
|
|
const id = newLayerId.data
|
|
|
|
const createdBy = osmConnection.userDetails.data.name
|
|
|
|
|
|
|
|
const loaded = await studio.fetchLayer(id, true)
|
|
|
|
initialLayerConfig = loaded ?? {id, credits: createdBy};
|
|
|
|
state = "editing_layer"}}>
|
2023-10-07 03:07:32 +02:00
|
|
|
Create this layer
|
|
|
|
</NextButton>
|
|
|
|
{/if}
|
|
|
|
{:else if state === "loading"}
|
2023-10-11 04:16:52 +02:00
|
|
|
<div class="w-8 h-8">
|
|
|
|
<Loading />
|
|
|
|
</div>
|
2023-10-07 03:07:32 +02:00
|
|
|
{:else if state === "editing_layer"}
|
|
|
|
<EditLayer {initialLayerConfig} />
|
|
|
|
{/if}
|
2023-10-11 04:16:52 +02:00
|
|
|
</LoginToggle>
|