forked from MapComplete/MapComplete
Studio: more fixes
This commit is contained in:
parent
3ceebaba12
commit
80b7a038cf
7 changed files with 129 additions and 77 deletions
|
@ -11,9 +11,9 @@
|
||||||
|
|
||||||
cp config.json config.json.bu &&
|
cp config.json config.json.bu &&
|
||||||
cp ./scripts/hetzner/config.json . && # Copy the config _before_ building, as the config might contain some needed URLs
|
cp ./scripts/hetzner/config.json . && # Copy the config _before_ building, as the config might contain some needed URLs
|
||||||
npm run reset:layeroverview
|
# npm run reset:layeroverview
|
||||||
npm run test
|
|
||||||
npm run prepare-deploy &&
|
npm run prepare-deploy &&
|
||||||
|
npm run test &&
|
||||||
zip dist.zip -r dist/* &&
|
zip dist.zip -r dist/* &&
|
||||||
mv config.json.bu config.json &&
|
mv config.json.bu config.json &&
|
||||||
scp ./scripts/hetzner/config/* hetzner:/root/ &&
|
scp ./scripts/hetzner/config/* hetzner:/root/ &&
|
||||||
|
|
|
@ -39,6 +39,12 @@ export class ConversionContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
static print(msg: ConversionMessage) {
|
static print(msg: ConversionMessage) {
|
||||||
|
const noString = msg.context.path.filter(
|
||||||
|
(p) => typeof p !== "string" && typeof p !== "number"
|
||||||
|
)
|
||||||
|
if (noString.length > 0) {
|
||||||
|
console.warn("Non-string value in path:", ...noString)
|
||||||
|
}
|
||||||
if (msg.level === "error") {
|
if (msg.level === "error") {
|
||||||
console.error(
|
console.error(
|
||||||
ConversionContext.red("ERR "),
|
ConversionContext.red("ERR "),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
|
||||||
import { LayerStateSender } from "./EditLayerState";
|
import EditLayerState, { LayerStateSender } from "./EditLayerState";
|
||||||
import layerSchemaRaw from "../../assets/schemas/layerconfigmeta.json";
|
import layerSchemaRaw from "../../assets/schemas/layerconfigmeta.json";
|
||||||
import Region from "./Region.svelte";
|
import Region from "./Region.svelte";
|
||||||
import TabbedGroup from "../Base/TabbedGroup.svelte";
|
import TabbedGroup from "../Base/TabbedGroup.svelte";
|
||||||
|
@ -8,11 +8,13 @@
|
||||||
import type { ConfigMeta } from "./configMeta";
|
import type { ConfigMeta } from "./configMeta";
|
||||||
import { Utils } from "../../Utils";
|
import { Utils } from "../../Utils";
|
||||||
import type { LayerConfigJson } from "../../Models/ThemeConfig/Json/LayerConfigJson";
|
import type { LayerConfigJson } from "../../Models/ThemeConfig/Json/LayerConfigJson";
|
||||||
|
import type { ConversionMessage } from "../../Models/ThemeConfig/Conversion/Conversion";
|
||||||
|
|
||||||
const layerSchema: ConfigMeta[] = <any>layerSchemaRaw;
|
const layerSchema: ConfigMeta[] = <any>layerSchemaRaw;
|
||||||
|
|
||||||
export let state;
|
export let state: EditLayerState;
|
||||||
const messages = state.messages;
|
const messages = state.messages;
|
||||||
|
const hasErrors = messages.map((m: ConversionMessage[]) => m.filter(m => m.level === "error").length);
|
||||||
export let initialLayerConfig: Partial<LayerConfigJson> = {};
|
export let initialLayerConfig: Partial<LayerConfigJson> = {};
|
||||||
state.configuration.setData(initialLayerConfig);
|
state.configuration.setData(initialLayerConfig);
|
||||||
const configuration = state.configuration;
|
const configuration = state.configuration;
|
||||||
|
@ -37,9 +39,18 @@
|
||||||
}
|
}
|
||||||
const leftoverRegions: string[] = allNames.filter(r => regionBlacklist.indexOf(r) < 0 && baselayerRegions.indexOf(r) < 0);
|
const leftoverRegions: string[] = allNames.filter(r => regionBlacklist.indexOf(r) < 0 && baselayerRegions.indexOf(r) < 0);
|
||||||
const title: Store<string> = state.getStoreFor(["id"]);
|
const title: Store<string> = state.getStoreFor(["id"]);
|
||||||
|
const wl = window.location
|
||||||
|
const baseUrl = wl.protocol+"//"+wl.host+"/theme.html?userlayout="
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<h3>Editing layer {$title}</h3>
|
<div class="w-full flex justify-between">
|
||||||
|
<h3>Editing layer {$title}</h3>
|
||||||
|
{#if $hasErrors > 0}
|
||||||
|
<div class="alert">{$hasErrors} errors detected</div>
|
||||||
|
{:else}
|
||||||
|
<a class="primary button" href={baseUrl+state.server.layerUrl(title.data)} target="_blank" rel="noopener">Try it out</a>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
<div class="m4">
|
<div class="m4">
|
||||||
<TabbedGroup tab={new UIEventSource(2)}>
|
<TabbedGroup tab={new UIEventSource(2)}>
|
||||||
<div slot="title0">General properties</div>
|
<div slot="title0">General properties</div>
|
||||||
|
|
|
@ -177,7 +177,12 @@ export default class EditLayerState {
|
||||||
}
|
}
|
||||||
entry = entry[breadcrumb]
|
entry = entry[breadcrumb]
|
||||||
}
|
}
|
||||||
if (v !== undefined && v !== null && v !== "") {
|
if (
|
||||||
|
v !== undefined &&
|
||||||
|
v !== null &&
|
||||||
|
v !== "" &&
|
||||||
|
!(typeof v === "object" && Object.keys({}).length === 0)
|
||||||
|
) {
|
||||||
entry[path.at(-1)] = v
|
entry[path.at(-1)] = v
|
||||||
} else if (entry) {
|
} else if (entry) {
|
||||||
delete entry[path.at(-1)]
|
delete entry[path.at(-1)]
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
export let state: EditLayerState
|
export let state: EditLayerState
|
||||||
export let path: (string | number)[] = []
|
export let path: (string | number)[] = []
|
||||||
export let schema: ConfigMeta
|
export let schema: ConfigMeta
|
||||||
let value = new UIEventSource<string>(undefined)
|
let value = new UIEventSource<string | any>(undefined)
|
||||||
|
|
||||||
const isTranslation = schema.hints.typehint === "translation" || schema.hints.typehint === "rendered" || ConfigMetaUtils.isTranslation(schema)
|
const isTranslation = schema.hints.typehint === "translation" || schema.hints.typehint === "rendered" || ConfigMetaUtils.isTranslation(schema)
|
||||||
let type = schema.hints.typehint ?? "string"
|
let type = schema.hints.typehint ?? "string"
|
||||||
|
@ -122,7 +122,7 @@
|
||||||
}
|
}
|
||||||
return Number(v)
|
return Number(v)
|
||||||
}
|
}
|
||||||
if (isTranslation) {
|
if (isTranslation && typeof v === "string") {
|
||||||
if (v === "") {
|
if (v === "") {
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,7 @@ export default class StudioServer {
|
||||||
|
|
||||||
async fetchLayer(layerId: string): Promise<LayerConfigJson> {
|
async fetchLayer(layerId: string): Promise<LayerConfigJson> {
|
||||||
try {
|
try {
|
||||||
return await Utils.downloadJson(
|
return await Utils.downloadJson(this.layerUrl(layerId))
|
||||||
this.url + "/layers/" + layerId + "/" + layerId + ".json"
|
|
||||||
)
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
@ -35,7 +33,7 @@ export default class StudioServer {
|
||||||
if (id === undefined || id === "") {
|
if (id === undefined || id === "") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await fetch(`${this.url}/layers/${id}/${id}.json`, {
|
await fetch(this.layerUrl(id), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json;charset=utf-8",
|
"Content-Type": "application/json;charset=utf-8",
|
||||||
|
@ -43,4 +41,8 @@ export default class StudioServer {
|
||||||
body: JSON.stringify(config, null, " "),
|
body: JSON.stringify(config, null, " "),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public layerUrl(id: string) {
|
||||||
|
return `${this.url}/layers/${id}/${id}.json`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,10 +15,12 @@
|
||||||
import { QueryParameters } from "../Logic/Web/QueryParameters";
|
import { QueryParameters } from "../Logic/Web/QueryParameters";
|
||||||
|
|
||||||
import layerSchemaRaw from "../../src/assets/schemas/layerconfigmeta.json";
|
import layerSchemaRaw from "../../src/assets/schemas/layerconfigmeta.json";
|
||||||
|
import If from "./Base/If.svelte";
|
||||||
|
|
||||||
export let studioUrl = /*"https://studio.mapcomplete.org"; /*/ "http://127.0.0.1:1235"; //*/
|
export let studioUrl = /* "https://studio.mapcomplete.org"; /*/ "http://127.0.0.1:1235"; //*/
|
||||||
const studio = new StudioServer(studioUrl);
|
const studio = new StudioServer(studioUrl);
|
||||||
let layers = UIEventSource.FromPromise(studio.fetchLayerOverview());
|
let layersWithErr = UIEventSource.FromPromiseWithErr(studio.fetchLayerOverview());
|
||||||
|
let layers = layersWithErr.mapD(l => l.success);
|
||||||
let state: undefined | "edit_layer" | "new_layer" | "edit_theme" | "new_theme" | "editing_layer" | "loading" = undefined;
|
let state: undefined | "edit_layer" | "new_layer" | "edit_theme" | "new_theme" | "editing_layer" | "loading" = undefined;
|
||||||
|
|
||||||
let initialLayerConfig: { id: string };
|
let initialLayerConfig: { id: string };
|
||||||
|
@ -61,8 +63,8 @@
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
lineRendering : [{
|
lineRendering: [{
|
||||||
width : 1,
|
width: 1,
|
||||||
color: "blue"
|
color: "blue"
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
|
@ -82,73 +84,99 @@
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<LoginToggle state={{osmConnection}} ignoreLoading={true}>
|
<If condition={layersWithErr.map(d => d?.error !== undefined)}>
|
||||||
<div slot="not-logged-in">
|
<div>
|
||||||
<NextButton clss="primary">
|
<div class="alert">
|
||||||
Please log in to use MapComplete Studio
|
Something went wrong while contacting the MapComplete Studio Server: {$layersWithErr["error"]}
|
||||||
</NextButton>
|
</div>
|
||||||
</div>
|
The server might be offline. Please:
|
||||||
{#if state === undefined}
|
<ul>
|
||||||
<h1>MapComplete Studio</h1>
|
|
||||||
<div class="w-full flex flex-col">
|
|
||||||
|
|
||||||
<NextButton on:click={() => state = "edit_layer"}>
|
<li>
|
||||||
Edit an existing layer
|
Try again in a few minutes
|
||||||
</NextButton>
|
</li>
|
||||||
<NextButton on:click={() => state = "new_layer"}>
|
<li>
|
||||||
Create a new layer
|
Contact <a href="https://app.element.io/#/room/#MapComplete:matrix.org">the MapComplete community via the
|
||||||
</NextButton>
|
chat.</a> Someone might be able to help you
|
||||||
<NextButton on:click={() => state = "edit_theme"}>
|
</li>
|
||||||
Edit a theme
|
<li>
|
||||||
</NextButton>
|
File <a href="https://github.com/pietervdvn/MapComplete/issues">an issue</a>
|
||||||
<NextButton on:click={() => state = "new_theme"}>
|
</li>
|
||||||
Create a new theme
|
<li>
|
||||||
|
Contact the devs via <a href="mailto:info@posteo.net">email</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<LoginToggle ignoreLoading={true} slot="else" state={{osmConnection}}>
|
||||||
|
<div slot="not-logged-in">
|
||||||
|
<NextButton clss="primary">
|
||||||
|
Please log in to use MapComplete Studio
|
||||||
</NextButton>
|
</NextButton>
|
||||||
</div>
|
</div>
|
||||||
{:else if state === "edit_layer"}
|
{#if state === undefined}
|
||||||
<div class="flex flex-wrap">
|
<h1>MapComplete Studio</h1>
|
||||||
{#each Array.from($layers) as layerId}
|
<div class="w-full flex flex-col">
|
||||||
<NextButton clss="small" on:click={async () => {
|
|
||||||
|
<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">
|
||||||
|
{#each Array.from($layers) as layerId}
|
||||||
|
<NextButton clss="small" on:click={async () => {
|
||||||
state = "loading"
|
state = "loading"
|
||||||
initialLayerConfig = await studio.fetchLayer(layerId)
|
initialLayerConfig = await studio.fetchLayer(layerId)
|
||||||
state = "editing_layer"
|
state = "editing_layer"
|
||||||
}}>
|
}}>
|
||||||
<div class="w-4 h-4 mr-1">
|
<div class="w-4 h-4 mr-1">
|
||||||
<Marker icons={fetchIconDescription(layerId)} />
|
<Marker icons={fetchIconDescription(layerId)} />
|
||||||
</div>
|
</div>
|
||||||
{layerId}
|
{layerId}
|
||||||
</NextButton>
|
</NextButton>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
|
||||||
{:else if state === "new_layer"}
|
|
||||||
<div class="interactive flex m-2 rounded-2xl flex-col p-2">
|
|
||||||
<h3>Enter the ID for the new layer</h3>
|
|
||||||
A good ID is:
|
|
||||||
<ul>
|
|
||||||
<li>a noun</li>
|
|
||||||
<li>singular</li>
|
|
||||||
<li>describes the object</li>
|
|
||||||
<li>in English</li>
|
|
||||||
</ul>
|
|
||||||
<div class="m-2 p-2 w-full">
|
|
||||||
|
|
||||||
<ValidatedInput type="id" value={newLayerId} feedback={layerIdFeedback} on:submit={() => createNewLayer()} />
|
|
||||||
</div>
|
</div>
|
||||||
{#if $layerIdFeedback !== undefined}
|
{:else if state === "new_layer"}
|
||||||
<div class="alert">
|
<div class="interactive flex m-2 rounded-2xl flex-col p-2">
|
||||||
{$layerIdFeedback}
|
<h3>Enter the ID for the new layer</h3>
|
||||||
|
A good ID is:
|
||||||
|
<ul>
|
||||||
|
<li>a noun</li>
|
||||||
|
<li>singular</li>
|
||||||
|
<li>describes the object</li>
|
||||||
|
<li>in English</li>
|
||||||
|
</ul>
|
||||||
|
<div class="m-2 p-2 w-full">
|
||||||
|
|
||||||
|
<ValidatedInput type="id" value={newLayerId} feedback={layerIdFeedback} on:submit={() => createNewLayer()} />
|
||||||
</div>
|
</div>
|
||||||
{:else }
|
{#if $layerIdFeedback !== undefined}
|
||||||
<NextButton clss="primary" on:click={() => createNewLayer()}>
|
<div class="alert">
|
||||||
Create layer {$newLayerId}
|
{$layerIdFeedback}
|
||||||
</NextButton>
|
</div>
|
||||||
{/if}
|
{:else }
|
||||||
</div>
|
<NextButton clss="primary" on:click={() => createNewLayer()}>
|
||||||
{:else if state === "loading"}
|
Create layer {$newLayerId}
|
||||||
<div class="w-8 h-8">
|
</NextButton>
|
||||||
<Loading />
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{:else if state === "editing_layer"}
|
{:else if state === "loading"}
|
||||||
<EditLayer {initialLayerConfig} state={editLayerState} />
|
<div class="w-8 h-8">
|
||||||
{/if}
|
<Loading />
|
||||||
</LoginToggle>
|
</div>
|
||||||
|
{:else if state === "editing_layer"}
|
||||||
|
<EditLayer {initialLayerConfig} state={editLayerState} />
|
||||||
|
{/if}
|
||||||
|
</LoginToggle>
|
||||||
|
</If>
|
||||||
|
|
Loading…
Add table
Reference in a new issue