Improve preferences window: allow to salvage broken themes; delete all preferences
This commit is contained in:
parent
d2e51514bd
commit
134dbe2f42
1 changed files with 33 additions and 7 deletions
|
@ -7,6 +7,8 @@ import {UIElement} from "./UI/UIElement";
|
||||||
import {UIEventSource} from "./Logic/UIEventSource";
|
import {UIEventSource} from "./Logic/UIEventSource";
|
||||||
import {Utils} from "./Utils";
|
import {Utils} from "./Utils";
|
||||||
import {SubtleButton} from "./UI/Base/SubtleButton";
|
import {SubtleButton} from "./UI/Base/SubtleButton";
|
||||||
|
import LZString from "lz-string";
|
||||||
|
import {LayoutConfigJson} from "./Customizations/JSON/LayoutConfigJson";
|
||||||
|
|
||||||
|
|
||||||
const connection = new OsmConnection(false, new UIEventSource<string>(undefined), "");
|
const connection = new OsmConnection(false, new UIEventSource<string>(undefined), "");
|
||||||
|
@ -45,26 +47,49 @@ function salvageThemes(preferences: any) {
|
||||||
let foundValue = undefined
|
let foundValue = undefined
|
||||||
let combined = ""
|
let combined = ""
|
||||||
do {
|
do {
|
||||||
|
const prefix = "mapcomplete-installed-theme-";
|
||||||
const key = prefix + failedTheme + "-combined-" + i;
|
const key = prefix + failedTheme + "-combined-" + i;
|
||||||
foundValue = preferences[key]
|
foundValue = preferences[key]
|
||||||
|
console.log(key,"-->",foundValue)
|
||||||
i++;
|
i++;
|
||||||
combined += foundValue ?? ""
|
combined += foundValue ?? ""
|
||||||
} while (foundValue !== undefined);
|
} while (foundValue !== undefined);
|
||||||
|
|
||||||
const json = Utils.UnMinify(combined);
|
if(combined === ""){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("COmbined value is", combined)
|
||||||
|
let jsonObject;
|
||||||
|
try {
|
||||||
|
jsonObject = JSON.parse(atob(combined));
|
||||||
|
} catch (e) {
|
||||||
|
// We try to decode with lz-string
|
||||||
|
jsonObject = JSON.parse(Utils.UnMinify(LZString.decompressFromBase64(combined))) as LayoutConfigJson;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
themeName: failedTheme,
|
themeName: failedTheme,
|
||||||
contents: json
|
contents: JSON.stringify(jsonObject, null, " ")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return missingValues;
|
return Utils.NoNull(missingValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SalvageButton(theme: {themeName: string, contents: string}){
|
function clearAll(preferences){
|
||||||
return new SubtleButton("bug.svg", "Download broken theme "+theme.themeName).onClick(
|
for (const key in preferences) {
|
||||||
|
const pref = connection.GetPreference(key, "");
|
||||||
|
if (key.startsWith("mapcomplete")) {
|
||||||
|
pref.setData("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function SalvageButton(theme: { themeName: string, contents: string }) {
|
||||||
|
return new SubtleButton("./assets/svg/bug.svg", "Download broken theme " + theme.themeName).onClick(
|
||||||
() => {
|
() => {
|
||||||
Utils.downloadTxtFile(theme.contents, theme.themeName+".json")
|
Utils.downloadTxtFile(theme.contents, theme.themeName + ".json")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -103,7 +128,8 @@ function createTable(preferences: any) {
|
||||||
...salvageThemes(preferences).map(theme => SalvageButton(theme)),
|
...salvageThemes(preferences).map(theme => SalvageButton(theme)),
|
||||||
"<table>",
|
"<table>",
|
||||||
...prefs,
|
...prefs,
|
||||||
"</table>"]
|
"</table>",
|
||||||
|
new SubtleButton("./assets/svg/delete_icon.svg", "Delete all mapcomplete preferences (mangrove identies are preserved)").onClick(() => clearAll(preferences))]
|
||||||
).AttachTo("maindiv");
|
).AttachTo("maindiv");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue