From 83777f5883377978797e9c20fe230a11fb0b4de0 Mon Sep 17 00:00:00 2001 From: Keiichi Hikita Date: Thu, 7 Jun 2018 15:44:33 +0900 Subject: [PATCH] Add support for OS::Swift::Container Add support for OS::Swift::Container as a new resource that you can use from Template Generator. Change-Id: Id263c988b2ed8e1083431cd62a19841c340fdb1c Task: #19666 Story: #2002025 --- .gitignore | 1 + .../components/modal-template.controller.js | 2 + .../os__swift__container-blue.svg | 6 + .../os__swift__container-gray.svg | 6 + .../os__swift__container-green.svg | 6 + .../os__swift__container-red.svg | 6 + .../os__swift__container.html | 64 +++++++++++ .../os__swift__container.js | 108 ++++++++++++++++++ .../os__swift__container.spec.js | 80 +++++++++++++ .../os__swift__container.svg | 6 + 10 files changed, 285 insertions(+) create mode 100644 heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container-blue.svg create mode 100644 heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container-gray.svg create mode 100644 heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container-green.svg create mode 100644 heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container-red.svg create mode 100644 heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container.html create mode 100644 heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container.js create mode 100644 heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container.spec.js create mode 100644 heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container.svg diff --git a/.gitignore b/.gitignore index f0a19a1a..7980b2cb 100644 --- a/.gitignore +++ b/.gitignore @@ -105,6 +105,7 @@ ENV/ # own settings .idea/* +.vscode/* # angular old versions *angular-1.3.7* diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/components/modal-template.controller.js b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/components/modal-template.controller.js index 12e4a1d5..5a98c3f4 100644 --- a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/components/modal-template.controller.js +++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/components/modal-template.controller.js @@ -47,6 +47,8 @@ func = hotgenUtils.escape_characters; break; case 'metadata': + case 'X-Account-Meta': + case 'X-Container-Meta': case 'scheduler_hints': case 'value_specs': func = hotgenUtils.extract_keyvalue; diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container-blue.svg b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container-blue.svg new file mode 100644 index 00000000..49ae4ca5 --- /dev/null +++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container-blue.svg @@ -0,0 +1,6 @@ + + Layer 1 + + + + diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container-gray.svg b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container-gray.svg new file mode 100644 index 00000000..9ecf38b7 --- /dev/null +++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container-gray.svg @@ -0,0 +1,6 @@ + + Layer 1 + + + + diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container-green.svg b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container-green.svg new file mode 100644 index 00000000..a0a3b306 --- /dev/null +++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container-green.svg @@ -0,0 +1,6 @@ + + Layer 1 + + + + diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container-red.svg b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container-red.svg new file mode 100644 index 00000000..bd8ff0ad --- /dev/null +++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container-red.svg @@ -0,0 +1,6 @@ + + Layer 1 + + + + diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container.html b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container.html new file mode 100644 index 00000000..022c8979 --- /dev/null +++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container.html @@ -0,0 +1,64 @@ + + + + + + + +
+
That doesn't look like a valid container name.
+
Your container name is too long.
+
+
+ + + + + + + + + + + + + +
+
+ + + + + + + + + +
+
+ + + +
+
+ + + + + + + + + +
+
+ + + + Purge on Delete + + + +
+
+
diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container.js b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container.js new file mode 100644 index 00000000..8ec14016 --- /dev/null +++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container.js @@ -0,0 +1,108 @@ +(function() { + 'use strict'; + var c_meta_key = "X-Container-Meta", + a_meta_key = "X-Account-Meta", + c_read_key = "X-Container-Read", + c_write_key = "X-Container-Write", + purge_key = "PurgeOnDelete"; + + /** + * OS::Swift::Container + */ + angular.module('horizon.dashboard.project.heat_dashboard.template_generator') + .value('osSwiftContainerSettings', + { + resource_key: "OS__Swift__Container", + admin: false, + icon: { + class: 'fa-archive ', + name: 'OS::Swift::Container', + code: '\uf0a0', + color: '#0bb238' + }, + label: 'name', + modal_component: '', + edge_settings: null, + necessary_properties: { + name: null + } + } + ) + + // Register the resource to globals + angular.module('horizon.dashboard.project.heat_dashboard.template_generator') + .run(['osSwiftContainerSettings','hotgenGlobals', function(osSwiftContainerSettings, hotgenGlobals){ + hotgenGlobals.update_resource_icons( + osSwiftContainerSettings.resource_key , + osSwiftContainerSettings.icon); + + hotgenGlobals.update_resource_components( + osSwiftContainerSettings.resource_key, + osSwiftContainerSettings.modal_component); + + hotgenGlobals.update_node_labels( + osSwiftContainerSettings.resource_key, + osSwiftContainerSettings.label); + }]); + + // Define controller + function osSwiftContainerController($scope, hotgenGlobals, hotgenNotify, validationRules) { + this.$onInit = function(){ + // Initialize X-Container-Meta + if (typeof this.container[c_meta_key] === 'undefined'){ + this.container[c_meta_key] = [{}]; + } + // Initialize X-Account-Meta + if (typeof this.container[a_meta_key] === 'undefined'){ + this.container[a_meta_key] = [{}]; + } + // Intialize Purge On Delete + if (typeof this.container[purge_key] === 'undefined'){ + this.container[purge_key] = false; + } + }; + + $scope.options = hotgenGlobals.get_resource_options(); + $scope.show_more = false; + $scope.validate_name = validationRules['name']; + + // Container Metadata manipulation functions + this.add_x_container_meta = function(){ + this.container[c_meta_key].push({}) + } + this.delete_x_container_meta = function(index){ + this.container[c_meta_key].splice(index, 1) + } + + // Account Metadata manipulation functions + this.add_x_account_meta = function(){ + this.container[a_meta_key].push({}) + } + this.delete_x_account_meta = function(index){ + this.container[a_meta_key].splice(index, 1) + } + } + + function osSwiftContainerPath (basePath){ + return basePath + 'js/resources/os__swift__container/os__swift__container.html'; + } + + osSwiftContainerController.$inject = [ + '$scope', + 'hotgenGlobals', + 'hotgenNotify', + 'horizon.dashboard.project.heat_dashboard.template_generator.validationRules', + ]; + + osSwiftContainerPath.$inject = ['horizon.dashboard.project.heat_dashboard.template_generator.basePath']; + + angular.module('horizon.dashboard.project.heat_dashboard.template_generator') + .component('osSwiftContainer', { + templateUrl: osSwiftContainerPath, + controller: osSwiftContainerController, + bindings: { + 'container': '=', + 'formReference': '<', + } + }); +})(); diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container.spec.js b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container.spec.js new file mode 100644 index 00000000..040a095b --- /dev/null +++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container.spec.js @@ -0,0 +1,80 @@ +(function() { + 'use strict'; + + describe('component os-swift-container', function(){ + + beforeEach(module('horizon.dashboard.project.heat_dashboard.template_generator')); + + beforeEach(module('appTemplates')); + + var $scope, $isolateScope, $compile; + var element; + + beforeEach(inject(function($injector) { + $scope = $injector.get('$rootScope').$new(); + $compile = $injector.get('$compile'); + + $scope.resource = {}; + $scope.resourceForm = {}; + + // element will enable you to test your directive's element on the DOM + element = $compile(angular.element(''))($scope); + + // Digest needs to be called to set any values on the directive's scope + $scope.$digest(); + + $isolateScope = element.isolateScope(); + })); + + it('find tab title Properties', function() { + expect(element.find('span').html()).toContain("Properties"); + }); + + it('find tab title with resource set', function() { + $scope.resource = {metadata: [], scheduler_hints:[]}; + + // element will enable you to test your directive's element on the DOM + element = $compile(angular.element(''))($scope); + + // Digest needs to be called to set any values on the directive's scope + $scope.$digest(); + + $isolateScope = element.isolateScope(); + + expect(element.find('span').html()).toContain("Properties"); + }); + + // X-Container-Meta + it('x-container-meta should be successfully added', function() { + var $ctrl = element.isolateScope().$ctrl; + $ctrl.add_x_container_meta(); + + expect($scope.resource['X-Container-Meta'].length).toEqual(2); + }); + + it('x-container-meta should be successfully deleted', function() { + var $ctrl = element.isolateScope().$ctrl; + $ctrl.delete_x_container_meta(); + + expect($scope.resource['X-Container-Meta'].length).toEqual(0); + }); + + // X-Account-Meta + it('x-account-meta should be successfully added', function() { + var $ctrl = element.isolateScope().$ctrl; + $ctrl.add_x_account_meta(); + + expect($scope.resource['X-Account-Meta'].length).toEqual(2); + }); + + it('x-account-meta should be successfully deleted', function() { + var $ctrl = element.isolateScope().$ctrl; + $ctrl.delete_x_account_meta(); + + expect($scope.resource['X-Account-Meta'].length).toEqual(0); + }); + + }); +})(); diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container.svg b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container.svg new file mode 100644 index 00000000..395f7f22 --- /dev/null +++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__swift__container/os__swift__container.svg @@ -0,0 +1,6 @@ + + Layer 1 + + + +