forked from MapComplete/MapComplete
Refactoring: move all code files into a src directory
This commit is contained in:
parent
de99f56ca8
commit
e75d2789d2
389 changed files with 0 additions and 12 deletions
64
src/Models/ThemeConfig/Conversion/ValidationUtils.ts
Normal file
64
src/Models/ThemeConfig/Conversion/ValidationUtils.ts
Normal file
|
@ -0,0 +1,64 @@
|
|||
import { TagRenderingConfigJson } from "../Json/TagRenderingConfigJson"
|
||||
import { Utils } from "../../../Utils"
|
||||
import SpecialVisualizations from "../../../UI/SpecialVisualizations"
|
||||
import { RenderingSpecification, SpecialVisualization } from "../../../UI/SpecialVisualization"
|
||||
import { LayerConfigJson } from "../Json/LayerConfigJson"
|
||||
|
||||
export default class ValidationUtils {
|
||||
public static hasSpecialVisualisation(
|
||||
layer: LayerConfigJson,
|
||||
specialVisualisation: string
|
||||
): boolean {
|
||||
return (
|
||||
layer.tagRenderings?.some((tagRendering) => {
|
||||
if (tagRendering === undefined) {
|
||||
return false
|
||||
}
|
||||
|
||||
const spec = ValidationUtils.getSpecialVisualisations(
|
||||
<TagRenderingConfigJson>tagRendering
|
||||
)
|
||||
return spec.some((vis) => vis.funcName === specialVisualisation)
|
||||
}) ?? false
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives all the (function names of) used special visualisations
|
||||
* @param renderingConfig
|
||||
*/
|
||||
public static getSpecialVisualisations(
|
||||
renderingConfig: TagRenderingConfigJson
|
||||
): SpecialVisualization[] {
|
||||
return ValidationUtils.getSpecialVisualsationsWithArgs(renderingConfig).map(
|
||||
(spec) => spec["func"]
|
||||
)
|
||||
}
|
||||
|
||||
public static getSpecialVisualsationsWithArgs(
|
||||
renderingConfig: TagRenderingConfigJson
|
||||
): RenderingSpecification[] {
|
||||
const translations: any[] = Utils.NoNull([
|
||||
renderingConfig.render,
|
||||
...(renderingConfig.mappings ?? []).map((m) => m.then),
|
||||
])
|
||||
const all: RenderingSpecification[] = []
|
||||
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")
|
||||
all.push(...specials)
|
||||
}
|
||||
}
|
||||
return all
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue