Add UI to sync dns

This commit is contained in:
Girish Ramakrishnan
2021-02-24 22:18:39 -08:00
parent 5f0ff047d4
commit 8dc0236e89
3 changed files with 94 additions and 2 deletions

View File

@@ -2,7 +2,7 @@
/* global async */
/* global angular */
/* global $ */
/* global $, TASK_TYPES */
angular.module('Application').controller('DomainsController', ['$scope', '$location', 'Client', function ($scope, $location, Client) {
Client.onReady(function () { if (!Client.getUserInfo().isAtLeastAdmin) $location.path('/'); });
@@ -389,7 +389,7 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat
taskId: '',
checkStatus: function () {
Client.getLatestTaskByType('renewcerts', function (error, task) {
Client.getLatestTaskByType(TASK_TYPES.TASK_RENEW_CERTS, function (error, task) {
if (error) return console.error(error);
if (!task) return;
@@ -439,6 +439,64 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat
}
};
$scope.syncDns = {
busy: false,
percent: 0,
message: '',
errorMessage: '',
taskId: '',
checkStatus: function () {
Client.getLatestTaskByType(TASK_TYPES.TASK_SYNC_DNS_RECORDS, function (error, task) {
if (error) return console.error(error);
if (!task) return;
$scope.syncDns.taskId = task.id;
$scope.syncDns.updateStatus();
});
},
updateStatus: function () {
Client.getTask($scope.syncDns.taskId, function (error, data) {
if (error) return window.setTimeout($scope.syncDns.updateStatus, 5000);
if (!data.active) {
$scope.syncDns.busy = false;
$scope.syncDns.message = '';
$scope.syncDns.percent = 100; // indicates that 'result' is valid
$scope.syncDns.errorMessage = data.success ? '' : data.error.message;
return;
}
$scope.syncDns.busy = true;
$scope.syncDns.percent = data.percent;
$scope.syncDns.message = data.message;
window.setTimeout($scope.syncDns.updateStatus, 500);
});
},
sync: function () {
$scope.syncDns.busy = true;
$scope.syncDns.percent = 0;
$scope.syncDns.message = '';
$scope.syncDns.errorMessage = '';
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.domainRemove = {
busy: false,
error: null,