forked from MapComplete/MapComplete
		
	Add option that a TagRendering can automatically introduce a builtin filter when added
This commit is contained in:
		
							parent
							
								
									f33e9f78b7
								
							
						
					
					
						commit
						5bd14c64da
					
				
					 10 changed files with 54 additions and 16 deletions
				
			
		|  | @ -613,7 +613,6 @@ | ||||||
|     } |     } | ||||||
|   ], |   ], | ||||||
|   "filter": [ |   "filter": [ | ||||||
|     "open_now", |  | ||||||
|     { |     { | ||||||
|       "id": "speech_output", |       "id": "speech_output", | ||||||
|       "options": [ |       "options": [ | ||||||
|  |  | ||||||
|  | @ -893,7 +893,6 @@ | ||||||
|     "description" |     "description" | ||||||
|   ], |   ], | ||||||
|   "filter": [ |   "filter": [ | ||||||
|     "open_now", |  | ||||||
|     { |     { | ||||||
|       "id": "sells_second-hand", |       "id": "sells_second-hand", | ||||||
|       "options": [ |       "options": [ | ||||||
|  |  | ||||||
|  | @ -435,7 +435,6 @@ | ||||||
|     "check_date" |     "check_date" | ||||||
|   ], |   ], | ||||||
|   "filter": [ |   "filter": [ | ||||||
|     "open_now", |  | ||||||
|     "accepts_debit_cards", |     "accepts_debit_cards", | ||||||
|     "accepts_credit_cards" |     "accepts_credit_cards" | ||||||
|   ], |   ], | ||||||
|  |  | ||||||
|  | @ -1304,10 +1304,10 @@ | ||||||
|         } |         } | ||||||
|       ] |       ] | ||||||
|     }, |     }, | ||||||
|     "has_organic", |     "filters.has_organic", | ||||||
|     "sugar_free", |     "filters.sugar_free", | ||||||
|     "gluten_free", |     "filters.gluten_free", | ||||||
|     "lactose_free", |     "filters.lactose_free", | ||||||
|     "accepts_cash", |     "accepts_cash", | ||||||
|     "accepts_cards", |     "accepts_cards", | ||||||
|     "dogs" |     "dogs" | ||||||
|  |  | ||||||
|  | @ -663,9 +663,6 @@ | ||||||
|         } |         } | ||||||
|       ] |       ] | ||||||
|     }, |     }, | ||||||
|     "accepts_cash", |  | ||||||
|     "accepts_cards", |  | ||||||
|     "has_organic", |  | ||||||
|     { |     { | ||||||
|       "id": "second_hand", |       "id": "second_hand", | ||||||
|       "options": [ |       "options": [ | ||||||
|  | @ -686,9 +683,7 @@ | ||||||
|         } |         } | ||||||
|       ] |       ] | ||||||
|     }, |     }, | ||||||
|     "sugar_free", |     "filters.has_organic" | ||||||
|     "gluten_free", |  | ||||||
|     "lactose_free" |  | ||||||
|   ], |   ], | ||||||
|   "deletion": { |   "deletion": { | ||||||
|     "softDeletionTags": { |     "softDeletionTags": { | ||||||
|  |  | ||||||
|  | @ -236,8 +236,11 @@ export class GenerateFavouritesLayer extends Script { | ||||||
|                 if (seenTitleIcons.has(titleIcon.id)) { |                 if (seenTitleIcons.has(titleIcon.id)) { | ||||||
|                     continue |                     continue | ||||||
|                 } |                 } | ||||||
|  |                 if(titleIcon.id === undefined){ | ||||||
|  |                    continue | ||||||
|  |                 } | ||||||
|                 seenTitleIcons.add(titleIcon.id) |                 seenTitleIcons.add(titleIcon.id) | ||||||
|                 console.log("Adding ", titleIcon.id) |                 console.log("Adding title icon", titleIcon.id) | ||||||
|                 titleIcons.push(titleIcon) |                 titleIcons.push(titleIcon) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -332,6 +332,7 @@ class LayerOverviewUtils extends Script { | ||||||
|             return <QuestionableTagRenderingConfigJson[]>sharedQuestions.tagRenderings |             return <QuestionableTagRenderingConfigJson[]>sharedQuestions.tagRenderings | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|         return this.getSharedTagRenderings( |         return this.getSharedTagRenderings( | ||||||
|             doesImageExist, |             doesImageExist, | ||||||
|             dict, |             dict, | ||||||
|  |  | ||||||
|  | @ -62,8 +62,37 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> { | ||||||
| 
 | 
 | ||||||
|         const newFilters: FilterConfigJson[] = [] |         const newFilters: FilterConfigJson[] = [] | ||||||
|         const filters = <(FilterConfigJson | string)[]>json.filter |         const filters = <(FilterConfigJson | string)[]>json.filter | ||||||
|  | 
 | ||||||
|  |         for (let i = 0; i < json.tagRenderings?.length; i++){ | ||||||
|  |             const tagRendering = <TagRenderingConfigJson> json.tagRenderings[i] | ||||||
|  |             if(!tagRendering.filter){ | ||||||
|  |                 continue | ||||||
|  |             } | ||||||
|  |             for (const filterName of tagRendering.filter ?? []) { | ||||||
|  |                 if(typeof filterName !== "string"){ | ||||||
|  |                     context.enters("tagRenderings",i,"filter").err("Not a string: "+ filterName) | ||||||
|  |                 } | ||||||
|  |                 const exists = filters.some(existing => { | ||||||
|  |                     const id : string =  existing["id"] ?? existing | ||||||
|  |                     return filterName === id || (filterName.startsWith("filters.") && filterName.endsWith("."+id)) | ||||||
|  |                 }) | ||||||
|  |                 if(exists){ | ||||||
|  |                     continue | ||||||
|  |                 } | ||||||
|  |                 if(!filterName){ | ||||||
|  |                     context.err("Got undefined as filter expansion in "+tagRendering["id"]) | ||||||
|  |                     continue | ||||||
|  |                 } | ||||||
|  |                 console.log("Adding filter",filterName," due to", tagRendering["id"]) | ||||||
|  |                 filters.push(filterName) | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         for (let i = 0; i < filters.length; i++) { |         for (let i = 0; i < filters.length; i++) { | ||||||
|             const filter = filters[i] |             const filter = filters[i] | ||||||
|  |             if(filter === undefined){ | ||||||
|  |                 continue | ||||||
|  |             } | ||||||
|             if (typeof filter !== "string") { |             if (typeof filter !== "string") { | ||||||
|                 newFilters.push(filter) |                 newFilters.push(filter) | ||||||
|                 continue |                 continue | ||||||
|  | @ -85,7 +114,7 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> { | ||||||
|                     osmTags: mapping.if, |                     osmTags: mapping.if, | ||||||
|                 })) |                 })) | ||||||
|                 options.unshift({ |                 options.unshift({ | ||||||
|                     question: { |                     question: matchingTr["question"] ?? { | ||||||
|                         en: "All types", |                         en: "All types", | ||||||
|                     }, |                     }, | ||||||
|                     osmTags: undefined, |                     osmTags: undefined, | ||||||
|  | @ -113,7 +142,11 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> { | ||||||
|                     const expandedFilter = (<(FilterConfigJson | string)[]>layer.filter).find( |                     const expandedFilter = (<(FilterConfigJson | string)[]>layer.filter).find( | ||||||
|                         (f) => typeof f !== "string" && f.id === expectedId |                         (f) => typeof f !== "string" && f.id === expectedId | ||||||
|                     ) |                     ) | ||||||
|  |                     if(expandedFilter === undefined){ | ||||||
|  |                         context.err("Did not find filter with name "+filter) | ||||||
|  |                     }else{ | ||||||
|                         newFilters.push(<FilterConfigJson>expandedFilter) |                         newFilters.push(<FilterConfigJson>expandedFilter) | ||||||
|  |                     } | ||||||
|                 } else { |                 } else { | ||||||
|                     // This is a bootstrapping-run, we can safely ignore this
 |                     // This is a bootstrapping-run, we can safely ignore this
 | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|  | @ -1761,6 +1761,10 @@ export class ValidateFilter extends DesugaringStep<FilterConfigJson> { | ||||||
|             // Calling another filter, we skip
 |             // Calling another filter, we skip
 | ||||||
|             return filter |             return filter | ||||||
|         } |         } | ||||||
|  |         if(filter === undefined){ | ||||||
|  |             context.err("Trying to validate a filter, but this filter is undefined") | ||||||
|  |             return undefined | ||||||
|  |         } | ||||||
|         for (const option of filter.options) { |         for (const option of filter.options) { | ||||||
|             for (let i = 0; i < option.fields?.length ?? 0; i++) { |             for (let i = 0; i < option.fields?.length ?? 0; i++) { | ||||||
|                 const field = option.fields[i] |                 const field = option.fields[i] | ||||||
|  |  | ||||||
|  | @ -222,4 +222,9 @@ export interface TagRenderingConfigJson { | ||||||
|      * Values are split on ` `  (space) |      * Values are split on ` `  (space) | ||||||
|      */ |      */ | ||||||
|     classes?: string |     classes?: string | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * This tagRendering can introduce this builtin filter | ||||||
|  |      */ | ||||||
|  |     filter?: string[] | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue