From ee397c48e10e533b50b8d74fd3d4706e9b9b7730 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Fri, 25 Jul 2025 21:49:52 +0000 Subject: [PATCH] add restore function to backups --- web/images/actions/backups/restore.svg | 1 + web/scripts/backups.js | 27 ++++++++++++++++++++++++++ web/templates/backups.go.tmpl | 3 ++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 web/images/actions/backups/restore.svg diff --git a/web/images/actions/backups/restore.svg b/web/images/actions/backups/restore.svg new file mode 100644 index 0000000..4c3773a --- /dev/null +++ b/web/images/actions/backups/restore.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/web/scripts/backups.js b/web/scripts/backups.js index 6b7d194..1fc805b 100644 --- a/web/scripts/backups.js +++ b/web/scripts/backups.js @@ -47,6 +47,17 @@ class BackupCard extends HTMLElement { } }; } + + const restoreButton = this.shadowRoot.querySelector("#restore-btn"); + if (restoreButton.classList.contains("clickable")) { + restoreButton.onclick = this.handleRestoreButton.bind(this); + restoreButton.onkeydown = (event) => { + if (event.key === "Enter") { + event.preventDefault(); + this.handleRestoreButton(); + } + }; + } } get volid () { @@ -85,6 +96,22 @@ class BackupCard extends HTMLElement { } }); } + + async handleRestoreButton () { + const template = this.shadowRoot.querySelector("#restore-dialog"); + dialog(template, async (result, form) => { + if (result === "confirm") { + const body = { + volid: this.volid + }; + const result = await requestAPI(`/cluster/${node}/${type}/${vmid}/backup/restore`, "POST", body); + if (result.status !== 200) { + alert(`Attempted to delete backup but got: ${result.error}`); + } + refreshBackups(); + } + }); + } } customElements.define("backup-card", BackupCard); diff --git a/web/templates/backups.go.tmpl b/web/templates/backups.go.tmpl index b58a4d2..15f8e2a 100644 --- a/web/templates/backups.go.tmpl +++ b/web/templates/backups.go.tmpl @@ -83,7 +83,8 @@

Are you sure you want to restore from the backup made at {{.TimeFormatted}}?
- WARNING: Restoring from a backup will WIPE disks NOT contained in the backup!!! +
+ WARNING: Restoring from a backup will WIPE disks NOT contained in the backup!!!