From 3334e0d384bef7edc9b0cb37bcd823382811ad32 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Mon, 8 Nov 2021 03:00:58 +0100 Subject: [PATCH] Stricter layer checking --- Customizations/SharedTagRenderings.ts | 2 + Models/Constants.ts | 2 +- Models/ThemeConfig/LayerConfig.ts | 28 ++- Utils.ts | 15 ++ assets/layers/toilet/toilet.json | 253 -------------------------- 5 files changed, 42 insertions(+), 258 deletions(-) diff --git a/Customizations/SharedTagRenderings.ts b/Customizations/SharedTagRenderings.ts index c44156345..977dc2b4d 100644 --- a/Customizations/SharedTagRenderings.ts +++ b/Customizations/SharedTagRenderings.ts @@ -37,6 +37,8 @@ export default class SharedTagRenderings { for (const key in icons) { dict.set(key, icons[key]) } + + dict.forEach((value, key) => value.id = key) return dict; } diff --git a/Models/Constants.ts b/Models/Constants.ts index ed4d21c37..dfc3ccf8f 100644 --- a/Models/Constants.ts +++ b/Models/Constants.ts @@ -2,7 +2,7 @@ import {Utils} from "../Utils"; export default class Constants { - public static vNumber = "0.12.1"; + public static vNumber = "0.12.2"; public static ImgurApiKey = '7070e7167f0a25a' public static readonly mapillary_client_token_v3 = 'TXhLaWthQ1d4RUg0czVxaTVoRjFJZzowNDczNjUzNmIyNTQyYzI2' public static readonly mapillary_client_token_v4 = "MLY|4441509239301885|b40ad2d3ea105435bd40c7e76993ae85" diff --git a/Models/ThemeConfig/LayerConfig.ts b/Models/ThemeConfig/LayerConfig.ts index 34918c7dd..d8a067701 100644 --- a/Models/ThemeConfig/LayerConfig.ts +++ b/Models/ThemeConfig/LayerConfig.ts @@ -21,6 +21,7 @@ import Combine from "../../UI/Base/Combine"; import Title from "../../UI/Base/Title"; import List from "../../UI/Base/List"; import Link from "../../UI/Base/Link"; +import {Utils} from "../../Utils"; export default class LayerConfig extends WithContextLoader { @@ -203,19 +204,38 @@ export default class LayerConfig extends WithContextLoader { .filter(r => r["location"] === undefined) .map((r, i) => new LineRenderingConfig(r, context + ".mapRendering[" + i + "]")) - - this.tagRenderings = this.ExtractLayerTagRenderings(json) const missingIds = json.tagRenderings?.filter(tr => typeof tr !== "string" && tr["builtin"] === undefined && tr["id"] === undefined && tr["rewrite"] === undefined) ?? []; - - if (missingIds.length > 0 && official) { + if (missingIds?.length > 0 && official) { console.error("Some tagRenderings of", this.id, "are missing an id:", missingIds) throw "Missing ids in tagrenderings" } + this.tagRenderings = this.ExtractLayerTagRenderings(json) + { + + + const emptyIds = this.tagRenderings.filter(tr => tr.id === ""); + if (emptyIds.length > 0) { + throw `Some tagrendering-ids are empty or have an emtpy string; this is not allowed (at ${context})` + } + + const duplicateIds = Utils.Dupicates(this.tagRenderings.map(f => f.id).filter(id => id !== "questions")) + if (duplicateIds.length > 0) { + throw `Some tagRenderings have a duplicate id: ${duplicateIds} (at ${context}.tagRenderings)` + } + } + this.filters = (json.filter ?? []).map((option, i) => { return new FilterConfig(option, `${context}.filter-[${i}]`) }); + { + const duplicateIds = Utils.Dupicates(this.filters.map(f => f.id)) + if (duplicateIds.length > 0) { + throw `Some filters have a duplicate id: ${duplicateIds} (at ${context}.filters)` + } + } + if (json["filters"] !== undefined) { throw "Error in " + context + ": use 'filter' instead of 'filters'" } diff --git a/Utils.ts b/Utils.ts index 21210a086..30727e345 100644 --- a/Utils.ts +++ b/Utils.ts @@ -144,6 +144,21 @@ Note that these values can be prepare with javascript in the theme by using a [c return newArr; } + public static Dupicates(arr: string[]): string[] { + if (arr === undefined) { + return undefined; + } + const newArr = []; + const seen = new Set(); + for (const string of arr) { + if(seen.has(string)){ + newArr.push(string) + } + seen.add(string) + } + return newArr; + } + public static Identical(t1: T[], t2: T[], eq?: (t: T, t0: T) => boolean): boolean { if (t1.length !== t2.length) { return false diff --git a/assets/layers/toilet/toilet.json b/assets/layers/toilet/toilet.json index ffef24701..f7c16b5e9 100644 --- a/assets/layers/toilet/toilet.json +++ b/assets/layers/toilet/toilet.json @@ -148,246 +148,6 @@ ], "id": "toilet-access" }, - { - "question": { - "en": "Are these toilets publicly accessible?", - "de": "Sind diese Toiletten öffentlich zugänglich?", - "fr": "Ces toilettes sont-elles accessibles au public ?", - "nl": "Zijn deze toiletten publiek toegankelijk?", - "it": "Questi servizi igienici sono aperti al pubblico?", - "ru": "Есть ли свободный доступ к этим туалетам?" - }, - "render": { - "en": "Access is {access}", - "de": "Zugang ist {access}", - "fr": "L'accès est {access}", - "nl": "Toegankelijkheid is {access}", - "it": "L'accesso è {access}" - }, - "freeform": { - "key": "access", - "addExtraTags": [ - "fixme=the tag access was filled out by the user and might need refinement" - ] - }, - "mappings": [ - { - "if": "access=yes", - "then": { - "en": "Public access", - "de": "Öffentlicher Zugang", - "fr": "Accès publique", - "nl": "Publiek toegankelijk", - "it": "Accesso pubblico", - "ru": "Свободный доступ" - } - }, - { - "if": "access=customers", - "then": { - "en": "Only access to customers", - "de": "Nur Zugang für Kunden", - "fr": "Accès réservé aux clients", - "nl": "Enkel toegang voor klanten", - "it": "Accesso riservato ai clienti e alle clienti" - } - }, - { - "if": "access=no", - "then": { - "en": "Not accessible", - "de": "Nicht zugänglich", - "fr": "Toilettes privées", - "nl": "Niet toegankelijk", - "ru": "Недоступно", - "it": "Non accessibile" - } - }, - { - "if": "access=key", - "then": { - "en": "Accessible, but one has to ask a key to enter", - "de": "Zugänglich, aber man muss einen Schlüssel für die Eingabe verlangen", - "fr": "Accessible, mais vous devez demander la clé", - "nl": "Toegankelijk na het vragen van de sleutel", - "it": "Accessibile, ma occorre chiedere una chiave per accedere" - } - }, - { - "if": "access=public", - "then": { - "en": "Public access", - "de": "Öffentlicher Zugang", - "fr": "Accès publique", - "nl": "Publiek toegankelijk", - "it": "Accesso pubblico", - "ru": "Свободный доступ" - }, - "hideInAnswer": true - } - ], - "id": "toilet-access" - }, - { - "question": { - "en": "Are these toilets publicly accessible?", - "de": "Sind diese Toiletten öffentlich zugänglich?", - "fr": "Ces toilettes sont-elles accessibles au public ?", - "nl": "Zijn deze toiletten publiek toegankelijk?", - "it": "Questi servizi igienici sono aperti al pubblico?", - "ru": "Есть ли свободный доступ к этим туалетам?" - }, - "render": { - "en": "Access is {access}", - "de": "Zugang ist {access}", - "fr": "L'accès est {access}", - "nl": "Toegankelijkheid is {access}", - "it": "L'accesso è {access}" - }, - "freeform": { - "key": "access", - "addExtraTags": [ - "fixme=the tag access was filled out by the user and might need refinement" - ] - }, - "mappings": [ - { - "if": "access=yes", - "then": { - "en": "Public access", - "de": "Öffentlicher Zugang", - "fr": "Accès publique", - "nl": "Publiek toegankelijk", - "it": "Accesso pubblico", - "ru": "Свободный доступ" - } - }, - { - "if": "access=customers", - "then": { - "en": "Only access to customers", - "de": "Nur Zugang für Kunden", - "fr": "Accès réservé aux clients", - "nl": "Enkel toegang voor klanten", - "it": "Accesso riservato ai clienti e alle clienti" - } - }, - { - "if": "access=no", - "then": { - "en": "Not accessible", - "de": "Nicht zugänglich", - "fr": "Toilettes privées", - "nl": "Niet toegankelijk", - "ru": "Недоступно", - "it": "Non accessibile" - } - }, - { - "if": "access=key", - "then": { - "en": "Accessible, but one has to ask a key to enter", - "de": "Zugänglich, aber man muss einen Schlüssel für die Eingabe verlangen", - "fr": "Accessible, mais vous devez demander la clé", - "nl": "Toegankelijk na het vragen van de sleutel", - "it": "Accessibile, ma occorre chiedere una chiave per accedere" - } - }, - { - "if": "access=public", - "then": { - "en": "Public access", - "de": "Öffentlicher Zugang", - "fr": "Accès publique", - "nl": "Publiek toegankelijk", - "it": "Accesso pubblico", - "ru": "Свободный доступ" - }, - "hideInAnswer": true - } - ], - "id": "toilet-access" - }, - { - "question": { - "en": "Are these toilets publicly accessible?", - "de": "Sind diese Toiletten öffentlich zugänglich?", - "fr": "Ces toilettes sont-elles accessibles au public ?", - "nl": "Zijn deze toiletten publiek toegankelijk?", - "it": "Questi servizi igienici sono aperti al pubblico?", - "ru": "Есть ли свободный доступ к этим туалетам?" - }, - "render": { - "en": "Access is {access}", - "de": "Zugang ist {access}", - "fr": "L'accès est {access}", - "nl": "Toegankelijkheid is {access}", - "it": "L'accesso è {access}" - }, - "freeform": { - "key": "access", - "addExtraTags": [ - "fixme=the tag access was filled out by the user and might need refinement" - ] - }, - "mappings": [ - { - "if": "access=yes", - "then": { - "en": "Public access", - "de": "Öffentlicher Zugang", - "fr": "Accès publique", - "nl": "Publiek toegankelijk", - "it": "Accesso pubblico", - "ru": "Свободный доступ" - } - }, - { - "if": "access=customers", - "then": { - "en": "Only access to customers", - "de": "Nur Zugang für Kunden", - "fr": "Accès réservé aux clients", - "nl": "Enkel toegang voor klanten", - "it": "Accesso riservato ai clienti e alle clienti" - } - }, - { - "if": "access=no", - "then": { - "en": "Not accessible", - "de": "Nicht zugänglich", - "fr": "Toilettes privées", - "nl": "Niet toegankelijk", - "ru": "Недоступно", - "it": "Non accessibile" - } - }, - { - "if": "access=key", - "then": { - "en": "Accessible, but one has to ask a key to enter", - "de": "Zugänglich, aber man muss einen Schlüssel für die Eingabe verlangen", - "fr": "Accessible, mais vous devez demander la clé", - "nl": "Toegankelijk na het vragen van de sleutel", - "it": "Accessibile, ma occorre chiedere una chiave per accedere" - } - }, - { - "if": "access=public", - "then": { - "en": "Public access", - "de": "Öffentlicher Zugang", - "fr": "Accès publique", - "nl": "Publiek toegankelijk", - "it": "Accesso pubblico", - "ru": "Свободный доступ" - }, - "hideInAnswer": true - } - ], - "id": "toilet-access" - }, { "id": "toilets-fee", "question": { @@ -679,19 +439,6 @@ } ], "filter": [ - { - "id": "wheelchair", - "options": [ - { - "question": { - "en": "Wheelchair accessible", - "nl": "Rolstoel toegankelijk", - "de": "Rollstuhlgerecht" - }, - "osmTags": "wheelchair=yes" - } - ] - }, { "id": "wheelchair", "options": [