volumes: auto-refresh state when activating

This commit is contained in:
Girish Ramakrishnan
2021-05-14 10:46:31 -07:00
parent 0148a46244
commit a3ea2a32f1
+23 -5
View File
@@ -2,10 +2,13 @@
/* global angular */
/* global $ */
/* global async */
angular.module('Application').controller('VolumesController', ['$scope', '$location', '$timeout', 'Client', function ($scope, $location, $timeout, Client) {
Client.onReady(function () { if (!Client.getUserInfo().isAtLeastUserManager) $location.path('/'); });
var refreshVolumesTimerId = null;
$scope.config = Client.getConfig();
$scope.volumes = [];
$scope.ready = false;
@@ -19,20 +22,35 @@ angular.module('Application').controller('VolumesController', ['$scope', '$locat
];
function refreshVolumes(callback) {
let refreshAgain = false;
Client.getVolumes(function (error, results) {
if (error) return console.error(error);
$scope.volumes = results;
$scope.volumes.forEach(function (volume) {
async.eachSeries($scope.volumes, function (volume, iteratorDone) {
Client.getVolumeStatus(volume.id, function (error, result) {
if (error) return console.error('Failed to fetch volume status', volume.name, error);
if (error) {
console.error('Failed to fetch volume status', volume.name, error);
iteratorDone();
}
volume.status = result;
});
});
if (volume.status.state === 'activating') refreshAgain = true;
if (callback) callback();
iteratorDone();
});
}, function () {
if (!refreshAgain) {
clearTimeout(refreshVolumesTimerId);
refreshVolumesTimerId = null;
} else if (!refreshVolumesTimerId) {
refreshVolumesTimerId = setTimeout(refreshVolumes, 5000);
}
if (callback) callback();
});
});
}