| 
									
										
										
										
											2020-11-21 16:44:48 +01:00
										 |  |  | import * as questions from "../assets/tagRenderings/questions.json" | 
					
						
							|  |  |  | import * as icons from "../assets/tagRenderings/icons.json" | 
					
						
							| 
									
										
										
										
											2021-07-04 20:36:19 +02:00
										 |  |  | import { Utils } from "../Utils" | 
					
						
							| 
									
										
										
										
											2021-08-07 23:11:34 +02:00
										 |  |  | import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig" | 
					
						
							| 
									
										
										
										
											2021-09-09 20:26:12 +02:00
										 |  |  | import { TagRenderingConfigJson } from "../Models/ThemeConfig/Json/TagRenderingConfigJson" | 
					
						
							| 
									
										
										
										
											2022-02-14 23:42:32 +01:00
										 |  |  | import BaseUIElement from "../UI/BaseUIElement" | 
					
						
							|  |  |  | import Combine from "../UI/Base/Combine" | 
					
						
							|  |  |  | import Title from "../UI/Base/Title" | 
					
						
							|  |  |  | import { FixedUiElement } from "../UI/Base/FixedUiElement" | 
					
						
							|  |  |  | import List from "../UI/Base/List" | 
					
						
							| 
									
										
										
										
											2020-10-27 01:01:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default class SharedTagRenderings { | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |     public static SharedTagRendering: Map<string, TagRenderingConfig> = | 
					
						
							|  |  |  |         SharedTagRenderings.generatedSharedFields() | 
					
						
							| 
									
										
										
										
											2021-09-09 20:26:12 +02:00
										 |  |  |     public static SharedTagRenderingJson: Map<string, TagRenderingConfigJson> = | 
					
						
							|  |  |  |         SharedTagRenderings.generatedSharedFieldsJsons() | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |     public static SharedIcons: Map<string, TagRenderingConfig> = | 
					
						
							|  |  |  |         SharedTagRenderings.generatedSharedFields(true) | 
					
						
							| 
									
										
										
										
											2020-10-27 01:01:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |     private static generatedSharedFields(iconsOnly = false): Map<string, TagRenderingConfig> { | 
					
						
							| 
									
										
										
										
											2021-09-09 20:26:12 +02:00
										 |  |  |         const configJsons = SharedTagRenderings.generatedSharedFieldsJsons(iconsOnly) | 
					
						
							|  |  |  |         const d = new Map<string, TagRenderingConfig>() | 
					
						
							|  |  |  |         for (const key of Array.from(configJsons.keys())) { | 
					
						
							| 
									
										
										
										
											2020-10-27 01:01:34 +01:00
										 |  |  |             try { | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |                 d.set( | 
					
						
							|  |  |  |                     key, | 
					
						
							|  |  |  |                     new TagRenderingConfig(configJsons.get(key), `SharedTagRenderings.${key}`) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2020-10-27 01:01:34 +01:00
										 |  |  |             } catch (e) { | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |                 if (!Utils.runningFromConsole) { | 
					
						
							| 
									
										
										
										
											2021-07-04 20:36:19 +02:00
										 |  |  |                     console.error( | 
					
						
							|  |  |  |                         "BUG: could not parse", | 
					
						
							|  |  |  |                         key, | 
					
						
							|  |  |  |                         " from questions.json or icons.json - this error happened during the build step of the SharedTagRenderings", | 
					
						
							|  |  |  |                         e | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-10-27 01:01:34 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-09-09 20:26:12 +02:00
										 |  |  |         return d | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private static generatedSharedFieldsJsons( | 
					
						
							|  |  |  |         iconsOnly = false | 
					
						
							|  |  |  |     ): Map<string, TagRenderingConfigJson> { | 
					
						
							|  |  |  |         const dict = new Map<string, TagRenderingConfigJson>() | 
					
						
							| 
									
										
										
										
											2020-12-06 00:20:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (!iconsOnly) { | 
					
						
							|  |  |  |             for (const key in questions) { | 
					
						
							| 
									
										
										
										
											2022-01-26 21:40:38 +01:00
										 |  |  |                 if (key === "id") { | 
					
						
							| 
									
										
										
										
											2022-01-24 00:24:51 +01:00
										 |  |  |                     continue | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-09-09 20:26:12 +02:00
										 |  |  |                 dict.set(key, <TagRenderingConfigJson>questions[key]) | 
					
						
							| 
									
										
										
										
											2020-12-06 00:20:27 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-11-21 16:44:48 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         for (const key in icons) { | 
					
						
							| 
									
										
										
										
											2022-01-26 21:40:38 +01:00
										 |  |  |             if (key === "id") { | 
					
						
							| 
									
										
										
										
											2022-01-24 00:24:51 +01:00
										 |  |  |                 continue | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-09-09 20:26:12 +02:00
										 |  |  |             dict.set(key, <TagRenderingConfigJson>icons[key]) | 
					
						
							| 
									
										
										
										
											2020-11-21 16:44:48 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-12-21 18:35:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         dict.forEach((value, key) => { | 
					
						
							| 
									
										
										
										
											2022-01-26 21:40:38 +01:00
										 |  |  |             if (key === "id") { | 
					
						
							| 
									
										
										
										
											2022-01-24 00:24:51 +01:00
										 |  |  |                 return | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-12-21 18:35:31 +01:00
										 |  |  |             value.id = value.id ?? key | 
					
						
							| 
									
										
										
										
											2022-01-29 02:45:59 +01:00
										 |  |  |             if (value["builtin"] !== undefined) { | 
					
						
							|  |  |  |                 if (value["override"] == undefined) { | 
					
						
							|  |  |  |                     throw ( | 
					
						
							|  |  |  |                         "HUH? Why whould you want to reuse a builtin if one doesn't override? In questions.json/" + | 
					
						
							|  |  |  |                         key | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                     ) | 
					
						
							| 
									
										
										
										
											2022-01-29 02:45:59 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |                 if (typeof value["builtin"] !== "string") { | 
					
						
							|  |  |  |                     return | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 // This is a really funny situation: we extend another tagRendering!
 | 
					
						
							|  |  |  |                 const parent = Utils.Clone(dict.get(value["builtin"])) | 
					
						
							|  |  |  |                 delete parent.id | 
					
						
							|  |  |  |                 Utils.Merge(value["override"], parent) | 
					
						
							|  |  |  |                 delete value["builtin"] | 
					
						
							|  |  |  |                 delete value["override"] | 
					
						
							|  |  |  |                 for (const pkey in parent) { | 
					
						
							|  |  |  |                     value[pkey] = parent[pkey] | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-12-21 18:35:31 +01:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2020-12-06 00:20:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-27 01:01:34 +01:00
										 |  |  |         return dict | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-14 23:42:32 +01:00
										 |  |  |     public static HelpText(): BaseUIElement { | 
					
						
							|  |  |  |         return new Combine([ | 
					
						
							|  |  |  |             new Combine([ | 
					
						
							|  |  |  |                 new Title("Builtin questions", 1), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 "The following items can be easily reused in your layers", | 
					
						
							|  |  |  |             ]).SetClass("flex flex-col"), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             ...Array.from(SharedTagRenderings.SharedTagRendering.keys()).map((key) => { | 
					
						
							|  |  |  |                 const tr = SharedTagRenderings.SharedTagRendering.get(key) | 
					
						
							|  |  |  |                 let mappings: BaseUIElement = undefined | 
					
						
							|  |  |  |                 if (tr.mappings?.length > 0) { | 
					
						
							|  |  |  |                     mappings = new List(tr.mappings.map((m) => m.then.textFor("en"))) | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 return new Combine([ | 
					
						
							|  |  |  |                     new Title(key), | 
					
						
							|  |  |  |                     tr.render?.textFor("en"), | 
					
						
							|  |  |  |                     tr.question?.textFor("en") ?? | 
					
						
							|  |  |  |                         new FixedUiElement("Read-only tagrendering").SetClass("font-bold"), | 
					
						
							|  |  |  |                     mappings, | 
					
						
							|  |  |  |                 ]).SetClass("flex flex-col") | 
					
						
							|  |  |  |             }), | 
					
						
							|  |  |  |         ]).SetClass("flex flex-col") | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-10-27 01:01:34 +01:00
										 |  |  | } |