2016-08-17 05:25:42 +00:00
|
|
|
angular.module('createVolume', [])
|
2017-07-25 14:21:32 +00:00
|
|
|
.controller('CreateVolumeController', ['$q', '$scope', '$state', 'VolumeService', 'PluginService', 'ResourceControlService', 'Authentication', 'Notifications', 'FormValidator',
|
|
|
|
function ($q, $scope, $state, VolumeService, PluginService, ResourceControlService, Authentication, Notifications, FormValidator) {
|
2016-08-17 05:25:42 +00:00
|
|
|
|
|
|
|
$scope.formValues = {
|
2017-04-01 10:18:46 +00:00
|
|
|
Driver: 'local',
|
2017-07-12 07:51:51 +00:00
|
|
|
DriverOptions: [],
|
|
|
|
AccessControlData: new AccessControlFormData()
|
2016-08-17 05:25:42 +00:00
|
|
|
};
|
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-07-12 07:51:51 +00:00
|
|
|
var accessControlData = $scope.formValues.AccessControlData;
|
2017-05-23 18:56:10 +00:00
|
|
|
var userDetails = Authentication.getUserDetails();
|
|
|
|
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-07-25 14:21:32 +00:00
|
|
|
var endpointProvider = $scope.applicationState.endpoint.mode.provider;
|
|
|
|
var apiVersion = $scope.applicationState.endpoint.apiVersion;
|
|
|
|
if (endpointProvider !== 'DOCKER_SWARM') {
|
2017-08-13 11:31:50 +00:00
|
|
|
PluginService.volumePlugins(apiVersion < 1.25 || endpointProvider === 'VMWARE_VIC')
|
2017-07-12 14:11:11 +00:00
|
|
|
.then(function success(data) {
|
|
|
|
$scope.availableVolumeDrivers = data;
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve volume drivers');
|
|
|
|
})
|
|
|
|
.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
|
|
|
}]);
|