Add the possibility to define a postfix and prefix for opening hours

This commit is contained in:
Pieter Vander Vennet 2021-10-29 03:42:33 +02:00
parent 9c147b6ec6
commit a2306c2c6f
10 changed files with 281 additions and 81 deletions

View file

@ -23,10 +23,16 @@ export default class OpeningHoursVisualization extends Toggle {
Translations.t.general.weekdays.abbreviations.sunday,
]
constructor(tags: UIEventSource<any>, key: string) {
constructor(tags: UIEventSource<any>, key: string, prefix = "", postfix = "") {
const tagsDirect = tags.data;
const ohTable = new VariableUiElement(tags
.map(tags => tags[key]) // This mapping will absorb all other changes to tags in order to prevent regeneration
.map(tags => {
const value : string = tags[key];
if(value.startsWith(prefix) && value.endsWith(postfix)){
return value.substring(prefix.length, value.length - postfix.length)
}
return value;
}) // This mapping will absorb all other changes to tags in order to prevent regeneration
.map(ohtext => {
try {
// noinspection JSPotentiallyInvalidConstructorUsage