diff --git a/extensions/mistral/static/mistral/css/mistral.scss b/extensions/mistral/static/mistral/css/mistral.scss index f43df17..8e13b30 100644 --- a/extensions/mistral/static/mistral/css/mistral.scss +++ b/extensions/mistral/static/mistral/css/mistral.scss @@ -91,7 +91,7 @@ } } -.fa-minus-circle.input-group-addon { +.fa-minus-circle { color: red; } @@ -119,6 +119,9 @@ .list .add-btn { margin-top: 2px; + &.varlist-1st-row { + margin-top: 26px; + } } .right-column .form-group { diff --git a/extensions/mistral/static/mistral/js/angular-templates/collapsible-group.html b/extensions/mistral/static/mistral/js/angular-templates/collapsible-group.html index 6e68ab4..6a9c903 100644 --- a/extensions/mistral/static/mistral/js/angular-templates/collapsible-group.html +++ b/extensions/mistral/static/mistral/js/angular-templates/collapsible-group.html @@ -4,10 +4,12 @@
{$ title $}
- +
- + +
diff --git a/extensions/mistral/static/mistral/js/angular-templates/collapsible-panel.html b/extensions/mistral/static/mistral/js/angular-templates/collapsible-panel.html index bc41daf..a954cdf 100644 --- a/extensions/mistral/static/mistral/js/angular-templates/collapsible-panel.html +++ b/extensions/mistral/static/mistral/js/angular-templates/collapsible-panel.html @@ -2,7 +2,7 @@

{$ title $} -

+
diff --git a/extensions/mistral/static/mistral/js/angular-templates/fields/list.html b/extensions/mistral/static/mistral/js/angular-templates/fields/list.html index 0134a02..4db9d73 100644 --- a/extensions/mistral/static/mistral/js/angular-templates/fields/list.html +++ b/extensions/mistral/static/mistral/js/angular-templates/fields/list.html @@ -1,10 +1,14 @@ - +
-
+
- - + + + +
diff --git a/extensions/mistral/static/mistral/js/angular-templates/fields/varlist.html b/extensions/mistral/static/mistral/js/angular-templates/fields/varlist.html index 006df7e..d228694 100644 --- a/extensions/mistral/static/mistral/js/angular-templates/fields/varlist.html +++ b/extensions/mistral/static/mistral/js/angular-templates/fields/varlist.html @@ -1,10 +1,10 @@ - +
- @@ -15,12 +15,19 @@
- +
+ + + + +
-
+
@@ -29,32 +36,46 @@
- - + + + +
- +
-
+
- -
- - +
+ +
+ + + + +
-
- +
+
diff --git a/extensions/mistral/static/mistral/js/controllers.js b/extensions/mistral/static/mistral/js/controllers.js index 7a32a4c..ac2e9ac 100644 --- a/extensions/mistral/static/mistral/js/controllers.js +++ b/extensions/mistral/static/mistral/js/controllers.js @@ -3,9 +3,36 @@ */ (function() { + + function isObject(obj) { + return Object.prototype.toString.call(obj) === '[object Object]' + } + + function isArray(obj) { + return Object.prototype.toString.call(obj) === '[object Array]' + } + angular.module('hz') .controller('workbookCtrl', function($scope) { + $scope.defaults = { + 'actions': { + name: 'Action1', + base: 'nova.create_server', + baseInput: { + flavorId: { + title: 'Flavor Id', + type: 'string' + }, + imageId: { + title: 'Image Id', + type: 'string' + } + }, + input: [], + output: [] + } + }; $scope.data = { actions: [{ id: 'action1', @@ -81,14 +108,65 @@ $scope.isAtomic = function(type) { return ['string'].indexOf(type) > -1; + }; + + $scope.remove = function(parent, item) { + if ( angular.isString(parent) ) { + parent = $scope.data[parent]; + } + var index = parent.indexOf(item); + parent.splice(index, 1); + return parent.length; + }; + + $scope.removeKey = function(parent, key) { + if ( angular.isString(parent) ) { + parent = $scope.data[parent]; + } + if ( !angular.isObject(parent) ) { + return; + } + delete parent[key]; + return $scope.getKeys(parent).length; + }; + + $scope.addAutoKey = function(parent) { + if ( angular.isString(parent) ) { + parent = $scope.data[parent]; + } + if ( !angular.isObject(parent) ) { + return; + } + var maxNumber = $scope.getKeys(parent).map(function(key) { + var match = /[Kk]ey(\d+)/.exec(key); + if ( match ) { + return +match[1]; + } else { + return null; + } + }).filter(function(value) { + return value; + }).reduce(function(prevValue, curValue) { + return prevValue > curValue ? prevValue : curValue; + }, 0), + newKey = 'key' + (maxNumber+1); + parent[newKey] = ''; + }; + + $scope.add = function(parent, value) { + var defaultValue, key; + if ( angular.isString(parent) ) { + key = parent; + defaultValue = angular.copy($scope.defaults[key]); + parent = $scope.data[key]; + defaultValue.id = key + parent.length; + } + parent.push(value || defaultValue); } }) .controller('actionCtrl', function($scope) { - $scope.fixedFields = [['name', 'base']]; - $scope.fields = ['baseInput', 'input', 'output']; - var actionBase = null, baseTypes = { 'nova.create_server': { @@ -120,14 +198,14 @@ }) .controller('dictionaryCtrl', function($scope) { - if ( !$scope.item.value ) { - $scope.item.value = {'Key1': ''}; + if ( !isObject($scope.subItem.value) ) { + $scope.subItem.value = {'Key1': ''}; } }) .controller('listCtrl', function($scope) { - if ( !$scope.item.value ) { - $scope.item.value = ['']; + if ( !isArray($scope.subItem.value) ) { + $scope.subItem.value = ['']; } }) diff --git a/extensions/mistral/static/mistral/js/directives.js b/extensions/mistral/static/mistral/js/directives.js index 7dd70bd..d0e1dc0 100644 --- a/extensions/mistral/static/mistral/js/directives.js +++ b/extensions/mistral/static/mistral/js/directives.js @@ -67,15 +67,10 @@ transclude: true, scope: { title: '@', - removable: '@' + removable: '&' }, - compile: function(element, attrs) { - defaultSetter(attrs, 'removable', false); - return { - post: function(scope, element, attrs) { - disableClickDefaultBehaviour(element); - } - } + link: function(scope, element, attrs) { + disableClickDefaultBehaviour(element); } } }) @@ -87,16 +82,16 @@ transclude: true, scope: { title: '@', - additive: '@', - removable: '@' + onAdd: '&', + onRemove: '&' }, - compile: function(element, attrs) { - defaultSetter(attrs, 'removable', false); - defaultSetter(attrs, 'additive', false); - return { - post: function(scope, element) { - disableClickDefaultBehaviour(element); - } + link: function(scope, element, attrs) { + disableClickDefaultBehaviour(element); + if ( attrs.onAdd ) { + scope.additive = true; + } + if ( attrs.onRemove ) { + scope.removable = true; } } } diff --git a/extensions/mistral/templates/mistral/create.html b/extensions/mistral/templates/mistral/create.html index 2c82a90..df7ffb8 100644 --- a/extensions/mistral/templates/mistral/create.html +++ b/extensions/mistral/templates/mistral/create.html @@ -36,7 +36,7 @@
- +
@@ -71,7 +71,7 @@
- +