forked from MapComplete/MapComplete
refactoring: fix special renderings (partly), deprecate
This commit is contained in:
parent
9b2f92dedc
commit
aaaaf1948d
15 changed files with 160 additions and 95 deletions
|
@ -322,7 +322,9 @@ export class AddMiniMap extends DesugaringStep<LayerConfigJson> {
|
|||
* AddMiniMap.hasMinimap({render: "Some random value {minimap}"}) // => false
|
||||
*/
|
||||
static hasMinimap(renderingConfig: TagRenderingConfigJson): boolean {
|
||||
return ValidationUtils.getSpecialVisualisations(renderingConfig).indexOf("minimap") >= 0
|
||||
return ValidationUtils.getSpecialVisualisations(renderingConfig).some(
|
||||
(vis) => vis.funcName === "minimap"
|
||||
)
|
||||
}
|
||||
|
||||
convert(layerConfig: LayerConfigJson, context: string): { result: LayerConfigJson } {
|
||||
|
@ -344,7 +346,7 @@ export class AddMiniMap extends DesugaringStep<LayerConfigJson> {
|
|||
}
|
||||
}
|
||||
|
||||
class AddContextToTransltionsInLayout extends DesugaringStep<LayoutConfigJson> {
|
||||
class AddContextToTranslationsInLayout extends DesugaringStep<LayoutConfigJson> {
|
||||
constructor() {
|
||||
super(
|
||||
"Adds context to translations, including the prefix 'themes:json.id'; this is to make sure terms in an 'overrides' or inline layer are linkable too",
|
||||
|
@ -644,7 +646,7 @@ export class PrepareTheme extends Fuse<LayoutConfigJson> {
|
|||
super(
|
||||
"Fully prepares and expands a theme",
|
||||
|
||||
new AddContextToTransltionsInLayout(),
|
||||
new AddContextToTranslationsInLayout(),
|
||||
new PreparePersonalTheme(state),
|
||||
new WarnForUnsubstitutedLayersInTheme(),
|
||||
new On("layers", new Concat(new SubstituteLayer(state))),
|
||||
|
@ -663,4 +665,28 @@ export class PrepareTheme extends Fuse<LayoutConfigJson> {
|
|||
new On("layers", new Each(new AddMiniMap(state)))
|
||||
)
|
||||
}
|
||||
|
||||
convert(
|
||||
json: LayoutConfigJson,
|
||||
context: string
|
||||
): { result: LayoutConfigJson; errors: string[]; warnings: string[]; information: string[] } {
|
||||
const result = super.convert(json, context)
|
||||
|
||||
const needsNodeDatabase = result.result.layers?.some((l: LayerConfigJson) =>
|
||||
l.tagRenderings?.some((tr: TagRenderingConfigJson) =>
|
||||
ValidationUtils.getSpecialVisualisations(tr)?.some(
|
||||
(special) => special.needsNodeDatabase
|
||||
)
|
||||
)
|
||||
)
|
||||
if (needsNodeDatabase) {
|
||||
result.information.push(
|
||||
context +
|
||||
": setting 'enableNodeDatabase' as this theme uses a special visualisation which needs to keep track of _all_ nodes"
|
||||
)
|
||||
result.result.enableNodeDatabase = true
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
|
|
@ -620,6 +620,15 @@ class MiscTagRenderingChecks extends DesugaringStep<TagRenderingConfigJson> {
|
|||
': detected `special` on the top level. Did you mean `{"render":{ "special": ... }}`'
|
||||
)
|
||||
}
|
||||
if (json.group) {
|
||||
errors.push(
|
||||
"At " +
|
||||
context +
|
||||
': groups are deprecated, use `"label": ["' +
|
||||
json.group +
|
||||
'"]` instead'
|
||||
)
|
||||
}
|
||||
const freeformType = json["freeform"]?.["type"]
|
||||
if (freeformType) {
|
||||
if (Validators.AvailableTypes().indexOf(freeformType) < 0) {
|
||||
|
@ -688,6 +697,17 @@ export class ValidateLayer extends DesugaringStep<LayerConfigJson> {
|
|||
}
|
||||
}
|
||||
|
||||
if (json.source === "special") {
|
||||
if (!Constants.priviliged_layers.find((x) => x == json.id)) {
|
||||
errors.push(
|
||||
context +
|
||||
": layer " +
|
||||
json.id +
|
||||
" uses 'special' as source.osmTags. However, this layer is not a priviliged layer"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (json.tagRenderings !== undefined && json.tagRenderings.length > 0) {
|
||||
if (json.title === undefined) {
|
||||
errors.push(
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
import { TagRenderingConfigJson } from "../Json/TagRenderingConfigJson"
|
||||
import { Utils } from "../../../Utils"
|
||||
import SpecialVisualizations from "../../../UI/SpecialVisualizations"
|
||||
import { SpecialVisualization } from "../../../UI/SpecialVisualization"
|
||||
|
||||
export default class ValidationUtils {
|
||||
/**
|
||||
* Gives all the (function names of) used special visualisations
|
||||
* @param renderingConfig
|
||||
*/
|
||||
public static getSpecialVisualisations(renderingConfig: TagRenderingConfigJson): string[] {
|
||||
public static getSpecialVisualisations(
|
||||
renderingConfig: TagRenderingConfigJson
|
||||
): SpecialVisualization[] {
|
||||
const translations: any[] = Utils.NoNull([
|
||||
renderingConfig.render,
|
||||
...(renderingConfig.mappings ?? []).map((m) => m.then),
|
||||
])
|
||||
const all: string[] = []
|
||||
const all: SpecialVisualization[] = []
|
||||
for (let translation of translations) {
|
||||
if (typeof translation == "string") {
|
||||
translation = { "*": translation }
|
||||
|
@ -27,7 +30,7 @@ export default class ValidationUtils {
|
|||
const parts = SpecialVisualizations.constructSpecification(template)
|
||||
const specials = parts
|
||||
.filter((p) => typeof p !== "string")
|
||||
.map((special) => special["func"].funcName)
|
||||
.map((special) => special["func"])
|
||||
all.push(...specials)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -297,4 +297,12 @@ export interface LayoutConfigJson {
|
|||
* Set a different timeout for overpass queries - in seconds. Default: 30s
|
||||
*/
|
||||
overpassTimeout?: number
|
||||
|
||||
/**
|
||||
* Enables tracking of all nodes when data is loaded.
|
||||
* This is useful for the 'ImportWay' and 'ConflateWay'-buttons who need this database.
|
||||
*
|
||||
* Note: this flag will be automatically set.
|
||||
*/
|
||||
enableNodeDatabase?: boolean
|
||||
}
|
||||
|
|
|
@ -13,12 +13,6 @@ export interface TagRenderingConfigJson {
|
|||
*/
|
||||
id?: string
|
||||
|
||||
/**
|
||||
* If 'group' is defined on many tagRenderings, these are grouped together when shown. The questions are grouped together as well.
|
||||
* The first tagRendering of a group will always be a sticky element.
|
||||
*/
|
||||
group?: string
|
||||
|
||||
/**
|
||||
* A list of labels. These are strings that are used for various purposes, e.g. to filter them away
|
||||
*/
|
||||
|
|
|
@ -43,7 +43,6 @@ export interface Mapping {
|
|||
*/
|
||||
export default class TagRenderingConfig {
|
||||
public readonly id: string
|
||||
public readonly group: string
|
||||
public readonly render?: TypedTranslation<object>
|
||||
public readonly question?: TypedTranslation<object>
|
||||
public readonly questionhint?: TypedTranslation<object>
|
||||
|
@ -77,7 +76,6 @@ export default class TagRenderingConfig {
|
|||
this.question = null
|
||||
this.condition = null
|
||||
this.id = "questions"
|
||||
this.group = ""
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -115,7 +113,6 @@ export default class TagRenderingConfig {
|
|||
)
|
||||
}
|
||||
|
||||
this.group = json.group ?? ""
|
||||
this.labels = json.labels ?? []
|
||||
this.render = Translations.T(json.render, translationKey + ".render")
|
||||
this.question = Translations.T(json.question, translationKey + ".question")
|
||||
|
@ -684,13 +681,6 @@ export default class TagRenderingConfig {
|
|||
])
|
||||
}
|
||||
|
||||
let group: BaseUIElement = undefined
|
||||
if (this.group !== undefined && this.group !== "") {
|
||||
group = new Combine([
|
||||
"This tagrendering is part of group ",
|
||||
new FixedUiElement(this.group).SetClass("code"),
|
||||
])
|
||||
}
|
||||
let labels: BaseUIElement = undefined
|
||||
if (this.labels?.length > 0) {
|
||||
labels = new Combine([
|
||||
|
@ -713,7 +703,6 @@ export default class TagRenderingConfig {
|
|||
new Combine(withRender),
|
||||
mappings,
|
||||
condition,
|
||||
group,
|
||||
labels,
|
||||
]).SetClass("flex flex-col")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue