Fix missing layouts
This commit is contained in:
parent
dc5fa5dabc
commit
ce1568f2bb
2 changed files with 17 additions and 12 deletions
|
@ -34,27 +34,34 @@ import {GeoLocationHandler} from "./Logic/Leaflet/GeoLocationHandler";
|
|||
import {Layout} from "./Customizations/Layout";
|
||||
import {LocalStorageSource} from "./Logic/Web/LocalStorageSource";
|
||||
import {FromJSON} from "./Customizations/JSON/FromJSON";
|
||||
import {Utils} from "./Utils";
|
||||
|
||||
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) {
|
||||
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"
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// This 'leaks' the global state via the window object, useful for debugging
|
||||
// @ts-ignore
|
||||
window.mapcomplete_state = State.state;
|
||||
|
||||
if (layoutToUse.hideFromOverview) {
|
||||
State.state.osmConnection.GetPreference("hidden-theme-" + layoutToUse.id + "-enabled").setData("true");
|
||||
}
|
||||
|
||||
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") {
|
||||
State.state.osmConnection.OnLoggedIn(() => {
|
||||
State.state.osmConnection.GetLongPreference("installed-theme-" + layoutToUse.id).setData(State.state.layoutDefinition);
|
||||
|
@ -200,9 +207,7 @@ export class InitUiElements {
|
|||
new GeoLocationHandler().AttachTo("geolocate-button");
|
||||
State.state.locationControl.ping();
|
||||
|
||||
// This 'leaks' the global state via the window object, useful for debugging
|
||||
// @ts-ignore
|
||||
window.mapcomplete_state = State.state;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
10
index.ts
10
index.ts
|
@ -34,7 +34,6 @@ if (location.hostname === "localhost" || location.hostname === "127.0.0.1") {
|
|||
// ----------------- SELECT THE RIGHT QUESTSET -----------------
|
||||
|
||||
let defaultLayout = "bookcases"
|
||||
let hash = window.location.hash;
|
||||
|
||||
const path = window.location.pathname.split("/").slice(-1)[0];
|
||||
if (path !== "index.html" && path !== "") {
|
||||
|
@ -68,7 +67,7 @@ if (layoutFromBase64.startsWith("wiki:")) {
|
|||
const themeName = layoutFromBase64.substr("wiki:".length);
|
||||
new FixedUiElement(`Downloading ${themeName} from the wiki...`)
|
||||
.AttachTo("centermessage");
|
||||
const cleanUrl = `https://wiki.openstreetmap.org/wiki/${themeName}`;
|
||||
const cleanUrl = `https://wiki.openstreetmap.org/wiki/${themeName}`;
|
||||
const url = `https://cors-anywhere.herokuapp.com/` + cleanUrl; // VERY SAFE AND HACKER-PROOF!
|
||||
|
||||
$.ajax({
|
||||
|
@ -82,6 +81,7 @@ if (layoutFromBase64.startsWith("wiki:")) {
|
|||
try {
|
||||
console.log("DOWNLOADED:",layoutJson);
|
||||
const layout = FromJSON.LayoutFromJSON(JSON.parse(layoutJson));
|
||||
layout.id = layoutFromBase64;
|
||||
InitUiElements.InitAll(layout, layoutFromBase64, testing, layoutFromBase64);
|
||||
} catch (e) {
|
||||
new FixedUiElement(`<a href="${cleanUrl}">${themeName}</a> is invalid:<br/>${e}`)
|
||||
|
@ -96,9 +96,9 @@ if (layoutFromBase64.startsWith("wiki:")) {
|
|||
.AttachTo("centermessage");
|
||||
});
|
||||
|
||||
} else if (layoutFromBase64 !== "false") {
|
||||
layoutToUse = InitUiElements.LoadLayoutFromHash(userLayoutParam);
|
||||
InitUiElements.InitAll(layoutToUse, layoutFromBase64, testing, defaultLayout);
|
||||
} else {
|
||||
if (layoutFromBase64 !== "false") {
|
||||
layoutToUse = InitUiElements.LoadLayoutFromHash(userLayoutParam);
|
||||
}
|
||||
InitUiElements.InitAll(layoutToUse, layoutFromBase64, testing, defaultLayout);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue