2016-08-17 05:25:42 +00:00
|
|
|
angular.module('createVolume', [])
|
2017-06-20 11:00:32 +00:00
|
|
|
.controller('CreateVolumeController', ['$scope', '$state', 'VolumeService', 'SystemService', 'ResourceControlService', 'Authentication', 'Notifications', 'ControllerDataPipeline', 'FormValidator',
|
|
|
|
function ($scope, $state, VolumeService, SystemService, ResourceControlService, Authentication, Notifications, ControllerDataPipeline, FormValidator) {
|
2016-08-17 05:25:42 +00:00
|
|
|
|
|
|
|
$scope.formValues = {
|
2017-04-01 10:18:46 +00:00
|
|
|
Driver: 'local',
|
2016-08-17 05:25:42 +00:00
|
|
|
DriverOptions: []
|
|
|
|
};
|
2017-05-23 18:56:10 +00:00
|
|
|
|
|
|
|
$scope.state = {
|
|
|
|
formValidationError: ''
|
|
|
|
};
|
|
|
|
|
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-05-23 18:56:10 +00:00
|
|
|
function validateForm(accessControlData, isAdmin) {
|
|
|
|
$scope.state.formValidationError = '';
|
|
|
|
var error = '';
|
|
|
|
error = FormValidator.validateAccessControl(accessControlData, isAdmin);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
$scope.state.formValidationError = error;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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);
|
2017-05-23 18:56:10 +00:00
|
|
|
var userDetails = Authentication.getUserDetails();
|
|
|
|
var accessControlData = ControllerDataPipeline.getAccessControlFormData();
|
|
|
|
var isAdmin = userDetails.role === 1 ? true : false;
|
|
|
|
|
|
|
|
if (!validateForm(accessControlData, isAdmin)) {
|
|
|
|
$('#createVolumeSpinner').hide();
|
|
|
|
return;
|
|
|
|
}
|
2017-04-01 10:18:46 +00:00
|
|
|
|
|
|
|
VolumeService.createVolume(volumeConfiguration)
|
|
|
|
.then(function success(data) {
|
2017-05-23 18:56:10 +00:00
|
|
|
var volumeIdentifier = data.Id;
|
|
|
|
var userId = userDetails.ID;
|
|
|
|
return ResourceControlService.applyResourceControl('volume', volumeIdentifier, userId, accessControlData, []);
|
|
|
|
})
|
|
|
|
.then(function success(data) {
|
|
|
|
Notifications.success('Volume successfully created');
|
|
|
|
$state.go('volumes', {}, {reload: true});
|
2017-04-01 10:18:46 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'An error occured during volume creation');
|
2017-04-01 10:18:46 +00:00
|
|
|
})
|
|
|
|
.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();
|
2017-06-20 11:00:32 +00:00
|
|
|
SystemService.getVolumePlugins()
|
2017-04-01 10:18:46 +00:00
|
|
|
.then(function success(data) {
|
|
|
|
$scope.availableVolumeDrivers = data;
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve volume drivers');
|
2017-04-01 10:18:46 +00:00
|
|
|
})
|
|
|
|
.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
|
|
|
}]);
|