forked from MapComplete/MapComplete
		
	Refactoring: automatically generate code files from layer/theme files to avoid using 'Eval'
This commit is contained in:
		
							parent
							
								
									865b0bc44f
								
							
						
					
					
						commit
						39944a01fb
					
				
					 17 changed files with 269 additions and 31 deletions
				
			
		|  | @ -16,6 +16,7 @@ import LinkToWeblate from "../../UI/Base/LinkToWeblate" | |||
| import FeatureSwitchState from "./FeatureSwitchState" | ||||
| import Constants from "../../Models/Constants" | ||||
| import { QueryParameters } from "../Web/QueryParameters" | ||||
| import { ThemeMetaTagging } from "./UserSettingsMetaTagging" | ||||
| 
 | ||||
| /** | ||||
|  * The part of the state which keeps track of user-related stuff, e.g. the OSM-connection, | ||||
|  | @ -326,12 +327,15 @@ export default class UserRelatedState { | |||
|             }, | ||||
|             [translationMode] | ||||
|         ) | ||||
| 
 | ||||
|         const usersettingMetaTagging = new ThemeMetaTagging() | ||||
|         osmConnection.userDetails.addCallback((userDetails) => { | ||||
|             for (const k in userDetails) { | ||||
|                 amendedPrefs.data["_" + k] = "" + userDetails[k] | ||||
|             } | ||||
| 
 | ||||
|             for (const [name, code, _] of usersettingsConfig.calculatedTags) { | ||||
|             usersettingMetaTagging.metaTaggging_for_usersettings({ properties: amendedPrefs.data }) | ||||
|             /*for (const [name, code, _] of usersettingsConfig.calculatedTags) { | ||||
|                 try { | ||||
|                     let result = new Function("feat", "return " + code + ";")({ | ||||
|                         properties: amendedPrefs.data, | ||||
|  | @ -349,7 +353,7 @@ export default class UserRelatedState { | |||
|                         e | ||||
|                     ) | ||||
|                 } | ||||
|             } | ||||
|             }*/ | ||||
| 
 | ||||
|             const simplifiedName = userDetails.name.toLowerCase().replace(/\s+/g, "") | ||||
|             const isTranslator = translators.contributors.find( | ||||
|  |  | |||
							
								
								
									
										13
									
								
								src/Logic/State/UserSettingsMetaTagging.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/Logic/State/UserSettingsMetaTagging.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,13 @@ | |||
| import { Utils } from "../../Utils" | ||||
| /** This code is autogenerated - do not edit. Edit ./assets/layers/usersettings/usersettings.json instead */ | ||||
| export class ThemeMetaTagging { | ||||
|    public static readonly themeName = "usersettings" | ||||
| 
 | ||||
|    public metaTaggging_for_usersettings(feat: {properties: Record<string, string>}) { | ||||
|       Utils.AddLazyProperty(feat.properties, '_mastodon_candidate_md', () => feat.properties._description.match(/\[[^\]]*\]\((.*(mastodon|en.osm.town).*)\).*/)?.at(1) )  | ||||
|       Utils.AddLazyProperty(feat.properties, '_d', () => feat.properties._description?.replace(/</g,'<')?.replace(/>/g,'>') ?? '' )  | ||||
|       Utils.AddLazyProperty(feat.properties, '_mastodon_candidate_a', () => (feat => {const e = document.createElement('div');e.innerHTML = feat.properties._d;return Array.from(e.getElementsByTagName("a")).filter(a => a.href.match(/mastodon|en.osm.town/) !== null)[0]?.href   }) (feat)  )  | ||||
|       Utils.AddLazyProperty(feat.properties, '_mastodon_link', () => (feat => {const e = document.createElement('div');e.innerHTML = feat.properties._d;return Array.from(e.getElementsByTagName("a")).filter(a => a.getAttribute("rel")?.indexOf('me') >= 0)[0]?.href})(feat)  )  | ||||
|       Utils.AddLazyProperty(feat.properties, '_mastodon_candidate', () => feat.properties._mastodon_candidate_md ?? feat.properties._mastodon_candidate_a )  | ||||
|    } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue