forked from MapComplete/MapComplete
		
	Small fixes for the GRB theme and value substitution
This commit is contained in:
		
							parent
							
								
									328dc5577c
								
							
						
					
					
						commit
						71f4d4091e
					
				
					 17 changed files with 798 additions and 74 deletions
				
			
		|  | @ -28,10 +28,16 @@ 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 = [ | ||||
|  | @ -39,12 +45,13 @@ export class GrbToFix extends LayerDefinition { | |||
|             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({ | ||||
| 
 | ||||
|  | @ -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", "*")) | ||||
| 
 | ||||
| 
 | ||||
|         ]; | ||||
|  |  | |||
|  | @ -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[]; | ||||
|  |  | |||
|  | @ -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, | ||||
|  | @ -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; | ||||
|          | ||||
|         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; | ||||
|             } | ||||
|             const newTags = {}; | ||||
|             for (const k in properties) { | ||||
|                 newTags[k] = properties[k]; | ||||
|             } | ||||
|             options.tagsPreprocessor(newTags); | ||||
|             return newTags; | ||||
|         }; | ||||
|         ); | ||||
| 
 | ||||
|         if (options.question !== undefined) { | ||||
|             this._question = options.question; | ||||
|  | @ -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 | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
| 
 | ||||
|  | @ -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) | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|  | @ -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
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue