2024-05-16 02:34:50 +00:00
|
|
|
import { processItemsInBatches } from '@/react/common/processItemsInBatches';
|
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
angular.module('portainer.docker').controller('VolumesController', [
|
|
|
|
'$q',
|
|
|
|
'$scope',
|
|
|
|
'$state',
|
|
|
|
'VolumeService',
|
|
|
|
'ServiceService',
|
|
|
|
'VolumeHelper',
|
|
|
|
'Notifications',
|
|
|
|
'Authentication',
|
2021-02-09 08:09:06 +00:00
|
|
|
'endpoint',
|
2024-06-10 18:54:31 +00:00
|
|
|
function ($q, $scope, $state, VolumeService, ServiceService, VolumeHelper, Notifications, Authentication, endpoint) {
|
2024-05-16 02:34:50 +00:00
|
|
|
$scope.removeAction = async function (selectedItems) {
|
|
|
|
async function doRemove(volume) {
|
2024-07-31 00:12:26 +00:00
|
|
|
return VolumeService.remove(volume.Name, volume.NodeName)
|
2024-04-08 14:21:41 +00:00
|
|
|
.then(function success() {
|
2024-07-31 00:12:26 +00:00
|
|
|
Notifications.success('Volume successfully removed', volume.Name);
|
2024-04-08 14:21:41 +00:00
|
|
|
var index = $scope.volumes.indexOf(volume);
|
|
|
|
$scope.volumes.splice(index, 1);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to remove volume');
|
2020-04-10 21:54:53 +00:00
|
|
|
});
|
2024-05-16 02:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await processItemsInBatches(selectedItems, doRemove);
|
|
|
|
$state.reload();
|
2020-04-10 21:54:53 +00:00
|
|
|
};
|
2015-12-21 03:17:01 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
$scope.getVolumes = getVolumes;
|
|
|
|
function getVolumes() {
|
|
|
|
var endpointProvider = $scope.applicationState.endpoint.mode.provider;
|
|
|
|
var endpointRole = $scope.applicationState.endpoint.mode.role;
|
2018-01-25 07:13:56 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
$q.all({
|
2024-06-10 18:54:31 +00:00
|
|
|
attached: VolumeService.volumes({ dangling: ['false'] }),
|
|
|
|
dangling: VolumeService.volumes({ dangling: ['true'] }),
|
2020-04-10 21:54:53 +00:00
|
|
|
services: endpointProvider === 'DOCKER_SWARM_MODE' && endpointRole === 'MANAGER' ? ServiceService.services() : [],
|
|
|
|
})
|
|
|
|
.then(function success(data) {
|
|
|
|
var services = data.services;
|
|
|
|
$scope.volumes = data.attached
|
|
|
|
.map(function (volume) {
|
|
|
|
volume.dangling = false;
|
|
|
|
return volume;
|
|
|
|
})
|
|
|
|
.concat(
|
|
|
|
data.dangling.map(function (volume) {
|
|
|
|
volume.dangling = true;
|
|
|
|
if (VolumeHelper.isVolumeUsedByAService(volume, services)) {
|
|
|
|
volume.dangling = false;
|
|
|
|
}
|
|
|
|
return volume;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve volumes');
|
|
|
|
});
|
|
|
|
}
|
2018-01-21 16:26:24 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
function initView() {
|
|
|
|
getVolumes();
|
2019-10-08 00:17:58 +00:00
|
|
|
|
2021-02-09 08:09:06 +00:00
|
|
|
$scope.showBrowseAction = $scope.applicationState.endpoint.mode.agentProxy && (Authentication.isAdmin() || endpoint.SecuritySettings.allowVolumeBrowserForRegularUsers);
|
2020-04-10 21:54:53 +00:00
|
|
|
}
|
2019-07-22 10:54:59 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
initView();
|
|
|
|
},
|
|
|
|
]);
|