diff --git a/Models/ThemeConfig/Conversion/Conversion.ts b/Models/ThemeConfig/Conversion/Conversion.ts index 6d93c0158d..da5cca313a 100644 --- a/Models/ThemeConfig/Conversion/Conversion.ts +++ b/Models/ThemeConfig/Conversion/Conversion.ts @@ -19,14 +19,17 @@ export abstract class Conversion { } public static strict(fixed: { errors?: string[], warnings?: string[], information?: string[], result?: T }): T { - if (fixed?.errors !== undefined && fixed?.errors?.length > 0) { - throw fixed.errors.join("\n\n"); - } + fixed.information?.forEach(i => console.log(" ", i)) const yellow = (s) => "\x1b[33m"+s+"\x1b[0m" const red = s => '\x1b[31m'+s+'\x1b[0m' - fixed.warnings?.forEach(w => console.warn(red(` `), yellow (w))) + + if (fixed?.errors !== undefined && fixed?.errors?.length > 0) { + fixed.errors?.forEach(e => console.error(red(`ERR `+e))) + throw "Detected one or more errors, stopping now" + } + return fixed.result; } diff --git a/Models/ThemeConfig/Conversion/Validation.ts b/Models/ThemeConfig/Conversion/Validation.ts index 46d426793b..c5afde99f7 100644 --- a/Models/ThemeConfig/Conversion/Validation.ts +++ b/Models/ThemeConfig/Conversion/Validation.ts @@ -238,8 +238,25 @@ export class PrevalidateTheme extends Fuse { } export class DetectShadowedMappings extends DesugaringStep { - constructor() { + private readonly _calculatedTagNames: string[]; + constructor(layerConfig?: LayerConfigJson) { super("Checks that the mappings don't shadow each other", [], "DetectShadowedMappings"); + this._calculatedTagNames = DetectShadowedMappings.extractCalculatedTagNames(layerConfig); + } + + /** + * + * DetectShadowedMappings.extractCalculatedTagNames({calculatedTags: ["_abc:=js()"]}) // => ["_abc"] + * DetectShadowedMappings.extractCalculatedTagNames({calculatedTags: ["_abc=js()"]}) // => ["_abc"] + */ + private static extractCalculatedTagNames(layerConfig?: LayerConfigJson){ + return layerConfig?.calculatedTags?.map(ct => { + if(ct.indexOf(':=') >= 0){ + return ct.split(':=')[0] + } + return ct.split("=")[0] + }) ?? [] + } convert(json: TagRenderingConfigJson, context: string): { result: TagRenderingConfigJson; errors?: string[]; warnings?: string[] } { @@ -248,6 +265,10 @@ export class DetectShadowedMappings extends DesugaringStep { const ifTags = TagUtils.Tag(m.if); if(m.hideInAnswer !== undefined && m.hideInAnswer !== false && m.hideInAnswer !== true){ @@ -263,7 +284,7 @@ export class DetectShadowedMappings extends DesugaringStep { properties[k] = v @@ -289,10 +310,6 @@ export class DetectShadowedMappings extends DesugaringStep { - constructor() { + constructor(layerConfig: LayerConfigJson) { super("Various validation on tagRenderingConfigs", - new DetectShadowedMappings(), + new DetectShadowedMappings( layerConfig), new DetectMappingsWithImages() ); } @@ -439,7 +456,7 @@ export class ValidateLayer extends DesugaringStep { } } if (json.tagRenderings !== undefined) { - const r = new OnEvery("tagRenderings", new ValidateTagRenderings()).convert(json, context) + const r = new OnEvery("tagRenderings", new ValidateTagRenderings(json)).convert(json, context) warnings.push(...(r.warnings??[])) errors.push(...(r.errors??[])) information.push(...(r.information??[])) diff --git a/assets/themes/grb_import/grb_fixme.json b/assets/themes/grb_import/grb_fixme.json index 2ae057dfd4..f86e294e8b 100644 --- a/assets/themes/grb_import/grb_fixme.json +++ b/assets/themes/grb_import/grb_fixme.json @@ -127,16 +127,12 @@ }, { "if": "building=apartments", - "then": "An apartment building - highrise for living" + "then": "An apartment building (a highrise building for living)" }, { "if": "building=office", "then": "An office building - highrise for work" }, - { - "if": "building=apartments", - "then": "An apartment building" - }, { "if": "building=shed", "then": "A small shed, e.g. in a garden" diff --git a/assets/themes/uk_addresses/uk_addresses.json b/assets/themes/uk_addresses/uk_addresses.json index 4a46793bf1..e09a24ae05 100644 --- a/assets/themes/uk_addresses/uk_addresses.json +++ b/assets/themes/uk_addresses/uk_addresses.json @@ -256,13 +256,14 @@ }, "mappings": [ { - "if": "addr:unit=", - "then": "
Sub-unit (e.g. \"1\", \"Flat 2\", \"Unit C\")
", - "hideInAnswer": true + "if": "not:addr:unit=yes", + "then": "There is no sub-unit within this address", + "addExtraTags": ["addr:unit="] }, { "if": "addr:unit=", - "then": "There is no sub-unit within this address" + "then": "
Sub-unit (e.g. \"1\", \"Flat 2\", \"Unit C\")
", + "hideInAnswer": true } ], "condition": { @@ -291,17 +292,12 @@ "addr:housename=" ] }, - "then": "
House or building name
", - "hideInAnswer": true + "then": "This building has no housename" }, { - "if": { - "and": [ - "nohousename=yes", - "addr:housename=" - ] - }, - "then": "This building has no housename" + "if": "addr:housename=", + "then": "
House or building name
", + "hideInAnswer": true }, { "#": "By adding nohousenumber!=yes, this option will trigger when first added, but will be untriggered if a housenumber is added, resulting in the question poping up!", @@ -329,10 +325,18 @@ ] }, "mappings": [ + { + "if": "nohousenumber=yes", + "then": { + "en": "This building has no house number", + "nl": "Dit gebouw heeft geen huisnummer", + "de": "Dieses Gebäude hat keine Hausnummer" + }, + "addExtraTags": [ "addr:housenumber="] + }, { "if": { "and": [ - "nohousenumber=yes", "addr:housenumber=" ] }, @@ -340,19 +344,6 @@ "en": "
Number (e.g. 1, 1A, 2)
" }, "hideInAnswer": true - }, - { - "if": { - "and": [ - "nohousenumber=yes", - "addr:housenumber=" - ] - }, - "then": { - "en": "This building has no house number", - "nl": "Dit gebouw heeft geen huisnummer", - "de": "Dieses Gebäude hat keine Hausnummer" - } } ] }, @@ -373,17 +364,17 @@ }, "mappings": [ { + "if": "not:addr:substreet=yes", + "then": { + "en": "No extra place name is given or needed" + }, + "addExtraTags": ["addr:substreet="] + },{ "if": "addr:substreet=", "then": { "en": "
Place (e.g. \"Castle Mews\", \"West Business Park\")
" }, "hideInAnswer": true - }, - { - "if": "addr:substreet=", - "then": { - "en": "No extra place name is given or needed" - } } ], "condition": "addr:parentstreet=" @@ -403,18 +394,19 @@ ] }, "mappings": [ + { + "if": "not:addr:substreet=yes", + "then": { + "en": "No extra place name is given or needed" + }, + "addExtraTags": ["addr:substreet="] + }, { "if": "addr:substreet=", "then": { "en": "
Place (e.g. \"Castle Mews\", \"West Business Park\")
" }, "hideInAnswer": true - }, - { - "if": "addr:substreet=", - "then": { - "en": "No extra place name is given or needed" - } } ], "condition": { @@ -479,15 +471,9 @@ }, "mappings": [ { - "if": "addr:parentstreet=", - "then": { - "en": "
Parent street name
" - }, - "hideInAnswer": true - }, - { - "if": "addr:parentstreet=", - "then": "No parent street name is needed within this address" + "if": "not:addr:parentstreet=yes", + "then": "No parent street name is needed within this address", + "addExtraTags": ["addr:parentstreet="] }, { "if": "addr:parentstreet:={_closest_street:0:name}", @@ -503,6 +489,13 @@ "if": "addr:parentstreet:={_closest_street:2:name}", "then": "{_closest_street:2:name}", "hideInAnswer": "_closest_street:2:name=" + }, + { + "if": "addr:parentstreet=", + "then": { + "en": "
Parent street name
" + }, + "hideInAnswer": true } ], "condition": {