From b7b01d5605974896a1609f2eb444d2b8a93657a5 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Sun, 14 May 2023 11:47:21 +0200 Subject: [PATCH] domains: show current task in renewCert, syncDns --- dashboard/src/views/domains.js | 47 ++++++++++++---------------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/dashboard/src/views/domains.js b/dashboard/src/views/domains.js index 718c132fc..666a4ab51 100644 --- a/dashboard/src/views/domains.js +++ b/dashboard/src/views/domains.js @@ -489,23 +489,20 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat percent: 0, message: '', errorMessage: '', - taskId: '', tasks: [], - checkStatus: function () { + refreshTasks: function () { Client.getTasksByType(TASK_TYPES.TASK_CHECK_CERTS, function (error, tasks) { if (error) return console.error(error); - - if (!tasks.length) return; - $scope.renewCerts.tasks = tasks.slice(0, 10); - - $scope.renewCerts.taskId = tasks[0].id; + if ($scope.renewCerts.tasks.length) $scope.renewCerts.updateStatus(); }); }, updateStatus: function () { - Client.getTask($scope.renewCerts.taskId, function (error, data) { + var taskId = $scope.renewCerts.tasks[0].id; + + Client.getTask(taskId, function (error, data) { if (error) return window.setTimeout($scope.renewCerts.updateStatus, 5000); if (!data.active) { @@ -514,7 +511,7 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat $scope.renewCerts.percent = 100; // indicates that 'result' is valid $scope.renewCerts.errorMessage = data.success ? '' : data.error.message; - $scope.renewCerts.checkStatus(); + $scope.renewCerts.refreshTasks(); // update the tasks list dropdown return; } @@ -533,16 +530,13 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat $scope.renewCerts.errorMessage = ''; // always rebuild the nginx configs when triggered via the UI. we assume user is clicking this because something is wrong - Client.renewCerts({ rebuild: true }, function (error, taskId) { + Client.renewCerts({ rebuild: true }, function (error /*, taskId */) { if (error) { console.error(error); $scope.renewCerts.errorMessage = error.message; - $scope.renewCerts.busy = false; } else { - $scope.renewCerts.taskId = taskId; - $scope.renewCerts.updateStatus(); - $scope.renewCerts.checkStatus(); + $scope.renewCerts.refreshTasks(); } }); } @@ -553,23 +547,19 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat percent: 0, message: '', errorMessage: '', - taskId: '', tasks: [], - checkStatus: function () { + refreshTasks: function () { Client.getTasksByType(TASK_TYPES.TASK_SYNC_DNS_RECORDS, function (error, tasks) { if (error) return console.error(error); - - if (!tasks.length) return; - $scope.syncDns.tasks = tasks.slice(0, 10); - - $scope.syncDns.taskId = tasks[0].id; + if ($scope.syncDns.tasks.length) $scope.syncDns.updateStatus(); }); }, updateStatus: function () { - Client.getTask($scope.syncDns.taskId, function (error, data) { + var taskId = $scope.syncDns.tasks[0].id; + Client.getTask(taskId, function (error, data) { if (error) return window.setTimeout($scope.syncDns.updateStatus, 5000); if (!data.active) { @@ -578,7 +568,7 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat $scope.syncDns.percent = 100; // indicates that 'result' is valid $scope.syncDns.errorMessage = data.success ? '' : data.error.message; - $scope.syncDns.checkStatus(); + $scope.syncDns.refreshTasks(); // update the tasks list dropdown return; } @@ -596,16 +586,13 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat $scope.syncDns.message = ''; $scope.syncDns.errorMessage = ''; - Client.setDnsRecords({}, function (error, taskId) { + Client.setDnsRecords({}, function (error /*, taskId */) { if (error) { console.error(error); $scope.syncDns.errorMessage = error.message; - $scope.syncDns.busy = false; } else { - $scope.syncDns.taskId = taskId; - $scope.syncDns.updateStatus(); - $scope.syncDns.checkStatus(); + $scope.syncDns.refreshTasks(); } }); } @@ -744,8 +731,8 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat $scope.ready = true; }); - $scope.renewCerts.checkStatus(); - $scope.syncDns.checkStatus(); + $scope.renewCerts.refreshTasks(); + $scope.syncDns.refreshTasks(); }); document.getElementById('gcdnsKeyFileInput').onchange = readFileLocally($scope.domainConfigure.gcdnsKey, 'content', 'keyFileName');