| 
									
										
										
										
											2020-09-03 16:44:48 +02:00
										 |  |  | import {UIElement} from "../UIElement"; | 
					
						
							| 
									
										
										
										
											2021-01-04 04:36:21 +01:00
										 |  |  | import UserDetails, {OsmConnection} from "../../Logic/Osm/OsmConnection"; | 
					
						
							| 
									
										
										
										
											2020-09-03 16:44:48 +02:00
										 |  |  | import {UIEventSource} from "../../Logic/UIEventSource"; | 
					
						
							|  |  |  | import SingleSetting from "./SingleSetting"; | 
					
						
							|  |  |  | import GeneralSettings from "./GeneralSettings"; | 
					
						
							|  |  |  | import Combine from "../Base/Combine"; | 
					
						
							|  |  |  | import {VariableUiElement} from "../Base/VariableUIElement"; | 
					
						
							|  |  |  | import {TabbedComponent} from "../Base/TabbedComponent"; | 
					
						
							|  |  |  | import PageSplit from "../Base/PageSplit"; | 
					
						
							|  |  |  | import AllLayersPanel from "./AllLayersPanel"; | 
					
						
							|  |  |  | import SharePanel from "./SharePanel"; | 
					
						
							|  |  |  | import {LayoutConfigJson} from "../../Customizations/JSON/LayoutConfigJson"; | 
					
						
							|  |  |  | import {SubtleButton} from "../Base/SubtleButton"; | 
					
						
							|  |  |  | import {FixedUiElement} from "../Base/FixedUiElement"; | 
					
						
							|  |  |  | import SavePanel from "./SavePanel"; | 
					
						
							|  |  |  | import {LocalStorageSource} from "../../Logic/Web/LocalStorageSource"; | 
					
						
							| 
									
										
										
										
											2020-09-17 14:24:36 +02:00
										 |  |  | import HelpText from "./HelpText"; | 
					
						
							| 
									
										
										
										
											2020-11-06 04:02:53 +01:00
										 |  |  | import Svg from "../../Svg"; | 
					
						
							| 
									
										
										
										
											2021-01-02 19:09:49 +01:00
										 |  |  | import Constants from "../../Models/Constants"; | 
					
						
							| 
									
										
										
										
											2021-04-04 03:22:56 +02:00
										 |  |  | import LZString from "lz-string"; | 
					
						
							|  |  |  | import {Utils} from "../../Utils"; | 
					
						
							| 
									
										
										
										
											2020-09-03 16:44:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default class CustomGeneratorPanel extends UIElement { | 
					
						
							|  |  |  |     private mainPanel: UIElement; | 
					
						
							|  |  |  |     private loginButton: UIElement; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-03 19:05:18 +02:00
										 |  |  |     private readonly connection: OsmConnection; | 
					
						
							| 
									
										
										
										
											2020-09-03 16:44:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     constructor(connection: OsmConnection, layout: LayoutConfigJson) { | 
					
						
							|  |  |  |         super(connection.userDetails); | 
					
						
							|  |  |  |         this.connection = connection; | 
					
						
							|  |  |  |         this.SetClass("main-tabs"); | 
					
						
							|  |  |  |         this.loginButton = new SubtleButton("", "Login to create a custom theme").onClick(() => connection.AttemptLogin()) | 
					
						
							|  |  |  |         const self = this; | 
					
						
							|  |  |  |         self.mainPanel = new FixedUiElement("Attempting to log in..."); | 
					
						
							|  |  |  |         connection.OnLoggedIn(userDetails => { | 
					
						
							|  |  |  |             self.InitMainPanel(layout, userDetails, connection); | 
					
						
							|  |  |  |             self.Update(); | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private InitMainPanel(layout: LayoutConfigJson, userDetails: UserDetails, connection: OsmConnection) { | 
					
						
							|  |  |  |         const es = new UIEventSource(layout); | 
					
						
							| 
									
										
										
										
											2021-04-04 03:22:56 +02:00
										 |  |  |         const encoded = es.map(config => LZString.compressToBase64(Utils.MinifyJSON(JSON.stringify(config, null, 0)))); | 
					
						
							| 
									
										
										
										
											2020-09-03 19:05:18 +02:00
										 |  |  |         encoded.addCallback(encoded => LocalStorageSource.Get("last-custom-theme")) | 
					
						
							| 
									
										
										
										
											2020-09-03 16:44:48 +02:00
										 |  |  |         const liveUrl = encoded.map(encoded => `./index.html?userlayout=${es.data.id}#${encoded}`) | 
					
						
							| 
									
										
										
										
											2020-09-17 13:13:02 +02:00
										 |  |  |         const testUrl = encoded.map(encoded => `./index.html?test=true&userlayout=${es.data.id}#${encoded}`) | 
					
						
							|  |  |  |         const iframe = testUrl.map(url => `<iframe src='${url}' width='100%' height='99%' style="box-sizing: border-box" title='Theme Preview'></iframe>`); | 
					
						
							| 
									
										
										
										
											2020-09-03 16:44:48 +02:00
										 |  |  |         const currentSetting = new UIEventSource<SingleSetting<any>>(undefined) | 
					
						
							|  |  |  |         const generalSettings = new GeneralSettings(es, currentSetting); | 
					
						
							|  |  |  |         const languages = generalSettings.languages; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const chronic = UIEventSource.Chronic(120 * 1000) | 
					
						
							|  |  |  |             .map(date => { | 
					
						
							|  |  |  |                 if (es.data.id == undefined) { | 
					
						
							|  |  |  |                     return undefined | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 if (es.data.id === "") { | 
					
						
							|  |  |  |                     return undefined; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 const pref = connection.GetLongPreference("installed-theme-" + es.data.id); | 
					
						
							|  |  |  |                 pref.setData(encoded.data); | 
					
						
							|  |  |  |                 return date; | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const preview = new Combine([ | 
					
						
							| 
									
										
										
										
											2020-09-07 02:47:21 +02:00
										 |  |  |             new VariableUiElement(iframe) | 
					
						
							| 
									
										
										
										
											2020-09-03 16:44:48 +02:00
										 |  |  |         ]).SetClass("preview") | 
					
						
							|  |  |  |         this.mainPanel = new TabbedComponent([ | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2020-11-06 04:02:53 +01:00
										 |  |  |                 header: Svg.gear_img, | 
					
						
							| 
									
										
										
										
											2020-09-03 16:44:48 +02:00
										 |  |  |                 content: | 
					
						
							|  |  |  |                     new PageSplit( | 
					
						
							|  |  |  |                         generalSettings.SetStyle("width: 50vw;"), | 
					
						
							|  |  |  |                         new Combine([ | 
					
						
							|  |  |  |                             new HelpText(currentSetting).SetStyle("height:calc(100% - 65vh); width: 100%; display:block; overflow-y: auto"), | 
					
						
							|  |  |  |                             preview.SetStyle("height:65vh; width:100%; display:block") | 
					
						
							|  |  |  |                         ]).SetStyle("position:relative; width: 50%;") | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2020-11-06 04:02:53 +01:00
										 |  |  |                 header: Svg.layers_img, | 
					
						
							| 
									
										
										
										
											2020-09-03 16:44:48 +02:00
										 |  |  |                 content: new AllLayersPanel(es, languages, userDetails) | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2020-11-06 04:02:53 +01:00
										 |  |  |                 header: Svg.floppy_img, | 
					
						
							| 
									
										
										
										
											2020-09-03 16:44:48 +02:00
										 |  |  |                 content: new SavePanel(this.connection, es, chronic) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2020-11-06 04:02:53 +01:00
										 |  |  |                 header:Svg.share_img, | 
					
						
							| 
									
										
										
										
											2020-09-07 02:25:45 +02:00
										 |  |  |                 content: new SharePanel(es, liveUrl, userDetails) | 
					
						
							| 
									
										
										
										
											2020-09-03 16:44:48 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         ]) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     InnerRender(): string { | 
					
						
							|  |  |  |         const ud = this.connection.userDetails.data; | 
					
						
							|  |  |  |         if (!ud.loggedIn) { | 
					
						
							|  |  |  |             return new Combine([ | 
					
						
							|  |  |  |                 "<h3>Not Logged in</h3>", | 
					
						
							|  |  |  |                 "You need to be logged in in order to create a custom theme", | 
					
						
							|  |  |  |                 this.loginButton | 
					
						
							|  |  |  |             ]).Render(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-01-02 19:09:49 +01:00
										 |  |  |         const journey = Constants.userJourney; | 
					
						
							|  |  |  |         if (ud.csCount <= journey.themeGeneratorReadOnlyUnlock) { | 
					
						
							| 
									
										
										
										
											2020-09-03 16:44:48 +02:00
										 |  |  |             return new Combine([ | 
					
						
							| 
									
										
										
										
											2020-11-15 15:33:18 +01:00
										 |  |  |                 "<h3>Too little experience</h3>", | 
					
						
							| 
									
										
										
										
											2021-01-02 19:09:49 +01:00
										 |  |  |                 `<p>Creating your own (readonly) themes can only be done if you have more then <b>${journey.themeGeneratorReadOnlyUnlock}</b> changesets made</p>`, | 
					
						
							|  |  |  |                 `<p>Making a theme including survey options can be done at <b>${journey.themeGeneratorFullUnlock}</b> changesets</p>` | 
					
						
							| 
									
										
										
										
											2020-09-03 16:44:48 +02:00
										 |  |  |             ]).Render(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return this.mainPanel.Render() | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |