2018-02-01 13:27:52 +01:00
|
|
|
angular.module('portainer.docker')
|
2018-10-28 10:27:06 +01:00
|
|
|
.controller('VolumesController', ['$q', '$scope', '$state', 'VolumeService', 'ServiceService', 'VolumeHelper', 'Notifications', 'HttpRequestHelper', 'EndpointProvider',
|
|
|
|
function ($q, $scope, $state, VolumeService, ServiceService, VolumeHelper, Notifications, HttpRequestHelper, EndpointProvider) {
|
2017-03-12 17:24:15 +01:00
|
|
|
|
2017-12-06 12:04:02 +01:00
|
|
|
$scope.removeAction = function (selectedItems) {
|
|
|
|
var actionCount = selectedItems.length;
|
|
|
|
angular.forEach(selectedItems, function (volume) {
|
2018-05-06 09:15:57 +02:00
|
|
|
HttpRequestHelper.setPortainerAgentTargetHeader(volume.NodeName);
|
2017-12-06 12:04:02 +01:00
|
|
|
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 17:34:03 +12:00
|
|
|
});
|
|
|
|
};
|
2015-12-20 21:17:01 -06:00
|
|
|
|
2018-10-28 10:27:06 +01:00
|
|
|
$scope.offlineMode = false;
|
|
|
|
|
2017-05-23 20:56:10 +02:00
|
|
|
function initView() {
|
2018-01-25 08:13:56 +01:00
|
|
|
var endpointProvider = $scope.applicationState.endpoint.mode.provider;
|
|
|
|
var endpointRole = $scope.applicationState.endpoint.mode.role;
|
|
|
|
|
2017-07-09 19:49:36 +03:00
|
|
|
$q.all({
|
2017-12-06 12:04:02 +01:00
|
|
|
attached: VolumeService.volumes({ filters: { 'dangling': ['false'] } }),
|
2018-01-25 08:13:56 +01:00
|
|
|
dangling: VolumeService.volumes({ filters: { 'dangling': ['true'] } }),
|
|
|
|
services: endpointProvider === 'DOCKER_SWARM_MODE' && endpointRole === 'MANAGER' ? ServiceService.services() : []
|
2017-05-23 20:56:10 +02:00
|
|
|
})
|
2017-07-09 19:49:36 +03:00
|
|
|
.then(function success(data) {
|
2018-01-25 08:13:56 +01:00
|
|
|
var services = data.services;
|
2018-10-28 10:27:06 +01:00
|
|
|
$scope.offlineMode = EndpointProvider.offlineMode();
|
2017-07-09 19:49:36 +03:00
|
|
|
$scope.volumes = data.attached.map(function(volume) {
|
|
|
|
volume.dangling = false;
|
|
|
|
return volume;
|
|
|
|
}).concat(data.dangling.map(function(volume) {
|
|
|
|
volume.dangling = true;
|
2018-01-25 08:13:56 +01:00
|
|
|
if (VolumeHelper.isVolumeUsedByAService(volume, services)) {
|
|
|
|
volume.dangling = false;
|
|
|
|
}
|
2017-07-09 19:49:36 +03:00
|
|
|
return volume;
|
|
|
|
}));
|
|
|
|
}).catch(function error(err) {
|
2017-05-23 20:56:10 +02:00
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve volumes');
|
2016-06-02 17:34:03 +12:00
|
|
|
});
|
|
|
|
}
|
2018-01-21 17:26:24 +01:00
|
|
|
|
2017-05-23 20:56:10 +02:00
|
|
|
initView();
|
2016-06-02 17:34:03 +12:00
|
|
|
}]);
|