Add some IDs and validation on IDS

This commit is contained in:
Pieter Vander Vennet 2021-09-26 18:15:21 +02:00
parent 4cb09ba8e7
commit 699e609fd7
6 changed files with 20 additions and 285 deletions

View file

@ -8,7 +8,7 @@ export interface TagRenderingConfigJson {
/**
* The id of the tagrendering, should be an unique string.
* Used to keep the translations in sync
* Used to keep the translations in sync. Only used in the tagRenderings-array of a layerConfig, not requered otherwise
*/
id?: string,

View file

@ -275,7 +275,14 @@ export default class LayerConfig {
}
this.tagRenderings = trs(json.tagRenderings, false);
const missingIds = json.tagRenderings.filter(tr => typeof tr !== "string" && tr["builtin"] === undefined && tr["id"] === undefined);
if(missingIds.length > 0){
console.error("Some tagRenderings of", this.id, "are missing an id:", missingIds)
throw "Missing ids in tagrenderings"
}
this.filters = (json.filter ?? []).map((option, i) => {
return new FilterConfig(option, `${context}.filter-[${i}]`)
});

View file

@ -13,7 +13,7 @@ import {Utils} from "../../Utils";
*/
export default class TagRenderingConfig {
readonly id?: string;
readonly id: string;
readonly render?: Translation;
readonly question?: Translation;
readonly condition?: TagsFilter;
@ -57,6 +57,7 @@ export default class TagRenderingConfig {
return;
}
this.id = json.id ?? "";
this.render = Translations.T(json.render, context + ".render");
this.question = Translations.T(json.question, context + ".question");