From 9decbf54d59d03885d6ee9eeabc2ce4af83ceedb Mon Sep 17 00:00:00 2001 From: baron_l Date: Thu, 14 Feb 2019 15:53:11 +0100 Subject: [PATCH] feat(storidge): add new fields on profile create/edit --- app/extensions/storidge/models/profile.js | 68 +++++++++ .../create/createProfileController.js | 24 ++++ .../views/profiles/create/createprofile.html | 134 ++++++++++++++++++ .../storidge/views/profiles/edit/profile.html | 134 ++++++++++++++++++ .../views/profiles/edit/profileController.js | 31 ++++ .../components/slider/sliderController.js | 2 +- 6 files changed, 392 insertions(+), 1 deletion(-) diff --git a/app/extensions/storidge/models/profile.js b/app/extensions/storidge/models/profile.js index 6effb98cf..9b433825e 100644 --- a/app/extensions/storidge/models/profile.js +++ b/app/extensions/storidge/models/profile.js @@ -8,6 +8,16 @@ function StoridgeProfileDefaultModel() { this.MaxIOPS = 2000; this.MinBandwidth = 1; this.MaxBandwidth = 100; + this.Filesystem = 'btrfs'; + this.SnapshotEnabled = false; + this.SnapshotInterval = 60; + this.SnapshotMax = 1; + this.EncryptionEnabled = false; + this.InterfaceType = 'nfs'; + this.InterfaceDriver = ''; + this.InterfaceNetwork = ''; + this.InterfaceConf = ''; + this.Labels = []; } function StoridgeProfileListModel(data) { @@ -32,6 +42,37 @@ function StoridgeProfileModel(name, data) { this.MinBandwidth = data.bandwidth.min; this.MaxBandwidth = data.bandwidth.max; } + + this.Filesystem = data.filesystem; + + var service = data.service; + + if (service.snapshot) { + this.SnapshotEnabled = service.snapshot.enabled; + this.SnapshotInterval = service.snapshot.interval; + this.SnapshotMax = service.snapshot.max; + } else { + this.SnapshotEnabled = false; + } + + if (service.encryption) { + this.EncryptionEnabled = service.encryption.enabled; + } else { + this.EncryptionEnabled = false; + } + + if (data.interface) { + this.InterfaceType = data.interface.type; + this.InterfaceDriver = data.interface.driver; + this.InterfaceNetwork = data.interface.network; + this.InterfaceConf = data.interface.conf; + } + + if (data.label) { + this.Labels = data.label; + } else { + this.Labels = []; + } } function StoridgeCreateProfileRequest(model) { @@ -54,4 +95,31 @@ function StoridgeCreateProfileRequest(model) { max: model.MaxBandwidth }; } + + this.filesystem = model.Filesystem; + + var service = {}; + + service.snapshot = { + enabled: model.SnapshotEnabled + }; + if (model.SnapshotEnabled) { + service.snapshot.interval = model.SnapshotInterval; + service.snapshot.max = model.SnapshotMax; + } + + service.encryption = { + enabled: model.EncryptionEnabled + }; + + this.service = service; + + this.interface = { + type: model.InterfaceType, + driver: model.InterfaceDriver, + network: model.InterfaceNetwork, + conf: model.InterfaceConf + }; + + this.label = model.Labels; } diff --git a/app/extensions/storidge/views/profiles/create/createProfileController.js b/app/extensions/storidge/views/profiles/create/createProfileController.js index 0246d1716..da767dca3 100644 --- a/app/extensions/storidge/views/profiles/create/createProfileController.js +++ b/app/extensions/storidge/views/profiles/create/createProfileController.js @@ -2,6 +2,10 @@ angular.module('extension.storidge') .controller('StoridgeCreateProfileController', ['$scope', '$state', '$transition$', 'Notifications', 'StoridgeProfileService', function ($scope, $state, $transition$, Notifications, StoridgeProfileService) { + $scope.formValues = { + Labels: [] + }; + $scope.state = { NoLimit: true, LimitIOPS: false, @@ -15,6 +19,24 @@ function ($scope, $state, $transition$, Notifications, StoridgeProfileService) { { value: 3, label: '3-copy' } ]; + $scope.addLabel = function() { + $scope.formValues.Labels.push({ name: '', value: ''}); + }; + + $scope.removeLabel = function(index) { + $scope.formValues.Labels.splice(index, 1); + }; + + function prepareLabels(profile) { + var labels = {}; + $scope.formValues.Labels.forEach(function (label) { + if (label.name && label.value) { + labels[label.name] = label.value; + } + }); + profile.Labels = labels; + } + $scope.create = function () { var profile = $scope.model; @@ -28,6 +50,8 @@ function ($scope, $state, $transition$, Notifications, StoridgeProfileService) { delete profile.MaxBandwidth; } + prepareLabels(profile); + $scope.state.actionInProgress = true; StoridgeProfileService.create(profile) .then(function success() { diff --git a/app/extensions/storidge/views/profiles/create/createprofile.html b/app/extensions/storidge/views/profiles/create/createprofile.html index 7680d515e..038438ad2 100644 --- a/app/extensions/storidge/views/profiles/create/createprofile.html +++ b/app/extensions/storidge/views/profiles/create/createprofile.html @@ -91,6 +91,140 @@ + +
+ +
+ +
+
+ + +
+
+ + +
+
+ + +
+ +
+ +
+
+ +
+
+

+ Snapshot interval (s) +

+
+
+ + +
+ +
+ +
+
+ +
+
+

+ Snapshot max (count) +

+
+
+ + +
+
+ + +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+
+ + + add label + +
+ +
+
+
+ name + +
+
+ value + +
+ +
+
+ +
+
diff --git a/app/extensions/storidge/views/profiles/edit/profile.html b/app/extensions/storidge/views/profiles/edit/profile.html index 12994ad5f..fb2692db5 100644 --- a/app/extensions/storidge/views/profiles/edit/profile.html +++ b/app/extensions/storidge/views/profiles/edit/profile.html @@ -84,6 +84,140 @@
+ +
+ +
+ +
+
+ + +
+
+ + +
+
+ + +
+ +
+ +
+
+ +
+
+

+ Snapshot interval (s) +

+
+
+ + +
+ +
+ +
+
+ +
+
+

+ Snapshot max (count) +

+
+
+ + +
+
+ + +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+
+ + + add label + +
+ +
+
+
+ name + +
+
+ value + +
+ +
+
+ +
+
diff --git a/app/extensions/storidge/views/profiles/edit/profileController.js b/app/extensions/storidge/views/profiles/edit/profileController.js index ff6aecfc0..c6a4c192a 100644 --- a/app/extensions/storidge/views/profiles/edit/profileController.js +++ b/app/extensions/storidge/views/profiles/edit/profileController.js @@ -2,6 +2,10 @@ angular.module('extension.storidge') .controller('StoridgeProfileController', ['$scope', '$state', '$transition$', 'Notifications', 'StoridgeProfileService', 'ModalService', function ($scope, $state, $transition$, Notifications, StoridgeProfileService, ModalService) { + $scope.formValues = { + Labels: [] + }; + $scope.state = { NoLimit: false, LimitIOPS: false, @@ -10,6 +14,30 @@ function ($scope, $state, $transition$, Notifications, StoridgeProfileService, M deleteInProgress: false }; + $scope.addLabel = function() { + $scope.formValues.Labels.push({ name: '', value: ''}); + }; + + $scope.removeLabel = function(index) { + $scope.formValues.Labels.splice(index, 1); + }; + + function prepareLabels(profile) { + var labels = {}; + $scope.formValues.Labels.forEach(function (label) { + if (label.name && label.value) { + labels[label.name] = label.value; + } + }); + profile.Labels = labels; + } + + function initLabels(labels) { + $scope.formValues.Labels = Object.keys(labels).map(function(key) { + return { name:key, value:labels[key] }; + }); + } + $scope.RedundancyOptions = [ { value: 2, label: '2-copy' }, { value: 3, label: '3-copy' } @@ -29,6 +57,8 @@ function ($scope, $state, $transition$, Notifications, StoridgeProfileService, M delete profile.MaxBandwidth; } + prepareLabels(profile); + $scope.state.updateInProgress = true; StoridgeProfileService.update(profile) .then(function success() { @@ -81,6 +111,7 @@ function ($scope, $state, $transition$, Notifications, StoridgeProfileService, M } else { $scope.state.NoLimit = true; } + initLabels(profile.Labels); $scope.profile = profile; }) .catch(function error(err) { diff --git a/app/portainer/components/slider/sliderController.js b/app/portainer/components/slider/sliderController.js index 21175579d..8755097cb 100644 --- a/app/portainer/components/slider/sliderController.js +++ b/app/portainer/components/slider/sliderController.js @@ -10,7 +10,7 @@ angular.module('portainer.app') showSelectionBar: true, enforceStep: false, translate: function(value, sliderId, label) { - if (label === 'floor' || value === 0) { + if ((label === 'floor' && ctrl.floor === 0) || value === 0) { return 'unlimited'; } return value;