This commit is contained in:
35
www/maps.js
35
www/maps.js
@@ -530,12 +530,45 @@
|
||||
renderList();
|
||||
}
|
||||
|
||||
async function importSiteBundle() {
|
||||
const site_id = createSiteSelectEl?.value || store.sites[0]?.id;
|
||||
if (!site_id) {
|
||||
alert(t("maps.importNoSite"));
|
||||
return;
|
||||
}
|
||||
const input = document.createElement("input");
|
||||
input.type = "file";
|
||||
input.accept = ".json,application/json";
|
||||
input.addEventListener("change", async () => {
|
||||
const file = input.files?.[0];
|
||||
if (!file) return;
|
||||
try {
|
||||
const text = await file.text();
|
||||
const result = await api(`/api/sites/${encodeURIComponent(site_id)}/import`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: text,
|
||||
});
|
||||
await loadMaps();
|
||||
const counts = [
|
||||
Array.isArray(result.maps) ? result.maps.length : 0,
|
||||
Array.isArray(result.io_modules) ? result.io_modules.length : 0,
|
||||
Array.isArray(result.transitions) ? result.transitions.length : 0,
|
||||
];
|
||||
alert(t("maps.importSuccess", { maps: counts[0], io: counts[1], transitions: counts[2] }));
|
||||
} catch (e) {
|
||||
alert(e.message);
|
||||
}
|
||||
});
|
||||
input.click();
|
||||
}
|
||||
|
||||
function bindEvents() {
|
||||
el("mapsCreateOpenBtn")?.addEventListener("click", openCreatePage);
|
||||
el("mapsCreateGoBackBtn")?.addEventListener("click", showList);
|
||||
el("mapsCreateCancelBtn")?.addEventListener("click", showList);
|
||||
el("mapsCreateHelpBtn")?.addEventListener("click", () => alert(t("maps.createPage.helpText")));
|
||||
el("mapsImportSiteBtn")?.addEventListener("click", () => alert(t("maps.importComingSoon")));
|
||||
el("mapsImportSiteBtn")?.addEventListener("click", () => importSiteBundle().catch((e) => alert(e.message)));
|
||||
el("mapsClearFiltersBtn")?.addEventListener("click", clearFilters);
|
||||
el("mapsHelpBtn")?.addEventListener("click", () => alert(t("maps.helpText")));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user