portainer/app/docker/views/volumes/edit/volumeController.js

45 lines
1.6 KiB
JavaScript
Raw Normal View History

angular.module('portainer.docker')
2018-05-06 07:15:57 +00:00
.controller('VolumeController', ['$scope', '$state', '$transition$', 'VolumeService', 'ContainerService', 'Notifications', 'HttpRequestHelper',
function ($scope, $state, $transition$, VolumeService, ContainerService, Notifications, HttpRequestHelper) {
$scope.removeVolume = function removeVolume() {
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');
});
};
function getVolumeDataFromContainer(container, volumeId) {
return container.Mounts.find(function(volume) {
return volume.Name === volumeId;
});
}
function initView() {
2018-05-06 07:15:57 +00:00
HttpRequestHelper.setPortainerAgentTargetHeader($transition$.params().nodeName);
VolumeService.volume($transition$.params().id)
.then(function success(data) {
var volume = data;
$scope.volume = volume;
var containerFilter = { volume: [volume.Id] };
return ContainerService.containers(1, containerFilter);
})
.then(function success(data) {
var containers = data.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');
});
}
initView();
}]);