Feat(studio): add possibility to directly write into the theme files

This commit is contained in:
Pieter Vander Vennet 2024-09-25 11:40:45 +02:00
parent ea133c5eff
commit 0be7c64ea1
3 changed files with 39 additions and 28 deletions

View file

@ -5,7 +5,7 @@ import {
Conversion,
ConversionMessage,
DesugaringContext,
Pipe,
Pipe
} from "../../Models/ThemeConfig/Conversion/Conversion"
import { PrepareLayer } from "../../Models/ThemeConfig/Conversion/PrepareLayer"
import { PrevalidateTheme, ValidateLayer } from "../../Models/ThemeConfig/Conversion/Validation"
@ -97,16 +97,19 @@ export abstract class EditJsonState<T> {
public startSavingUpdates(enabled = true) {
this.sendingUpdates = enabled
this.register(
["credits"],
this.osmConnection.userDetails.mapD((u) => u.name),
false
)
this.register(
["credits:uid"],
this.osmConnection.userDetails.mapD((u) => u.uid),
false
)
if (!this.server.isDirect) {
this.register(
["credits"],
this.osmConnection.userDetails.mapD((u) => u.name),
false
)
this.register(
["credits:uid"],
this.osmConnection.userDetails.mapD((u) => u.uid),
false
)
}
if (enabled) {
this.configuration.ping()
}
@ -159,7 +162,7 @@ export abstract class EditJsonState<T> {
}
public getSchemaStartingWith(path: string[]) {
if(path === undefined){
if (path === undefined) {
return undefined
}
return this.schema.filter(
@ -174,10 +177,10 @@ export abstract class EditJsonState<T> {
path,
type: "translation",
hints: {
typehint: "translation",
typehint: "translation"
},
required: origConfig.required ?? false,
description: origConfig.description ?? "A translatable object",
description: origConfig.description ?? "A translatable object"
}
}
@ -329,7 +332,7 @@ export default class EditLayerState extends EditJsonState<LayerConfigJson> {
public readonly imageUploadManager = {
getCountsFor() {
return 0
},
}
}
public readonly layout: { getMatchingLayer: (key: any) => LayerConfig }
public readonly featureSwitches: {
@ -345,8 +348,8 @@ export default class EditLayerState extends EditJsonState<LayerConfigJson> {
properties: this.testTags.data,
geometry: {
type: "Point",
coordinates: [3.21, 51.2],
},
coordinates: [3.21, 51.2]
}
}
constructor(
@ -363,10 +366,10 @@ export default class EditLayerState extends EditJsonState<LayerConfigJson> {
} catch (e) {
return undefined
}
},
}
}
this.featureSwitches = {
featureSwitchIsDebugging: new UIEventSource<boolean>(true),
featureSwitchIsDebugging: new UIEventSource<boolean>(true)
}
this.addMissingTagRenderingIds()
@ -455,7 +458,7 @@ export default class EditLayerState extends EditJsonState<LayerConfigJson> {
}
const state: DesugaringContext = {
tagRenderings: sharedQuestions,
sharedLayers: layers,
sharedLayers: layers
}
const prepare = this.buildValidation(state)
const context = ConversionContext.construct([], ["prepare"])
@ -531,7 +534,7 @@ export class EditThemeState extends EditJsonState<LayoutConfigJson> {
}
const state: DesugaringContext = {
tagRenderings: sharedQuestions,
sharedLayers: layers,
sharedLayers: layers
}
const prepare = this.buildValidation(state)
const context = ConversionContext.construct([], ["prepare"])

View file

@ -18,8 +18,9 @@ export default class StudioServer {
| { error: any }
| undefined
>
public isDirect: boolean
constructor(url: string, userId: Store<number>) {
constructor(url: string, userId: Store<number | undefined>, isDirect: boolean) {
this.url = url
this._userId = userId
this.overview = UIEventSource.FromPromiseWithErr(this.fetchOverviewRaw())
@ -123,7 +124,7 @@ export default class StudioServer {
public urlFor(id: string, category: "layers" | "themes", uid?: number) {
uid ??= this._userId.data
const uidStr = uid !== undefined ? "/" + uid : ""
const uidStr = uid !== null ? "/" + uid : ""
return `${this.url}${uidStr}/${category}/${id}/${id}.json`
}
}

View file

@ -31,12 +31,15 @@
import Add from "../assets/svg/Add.svelte"
import { SearchIcon } from "@rgossiaux/svelte-heroicons/solid"
import Hash from "../Logic/Web/Hash"
const directEntry = QueryParameters.GetBooleanQueryParameter("direct",false,"If set, write directly into the theme files")
export let studioUrl =
window.location.hostname === "127.0.0.2"
window.location.hostname === "127.0.0.2" || directEntry.data
? "http://127.0.0.1:1235"
: "https://studio.mapcomplete.org"
console.log("Using studio URL", studioUrl, "direct?", directEntry.data)
const oauth_token = QueryParameters.GetQueryParameter(
"oauth_token",
undefined,
@ -57,8 +60,8 @@
)
expertMode.addCallbackAndRunD((expert) => console.log("Expert mode is", expert))
const createdBy = osmConnection.userDetails.data.name
const uid = osmConnection.userDetails.map((ud) => ud?.uid)
const studio = new StudioServer(studioUrl, uid)
const uid = osmConnection.userDetails.map((ud) => directEntry.data ? null : ud?.uid, [directEntry])
const studio = new StudioServer(studioUrl, uid, directEntry.data)
let layersWithErr = studio.fetchOverview()
let layerFilterTerm: string = ""
@ -285,7 +288,11 @@
<div class="flex justify-between">
<Checkbox selected={expertMode}>Enable more options (expert mode)</Checkbox>
<span class="subtle">MapComplete version {version}</span>
<div>{$uid}</div>
<div>{$uid} {studioUrl}
{#if $directEntry}
<b>direct</b>
{/if}
</div>
</div>
</div>
{:else if state === "edit_layer"}
@ -368,7 +375,7 @@
</div>
{:else if state === "loading"}
<div class="h-8 w-8">
<Loading />
<Loading >Fetching information from {studioUrl}</Loading>
</div>
{:else if state === "editing_layer"}
<EditLayer state={editLayerState} {backToStudio}>