diff --git a/src/js/client.js b/src/js/client.js index 356ddbbb0..66c29ce03 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -1317,21 +1317,6 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout }); }; - Client.prototype.waitForTask = function (taskId, callback) { - var that = this; - - function checkTask() { - that.getTask(taskId, function (error, result) { - if (error) return callback(error); - if (result.pending || result.active) return setTimeout(checkTask, 1000); - - callback(result.error, result.result); - }); - } - - checkTask(); - }; - Client.prototype.getTask = function (taskId, callback) { get('/api/v1/tasks/' + taskId, null, function (error, data, status) { if (error) return callback(error); @@ -1982,7 +1967,7 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout if (error) return callback(error); if (status !== 201) return callback(new ClientError(status, data)); - that.waitForTask(data.taskId, callback); + callback(null, data.taskId); }); }; diff --git a/src/views/system.js b/src/views/system.js index 0139fd29d..8a24237ea 100644 --- a/src/views/system.js +++ b/src/views/system.js @@ -59,6 +59,7 @@ angular.module('Application').controller('SystemController', ['$scope', '$locati busy: true, busyRefresh: false, ts: 0, + taskId: '', disks: [], show: function () { @@ -121,15 +122,44 @@ angular.module('Application').controller('SystemController', ['$scope', '$locati }); }, + checkStatus: function () { + Client.getLatestTaskByType('updateDiskUsage', function (error, task) { + if (error) return console.error(error); + + if (!task) return; + + $scope.disks.taskId = task.id; + $scope.disks.busyRefresh = true; + $scope.disks.updateStatus(); + }); + }, + + updateStatus: function () { + Client.getTask($scope.disks.taskId, function (error, data) { + if (error) return $timeout($scope.disks.updateStatus, 3000); + + if (!data.active) { + $scope.disks.busyRefresh = false; + $scope.disks.taskId = ''; + $scope.disks.show(); + return; + } + + $timeout($scope.disks.updateStatus, 3000); + }); + }, + refresh: function () { $scope.disks.busyRefresh = true; - Client.refreshDiskUsage(function (error) { - $scope.disks.busyRefresh = false; + Client.refreshDiskUsage(function (error, taskId) { + if (error) { + $scope.disks.busyRefresh = false; + return console.error('Failed to refresh disk usage.', error); + } - if (error) return console.error('Failed to refresh disk usage.', error); - - $scope.disks.show(); + $scope.disks.taskId = taskId; + $timeout($scope.disks.updateStatus, 3000); }); } }; @@ -299,7 +329,9 @@ angular.module('Application').controller('SystemController', ['$scope', '$locati volumes.forEach(function (v) { $scope.volumesById[v.id] = v; }); $scope.graphs.refresh(); + $scope.disks.show(); + $scope.disks.checkStatus(); }); }); });