From 446322dcbe4de05fbc8821144418a316f58d216c Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Wed, 6 Jul 2016 15:14:40 +1200 Subject: [PATCH] feat(ui): new volume creation view (#36) --- app/app.js | 5 ++ .../createContainerController.js | 1 - app/components/createVolume/createVolume.html | 40 ----------- .../createVolume/createVolumeController.js | 65 ++++++++++------- app/components/createVolume/createvolume.html | 69 +++++++++++++++++++ app/components/volumes/volumes.html | 6 +- 6 files changed, 117 insertions(+), 69 deletions(-) delete mode 100644 app/components/createVolume/createVolume.html create mode 100644 app/components/createVolume/createvolume.html diff --git a/app/app.js b/app/app.js index 6c882a01e..c21c25c79 100644 --- a/app/app.js +++ b/app/app.js @@ -72,6 +72,11 @@ angular.module('uifordocker', [ templateUrl: 'app/components/createContainer/createcontainer.html', controller: 'CreateContainerController' }) + .state('actions.create.volume', { + url: "/volume", + templateUrl: 'app/components/createVolume/createvolume.html', + controller: 'CreateVolumeController' + }) .state('docker', { url: '/docker/', templateUrl: 'app/components/docker/docker.html', diff --git a/app/components/createContainer/createContainerController.js b/app/components/createContainer/createContainerController.js index 99b0e23df..ba4d929db 100644 --- a/app/components/createContainer/createContainerController.js +++ b/app/components/createContainer/createContainerController.js @@ -201,7 +201,6 @@ function ($scope, $state, Config, Container, Image, Volume, Network, Messages, V $scope.create = function () { var config = prepareConfiguration(); - console.log(JSON.stringify(config, null, 4)); if ($scope.state.alwaysPull) { pullImageAndCreateContainer(config); diff --git a/app/components/createVolume/createVolume.html b/app/components/createVolume/createVolume.html deleted file mode 100644 index 7e6a5987c..000000000 --- a/app/components/createVolume/createVolume.html +++ /dev/null @@ -1,40 +0,0 @@ - diff --git a/app/components/createVolume/createVolumeController.js b/app/components/createVolume/createVolumeController.js index 9193b9f71..d33d4c7e1 100644 --- a/app/components/createVolume/createVolumeController.js +++ b/app/components/createVolume/createVolumeController.js @@ -1,39 +1,56 @@ angular.module('createVolume', []) -.controller('CreateVolumeController', ['$scope', '$state', 'Messages', 'Volume', 'ViewSpinner', 'errorMsgFilter', -function ($scope, $state, Messages, Volume, ViewSpinner, errorMsgFilter) { - $scope.template = 'app/components/createVolume/createVolume.html'; +.controller('CreateVolumeController', ['$scope', '$state', 'Volume', 'Messages', 'ViewSpinner', 'errorMsgFilter', +function ($scope, $state, Volume, Messages, ViewSpinner, errorMsgFilter) { - $scope.init = function () { - $scope.createVolumeConfig = { - "Name": "", - "Driver": "", - "DriverOpts": {} - }; - $scope.availableDrivers = ['local', 'local-persist']; - $scope.selectedDriver = { value: $scope.availableDrivers[0] }; + $scope.formValues = { + DriverOptions: [] }; - $scope.init(); + $scope.config = { + Driver: 'local' + }; - $scope.addVolume = function addVolume(createVolumeConfig) { - $('#error-message').hide(); + $scope.addDriverOption = function() { + $scope.formValues.DriverOptions.push({ name: '', value: '' }); + }; + + $scope.removeDriverOption = function(index) { + $scope.formValues.DriverOptions.splice(index, 1); + }; + + function createVolume(config) { ViewSpinner.spin(); - $('#create-volume-modal').modal('hide'); - createVolumeConfig.Driver = $scope.selectedDriver.value; - console.log(JSON.stringify(createVolumeConfig, null, 4)); - Volume.create(createVolumeConfig, function (d) { + Volume.create(config, function (d) { if (d.Name) { Messages.send("Volume created", d.Name); + ViewSpinner.stop(); + $state.go('volumes', {}, {reload: true}); } else { - Messages.error('Failure', errorMsgFilter(d)); + ViewSpinner.stop(); + Messages.error('Unable to create volume', errorMsgFilter(d)); } - ViewSpinner.stop(); - $state.go('volumes', {}, {reload: true}); }, function (e) { ViewSpinner.stop(); - $scope.error = "Cannot create volume " + createVolumeConfig.Name + " Reason: " + e.data; - $('#create-volume-modal').modal('show'); - $('#error-message').show(); + Messages.error('Unable to create volume', e.data); }); + } + + function prepareDriverOptions(config) { + var options = {}; + $scope.formValues.DriverOptions.forEach(function (option) { + options[option.name] = option.value; + }); + config.DriverOpts = options; + } + + function prepareConfiguration() { + var config = angular.copy($scope.config); + prepareDriverOptions(config); + return config; + } + + $scope.create = function () { + var config = prepareConfiguration(); + createVolume(config); }; }]); diff --git a/app/components/createVolume/createvolume.html b/app/components/createVolume/createvolume.html new file mode 100644 index 000000000..d6fb53e5a --- /dev/null +++ b/app/components/createVolume/createvolume.html @@ -0,0 +1,69 @@ + + + + Volumes > Add volume + + + +
+
+ + +
+ +
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ + driver option + +
+ +
+
+
+ name + +
+
+ value + + + + +
+
+
+ +
+ +
+
+
+
+
+ +
+
+ + Cancel +
+
diff --git a/app/components/volumes/volumes.html b/app/components/volumes/volumes.html index 0c8e51104..5919b014b 100644 --- a/app/components/volumes/volumes.html +++ b/app/components/volumes/volumes.html @@ -15,10 +15,8 @@
-
- - -
+ + Add volume