diff --git a/src/js/client.js b/src/js/client.js index 466c6ff64..4e1909891 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -662,7 +662,7 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N if (error) return callback(error); if (status !== 200) return callback(new ClientError(status, data)); - callback(null, data.tasks[0] || null); + callback(null, data.tasks.length ? data.tasks[0] : null); }); }; @@ -701,7 +701,7 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N Client.prototype.stopTask = function (taskId, callback) { post('/api/v1/tasks/' + taskId + '/stop', {}, null, function (error, data, status) { if (error) return callback(error); - if (status !== 202) return callback(new ClientError(status, data)); + if (status !== 204) return callback(new ClientError(status, data)); callback(null, data); }); diff --git a/src/views/domains.html b/src/views/domains.html index 3e2d5a81d..8a7365dae 100644 --- a/src/views/domains.html +++ b/src/views/domains.html @@ -317,7 +317,7 @@

- Use this to move this dashboard to another domain. + This will move the dashboard to the mysubdomain of the selected domain.

@@ -325,8 +325,6 @@
-
-
@@ -343,8 +341,9 @@

- - Show Logs + + + Show Logs
diff --git a/src/views/domains.js b/src/views/domains.js index bf99f63cb..4ad527f9d 100644 --- a/src/views/domains.js +++ b/src/views/domains.js @@ -69,7 +69,7 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat }; } - function getDomains(callback) { + function refreshDomains(callback) { var domains = [ ]; Client.getDomains(function (error, results) { @@ -89,7 +89,12 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat iteratorDone(); }); }, function (error) { - callback(error, domains); + angular.copy(domains, $scope.domains); + + $scope.changeDashboard.selectedDomain = $scope.changeDashboard.adminDomain = $scope.domains.find(function (d) { return d.domain === $scope.config.adminDomain; }); + + if (error) console.error(error); + if (callback) callback(error); }); }); } @@ -261,12 +266,7 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat $('#domainConfigureModal').modal('hide'); $scope.domainConfigure.reset(); - // reload the domains - getDomains(function (error, result) { - if (error) return console.error(error); - - $scope.domains = result; - }); + refreshDomains(); }); }, @@ -440,12 +440,7 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat $('#domainRemoveModal').modal('hide'); $scope.domainRemove.reset(); - // reload the domains - getDomains(function (error, result) { - if (error) return console.error(error); - - $scope.domains = result; - }); + refreshDomains(); } $scope.domainRemove.busy = false; @@ -472,7 +467,29 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat selectedDomain: null, adminDomain: null, + stop: function () { + Client.stopTask($scope.changeDashboard.taskId, function (error) { + if (error) console.error(error); + $scope.changeDashboard.busy = false; + }); + }, + + // this function is not called intentionally. currently, we do switching in two steps - prepare and set + // if the user refreshed the UI in the middle of prepare, then it would be awkward to resume/call 'set' when the + // user visits the UI the next time around. + checkStatus: function () { + Client.getLatestTaskByType('prepareDashboardDomain', function (error, task) { + if (error) return console.error(error); + if (!task) return; + + $scope.changeDashboard.taskId = task.id; + $scope.changeDashboard.updateStatus(); + }); + }, + updateStatus: function () { + if (!$scope.changeDashboard.busy) return; // task got stopped + Client.getTask($scope.changeDashboard.taskId, function (error, data) { if (error) return window.setTimeout($scope.changeDashboard.updateStatus, 5000); @@ -508,6 +525,11 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat }, change: function () { + $scope.changeDashboard.busy = true; + $scope.changeDashboard.message = 'Preparing dashboard domain'; + $scope.changeDashboard.percent = 0; + $scope.changeDashboard.errorMessage = ''; + Client.prepareDashboardDomain($scope.changeDashboard.selectedDomain.domain, function (error, taskId) { if (error) { console.error(error); @@ -554,14 +576,11 @@ angular.module('Application').controller('DomainsController', ['$scope', '$locat }; Client.onReady(function () { - getDomains(function (error, result) { + refreshDomains(function (error) { if (error) return console.error(error); - $scope.domains = result; $scope.ready = true; - $scope.changeDashboard.selectedDomain = $scope.changeDashboard.adminDomain = $scope.domains.find(function (d) { return d.domain === $scope.config.adminDomain; }); - if (!$scope.config.managed) { $scope.dyndnsConfigure.refresh(); } diff --git a/src/views/settings.js b/src/views/settings.js index eb5a99b3d..173c52644 100644 --- a/src/views/settings.js +++ b/src/views/settings.js @@ -57,6 +57,7 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca checkStatus: function () { Client.getLatestTaskByType('update', function (error, task) { if (error) return console.error(error); + if (!task) return; $scope.update.taskId = task.id; $scope.update.updateStatus();