2016-06-02 05:34:03 +00:00
|
|
|
angular.module('volumes', [])
|
2017-12-06 11:04:02 +00:00
|
|
|
.controller('VolumesController', ['$q', '$scope', '$state', 'VolumeService', 'Notifications',
|
|
|
|
function ($q, $scope, $state, VolumeService, Notifications) {
|
2017-03-12 16:24:15 +00:00
|
|
|
|
2017-12-06 11:04:02 +00:00
|
|
|
$scope.removeAction = function (selectedItems) {
|
|
|
|
var actionCount = selectedItems.length;
|
|
|
|
angular.forEach(selectedItems, function (volume) {
|
|
|
|
VolumeService.remove(volume)
|
|
|
|
.then(function success() {
|
|
|
|
Notifications.success('Volume successfully removed', volume.Id);
|
|
|
|
var index = $scope.volumes.indexOf(volume);
|
|
|
|
$scope.volumes.splice(index, 1);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to remove volume');
|
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
--actionCount;
|
|
|
|
if (actionCount === 0) {
|
|
|
|
$state.reload();
|
|
|
|
}
|
|
|
|
});
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
};
|
2015-12-21 03:17:01 +00:00
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
function initView() {
|
2017-07-09 16:49:36 +00:00
|
|
|
$q.all({
|
2017-12-06 11:04:02 +00:00
|
|
|
attached: VolumeService.volumes({ filters: { 'dangling': ['false'] } }),
|
|
|
|
dangling: VolumeService.volumes({ filters: { 'dangling': ['true'] } })
|
2017-05-23 18:56:10 +00:00
|
|
|
})
|
2017-07-09 16:49:36 +00:00
|
|
|
.then(function success(data) {
|
|
|
|
$scope.volumes = data.attached.map(function(volume) {
|
|
|
|
volume.dangling = false;
|
|
|
|
return volume;
|
|
|
|
}).concat(data.dangling.map(function(volume) {
|
|
|
|
volume.dangling = true;
|
|
|
|
return volume;
|
|
|
|
}));
|
|
|
|
}).catch(function error(err) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve volumes');
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
}
|
2018-01-21 16:26:24 +00:00
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
initView();
|
2016-06-02 05:34:03 +00:00
|
|
|
}]);
|