2018-02-01 12:27:52 +00:00
|
|
|
angular.module('portainer.docker')
|
2018-10-28 09:27:06 +00: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 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) {
|
2018-05-06 07:15:57 +00:00
|
|
|
HttpRequestHelper.setPortainerAgentTargetHeader(volume.NodeName);
|
2017-12-06 11:04:02 +00: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 05:34:03 +00:00
|
|
|
});
|
|
|
|
};
|
2015-12-21 03:17:01 +00:00
|
|
|
|
2018-10-28 09:27:06 +00:00
|
|
|
$scope.offlineMode = false;
|
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
function initView() {
|
2018-01-25 07:13:56 +00:00
|
|
|
var endpointProvider = $scope.applicationState.endpoint.mode.provider;
|
|
|
|
var endpointRole = $scope.applicationState.endpoint.mode.role;
|
|
|
|
|
2017-07-09 16:49:36 +00:00
|
|
|
$q.all({
|
2017-12-06 11:04:02 +00:00
|
|
|
attached: VolumeService.volumes({ filters: { 'dangling': ['false'] } }),
|
2018-01-25 07:13:56 +00:00
|
|
|
dangling: VolumeService.volumes({ filters: { 'dangling': ['true'] } }),
|
|
|
|
services: endpointProvider === 'DOCKER_SWARM_MODE' && endpointRole === 'MANAGER' ? ServiceService.services() : []
|
2017-05-23 18:56:10 +00:00
|
|
|
})
|
2017-07-09 16:49:36 +00:00
|
|
|
.then(function success(data) {
|
2018-01-25 07:13:56 +00:00
|
|
|
var services = data.services;
|
2018-10-28 09:27:06 +00:00
|
|
|
$scope.offlineMode = EndpointProvider.offlineMode();
|
2017-07-09 16:49:36 +00: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 07:13:56 +00:00
|
|
|
if (VolumeHelper.isVolumeUsedByAService(volume, services)) {
|
|
|
|
volume.dangling = false;
|
|
|
|
}
|
2017-07-09 16:49:36 +00:00
|
|
|
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
|
|
|
}]);
|