2016-08-17 05:25:42 +00:00
|
|
|
angular.module('createVolume', [])
|
2017-04-01 10:18:46 +00:00
|
|
|
.controller('CreateVolumeController', ['$scope', '$state', 'VolumeService', 'InfoService', 'ResourceControlService', 'Authentication', 'Messages',
|
|
|
|
function ($scope, $state, VolumeService, InfoService, ResourceControlService, Authentication, Messages) {
|
2016-08-17 05:25:42 +00:00
|
|
|
|
|
|
|
$scope.formValues = {
|
2017-03-12 16:24:15 +00:00
|
|
|
Ownership: $scope.applicationState.application.authentication ? 'private' : '',
|
2017-04-01 10:18:46 +00:00
|
|
|
Driver: 'local',
|
2016-08-17 05:25:42 +00:00
|
|
|
DriverOptions: []
|
|
|
|
};
|
2017-04-01 10:18:46 +00:00
|
|
|
$scope.availableVolumeDrivers = [];
|
2016-08-17 05:25:42 +00:00
|
|
|
|
|
|
|
$scope.addDriverOption = function() {
|
|
|
|
$scope.formValues.DriverOptions.push({ name: '', value: '' });
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removeDriverOption = function(index) {
|
|
|
|
$scope.formValues.DriverOptions.splice(index, 1);
|
|
|
|
};
|
|
|
|
|
2017-04-01 10:18:46 +00:00
|
|
|
$scope.create = function () {
|
2016-08-17 05:25:42 +00:00
|
|
|
$('#createVolumeSpinner').show();
|
2017-04-01 10:18:46 +00:00
|
|
|
|
|
|
|
var name = $scope.formValues.Name;
|
|
|
|
var driver = $scope.formValues.Driver;
|
|
|
|
var driverOptions = $scope.formValues.DriverOptions;
|
|
|
|
var volumeConfiguration = VolumeService.createVolumeConfiguration(name, driver, driverOptions);
|
|
|
|
|
|
|
|
VolumeService.createVolume(volumeConfiguration)
|
|
|
|
.then(function success(data) {
|
|
|
|
if ($scope.formValues.Ownership === 'private') {
|
|
|
|
ResourceControlService.setVolumeResourceControl(Authentication.getUserDetails().ID, data.Name)
|
|
|
|
.then(function success() {
|
|
|
|
Messages.send("Volume created", data.Name);
|
2017-03-12 16:24:15 +00:00
|
|
|
$state.go('volumes', {}, {reload: true});
|
2017-04-01 10:18:46 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Messages.error("Failure", err, 'Unable to apply resource control on volume');
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Messages.send("Volume created", data.Name);
|
|
|
|
$state.go('volumes', {}, {reload: true});
|
2016-08-17 05:25:42 +00:00
|
|
|
}
|
2017-04-01 10:18:46 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Messages.error('Failure', err, 'Unable to create volume');
|
|
|
|
})
|
|
|
|
.finally(function final() {
|
2016-08-17 05:25:42 +00:00
|
|
|
$('#createVolumeSpinner').hide();
|
|
|
|
});
|
2017-04-01 10:18:46 +00:00
|
|
|
};
|
2016-08-17 05:25:42 +00:00
|
|
|
|
2017-04-01 10:18:46 +00:00
|
|
|
function initView() {
|
|
|
|
$('#loadingViewSpinner').show();
|
|
|
|
InfoService.getVolumePlugins()
|
|
|
|
.then(function success(data) {
|
|
|
|
$scope.availableVolumeDrivers = data;
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Messages.error("Failure", err, 'Unable to retrieve volume plugin information');
|
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
$('#loadingViewSpinner').hide();
|
2016-08-17 05:25:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-04-01 10:18:46 +00:00
|
|
|
initView();
|
2016-08-17 05:25:42 +00:00
|
|
|
}]);
|