2022-09-07 04:25:00 +00:00
|
|
|
import { ResourceControlType } from '@/react/portainer/access-control/types';
|
2023-02-14 08:19:41 +00:00
|
|
|
import { confirmDelete } from '@@/modals/confirm';
|
2022-03-16 06:35:32 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
angular.module('portainer.docker').controller('VolumeController', [
|
|
|
|
'$scope',
|
|
|
|
'$state',
|
|
|
|
'$transition$',
|
|
|
|
'VolumeService',
|
|
|
|
'ContainerService',
|
|
|
|
'Notifications',
|
|
|
|
'HttpRequestHelper',
|
2023-02-14 08:19:41 +00:00
|
|
|
function ($scope, $state, $transition$, VolumeService, ContainerService, Notifications, HttpRequestHelper) {
|
2022-03-16 06:35:32 +00:00
|
|
|
$scope.resourceType = ResourceControlType.Volume;
|
|
|
|
|
|
|
|
$scope.onUpdateResourceControlSuccess = function () {
|
|
|
|
$state.reload();
|
|
|
|
};
|
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
$scope.removeVolume = function removeVolume() {
|
2023-02-14 08:19:41 +00:00
|
|
|
confirmDelete('Do you want to remove this volume?').then((confirmed) => {
|
2020-12-16 06:57:31 +00:00
|
|
|
if (confirmed) {
|
|
|
|
VolumeService.remove($scope.volume)
|
|
|
|
.then(function success() {
|
|
|
|
Notifications.success('Volume successfully removed', $transition$.params().id);
|
|
|
|
$state.go('docker.volumes', {});
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to remove volume');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2020-04-10 21:54:53 +00:00
|
|
|
};
|
2017-05-23 18:56:10 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
function getVolumeDataFromContainer(container, volumeId) {
|
|
|
|
return container.Mounts.find(function (volume) {
|
|
|
|
return volume.Name === volumeId;
|
|
|
|
});
|
|
|
|
}
|
2017-10-17 08:12:16 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
function initView() {
|
|
|
|
HttpRequestHelper.setPortainerAgentTargetHeader($transition$.params().nodeName);
|
2017-05-23 18:56:10 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
VolumeService.volume($transition$.params().id)
|
|
|
|
.then(function success(data) {
|
|
|
|
var volume = data;
|
|
|
|
$scope.volume = volume;
|
|
|
|
var containerFilter = { volume: [volume.Id] };
|
2019-05-24 21:53:10 +00:00
|
|
|
|
2022-02-08 16:47:11 +00:00
|
|
|
return ContainerService.containers(1, containerFilter);
|
2020-04-10 21:54:53 +00:00
|
|
|
})
|
|
|
|
.then(function success(data) {
|
|
|
|
var dataContainers = $scope.isCioDriver ? data.containers : data;
|
2019-05-24 21:53:10 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
var containers = dataContainers.map(function (container) {
|
|
|
|
container.volumeData = getVolumeDataFromContainer(container, $scope.volume.Id);
|
|
|
|
return container;
|
|
|
|
});
|
|
|
|
$scope.containersUsingVolume = containers;
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve volume details');
|
|
|
|
});
|
|
|
|
}
|
2017-05-23 18:56:10 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
initView();
|
|
|
|
},
|
|
|
|
]);
|