| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  | import {UIElement} from "../UIElement"; | 
					
						
							|  |  |  | import {VariableUiElement} from "../Base/VariableUIElement"; | 
					
						
							|  |  |  | import LayoutConfig from "../../Customizations/JSON/LayoutConfig"; | 
					
						
							|  |  |  | import {AllKnownLayouts} from "../../Customizations/AllKnownLayouts"; | 
					
						
							|  |  |  | import Svg from "../../Svg"; | 
					
						
							|  |  |  | import State from "../../State"; | 
					
						
							|  |  |  | import Combine from "../Base/Combine"; | 
					
						
							|  |  |  | import {SubtleButton} from "../Base/SubtleButton"; | 
					
						
							|  |  |  | import Translations from "../i18n/Translations"; | 
					
						
							|  |  |  | import * as personal from "../../assets/themes/personalLayout/personalLayout.json" | 
					
						
							|  |  |  | import Constants from "../../Models/Constants"; | 
					
						
							| 
									
										
										
										
											2021-01-14 22:25:11 +01:00
										 |  |  | import LanguagePicker from "../LanguagePicker"; | 
					
						
							| 
									
										
										
										
											2021-01-18 02:51:42 +01:00
										 |  |  | import IndexText from "./IndexText"; | 
					
						
							| 
									
										
										
										
											2020-07-29 15:48:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  | export default class MoreScreen extends UIElement { | 
					
						
							| 
									
										
										
										
											2021-01-14 22:25:11 +01:00
										 |  |  |     private readonly _onMainScreen: boolean; | 
					
						
							| 
									
										
										
										
											2021-01-17 21:04:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 22:25:11 +01:00
										 |  |  |     private _component: UIElement; | 
					
						
							| 
									
										
										
										
											2020-07-29 15:48:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-17 21:04:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 22:25:11 +01:00
										 |  |  |     constructor(onMainScreen: boolean = false) { | 
					
						
							| 
									
										
										
										
											2020-07-31 01:45:54 +02:00
										 |  |  |         super(State.state.locationControl); | 
					
						
							| 
									
										
										
										
											2021-01-14 22:25:11 +01:00
										 |  |  |         this._onMainScreen = onMainScreen; | 
					
						
							| 
									
										
										
										
											2020-07-31 16:17:16 +02:00
										 |  |  |         this.ListenTo(State.state.osmConnection.userDetails); | 
					
						
							| 
									
										
										
										
											2020-08-26 20:11:43 +02:00
										 |  |  |         this.ListenTo(State.state.installedThemes); | 
					
						
							| 
									
										
										
										
											2020-08-26 15:36:04 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |     InnerRender(): string { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const tr = Translations.t.general.morescreen; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const els: UIElement[] = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const themeButtons: UIElement[] = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (const layout of AllKnownLayouts.layoutsList) { | 
					
						
							|  |  |  |             if (layout.id === personal.id) { | 
					
						
							|  |  |  |                 if (State.state.osmConnection.userDetails.data.csCount < Constants.userJourney.personalLayoutUnlock) { | 
					
						
							|  |  |  |                     continue; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             themeButtons.push(this.createLinkButton(layout)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         els.push(new VariableUiElement( | 
					
						
							|  |  |  |             State.state.osmConnection.userDetails.map(userDetails => { | 
					
						
							|  |  |  |                 if (userDetails.csCount < Constants.userJourney.themeGeneratorReadOnlyUnlock) { | 
					
						
							|  |  |  |                     return new SubtleButton(null, tr.requestATheme, {url:"https://github.com/pietervdvn/MapComplete/issues", newTab: true}).Render(); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 return new SubtleButton(Svg.pencil_ui(), tr.createYourOwnTheme, { | 
					
						
							|  |  |  |                     url: "./customGenerator.html", | 
					
						
							|  |  |  |                     newTab: false | 
					
						
							|  |  |  |                 }).Render(); | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |         )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         els.push(new Combine(themeButtons)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const customThemesNames = State.state.installedThemes.data ?? []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (customThemesNames.length > 0) { | 
					
						
							|  |  |  |             els.push(Translations.t.general.customThemeIntro) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             for (const installed of State.state.installedThemes.data) { | 
					
						
							|  |  |  |                 els.push(this.createLinkButton(installed.layout, installed.definition)); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let intro: UIElement = tr.intro; | 
					
						
							|  |  |  |         const themeButtonsElement = new Combine(els) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (this._onMainScreen) { | 
					
						
							|  |  |  |             intro = new Combine([ | 
					
						
							|  |  |  |                 LanguagePicker.CreateLanguagePicker(Translations.t.index.title.SupportedLanguages()) | 
					
						
							|  |  |  |                     .SetClass("absolute top-2 right-3"), | 
					
						
							|  |  |  |                 new IndexText() | 
					
						
							|  |  |  |             ]) | 
					
						
							|  |  |  |             themeButtons.map(e => e?.SetClass("h-32 min-h-32 max-h-32 overflow-ellipsis overflow-hidden")) | 
					
						
							|  |  |  |             themeButtonsElement.SetClass("md:grid md:grid-flow-row md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-g4 gap-4") | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this._component = new Combine([ | 
					
						
							|  |  |  |             intro, | 
					
						
							|  |  |  |             themeButtonsElement, | 
					
						
							|  |  |  |             tr.streetcomplete.SetClass("block text-base mx-10 my-3 mb-10") | 
					
						
							|  |  |  |         ]); | 
					
						
							|  |  |  |         return this._component.Render(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-11 16:23:49 +01:00
										 |  |  |     private createLinkButton(layout: LayoutConfig, customThemeDefinition: string = undefined) { | 
					
						
							| 
									
										
										
										
											2020-08-30 01:13:18 +02:00
										 |  |  |         if (layout === undefined) { | 
					
						
							|  |  |  |             return undefined; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |         if (layout.id === undefined) { | 
					
						
							|  |  |  |             console.error("ID is undefined for layout", layout); | 
					
						
							| 
									
										
										
										
											2020-08-31 02:59:47 +02:00
										 |  |  |             return undefined; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |         if (layout.hideFromOverview) { | 
					
						
							| 
									
										
										
										
											2020-09-05 23:44:33 +02:00
										 |  |  |             const pref = State.state.osmConnection.GetPreference("hidden-theme-" + layout.id + "-enabled"); | 
					
						
							|  |  |  |             this.ListenTo(pref); | 
					
						
							|  |  |  |             if (pref.data !== "true") { | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |                 return undefined; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-08-26 15:36:04 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-01-14 22:25:11 +01:00
										 |  |  |         if (layout.id === State.state.layoutToUse.data?.id) { | 
					
						
							| 
									
										
										
										
											2020-08-26 15:36:04 +02:00
										 |  |  |             return undefined; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const currentLocation = State.state.locationControl.data; | 
					
						
							| 
									
										
										
										
											2021-01-06 01:11:07 +01:00
										 |  |  |         let path = window.location.pathname; | 
					
						
							|  |  |  |         // Path starts with a '/' and contains everything, e.g. '/dir/dir/page.html'
 | 
					
						
							|  |  |  |         path = path.substr(0, path.lastIndexOf("/")); | 
					
						
							|  |  |  |         // Path will now contain '/dir/dir', or empty string in case of nothing
 | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |         if (path === "") { | 
					
						
							| 
									
										
										
										
											2021-01-06 01:11:07 +01:00
										 |  |  |             path = "." | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-06 01:33:09 +02:00
										 |  |  |         const params = `z=${currentLocation.zoom ?? 1}&lat=${currentLocation.lat ?? 0}&lon=${currentLocation.lon ?? 0}` | 
					
						
							| 
									
										
										
										
											2020-08-26 15:36:04 +02:00
										 |  |  |         let linkText = | 
					
						
							| 
									
										
										
										
											2021-05-10 16:03:40 +02:00
										 |  |  |             `${path}/${layout.id.toLowerCase()}.html?${params}` | 
					
						
							| 
									
										
										
										
											2020-08-26 15:36:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (location.hostname === "localhost" || location.hostname === "127.0.0.1") { | 
					
						
							| 
									
										
										
										
											2021-05-06 01:33:09 +02:00
										 |  |  |             linkText = `${path}/index.html?layout=${layout.id}&${params}` | 
					
						
							| 
									
										
										
										
											2020-08-26 15:36:04 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (customThemeDefinition) { | 
					
						
							| 
									
										
										
										
											2021-05-10 16:03:40 +02:00
										 |  |  |             linkText = `${path}/index.html?userlayout=${layout.id}&${params}#${customThemeDefinition}` | 
					
						
							| 
									
										
										
										
											2020-08-26 15:36:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-11 16:23:49 +01:00
										 |  |  |         let description = Translations.W(layout.shortDescription); | 
					
						
							| 
									
										
										
										
											2021-01-03 00:19:42 +01:00
										 |  |  |         return new SubtleButton(layout.icon, | 
					
						
							|  |  |  |             new Combine([ | 
					
						
							| 
									
										
										
										
											2021-01-17 21:14:48 +01:00
										 |  |  |                 `<dt class='text-lg leading-6 font-medium text-gray-900 group-hover:text-blue-800'>`, | 
					
						
							| 
									
										
										
										
											2021-01-03 00:19:42 +01:00
										 |  |  |                 Translations.W(layout.title), | 
					
						
							| 
									
										
										
										
											2021-01-17 21:14:48 +01:00
										 |  |  |                 `</dt>`, | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |                 `<dd class='mt-1 text-base text-gray-500 group-hover:text-blue-900 overflow-ellipsis'>`, | 
					
						
							| 
									
										
										
										
											2021-01-03 00:19:42 +01:00
										 |  |  |                 description ?? "", | 
					
						
							| 
									
										
										
										
											2021-01-17 21:14:48 +01:00
										 |  |  |                 `</dd>`, | 
					
						
							| 
									
										
										
										
											2021-01-03 00:19:42 +01:00
										 |  |  |             ]), {url: linkText, newTab: false}); | 
					
						
							| 
									
										
										
										
											2020-07-29 15:48:21 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |