| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  | import {VariableUiElement} from "../Base/VariableUIElement"; | 
					
						
							|  |  |  | 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"; | 
					
						
							| 
									
										
										
										
											2021-07-26 18:02:55 +02:00
										 |  |  | import * as personal from "../../assets/themes/personal/personal.json" | 
					
						
							| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  | 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"; | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  | import BaseUIElement from "../BaseUIElement"; | 
					
						
							| 
									
										
										
										
											2021-08-07 23:11:34 +02:00
										 |  |  | import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"; | 
					
						
							| 
									
										
										
										
											2020-07-29 15:48:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  | export default class MoreScreen extends Combine { | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |         super(MoreScreen.Init(onMainScreen, State.state)); | 
					
						
							| 
									
										
										
										
											2020-08-26 15:36:04 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |     private static Init(onMainScreen: boolean, state: State): BaseUIElement [] { | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |         const tr = Translations.t.general.morescreen; | 
					
						
							| 
									
										
										
										
											2021-06-13 15:04:55 +02:00
										 |  |  |         let intro: BaseUIElement = tr.intro.Clone(); | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |         let themeButtonStyle = "" | 
					
						
							|  |  |  |         let themeListStyle = "" | 
					
						
							|  |  |  |         if (onMainScreen) { | 
					
						
							|  |  |  |             intro = new Combine([ | 
					
						
							|  |  |  |                 LanguagePicker.CreateLanguagePicker(Translations.t.index.title.SupportedLanguages()) | 
					
						
							|  |  |  |                     .SetClass("absolute top-2 right-3"), | 
					
						
							|  |  |  |                 new IndexText() | 
					
						
							| 
									
										
										
										
											2021-06-23 03:00:21 +02:00
										 |  |  |             ]); | 
					
						
							|  |  |  |              | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |             themeButtonStyle = "h-32 min-h-32 max-h-32 overflow-ellipsis overflow-hidden" | 
					
						
							|  |  |  |             themeListStyle = "md:grid md:grid-flow-row md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-g4 gap-4" | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |         return[ | 
					
						
							|  |  |  |             intro, | 
					
						
							|  |  |  |             MoreScreen.createOfficialThemesList(state, themeButtonStyle).SetClass(themeListStyle), | 
					
						
							|  |  |  |             MoreScreen.createUnofficialThemeList(themeButtonStyle)?.SetClass(themeListStyle), | 
					
						
							| 
									
										
										
										
											2021-06-13 15:04:55 +02:00
										 |  |  |             tr.streetcomplete.Clone().SetClass("block text-base mx-10 my-3 mb-10") | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |         ]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     private static createUnofficialThemeList(buttonClass: string): BaseUIElement{ | 
					
						
							| 
									
										
										
										
											2021-06-17 00:54:06 +02:00
										 |  |  |         return new VariableUiElement(State.state.installedThemes.map(customThemes => { | 
					
						
							|  |  |  |             const els : BaseUIElement[] = [] | 
					
						
							|  |  |  |             if (customThemes.length > 0) { | 
					
						
							|  |  |  |                 els.push(Translations.t.general.customThemeIntro.Clone()) | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-17 00:54:06 +02:00
										 |  |  |                 const customThemesElement = new Combine( | 
					
						
							|  |  |  |                     customThemes.map(theme => MoreScreen.createLinkButton(theme.layout, theme.definition)?.SetClass(buttonClass)) | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |                 els.push(customThemesElement) | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return els; | 
					
						
							|  |  |  |         })); | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |     private static createOfficialThemesList(state: State, buttonClass: string): BaseUIElement { | 
					
						
							|  |  |  |         let officialThemes = AllKnownLayouts.layoutsList | 
					
						
							| 
									
										
										
										
											2021-06-23 03:00:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         let buttons = officialThemes.map((layout) => { | 
					
						
							| 
									
										
										
										
											2021-07-12 13:38:38 +02:00
										 |  |  |             if(layout === undefined){ | 
					
						
							|  |  |  |                 console.trace("Layout is undefined") | 
					
						
							|  |  |  |                 return undefined | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-06-23 03:00:21 +02:00
										 |  |  |             const button = MoreScreen.createLinkButton(layout)?.SetClass(buttonClass); | 
					
						
							|  |  |  |             if(layout.id === personal.id){ | 
					
						
							|  |  |  |                 return new VariableUiElement( | 
					
						
							|  |  |  |                     State.state.osmConnection.userDetails.map(userdetails => userdetails.csCount) | 
					
						
							|  |  |  |                         .map(csCount => { | 
					
						
							|  |  |  |                             if(csCount < Constants.userJourney.personalLayoutUnlock){ | 
					
						
							|  |  |  |                                 return undefined | 
					
						
							|  |  |  |                             }else{ | 
					
						
							|  |  |  |                                 return button | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                         }) | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return button; | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |         let customGeneratorLink = MoreScreen.createCustomGeneratorButton(state) | 
					
						
							|  |  |  |         buttons.splice(0, 0, customGeneratorLink); | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |         return new Combine(buttons) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* | 
					
						
							|  |  |  |     * Returns either a link to the issue tracker or a link to the custom generator, depending on the achieved number of changesets | 
					
						
							|  |  |  |     * */ | 
					
						
							|  |  |  |     private static createCustomGeneratorButton(state: State): VariableUiElement { | 
					
						
							|  |  |  |         const tr = Translations.t.general.morescreen; | 
					
						
							|  |  |  |         return new VariableUiElement( | 
					
						
							|  |  |  |             state.osmConnection.userDetails.map(userDetails => { | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |                 if (userDetails.csCount < Constants.userJourney.themeGeneratorReadOnlyUnlock) { | 
					
						
							| 
									
										
										
										
											2021-06-13 15:04:55 +02:00
										 |  |  |                     return new SubtleButton(null, tr.requestATheme.Clone(), { | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |                         url: "https://github.com/pietervdvn/MapComplete/issues", | 
					
						
							|  |  |  |                         newTab: true | 
					
						
							|  |  |  |                     }); | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-06-13 15:04:55 +02:00
										 |  |  |                 return new SubtleButton(Svg.pencil_ui(), tr.createYourOwnTheme.Clone(), { | 
					
						
							| 
									
										
										
										
											2021-06-18 16:19:07 +02:00
										 |  |  |                     url: "https://pietervdvn.github.io/mc/legacy/070/customGenerator.html", | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |                     newTab: false | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |                 }); | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |             }) | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-05-30 00:17:31 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Creates a button linking to the given theme | 
					
						
							|  |  |  |      * @param layout | 
					
						
							|  |  |  |      * @param customThemeDefinition | 
					
						
							|  |  |  |      * @private | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private static createLinkButton(layout: LayoutConfig, customThemeDefinition: string = undefined): BaseUIElement { | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +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; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |         const currentLocation = State.state.locationControl; | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											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-06-10 01:36:20 +02:00
										 |  |  |         let linkPrefix = `${path}/${layout.id.toLowerCase()}.html?` | 
					
						
							|  |  |  |         let linkSuffix = "" | 
					
						
							| 
									
										
										
										
											2020-08-26 15:36:04 +02:00
										 |  |  |         if (location.hostname === "localhost" || location.hostname === "127.0.0.1") { | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |             linkPrefix = `${path}/index.html?layout=${layout.id}&` | 
					
						
							| 
									
										
										
										
											2020-08-26 15:36:04 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (customThemeDefinition) { | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |             linkPrefix = `${path}/index.html?userlayout=${layout.id}&` | 
					
						
							|  |  |  |             linkSuffix = `#${customThemeDefinition}` | 
					
						
							| 
									
										
										
										
											2020-08-26 15:36:04 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |         const linkText = currentLocation.map(currentLocation => { | 
					
						
							|  |  |  |             const params = [ | 
					
						
							|  |  |  |                 ["z", currentLocation?.zoom], | 
					
						
							|  |  |  |                 ["lat", currentLocation?.lat], | 
					
						
							|  |  |  |                 ["lon",currentLocation?.lon] | 
					
						
							|  |  |  |             ].filter(part => part[1] !== undefined) | 
					
						
							|  |  |  |                 .map(part => part[0]+"="+part[1]) | 
					
						
							|  |  |  |                 .join("&") | 
					
						
							|  |  |  |             return `${linkPrefix}${params}${linkSuffix}`; | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |         | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-13 15:04:55 +02:00
										 |  |  |         let description = Translations.WT(layout.shortDescription).Clone(); | 
					
						
							| 
									
										
										
										
											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-06-13 15:04:55 +02:00
										 |  |  |                 Translations.WT(layout.title).Clone(), | 
					
						
							| 
									
										
										
										
											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-06-13 15:04:55 +02:00
										 |  |  |                 description.Clone().SetClass("subtle") ?? "", | 
					
						
							| 
									
										
										
										
											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
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-29 15:48:21 +02:00
										 |  |  | } |