fix(settings): make data imports real buttons and confirm the full import
The JSON imports were bare file inputs next to the export buttons and didn't read as imports. They are now buttons like the CSV imports; the full import asks before it replaces all race data.
This commit is contained in:
1 parent
f4dc3bb5bd
commit
f51aa0ba37
4 files changed
+50
-5
No files matched your search
@@ -2276,6 +2276,7 @@ const TRANSLATIONS = {
|
||||
"settings.clear_training_confirm": "Rensa all träningsstatistik, mål, belöningar och publika profillänkar? Detta kan inte ångras.",
|
||||
"settings.clear_all_confirm": "Rensa alla klasser, förare, bilar, race, sessioner, resultat och all träningsstatistik? Systeminställningar behålls. Detta kan inte ångras.",
|
||||
"settings.clear_success": "Valda data har rensats.",
|
||||
"settings.import_full_confirm": "Importera \"{name}\"?\n\nAll nuvarande race-data (klasser, förare, bilar, race, sessioner och resultat) ersätts med filens innehåll. En backup tas först och finns under SQLite-backuper på servern.",
|
||||
"settings.import_full_success": "Race-data importerad och ersatte nuvarande tävlingsdata.",
|
||||
"settings.import_directory_success": "Klasser, förare och bilar importerades in i befintlig data.",
|
||||
"settings.import_failed": "Import misslyckades: {msg}",
|
||||
@@ -4114,6 +4115,7 @@ const TRANSLATIONS = {
|
||||
"settings.clear_training_confirm": "Clear all training statistics, goals, rewards, and public profile links? This cannot be undone.",
|
||||
"settings.clear_all_confirm": "Clear all classes, drivers, cars, races, sessions, results, and training statistics? System settings are retained. This cannot be undone.",
|
||||
"settings.clear_success": "The selected data has been cleared.",
|
||||
"settings.import_full_confirm": "Import \"{name}\"?\n\nAll current race data (classes, drivers, cars, races, sessions and results) is replaced with the file's contents. A backup is taken first and is listed under Server SQLite backups.",
|
||||
"settings.import_full_success": "Race data imported and replaced the current competition data.",
|
||||
"settings.import_directory_success": "Classes, drivers and cars were imported into the existing data.",
|
||||
"settings.import_failed": "Import failed: {msg}",
|
||||
|
||||
+17
-4
@@ -525,14 +525,16 @@ export function renderSettings(deps) {
|
||||
<p class="hint">${t("settings.storage_note_full")}</p>
|
||||
<div class="actions">
|
||||
<button id="exportData" class="btn" type="button">${t("settings.export_all_data")}</button>
|
||||
<input id="importData" type="file" accept="application/json" />
|
||||
<button id="selectImportData" class="btn" type="button">${t("settings.import_all_data")}</button>
|
||||
<input id="importData" type="file" accept="application/json,.json" hidden />
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-16">
|
||||
<p class="hint">${t("settings.storage_note_directory")}</p>
|
||||
<div class="actions">
|
||||
<button id="exportDirectoryData" class="btn" type="button">${t("settings.export_directory")}</button>
|
||||
<input id="importDirectoryData" type="file" accept="application/json" />
|
||||
<button id="selectImportDirectoryData" class="btn" type="button">${t("settings.import_directory")}</button>
|
||||
<input id="importDirectoryData" type="file" accept="application/json,.json" hidden />
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-16">
|
||||
@@ -918,18 +920,28 @@ Erik Eriksson;654321;4WD;Associated;;</code></pre>
|
||||
downloadJsonFile("live_rc_full_export.json", payload);
|
||||
});
|
||||
|
||||
// The file inputs are hidden behind real buttons: a bare "Choose file" didn't read as an import.
|
||||
document.getElementById("selectImportData")?.addEventListener("click", () => document.getElementById("importData")?.click());
|
||||
document.getElementById("selectImportDirectoryData")?.addEventListener("click", () => document.getElementById("importDirectoryData")?.click());
|
||||
|
||||
document.getElementById("importData")?.addEventListener("change", (event) => {
|
||||
const input = event.currentTarget;
|
||||
const file = input instanceof HTMLInputElement ? input.files?.[0] : null;
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
// A full import replaces every race, session and result - ask first (a safety backup is
|
||||
// still taken). Clearing the input lets the same file be picked again.
|
||||
if (!window.confirm(t("settings.import_full_confirm", { name: file.name }))) {
|
||||
input.value = "";
|
||||
return;
|
||||
}
|
||||
const reader = new FileReader();
|
||||
reader.onload = async () => {
|
||||
try {
|
||||
const parsed = JSON.parse(String(reader.result || "{}"));
|
||||
const completed = await runWithSafetyBackup(() => importDataPayload(parsed, "full"));
|
||||
if (!completed && input instanceof HTMLInputElement) input.value = "";
|
||||
await runWithSafetyBackup(() => importDataPayload(parsed, "full"));
|
||||
if (input instanceof HTMLInputElement) input.value = "";
|
||||
} catch (error) {
|
||||
settingsStorageNotice = t("settings.import_failed", { msg: error instanceof Error ? error.message : String(error) });
|
||||
settingsStorageNoticeIsError = true;
|
||||
@@ -995,6 +1007,7 @@ Erik Eriksson;654321;4WD;Associated;;</code></pre>
|
||||
try {
|
||||
const parsed = JSON.parse(String(reader.result || "{}"));
|
||||
importDataPayload(parsed, "directory");
|
||||
if (input instanceof HTMLInputElement) input.value = "";
|
||||
} catch (error) {
|
||||
settingsStorageNotice = t("settings.import_failed", { msg: error instanceof Error ? error.message : String(error) });
|
||||
settingsStorageNoticeIsError = true;
|
||||
|
||||
Reference in new issue
Block a user