From 6c91d2edee29a3b9dab8943984822a62d4bdcb5d Mon Sep 17 00:00:00 2001 From: bobbarnes1981 Date: Fri, 8 Nov 2024 09:51:13 +0000 Subject: [PATCH] Load link using ajax when page loaded and when export complete --- backup-module/backup_controller.php | 10 ++++++++++ backup-module/backup_view.php | 18 +++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/backup-module/backup_controller.php b/backup-module/backup_controller.php index 02266ee..81a7ff0 100644 --- a/backup-module/backup_controller.php +++ b/backup-module/backup_controller.php @@ -68,6 +68,16 @@ function backup_controller() } } + if ($route->action == 'exportlink') { + $route->format = "text"; + $backup_filename="emoncms-backup-".gethostname()."-".date("Y-m-d").".tar.gz"; + if (file_exists($parsed_ini['backup_location']."/".$backup_filename) && !file_exists("/tmp/backuplock")) { + $result = '

Right Click > Download:
'.$backup_filename.''; + } else { + $result = '

No backup file exists for today'; + } + } + if ($route->action == 'importlog') { $route->format = "text"; if (file_exists($import_logfile)) { diff --git a/backup-module/backup_view.php b/backup-module/backup_view.php index 271ba8a..aae74f3 100644 --- a/backup-module/backup_view.php +++ b/backup-module/backup_view.php @@ -73,14 +73,8 @@

-
Right Click > Download:
'.$backup_filename.''; - } - ?> +

-

Once export is complete refresh page to see download link.

Note: Export can take a long time; please be patient.

@@ -136,6 +130,7 @@ function selectTab(hash) { export_updater = setInterval(export_log_update,1000); import_updater = setInterval(import_log_update,1000); usb_import_updater = setInterval(usb_import_log_update,1000); +export_log_link(); $("#emonpi-backup").click(function() { $.ajax({ url: path+"backup/start", async: true, dataType: "text", success: function(result) { @@ -163,11 +158,20 @@ function export_log_update() { if (result.indexOf("=== Emoncms export complete! ===")!=-1 || result.indexOf("=== Emoncms export completed with ERRORS! ===")!=-1) { clearInterval(export_updater); + export_log_link(); } } }); } +function export_log_link() { + $.ajax({ url: path+"backup/exportlink", async: true, dataType: "text", success: function(result) + { + $("#export-link").html(result); + } + }); +} + function import_log_update() { $.ajax({ url: path+"backup/importlog", async: true, dataType: "text", success: function(result) {