Skip to content

Commit

Permalink
Small fixes for the GRB theme and value substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
pietervdvn committed Aug 26, 2020
1 parent 328dc55 commit 71f4d40
Show file tree
Hide file tree
Showing 17 changed files with 798 additions and 74 deletions.
48 changes: 35 additions & 13 deletions Customizations/Layers/GrbToFix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,30 @@ export class GrbToFix extends LayerDefinition {

this.title = new TagRenderingOptions({
freeform: {
key: "fixme",
renderTemplate: "{fixme}",
key: "addr:street",
renderTemplate: "{addr:street} <b>{addr:housenumber}</b>",
template: "Fixme $$$"
}
},
mappings: [
{
k: new Tag("fixme","*"),
txt: "{fixme}"
}
]
})

this.elementsToShow = [

new TagRenderingOptions(
{
freeform: {
key: "addr:street",
key: "addr:housenumber",
renderTemplate: "Het adres is {addr:street} <b>{addr:housenumber}</b>",
template: "Straat? $$$"
}
template: "Straat? $$$",
},
question: "Wat is het huisnummer?"
}
),
).OnlyShowIf(new Tag("fixme","*","")),

new TagRenderingOptions({

Expand All @@ -61,22 +68,37 @@ export class GrbToFix extends LayerDefinition {
freeform: {
key: "addr:housenumber",
template: "Het huisnummer is $$$",
renderTemplate: "Het huisnummer is <b>{addr:housenumber}</b>, GRB denkt <i>{grb:housenumber:human}</i>",
extraTags: new Tag("fixme", "")
renderTemplate: "Het adres is {addr:street} <b>{addr:housenumber}</b>, GRB denkt <i>{grb:housenumber:human}</i>",
extraTags: new And([new Tag("fixme", ""), new Tag("not:addr:housenumber", "")])
},
mappings: [
{
k: new And([new Tag("addr:housenumber", "{grb:housenumber}"), new Tag("fixme", "")]),
k: new And([new Tag("addr:housenumber", "{grb:housenumber}"), new Tag("fixme", ""), new Tag("not:addr:housenumber", "")]),
txt: "Volg GRB: <b>{grb:housenumber:human}</b>",
substitute: true
},
{
k: new And([new Tag("addr:housenumber", "{addr:housenumber}"), new Tag("fixme", "")]),
k: new And([new Tag("addr:housenumber", "{addr:housenumber}"), new Tag("fixme", ""), new Tag("not:addr:housenumber", "")]),
txt: "Volg OSM: <b>{addr:housenumber}</b>",
substitute: true
}
},
{
k: new And([new Tag("building", "garage"),
new Tag("not:addr:housenumber", "yes"),
new Tag("addr:housenumber", ""), new Tag("fixme", "")]),
txt: "Dit is een garage(poort) zonder nummer",
substitute: true
},
{
k: new And([
new Tag("not:addr:housenumber", "yes"),
new Tag("addr:housenumber", ""), new Tag("fixme", "")]),
txt: "Gewoon een huis zonder nummer",
substitute: true
},

]
})
}).OnlyShowIf(new Tag("fixme", "*"))


];
Expand Down
1 change: 1 addition & 0 deletions Customizations/Layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class Layout {
public maintainer: string;
public version: string;
public description: string | UIElement;
public changesetMessage: string;
public socialImage: string = "";

public layers: LayerDefinition[];
Expand Down
50 changes: 26 additions & 24 deletions Customizations/TagRendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export class TagRendering extends UIElement implements TagDependantUIElement {
private _question: string | Translation;
private _mapping: { k: TagsFilter, txt: string | UIElement, priority?: number }[];

private _tagsPreprocessor?: ((tags: any) => any);
private currentTags : UIEventSource<any> ;


private _freeform: {
key: string,
template: string | UIElement,
Expand Down Expand Up @@ -85,17 +87,23 @@ export class TagRendering extends UIElement implements TagDependantUIElement {
const self = this;

this._priority = options.priority ?? 0;
this._tagsPreprocessor = function (properties) {
if (options.tagsPreprocessor === undefined) {
return properties;
}
const newTags = {};
for (const k in properties) {
newTags[k] = properties[k];

this.currentTags = this._source.map(tags =>
{

if (options.tagsPreprocessor === undefined) {
return tags;
}
// we clone the tags...
let newTags = {};
for (const k in tags) {
newTags[k] = tags[k];
}
// ... in order to safely edit them here
options.tagsPreprocessor(newTags);
return newTags;
}
options.tagsPreprocessor(newTags);
return newTags;
};
);

if (options.question !== undefined) {
this._question = options.question;
Expand All @@ -106,19 +114,12 @@ export class TagRendering extends UIElement implements TagDependantUIElement {


for (const choice of options.mappings ?? []) {


let choiceSubbed = {
k: choice.k,
k: choice.k.substituteValues(this.currentTags.data),
txt: choice.txt,
priority: choice.priority
};

if (choice.substitute) {
const newTags = this._tagsPreprocessor(this._source.data);
choiceSubbed = {
k: choice.k.substituteValues(newTags),
txt: choice.txt,
priority: choice.priority
}
}


Expand Down Expand Up @@ -242,7 +243,9 @@ export class TagRendering extends UIElement implements TagDependantUIElement {


private InputElementForMapping(mapping: { k: TagsFilter, txt: string | Translation }) {
return new FixedInputElement(this.ApplyTemplate(mapping.txt), mapping.k);
return new FixedInputElement(this.ApplyTemplate(mapping.txt),
mapping.k.substituteValues(this.currentTags.data)
);
}


Expand Down Expand Up @@ -455,8 +458,7 @@ export class TagRendering extends UIElement implements TagDependantUIElement {
throw "Trying to apply a template, but the template is null/undefined"
}
const self = this;
const tags = this._source.map(tags => self._tagsPreprocessor(self._source.data));
return new VariableUiElement(tags.map(tags => {
return new VariableUiElement(this.currentTags.map(tags => {
const tr = Translations.WT(template);
if (tr.Subs === undefined) {
// This is a weird edge case
Expand Down
Loading

0 comments on commit 71f4d40

Please sign in to comment.