From f6d7e9a2d1d20ef8bdc9fba00742823b8baf662e Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 23 Nov 2023 07:54:38 +0000 Subject: [PATCH] Catch update complete + error states --- app/css/all.css | 4 ---- app/js/custom.js | 30 +++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/app/css/all.css b/app/css/all.css index 156d4f26..6553afa5 100644 --- a/app/css/all.css +++ b/app/css/all.css @@ -262,7 +262,3 @@ button > i.fas { border-bottom-right-radius: 0.35rem; } -.cmd-copy { - width: 95%; - height: 6rem; -} diff --git a/app/js/custom.js b/app/js/custom.js index 30ae715e..d7f9eff1 100644 --- a/app/js/custom.js +++ b/app/js/custom.js @@ -320,27 +320,39 @@ $('#performupdateModal').on('shown.bs.modal', function (e) { function fetchUpdateResponse() { const xhr = new XMLHttpRequest(); + const complete = 6; + const error = 7; let phpFile = 'ajax/system/sys_read_logfile.php'; $.ajax({ url: phpFile, type: 'GET', success: function(response) { + let endPolling = false; for (let i = 1; i <= 6; i++) { let divId = '#updateStep' + i; - if (response.includes(i)) { + if (response.includes(i.toString())) { $(divId).removeClass('invisible'); - if (response.includes('6')) { - $('#updateStep6').removeClass('invisible'); - $('#updateSync2').removeClass("fa-spin"); - break; - } else { - setTimeout(fetchUpdateResponse, 1000); - } } + if (response.includes(complete)) { + $('#updateStep6').removeClass('invisible'); + $('#updateSync2').removeClass("fa-spin"); + endPolling = true; + break; + } else if (response.includes(error)) { + var errorMsg = $('#errorMsg').data('message'); + $('#updateErr').after('' + errorMsg + ''); + $('#updateErr').removeClass('invisible'); + $('#updateSync2').removeClass("fa-spin"); + endPolling = true; + break; + } + } + if (!endPolling) { + setTimeout(fetchUpdateResponse, 500); } }, error: function(xhr, status, error) { - setTimeout(fetchUpdateResponse, 1000); + console.error(error); } }); }