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";
|
2023-10-24 22:01:10 +02:00
|
|
|
import { Store, UIEventSource } from "../Logic/UIEventSource";
|
2023-10-30 13:45:44 +01:00
|
|
|
import EditLayerState, { EditThemeState } from "./Studio/EditLayerState";
|
2023-10-07 03:07:32 +02:00
|
|
|
import EditLayer from "./Studio/EditLayer.svelte";
|
|
|
|
import Loading from "../assets/svg/Loading.svelte";
|
2023-10-11 04:16:52 +02:00
|
|
|
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
|
|
|
|
2023-10-13 18:46:56 +02:00
|
|
|
import layerSchemaRaw from "../../src/assets/schemas/layerconfigmeta.json";
|
2023-10-30 13:45:44 +01:00
|
|
|
import layoutSchemaRaw from "../../src/assets/schemas/layoutconfigmeta.json";
|
|
|
|
|
2023-10-16 15:06:50 +02:00
|
|
|
import If from "./Base/If.svelte";
|
2023-10-21 09:35:54 +02:00
|
|
|
import BackButton from "./Base/BackButton.svelte";
|
2023-10-24 22:01:10 +02:00
|
|
|
import ChooseLayerToEdit from "./Studio/ChooseLayerToEdit.svelte";
|
|
|
|
import { LocalStorageSource } from "../Logic/Web/LocalStorageSource";
|
|
|
|
import FloatOver from "./Base/FloatOver.svelte";
|
|
|
|
import Walkthrough from "./Walkthrough/Walkthrough.svelte";
|
|
|
|
import * as intro from "../assets/studio_introduction.json";
|
|
|
|
import { QuestionMarkCircleIcon } from "@babeard/svelte-heroicons/mini";
|
|
|
|
import type { ConfigMeta } from "./Studio/configMeta";
|
2023-10-30 13:45:44 +01:00
|
|
|
import EditTheme from "./Studio/EditTheme.svelte";
|
2023-11-02 04:35:32 +01:00
|
|
|
import * as meta from "../../package.json"
|
|
|
|
|
|
|
|
export let studioUrl = window.location.hostname === "127.0.0.2" ? "http://127.0.0.1:1235" : "https://studio.mapcomplete.org";
|
2023-10-07 03:07:32 +02:00
|
|
|
|
2023-10-24 22:01:10 +02:00
|
|
|
let osmConnection = new OsmConnection(new OsmConnection({
|
|
|
|
oauth_token: QueryParameters.GetQueryParameter(
|
|
|
|
"oauth_token",
|
|
|
|
undefined,
|
|
|
|
"Used to complete the login"
|
|
|
|
)
|
|
|
|
}));
|
|
|
|
const createdBy = osmConnection.userDetails.data.name;
|
|
|
|
const uid = osmConnection.userDetails.map(ud => ud?.uid);
|
|
|
|
const studio = new StudioServer(studioUrl, uid);
|
2023-10-07 03:07:32 +02:00
|
|
|
|
2023-10-30 13:45:44 +01:00
|
|
|
let layersWithErr = UIEventSource.FromPromiseWithErr(studio.fetchOverview());
|
|
|
|
let layers: Store<{ owner: number }[]> = layersWithErr.mapD(l => l.success?.filter(l => l.category === "layers"));
|
2023-10-24 22:01:10 +02:00
|
|
|
let selfLayers = layers.mapD(ls => ls.filter(l => l.owner === uid.data), [uid]);
|
2023-10-30 13:45:44 +01:00
|
|
|
let otherLayers = layers.mapD(ls => ls.filter(l => l.owner !== undefined && l.owner !== uid.data), [uid]);
|
|
|
|
let officialLayers = layers.mapD(ls => ls.filter(l => l.owner === undefined), [uid]);
|
|
|
|
|
|
|
|
|
|
|
|
let themes: Store<{ owner: number }[]> = layersWithErr.mapD(l => l.success?.filter(l => l.category === "themes"));
|
|
|
|
let selfThemes = themes.mapD(ls => ls.filter(l => l.owner === uid.data), [uid]);
|
|
|
|
let otherThemes = themes.mapD(ls => ls.filter(l => l.owner !== undefined && l.owner !== uid.data), [uid]);
|
|
|
|
let officialThemes = themes.mapD(ls => ls.filter(l => l.owner === undefined), [uid]);
|
2023-10-24 22:01:10 +02:00
|
|
|
|
2023-10-30 13:45:44 +01:00
|
|
|
let state: undefined | "edit_layer" | "edit_theme" | "editing_layer" | "editing_theme" | "loading" = undefined;
|
2023-10-07 03:07:32 +02:00
|
|
|
|
2023-10-13 18:46:56 +02:00
|
|
|
const layerSchema: ConfigMeta[] = <any>layerSchemaRaw;
|
2023-10-24 22:01:10 +02:00
|
|
|
let editLayerState = new EditLayerState(layerSchema, studio, osmConnection);
|
2023-10-30 13:45:44 +01:00
|
|
|
|
|
|
|
const layoutSchema: ConfigMeta[] = <any>layoutSchemaRaw;
|
|
|
|
let editThemeState = new EditThemeState(layoutSchema, studio);
|
|
|
|
|
2023-10-21 09:35:54 +02:00
|
|
|
let layerId = editLayerState.configuration.map(layerConfig => layerConfig.id);
|
2023-10-07 03:07:32 +02:00
|
|
|
|
2023-10-24 22:01:10 +02:00
|
|
|
let showIntro = UIEventSource.asBoolean(LocalStorageSource.Get("studio-show-intro", "true"));
|
2023-11-02 04:35:32 +01:00
|
|
|
const version = meta.version
|
2023-10-24 22:01:10 +02:00
|
|
|
async function editLayer(event: Event) {
|
2023-10-30 13:45:44 +01:00
|
|
|
const layerId: {owner: number, id: string} = event.detail;
|
2023-10-24 22:01:10 +02:00
|
|
|
state = "loading";
|
2023-11-02 04:35:32 +01:00
|
|
|
editLayerState.startSavingUpdates(false)
|
2023-10-30 13:45:44 +01:00
|
|
|
editLayerState.configuration.setData(await studio.fetch(layerId.id, "layers", layerId.owner));
|
2023-11-02 04:35:32 +01:00
|
|
|
editLayerState.startSavingUpdates()
|
2023-10-24 22:01:10 +02:00
|
|
|
state = "editing_layer";
|
2023-10-13 18:46:56 +02:00
|
|
|
}
|
|
|
|
|
2023-10-30 13:45:44 +01:00
|
|
|
async function editTheme(event: Event) {
|
|
|
|
const id : {id: string, owner: number} = event.detail;
|
|
|
|
state = "loading";
|
2023-11-02 04:35:32 +01:00
|
|
|
editThemeState.startSavingUpdates(false)
|
2023-10-30 13:45:44 +01:00
|
|
|
editThemeState.configuration.setData(await studio.fetch(id.id, "themes", id.owner));
|
2023-11-02 04:35:32 +01:00
|
|
|
editThemeState.startSavingUpdates()
|
2023-10-30 13:45:44 +01:00
|
|
|
state = "editing_theme";
|
|
|
|
}
|
|
|
|
|
2023-10-13 18:46:56 +02:00
|
|
|
async function createNewLayer() {
|
|
|
|
state = "loading";
|
2023-10-30 13:45:44 +01:00
|
|
|
const initialLayerConfig = {
|
2023-10-24 22:01:10 +02:00
|
|
|
credits: createdBy,
|
|
|
|
minzoom: 15,
|
|
|
|
pointRendering: [
|
|
|
|
{
|
|
|
|
location: ["point", "centroid"],
|
|
|
|
marker: [{
|
|
|
|
icon: "circle",
|
|
|
|
color: "white"
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
lineRendering: [{
|
|
|
|
width: 1,
|
|
|
|
color: "blue"
|
|
|
|
}]
|
|
|
|
};
|
2023-10-30 13:45:44 +01:00
|
|
|
editLayerState.configuration.setData(initialLayerConfig);
|
2023-10-13 18:46:56 +02:00
|
|
|
state = "editing_layer";
|
2023-10-11 04:16:52 +02:00
|
|
|
}
|
2023-10-13 18:46:56 +02:00
|
|
|
|
2023-10-11 04:16:52 +02:00
|
|
|
|
2023-06-16 02:36:11 +02:00
|
|
|
</script>
|
2023-10-11 04:16:52 +02:00
|
|
|
|
2023-10-16 15:06:50 +02:00
|
|
|
<If condition={layersWithErr.map(d => d?.error !== undefined)}>
|
|
|
|
<div>
|
|
|
|
<div class="alert">
|
|
|
|
Something went wrong while contacting the MapComplete Studio Server: {$layersWithErr["error"]}
|
|
|
|
</div>
|
|
|
|
The server might be offline. Please:
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
<li>
|
|
|
|
Try again in a few minutes
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
Contact <a href="https://app.element.io/#/room/#MapComplete:matrix.org">the MapComplete community via the
|
|
|
|
chat.</a> Someone might be able to help you
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
File <a href="https://github.com/pietervdvn/MapComplete/issues">an issue</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
Contact the devs via <a href="mailto:info@posteo.net">email</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2023-10-07 03:07:32 +02:00
|
|
|
</div>
|
2023-10-16 15:06:50 +02:00
|
|
|
<LoginToggle ignoreLoading={true} slot="else" state={{osmConnection}}>
|
|
|
|
<div slot="not-logged-in">
|
2023-10-17 17:03:13 +02:00
|
|
|
<NextButton clss="primary" on:click={() => osmConnection.AttemptLogin()}>
|
2023-10-16 15:06:50 +02:00
|
|
|
Please log in to use MapComplete Studio
|
2023-10-13 18:46:56 +02:00
|
|
|
</NextButton>
|
|
|
|
</div>
|
2023-10-16 15:06:50 +02:00
|
|
|
{#if state === undefined}
|
2023-10-24 22:01:10 +02:00
|
|
|
<div class="m-4">
|
|
|
|
<h1>MapComplete Studio</h1>
|
|
|
|
<div class="w-full flex flex-col">
|
|
|
|
|
|
|
|
<NextButton on:click={() => state = "edit_layer"}>
|
|
|
|
Edit an existing layer
|
2023-10-16 15:06:50 +02:00
|
|
|
</NextButton>
|
2023-10-24 22:01:10 +02:00
|
|
|
<NextButton on:click={() => createNewLayer()}>
|
|
|
|
Create a new layer
|
|
|
|
</NextButton>
|
|
|
|
<NextButton on:click={() => state = "edit_theme"}>
|
|
|
|
Edit a theme
|
|
|
|
</NextButton>
|
2023-10-30 13:45:44 +01:00
|
|
|
<NextButton on:click={() => {editThemeState.configuration.setData({}); state = "editing_theme"}}>
|
2023-10-24 22:01:10 +02:00
|
|
|
Create a new theme
|
2023-10-16 15:06:50 +02:00
|
|
|
</NextButton>
|
2023-10-24 22:01:10 +02:00
|
|
|
<NextButton clss="small" on:click={() => {showIntro.setData(true)} }>
|
|
|
|
<QuestionMarkCircleIcon class="w-6 h-6" />
|
|
|
|
Show the introduction again
|
|
|
|
</NextButton>
|
|
|
|
</div>
|
2023-11-02 04:35:32 +01:00
|
|
|
<span class="subtle">MapComplete version {version}</span>
|
2023-10-24 22:01:10 +02:00
|
|
|
</div>
|
|
|
|
{:else if state === "edit_layer"}
|
|
|
|
|
|
|
|
<div class="flex flex-col m-4">
|
|
|
|
<BackButton clss="small p-1" imageClass="w-8 h-8" on:click={() => {state =undefined}}>MapComplete Studio
|
|
|
|
</BackButton>
|
|
|
|
<h2>Choose a layer to edit</h2>
|
2023-11-02 04:35:32 +01:00
|
|
|
<ChooseLayerToEdit {osmConnection} layerIds={$selfLayers} on:layerSelected={editLayer}>
|
2023-10-24 22:01:10 +02:00
|
|
|
<h3 slot="title">Your layers</h3>
|
|
|
|
</ChooseLayerToEdit>
|
2023-10-30 13:45:44 +01:00
|
|
|
<h3>Layers by other contributors</h3>
|
2023-11-02 04:35:32 +01:00
|
|
|
<ChooseLayerToEdit {osmConnection} layerIds={$otherLayers} on:layerSelected={editLayer} />
|
2023-10-30 13:45:44 +01:00
|
|
|
|
|
|
|
<h3>Official layers by MapComplete</h3>
|
2023-11-02 04:35:32 +01:00
|
|
|
<ChooseLayerToEdit {osmConnection} layerIds={$officialLayers} on:layerSelected={editLayer} />
|
2023-10-30 13:45:44 +01:00
|
|
|
</div>
|
|
|
|
{:else if state === "edit_theme"}
|
|
|
|
|
|
|
|
<div class="flex flex-col m-4">
|
|
|
|
<BackButton clss="small p-1" imageClass="w-8 h-8" on:click={() => {state =undefined}}>MapComplete Studio
|
|
|
|
</BackButton>
|
|
|
|
<h2>Choose a theme to edit</h2>
|
2023-11-02 04:35:32 +01:00
|
|
|
<ChooseLayerToEdit {osmConnection} layerIds={$selfThemes} on:layerSelected={editTheme}>
|
2023-10-30 13:45:44 +01:00
|
|
|
<h3 slot="title">Your themes</h3>
|
|
|
|
</ChooseLayerToEdit>
|
|
|
|
<h3>Themes by other contributors</h3>
|
2023-11-02 04:35:32 +01:00
|
|
|
<ChooseLayerToEdit {osmConnection} layerIds={$otherThemes} on:layerSelected={editTheme} />
|
2023-10-30 13:45:44 +01:00
|
|
|
<h3>Official themes by MapComplete</h3>
|
2023-11-02 04:35:32 +01:00
|
|
|
<ChooseLayerToEdit {osmConnection} layerIds={$officialThemes} on:layerSelected={editTheme} />
|
2023-10-30 13:45:44 +01:00
|
|
|
|
2023-10-16 15:06:50 +02:00
|
|
|
</div>
|
|
|
|
{:else if state === "loading"}
|
|
|
|
<div class="w-8 h-8">
|
|
|
|
<Loading />
|
|
|
|
</div>
|
|
|
|
{:else if state === "editing_layer"}
|
2023-10-30 13:45:44 +01:00
|
|
|
<EditLayer state={editLayerState}>
|
2023-10-24 22:01:10 +02:00
|
|
|
<BackButton clss="small p-1" imageClass="w-8 h-8" on:click={() => {state =undefined}}>MapComplete Studio
|
|
|
|
</BackButton>
|
2023-10-21 09:35:54 +02:00
|
|
|
</EditLayer>
|
2023-10-30 13:45:44 +01:00
|
|
|
{:else if state === "editing_theme"}
|
|
|
|
<EditTheme state={editThemeState} >
|
|
|
|
<BackButton clss="small p-1" imageClass="w-8 h-8" on:click={() => {state =undefined}}>MapComplete Studio
|
|
|
|
</BackButton>
|
|
|
|
</EditTheme>
|
2023-10-16 15:06:50 +02:00
|
|
|
{/if}
|
|
|
|
</LoginToggle>
|
|
|
|
</If>
|
2023-10-24 22:01:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
{#if $showIntro}
|
2023-10-30 13:45:44 +01:00
|
|
|
<FloatOver on:close={() => {showIntro.setData(false)}}>
|
2023-10-24 22:01:10 +02:00
|
|
|
<div class="flex p-4 h-full">
|
|
|
|
<Walkthrough pages={intro.sections} on:done={() => {showIntro.setData(false)}} />
|
|
|
|
</div>
|
|
|
|
</FloatOver>
|
|
|
|
|
|
|
|
{/if}
|