| 
									
										
										
										
											2023-03-29 17:56:42 +02:00
										 |  |  | import { TagRenderingConfigJson } from "../Json/TagRenderingConfigJson" | 
					
						
							|  |  |  | import { Utils } from "../../../Utils" | 
					
						
							|  |  |  | import SpecialVisualizations from "../../../UI/SpecialVisualizations" | 
					
						
							| 
									
										
										
										
											2023-03-31 03:28:11 +02:00
										 |  |  | import { RenderingSpecification, SpecialVisualization } from "../../../UI/SpecialVisualization" | 
					
						
							| 
									
										
										
										
											2023-04-14 02:42:57 +02:00
										 |  |  | import { LayerConfigJson } from "../Json/LayerConfigJson" | 
					
						
							| 
									
										
										
										
											2023-03-29 17:56:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default class ValidationUtils { | 
					
						
							| 
									
										
										
										
											2023-04-14 02:42:57 +02:00
										 |  |  |     public static hasSpecialVisualisation( | 
					
						
							|  |  |  |         layer: LayerConfigJson, | 
					
						
							|  |  |  |         specialVisualisation: string | 
					
						
							|  |  |  |     ): boolean { | 
					
						
							|  |  |  |         return ( | 
					
						
							|  |  |  |             layer.tagRenderings?.some((tagRendering) => | 
					
						
							|  |  |  |                 ValidationUtils.getSpecialVisualisations(<TagRenderingConfigJson>tagRendering).some( | 
					
						
							|  |  |  |                     (vis) => vis.funcName === specialVisualisation | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             ) ?? false | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-29 17:56:42 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Gives all the (function names of) used special visualisations | 
					
						
							|  |  |  |      * @param renderingConfig | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2023-03-29 18:54:00 +02:00
										 |  |  |     public static getSpecialVisualisations( | 
					
						
							|  |  |  |         renderingConfig: TagRenderingConfigJson | 
					
						
							|  |  |  |     ): SpecialVisualization[] { | 
					
						
							| 
									
										
										
										
											2023-03-31 03:28:11 +02:00
										 |  |  |         return ValidationUtils.getSpecialVisualsationsWithArgs(renderingConfig).map( | 
					
						
							|  |  |  |             (spec) => spec["func"] | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-04-14 02:42:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 03:28:11 +02:00
										 |  |  |     public static getSpecialVisualsationsWithArgs( | 
					
						
							|  |  |  |         renderingConfig: TagRenderingConfigJson | 
					
						
							|  |  |  |     ): RenderingSpecification[] { | 
					
						
							| 
									
										
										
										
											2023-03-29 17:56:42 +02:00
										 |  |  |         const translations: any[] = Utils.NoNull([ | 
					
						
							|  |  |  |             renderingConfig.render, | 
					
						
							|  |  |  |             ...(renderingConfig.mappings ?? []).map((m) => m.then), | 
					
						
							|  |  |  |         ]) | 
					
						
							| 
									
										
										
										
											2023-03-31 03:28:11 +02:00
										 |  |  |         const all: RenderingSpecification[] = [] | 
					
						
							| 
									
										
										
										
											2023-03-29 17:56:42 +02:00
										 |  |  |         for (let translation of translations) { | 
					
						
							|  |  |  |             if (typeof translation == "string") { | 
					
						
							|  |  |  |                 translation = { "*": translation } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             for (const key in translation) { | 
					
						
							|  |  |  |                 if (!translation.hasOwnProperty(key)) { | 
					
						
							|  |  |  |                     continue | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 const template = translation[key] | 
					
						
							|  |  |  |                 const parts = SpecialVisualizations.constructSpecification(template) | 
					
						
							| 
									
										
										
										
											2023-03-31 03:28:11 +02:00
										 |  |  |                 const specials = parts.filter((p) => typeof p !== "string") | 
					
						
							| 
									
										
										
										
											2023-03-29 17:56:42 +02:00
										 |  |  |                 all.push(...specials) | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return all | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |