Fix missing layouts

This commit is contained in:
Pieter Vander Vennet 2020-09-15 00:25:25 +02:00
parent dc5fa5dabc
commit ce1568f2bb
2 changed files with 17 additions and 12 deletions

View file

@ -34,27 +34,34 @@ import {GeoLocationHandler} from "./Logic/Leaflet/GeoLocationHandler";
import {Layout} from "./Customizations/Layout"; import {Layout} from "./Customizations/Layout";
import {LocalStorageSource} from "./Logic/Web/LocalStorageSource"; import {LocalStorageSource} from "./Logic/Web/LocalStorageSource";
import {FromJSON} from "./Customizations/JSON/FromJSON"; import {FromJSON} from "./Customizations/JSON/FromJSON";
import {Utils} from "./Utils";
export class InitUiElements { export class InitUiElements {
static InitAll(layoutToUse: Layout, layoutFromBase64: string, testing: UIEventSource<string>, defaultLayout1: string ) { static InitAll(layoutToUse: Layout, layoutFromBase64: string, testing: UIEventSource<string>, layoutName: string ) {
if (layoutToUse === undefined) { if (layoutToUse === undefined) {
console.log("Incorrect layout") console.log("Incorrect layout")
new FixedUiElement("Error: incorrect layout <i>" + defaultLayout1 + "</i><br/><a href='https://pietervdvn.github.io/MapComplete/index.html'>Go back</a>").AttachTo("centermessage").onClick(() => { new FixedUiElement("Error: incorrect layout <i>" + layoutName + "</i><br/><a href='https://pietervdvn.github.io/MapComplete/index.html'>Go back</a>").AttachTo("centermessage").onClick(() => {
}); });
throw "Incorrect layout" throw "Incorrect layout"
} }
console.log("Using layout: ", layoutToUse.id); const hash = location.hash.substr(1);
console.log("Using layout: ", layoutToUse.id, "LayoutFromBase64 is ", layoutFromBase64);
State.state = new State(layoutToUse); State.state = new State(layoutToUse);
// This 'leaks' the global state via the window object, useful for debugging
// @ts-ignore
window.mapcomplete_state = State.state;
if (layoutToUse.hideFromOverview) { if (layoutToUse.hideFromOverview) {
State.state.osmConnection.GetPreference("hidden-theme-" + layoutToUse.id + "-enabled").setData("true"); State.state.osmConnection.GetPreference("hidden-theme-" + layoutToUse.id + "-enabled").setData("true");
} }
if (layoutFromBase64 !== "false") { if (layoutFromBase64 !== "false") {
State.state.layoutDefinition = location.hash.substr(1); State.state.layoutDefinition = hash;
console.log("Layout definition:",Utils.EllipsesAfter(State.state.layoutDefinition, 100))
if (testing.data !== "true") { if (testing.data !== "true") {
State.state.osmConnection.OnLoggedIn(() => { State.state.osmConnection.OnLoggedIn(() => {
State.state.osmConnection.GetLongPreference("installed-theme-" + layoutToUse.id).setData(State.state.layoutDefinition); State.state.osmConnection.GetLongPreference("installed-theme-" + layoutToUse.id).setData(State.state.layoutDefinition);
@ -200,9 +207,7 @@ export class InitUiElements {
new GeoLocationHandler().AttachTo("geolocate-button"); new GeoLocationHandler().AttachTo("geolocate-button");
State.state.locationControl.ping(); State.state.locationControl.ping();
// This 'leaks' the global state via the window object, useful for debugging
// @ts-ignore
window.mapcomplete_state = State.state;
} }

View file

@ -34,7 +34,6 @@ if (location.hostname === "localhost" || location.hostname === "127.0.0.1") {
// ----------------- SELECT THE RIGHT QUESTSET ----------------- // ----------------- SELECT THE RIGHT QUESTSET -----------------
let defaultLayout = "bookcases" let defaultLayout = "bookcases"
let hash = window.location.hash;
const path = window.location.pathname.split("/").slice(-1)[0]; const path = window.location.pathname.split("/").slice(-1)[0];
if (path !== "index.html" && path !== "") { if (path !== "index.html" && path !== "") {
@ -82,6 +81,7 @@ if (layoutFromBase64.startsWith("wiki:")) {
try { try {
console.log("DOWNLOADED:",layoutJson); console.log("DOWNLOADED:",layoutJson);
const layout = FromJSON.LayoutFromJSON(JSON.parse(layoutJson)); const layout = FromJSON.LayoutFromJSON(JSON.parse(layoutJson));
layout.id = layoutFromBase64;
InitUiElements.InitAll(layout, layoutFromBase64, testing, layoutFromBase64); InitUiElements.InitAll(layout, layoutFromBase64, testing, layoutFromBase64);
} catch (e) { } catch (e) {
new FixedUiElement(`<a href="${cleanUrl}">${themeName}</a> is invalid:<br/>${e}`) new FixedUiElement(`<a href="${cleanUrl}">${themeName}</a> is invalid:<br/>${e}`)
@ -96,9 +96,9 @@ if (layoutFromBase64.startsWith("wiki:")) {
.AttachTo("centermessage"); .AttachTo("centermessage");
}); });
} else { } else if (layoutFromBase64 !== "false") {
if (layoutFromBase64 !== "false") {
layoutToUse = InitUiElements.LoadLayoutFromHash(userLayoutParam); layoutToUse = InitUiElements.LoadLayoutFromHash(userLayoutParam);
} InitUiElements.InitAll(layoutToUse, layoutFromBase64, testing, defaultLayout);
} else {
InitUiElements.InitAll(layoutToUse, layoutFromBase64, testing, defaultLayout); InitUiElements.InitAll(layoutToUse, layoutFromBase64, testing, defaultLayout);
} }