Custom themes now stick to the user account and can be revisited, small improvements
This commit is contained in:
parent
bf6eae9af1
commit
4a0970a71f
23 changed files with 556 additions and 1748 deletions
114
UI/MoreScreen.ts
114
UI/MoreScreen.ts
|
@ -5,8 +5,12 @@ import {AllKnownLayouts} from "../Customizations/AllKnownLayouts";
|
|||
import Combine from "./Base/Combine";
|
||||
import {SubtleButton} from "./Base/SubtleButton";
|
||||
import {State} from "../State";
|
||||
import {CustomLayout} from "../Logic/CustomLayers";
|
||||
import {VariableUiElement} from "./Base/VariableUIElement";
|
||||
import {PersonalLayout} from "../Logic/PersonalLayout";
|
||||
import {FixedUiElement} from "./Base/FixedUiElement";
|
||||
import {Layout} from "../Customizations/Layout";
|
||||
import {CustomLayoutFromJSON} from "../Customizations/JSON/CustomLayoutFromJSON";
|
||||
import {All} from "../Customizations/Layouts/All";
|
||||
|
||||
|
||||
export class MoreScreen extends UIElement {
|
||||
|
@ -14,6 +18,48 @@ export class MoreScreen extends UIElement {
|
|||
constructor() {
|
||||
super(State.state.locationControl);
|
||||
this.ListenTo(State.state.osmConnection.userDetails);
|
||||
this.ListenTo(State.state.osmConnection._preferencesHandler.preferences);
|
||||
|
||||
}
|
||||
|
||||
private createLinkButton(layout: Layout, customThemeDefinition: string = undefined) {
|
||||
if (layout.hideFromOverview && State.state.osmConnection.userDetails.data.name !== "Pieter Vander Vennet") {
|
||||
return undefined;
|
||||
}
|
||||
if (layout.name === State.state.layoutToUse.data.name) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (layout.name === PersonalLayout.NAME) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const currentLocation = State.state.locationControl.data;
|
||||
let linkText =
|
||||
`./${layout.name}.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.name}&z=${currentLocation.zoom}&lat=${currentLocation.lat}&lon=${currentLocation.lon}`
|
||||
}
|
||||
|
||||
if (customThemeDefinition) {
|
||||
linkText = `./index.html?userlayout=${layout.name}&z=${currentLocation.zoom}&lat=${currentLocation.lat}&lon=${currentLocation.lon}#${customThemeDefinition}`
|
||||
|
||||
}
|
||||
|
||||
let description = Translations.W(layout.description);
|
||||
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;
|
||||
}
|
||||
|
||||
InnerRender(): string {
|
||||
|
@ -28,7 +74,7 @@ export class MoreScreen extends UIElement {
|
|||
return tr.requestATheme.Render();
|
||||
}
|
||||
return new SubtleButton("./assets/pencil.svg", tr.createYourOwnTheme, {
|
||||
url: "https://pietervdvn.github.io/MapComplete/customGenerator.html",
|
||||
url: "./customGenerator.html",
|
||||
newTab: false
|
||||
}).Render();
|
||||
})
|
||||
|
@ -53,40 +99,44 @@ export class MoreScreen extends UIElement {
|
|||
|
||||
|
||||
for (const k in AllKnownLayouts.allSets) {
|
||||
const layout = AllKnownLayouts.allSets[k]
|
||||
if (layout.hideFromOverview && State.state.osmConnection.userDetails.data.name !== "Pieter Vander Vennet") {
|
||||
continue
|
||||
els.push(this.createLinkButton(AllKnownLayouts.allSets[k]));
|
||||
}
|
||||
|
||||
const installedThemes = State.state.osmConnection._preferencesHandler.preferences.map(allPreferences => {
|
||||
const installedThemes = [];
|
||||
if(allPreferences === undefined){
|
||||
return installedThemes;
|
||||
}
|
||||
if (layout.name === State.state.layoutToUse.data.name) {
|
||||
|
||||
for (const allPreferencesKey in allPreferences) {
|
||||
"mapcomplete-installed-theme-Superficie-combined-length"
|
||||
const themename = allPreferencesKey.match(/^mapcomplete-installed-theme-(.*)-combined-length$/);
|
||||
if(themename){
|
||||
installedThemes.push(themename[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return installedThemes;
|
||||
|
||||
})
|
||||
const customThemesNames = installedThemes.data ?? [];
|
||||
if (customThemesNames !== []) {
|
||||
els.push(Translations.t.general.customThemeIntro)
|
||||
}
|
||||
|
||||
console.log(customThemesNames);
|
||||
for (const installedThemeName of customThemesNames) {
|
||||
if(installedThemeName === ""){
|
||||
continue;
|
||||
}
|
||||
|
||||
if (layout.name === CustomLayout.NAME) {
|
||||
continue;
|
||||
const customThemeDefinition = State.state.osmConnection.GetLongPreference("installed-theme-" + installedThemeName);
|
||||
try {
|
||||
const layout = CustomLayoutFromJSON.FromQueryParam(customThemeDefinition.data);
|
||||
els.push(this.createLinkButton(layout, customThemeDefinition.data));
|
||||
} catch (e) {
|
||||
console.log(customThemeDefinition.data);
|
||||
console.warn("Could not parse custom layout from preferences: ", installedThemeName, e);
|
||||
}
|
||||
|
||||
const currentLocation = State.state.locationControl.data;
|
||||
let linkText =
|
||||
`./${layout.name}.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.name}&z=${currentLocation.zoom}&lat=${currentLocation.lat}&lon=${currentLocation.lon}`
|
||||
}
|
||||
|
||||
let description = Translations.W(layout.description);
|
||||
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});
|
||||
|
||||
els.push(link)
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue