mapcomplete/UI/MoreScreen.ts

120 lines
4.2 KiB
TypeScript
Raw Normal View History

2020-07-29 15:48:21 +02:00
import {UIElement} from "./UIElement";
import {VerticalCombine} from "./Base/VerticalCombine";
import Translations from "./i18n/Translations";
import {AllKnownLayouts} from "../Customizations/AllKnownLayouts";
import Combine from "./Base/Combine";
import {SubtleButton} from "./Base/SubtleButton";
import State from "../State";
import {VariableUiElement} from "./Base/VariableUIElement";
2020-11-06 01:58:26 +01:00
import Svg from "../Svg";
2020-11-11 16:23:49 +01:00
import LayoutConfig from "../Customizations/JSON/LayoutConfig";
import * as personal from "../assets/themes/personalLayout/personalLayout.json"
2020-07-29 15:48:21 +02:00
export class MoreScreen extends UIElement {
constructor() {
super(State.state.locationControl);
2020-07-31 16:17:16 +02:00
this.ListenTo(State.state.osmConnection.userDetails);
this.ListenTo(State.state.installedThemes);
}
2020-11-11 16:23:49 +01:00
private createLinkButton(layout: LayoutConfig, customThemeDefinition: string = undefined) {
if (layout === undefined) {
return undefined;
}
if(layout.id === undefined){
console.error("ID is undefined for layout",layout);
return undefined;
}
if (layout.hideFromOverview) {
const pref = State.state.osmConnection.GetPreference("hidden-theme-" + layout.id + "-enabled");
this.ListenTo(pref);
if (pref.data !== "true") {
return undefined;
}
}
if (layout.id === State.state.layoutToUse.data.id) {
return undefined;
}
const currentLocation = State.state.locationControl.data;
let linkText =
`./${layout.id.toLowerCase()}.html?z=${currentLocation.zoom}&lat=${currentLocation.lat}&lon=${currentLocation.lon}`
if (location.hostname === "localhost" || location.hostname === "127.0.0.1") {
linkText = `./index.html?layout=${layout.id}&z=${currentLocation.zoom}&lat=${currentLocation.lat}&lon=${currentLocation.lon}`
}
if (customThemeDefinition) {
linkText = `./index.html?userlayout=${layout.id}&z=${currentLocation.zoom}&lat=${currentLocation.lat}&lon=${currentLocation.lon}#${customThemeDefinition}`
}
2020-11-11 16:23:49 +01:00
let description = Translations.W(layout.shortDescription);
if (description !== undefined) {
description = new Combine(["<br/>", description]);
}
const link =
new SubtleButton(layout.icon,
new Combine([
"<b>",
Translations.W(layout.title),
"</b>",
description ?? "",
]), {url: linkText, newTab: false})
return link;
2020-07-29 15:48:21 +02:00
}
InnerRender(): string {
2020-07-29 15:48:21 +02:00
const tr = Translations.t.general.morescreen;
const els: UIElement[] = []
els.push(new VariableUiElement(
State.state.osmConnection.userDetails.map(userDetails => {
if (userDetails.csCount < State.userJourney.themeGeneratorReadOnlyUnlock) {
return tr.requestATheme.Render();
}
2020-11-06 04:02:53 +01:00
return new SubtleButton(Svg.pencil_ui(), tr.createYourOwnTheme, {
url: "./customGenerator.html",
newTab: false
}).Render();
})
));
for (const k in AllKnownLayouts.allSets) {
2020-11-11 16:23:49 +01:00
const layout : LayoutConfig = AllKnownLayouts.allSets[k];
if (k === personal.id) {
if (State.state.osmConnection.userDetails.data.csCount < State.userJourney.personalLayoutUnlock) {
continue;
2020-08-24 20:24:53 +02:00
}
}
if (layout.id !== k) {
continue; // This layout was added multiple time due to an uppercase
}
els.push(this.createLinkButton(layout));
}
2020-07-29 15:48:21 +02:00
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));
}
2020-07-29 15:48:21 +02:00
}
return new VerticalCombine([
tr.intro,
new VerticalCombine(els),
tr.streetcomplete
2020-07-29 15:48:21 +02:00
]).Render();
}
}