2018-02-01 12:27:52 +00:00
|
|
|
angular.module('portainer.docker')
|
2019-05-24 21:53:10 +00:00
|
|
|
.controller('VolumeController', ['$scope', '$state', '$transition$', '$q', 'ModalService', 'VolumeService', 'ContainerService', 'Notifications', 'HttpRequestHelper', 'StoridgeVolumeService', 'StoridgeSnapshotService',
|
|
|
|
function ($scope, $state, $transition$, $q, ModalService, VolumeService, ContainerService, Notifications, HttpRequestHelper, StoridgeVolumeService, StoridgeSnapshotService) {
|
|
|
|
|
|
|
|
$scope.storidgeSnapshots = [];
|
|
|
|
$scope.storidgeVolume = {};
|
|
|
|
|
|
|
|
$scope.removeSnapshot = function (selectedItems) {
|
|
|
|
ModalService.confirm({
|
|
|
|
title: 'Are you sure?',
|
|
|
|
message: 'Do you want really want to remove this snapshot?',
|
|
|
|
buttons: {
|
|
|
|
confirm: {
|
|
|
|
label: 'Remove',
|
|
|
|
className: 'btn-danger'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
callback: function onConfirm(confirmed) {
|
|
|
|
if(!confirmed) { return; }
|
|
|
|
var actionCount = selectedItems.length;
|
|
|
|
angular.forEach(selectedItems, function (item) {
|
|
|
|
StoridgeSnapshotService.remove(item.Id)
|
|
|
|
.then(function success() {
|
|
|
|
Notifications.success('Snapshot successfully removed', item.Id);
|
|
|
|
var index = $scope.storidgeSnapshots.indexOf(item);
|
|
|
|
$scope.storidgeSnapshots.splice(index, 1);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to remove snapshot');
|
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
--actionCount;
|
|
|
|
if (actionCount === 0) {
|
|
|
|
$state.reload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2017-05-23 18:56:10 +00:00
|
|
|
|
|
|
|
$scope.removeVolume = function removeVolume() {
|
|
|
|
VolumeService.remove($scope.volume)
|
2018-08-22 15:33:06 +00:00
|
|
|
.then(function success() {
|
2017-09-21 14:00:53 +00:00
|
|
|
Notifications.success('Volume successfully removed', $transition$.params().id);
|
2018-02-01 12:27:52 +00:00
|
|
|
$state.go('docker.volumes', {});
|
2017-05-23 18:56:10 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to remove volume');
|
|
|
|
});
|
|
|
|
};
|
2017-10-17 08:12:16 +00:00
|
|
|
|
2017-10-17 06:45:19 +00:00
|
|
|
function getVolumeDataFromContainer(container, volumeId) {
|
|
|
|
return container.Mounts.find(function(volume) {
|
|
|
|
return volume.Name === volumeId;
|
|
|
|
});
|
|
|
|
}
|
2017-05-23 18:56:10 +00:00
|
|
|
|
|
|
|
function initView() {
|
2018-05-06 07:15:57 +00:00
|
|
|
HttpRequestHelper.setPortainerAgentTargetHeader($transition$.params().nodeName);
|
2019-05-24 21:53:10 +00:00
|
|
|
|
2017-09-21 14:00:53 +00:00
|
|
|
VolumeService.volume($transition$.params().id)
|
2017-05-23 18:56:10 +00:00
|
|
|
.then(function success(data) {
|
|
|
|
var volume = data;
|
|
|
|
$scope.volume = volume;
|
2017-10-17 08:12:16 +00:00
|
|
|
var containerFilter = { volume: [volume.Id] };
|
2019-05-24 21:53:10 +00:00
|
|
|
|
|
|
|
$scope.isCioDriver = volume.Driver.includes('cio');
|
|
|
|
if ($scope.isCioDriver) {
|
|
|
|
return $q.all({
|
|
|
|
containers: ContainerService.containers(1, containerFilter),
|
|
|
|
storidgeVolume: StoridgeVolumeService.volume($transition$.params().id)
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return ContainerService.containers(1, containerFilter);
|
|
|
|
}
|
2017-10-17 06:45:19 +00:00
|
|
|
})
|
|
|
|
.then(function success(data) {
|
2019-05-24 21:53:10 +00:00
|
|
|
var dataContainers = $scope.isCioDriver ? data.containers : data;
|
|
|
|
|
|
|
|
var containers = dataContainers.map(function(container) {
|
2017-10-17 06:45:19 +00:00
|
|
|
container.volumeData = getVolumeDataFromContainer(container, $scope.volume.Id);
|
|
|
|
return container;
|
|
|
|
});
|
|
|
|
$scope.containersUsingVolume = containers;
|
2019-05-24 21:53:10 +00:00
|
|
|
|
|
|
|
if ($scope.isCioDriver) {
|
|
|
|
$scope.storidgeVolume = data.storidgeVolume;
|
|
|
|
if ($scope.storidgeVolume.SnapshotEnabled) {
|
|
|
|
return StoridgeSnapshotService.snapshots(data.storidgeVolume.Vdisk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(function success(data) {
|
|
|
|
$scope.storidgeSnapshots = data;
|
2017-05-23 18:56:10 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve volume details');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
initView();
|
|
|
|
}]);
|