forked from MapComplete/MapComplete
refactoring: Fix generate:layeroverview
This commit is contained in:
parent
41e6a2c760
commit
9b2f92dedc
25 changed files with 194 additions and 216 deletions
|
@ -228,10 +228,13 @@ class ExpandTagRendering extends Conversion<
|
|||
let found: TagRenderingConfigJson = Utils.Clone(matchingTrs[i])
|
||||
if (this._options?.applyCondition) {
|
||||
// The matched tagRenderings are 'stolen' from another layer. This means that they must match the layer condition before being shown
|
||||
if (found.condition === undefined) {
|
||||
found.condition = layer.source.osmTags
|
||||
} else {
|
||||
found.condition = { and: [found.condition, layer.source.osmTags] }
|
||||
|
||||
if (typeof layer.source !== "string") {
|
||||
if (found.condition === undefined) {
|
||||
found.condition = layer.source.osmTags
|
||||
} else {
|
||||
found.condition = { and: [found.condition, layer.source.osmTags] }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,9 +17,9 @@ import Constants from "../../Constants"
|
|||
import CreateNoteImportLayer from "./CreateNoteImportLayer"
|
||||
import LayerConfig from "../LayerConfig"
|
||||
import { TagRenderingConfigJson } from "../Json/TagRenderingConfigJson"
|
||||
import { SubstitutedTranslation } from "../../../UI/SubstitutedTranslation"
|
||||
import DependencyCalculator from "../DependencyCalculator"
|
||||
import { AddContextToTranslations } from "./AddContextToTranslations"
|
||||
import ValidationUtils from "./ValidationUtils"
|
||||
|
||||
class SubstituteLayer extends Conversion<string | LayerConfigJson, LayerConfigJson[]> {
|
||||
private readonly _state: DesugaringContext
|
||||
|
@ -322,31 +322,7 @@ export class AddMiniMap extends DesugaringStep<LayerConfigJson> {
|
|||
* AddMiniMap.hasMinimap({render: "Some random value {minimap}"}) // => false
|
||||
*/
|
||||
static hasMinimap(renderingConfig: TagRenderingConfigJson): boolean {
|
||||
const translations: any[] = Utils.NoNull([
|
||||
renderingConfig.render,
|
||||
...(renderingConfig.mappings ?? []).map((m) => m.then),
|
||||
])
|
||||
for (let translation of translations) {
|
||||
if (typeof translation == "string") {
|
||||
translation = { "*": translation }
|
||||
}
|
||||
|
||||
for (const key in translation) {
|
||||
if (!translation.hasOwnProperty(key)) {
|
||||
continue
|
||||
}
|
||||
|
||||
const template = translation[key]
|
||||
const parts = SubstitutedTranslation.ExtractSpecialComponents(template)
|
||||
const hasMiniMap = parts
|
||||
.filter((part) => part.special !== undefined)
|
||||
.some((special) => special.special.func.funcName === "minimap")
|
||||
if (hasMiniMap) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
return ValidationUtils.getSpecialVisualisations(renderingConfig).indexOf("minimap") >= 0
|
||||
}
|
||||
|
||||
convert(layerConfig: LayerConfigJson, context: string): { result: LayerConfigJson } {
|
||||
|
|
|
@ -15,7 +15,8 @@ import Svg from "../../../Svg"
|
|||
import FilterConfigJson from "../Json/FilterConfigJson"
|
||||
import DeleteConfig from "../DeleteConfig"
|
||||
import { QuestionableTagRenderingConfigJson } from "../Json/QuestionableTagRenderingConfigJson"
|
||||
import ValidatedTextField from "../../../UI/Input/ValidatedTextField"
|
||||
import Validators from "../../../UI/InputElement/Validators"
|
||||
import xml2js from "xml2js"
|
||||
|
||||
class ValidateLanguageCompleteness extends DesugaringStep<any> {
|
||||
private readonly _languages: string[]
|
||||
|
@ -619,36 +620,16 @@ class MiscTagRenderingChecks extends DesugaringStep<TagRenderingConfigJson> {
|
|||
': detected `special` on the top level. Did you mean `{"render":{ "special": ... }}`'
|
||||
)
|
||||
}
|
||||
if (json["question"] && !this._options?.noQuestionHintCheck) {
|
||||
const question = Translations.T(
|
||||
new TypedTranslation(json["question"]),
|
||||
context + ".question"
|
||||
)
|
||||
for (const lng of question.SupportedLanguages()) {
|
||||
const html = document.createElement("p")
|
||||
html.innerHTML = question.textFor(lng)
|
||||
const divs = Array.from(html.getElementsByTagName("div"))
|
||||
const spans = Array.from(html.getElementsByTagName("span"))
|
||||
const brs = Array.from(html.getElementsByTagName("br"))
|
||||
const subtles = Array.from(html.getElementsByClassName("subtle"))
|
||||
if (divs.length + spans.length + brs.length + subtles.length > 0) {
|
||||
warnings.push(
|
||||
`At ${context}: the question for ${lng} contains a div, a span, a br or an element with class 'subtle'. Please, use a \`questionHint\` instead.
|
||||
The question is: ${question.textFor(lng)}`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
const freeformType = json["freeform"]?.["type"]
|
||||
if (freeformType) {
|
||||
if (ValidatedTextField.AvailableTypes().indexOf(freeformType) < 0) {
|
||||
if (Validators.AvailableTypes().indexOf(freeformType) < 0) {
|
||||
throw (
|
||||
"At " +
|
||||
context +
|
||||
".freeform.type is an unknown type: " +
|
||||
freeformType +
|
||||
"; try one of " +
|
||||
ValidatedTextField.AvailableTypes().join(", ")
|
||||
Validators.AvailableTypes().join(", ")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -942,13 +923,12 @@ export class ValidateFilter extends DesugaringStep<FilterConfigJson> {
|
|||
for (let i = 0; i < option.fields.length; i++) {
|
||||
const field = option.fields[i]
|
||||
const type = field.type ?? "string"
|
||||
if (!ValidatedTextField.ForType(type) !== undefined) {
|
||||
continue
|
||||
if (Validators.AvailableTypes().find((t) => t === type) === undefined) {
|
||||
const err = `Invalid filter: ${type} is not a valid textfield type (at ${context}.fields[${i}])\n\tTry one of ${Array.from(
|
||||
Validators.AvailableTypes()
|
||||
).join(",")}`
|
||||
errors.push(err)
|
||||
}
|
||||
const err = `Invalid filter: ${type} is not a valid validated textfield type (at ${context}.fields[${i}])\n\tTry one of ${Array.from(
|
||||
ValidatedTextField.AvailableTypes()
|
||||
).join(",")}`
|
||||
errors.push(err)
|
||||
}
|
||||
}
|
||||
return { result: filter, errors }
|
||||
|
|
36
Models/ThemeConfig/Conversion/ValidationUtils.ts
Normal file
36
Models/ThemeConfig/Conversion/ValidationUtils.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
import { TagRenderingConfigJson } from "../Json/TagRenderingConfigJson"
|
||||
import { Utils } from "../../../Utils"
|
||||
import SpecialVisualizations from "../../../UI/SpecialVisualizations"
|
||||
|
||||
export default class ValidationUtils {
|
||||
/**
|
||||
* Gives all the (function names of) used special visualisations
|
||||
* @param renderingConfig
|
||||
*/
|
||||
public static getSpecialVisualisations(renderingConfig: TagRenderingConfigJson): string[] {
|
||||
const translations: any[] = Utils.NoNull([
|
||||
renderingConfig.render,
|
||||
...(renderingConfig.mappings ?? []).map((m) => m.then),
|
||||
])
|
||||
const all: string[] = []
|
||||
for (let translation of translations) {
|
||||
if (typeof translation == "string") {
|
||||
translation = { "*": translation }
|
||||
}
|
||||
|
||||
for (const key in translation) {
|
||||
if (!translation.hasOwnProperty(key)) {
|
||||
continue
|
||||
}
|
||||
|
||||
const template = translation[key]
|
||||
const parts = SpecialVisualizations.constructSpecification(template)
|
||||
const specials = parts
|
||||
.filter((p) => typeof p !== "string")
|
||||
.map((special) => special["func"].funcName)
|
||||
all.push(...specials)
|
||||
}
|
||||
}
|
||||
return all
|
||||
}
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
import { SubstitutedTranslation } from "../../UI/SubstitutedTranslation"
|
||||
import TagRenderingConfig from "./TagRenderingConfig"
|
||||
import { ExtraFuncParams, ExtraFunctions } from "../../Logic/ExtraFunctions"
|
||||
import LayerConfig from "./LayerConfig"
|
||||
import { SpecialVisualization } from "../../UI/SpecialVisualization"
|
||||
import SpecialVisualizations from "../../UI/SpecialVisualizations"
|
||||
|
||||
export default class DependencyCalculator {
|
||||
public static GetTagRenderingDependencies(tr: TagRenderingConfig): string[] {
|
||||
|
@ -16,8 +16,9 @@ export default class DependencyCalculator {
|
|||
|
||||
for (const part of parts) {
|
||||
const specialVizs: { func: SpecialVisualization; args: string[] }[] =
|
||||
SubstitutedTranslation.ExtractSpecialComponents(part)
|
||||
.map((o) => o.special)
|
||||
SpecialVisualizations.constructSpecification(part)
|
||||
.filter((p) => typeof p !== "string")
|
||||
.map((p) => <{ func: SpecialVisualization; args: string[] }>p)
|
||||
.filter((o) => o?.func?.getLayerDependencies !== undefined)
|
||||
for (const specialViz of specialVizs) {
|
||||
deps.push(...specialViz.func.getLayerDependencies(specialViz.args))
|
||||
|
|
|
@ -89,9 +89,6 @@ export default class PointRenderingConfig extends WithContextLoader {
|
|||
this.iconSize = this.tr("iconSize", "40,40,center")
|
||||
this.label = this.tr("label", undefined)
|
||||
this.rotation = this.tr("rotation", "0")
|
||||
if (json.pitchAlignment) {
|
||||
console.log("Got a pitch alignment!", json.pitchAlignment)
|
||||
}
|
||||
this.pitchAlignment = this.tr("pitchAlignment", "canvas")
|
||||
this.rotationAlignment = this.tr(
|
||||
"rotationAlignment",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue