forked from MapComplete/MapComplete
Feature: add multiTitle, better error handling, improve help text of script
This commit is contained in:
parent
1bdff87bbd
commit
0d33e18a59
7 changed files with 29 additions and 7 deletions
|
@ -14,13 +14,20 @@ import { GenerateLicenseInfo } from "./generateLicenseInfo"
|
|||
|
||||
class ImportCustomTheme extends Script {
|
||||
constructor() {
|
||||
super("Given the path of a custom layer, will load the layer into mapcomplete as official")
|
||||
super(["Given the path of a custom layer, will load the layer into mapcomplete as official","",
|
||||
"Usage:",
|
||||
"vite-node scripts/importCustomTheme.ts <path-of-layer-or-theme>"].join("\n"))
|
||||
}
|
||||
|
||||
async main(args: string[]) {
|
||||
if(args.length === 0){
|
||||
this.printHelp()
|
||||
return
|
||||
}
|
||||
const path = args[0]
|
||||
|
||||
const layerconfig = <LayerConfigJson>JSON.parse(readFileSync(path, "utf-8"))
|
||||
const layerconfig = <LayerConfigJson>JSON.parse(
|
||||
readFileSync(path, "utf-8"))
|
||||
const id = layerconfig.id
|
||||
const dirPath = "./assets/layers/" + id
|
||||
if (!existsSync(dirPath)) {
|
||||
|
|
|
@ -216,6 +216,12 @@ export interface QuestionableTagRenderingConfigJson extends TagRenderingConfigJs
|
|||
*/
|
||||
multiAnswer?: boolean
|
||||
|
||||
/**
|
||||
* question: If one or more answers match (in case of a multiAnswer), what title/intro should be added?
|
||||
* ifunset: don't show a title
|
||||
*/
|
||||
multiTitle?: Translatable
|
||||
|
||||
/**
|
||||
* Allow freeform text input from the user
|
||||
*/
|
||||
|
|
|
@ -45,6 +45,7 @@ export interface ThemeConfigJson {
|
|||
* question: What is the title of this theme?
|
||||
*
|
||||
* The human-readable title, as shown in the welcome message and the index page
|
||||
* ifunset: reuse 'name' from the only layer
|
||||
* group: basic
|
||||
*/
|
||||
title: Translatable
|
||||
|
|
|
@ -92,6 +92,7 @@ export default class TagRenderingConfig {
|
|||
}
|
||||
|
||||
public readonly multiAnswer: boolean
|
||||
public readonly multiTitle?: Translation
|
||||
|
||||
public mappings: Mapping[]
|
||||
public readonly editButtonAriaLabel?: Translation
|
||||
|
@ -164,6 +165,7 @@ export default class TagRenderingConfig {
|
|||
this.questionHintIsMd = json["questionHintIsMd"] ?? false
|
||||
this.alwaysForceSaveButton = json["#force-save-button"] === "yes"
|
||||
this.description = Translations.T(json.description, translationKey + ".description")
|
||||
this.multiTitle = Translations.T(json.multiTitle, translationKey + ".multiTitle")
|
||||
this._definedIn = json._definedIn
|
||||
if (json.onSoftDelete && !Array.isArray(json.onSoftDelete)) {
|
||||
throw context + ".onSoftDelete Not an array: " + typeof json.onSoftDelete
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
import { twMerge } from "tailwind-merge"
|
||||
import { onDestroy } from "svelte"
|
||||
import { Lists } from "../../../Utils/Lists"
|
||||
import Tr from "../../Base/Tr.svelte"
|
||||
|
||||
export let tags: UIEventSource<Record<string, string> | undefined>
|
||||
|
||||
|
@ -34,10 +35,12 @@
|
|||
|
||||
{#if config !== undefined && (config?.condition === undefined || config.condition.matchesProperties($tags))}
|
||||
<div {id} class={twMerge("link-underline flex h-full flex-col", defaultSize, extraClasses)}>
|
||||
{#if $trs.length === 1}
|
||||
{#if $trs.length === 1 && config.multiTitle === undefined}
|
||||
<TagRenderingMapping mapping={$trs[0]} {tags} {state} {selectedElement} {layer} {noIcons} />
|
||||
{/if}
|
||||
{#if $trs.length > 1}
|
||||
{:else}
|
||||
{#if config.multiTitle}
|
||||
<Tr t={config.multiTitle} />
|
||||
{/if}
|
||||
<ul>
|
||||
{#each $trs as mapping}
|
||||
<li>
|
||||
|
|
|
@ -80,7 +80,9 @@ export default class StudioServer {
|
|||
try {
|
||||
return <any>await Utils.downloadJson(this.urlFor(layerId, category, uid))
|
||||
} catch (e) {
|
||||
return undefined
|
||||
console.error("Could not download layer", layerId,"due to",e)
|
||||
alert("Could not download item due to "+ e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -153,7 +153,8 @@
|
|||
const layerId: { owner: number; id: string } = event["detail"]
|
||||
state = "loading"
|
||||
editLayerState.startSavingUpdates(false)
|
||||
editLayerState.configuration.setData(await studio.fetch(layerId.id, "layers", layerId.owner))
|
||||
const layer = await studio.fetch(layerId.id, "layers", layerId.owner)
|
||||
editLayerState.configuration.setData(layer)
|
||||
editLayerState.startSavingUpdates()
|
||||
state = "editing_layer"
|
||||
return editLayerState
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue