From 5adc0ab6c21d4cd88ee86ca6825979a5c2cd5a2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Albert?= Date: Fri, 24 Jun 2016 18:25:19 +0200 Subject: [PATCH] Updated dashboard for Angular Add new step in the wizard when creating an instance. Change-Id: Ica78c8a25699b2947942e87b17575d8612b3fec1 (cherry picked from commit ce32d88e858b8e9a2cb141d1b4eee7ed8b615a2e) --- .../enabled/_31000_cloudkitty.py | 6 +++ .../cloudkitty/js/cloudkitty.controller.js | 44 +++++++++++++++++++ .../static/cloudkitty/js/cloudkitty.module.js | 26 +++++++++++ .../static/cloudkitty/js/cloudkitty.spec.js | 10 +++++ .../cloudkitty/templates/cloudkitty-help.html | 3 ++ .../cloudkitty/templates/cloudkitty-step.html | 6 +++ 6 files changed, 95 insertions(+) create mode 100644 cloudkittydashboard/enabled/_31000_cloudkitty.py create mode 100644 cloudkittydashboard/static/cloudkitty/js/cloudkitty.controller.js create mode 100644 cloudkittydashboard/static/cloudkitty/js/cloudkitty.module.js create mode 100644 cloudkittydashboard/static/cloudkitty/js/cloudkitty.spec.js create mode 100644 cloudkittydashboard/static/cloudkitty/templates/cloudkitty-help.html create mode 100644 cloudkittydashboard/static/cloudkitty/templates/cloudkitty-step.html diff --git a/cloudkittydashboard/enabled/_31000_cloudkitty.py b/cloudkittydashboard/enabled/_31000_cloudkitty.py new file mode 100644 index 0000000..79ab88e --- /dev/null +++ b/cloudkittydashboard/enabled/_31000_cloudkitty.py @@ -0,0 +1,6 @@ +FEATURE = 'cloudkitty' + +ADD_ANGULAR_MODULES = [ + 'horizon.dashboard.cloudkitty', +] +AUTO_DISCOVER_STATIC_FILES = True diff --git a/cloudkittydashboard/static/cloudkitty/js/cloudkitty.controller.js b/cloudkittydashboard/static/cloudkitty/js/cloudkitty.controller.js new file mode 100644 index 0000000..ba90340 --- /dev/null +++ b/cloudkittydashboard/static/cloudkitty/js/cloudkitty.controller.js @@ -0,0 +1,44 @@ +(function () { + 'use strict'; + + angular + .module('horizon.dashboard.cloudkitty') + .controller('CloudkittyStepController', CloudkittyStepController); + + CloudkittyStepController.$inject = [ + '$scope', + 'horizon.framework.widgets.wizard.events', + '$http' + ]; + + function CloudkittyStepController($scope, wizardEvents, $http) { + + var onSwitch = $scope.$on(wizardEvents.ON_SWITCH, function(evt, args) { + + if(!$scope.model.newInstanceSpec.flavor) return false; + + var disk_total = $scope.model.newInstanceSpec.flavor.ephemeral + $scope.model.newInstanceSpec.flavor.disk; + + var desc_form = { + 'flavor': $scope.model.newInstanceSpec.flavor.name, + 'flavor_id': $scope.model.newInstanceSpec.flavor.id, + 'vcpus': $scope.model.newInstanceSpec.flavor.vcpus, + 'disk': $scope.model.newInstanceSpec.flavor.disk, + 'ephemeral': $scope.model.newInstanceSpec.flavor.ephemeral, + 'disk_total': disk_total, + 'disk_total_display': disk_total, + 'ram': $scope.model.newInstanceSpec.flavor.ram, + 'source_type': $scope.model.newInstanceSpec.source_type.type, + 'source_val': $scope.model.newInstanceSpec.source[0].id, + 'image_id': $scope.model.newInstanceSpec.source[0].id, + } + + var form_data = [{"service": "compute", "desc": desc_form, "volume": $scope.model.newInstanceSpec.instance_count}]; + + $http.post('/dashboard/project/rating/quote', form_data).then(function(res, status) { + $scope.price = res.data; + }); + }); + } + +})(); diff --git a/cloudkittydashboard/static/cloudkitty/js/cloudkitty.module.js b/cloudkittydashboard/static/cloudkitty/js/cloudkitty.module.js new file mode 100644 index 0000000..50877d7 --- /dev/null +++ b/cloudkittydashboard/static/cloudkitty/js/cloudkitty.module.js @@ -0,0 +1,26 @@ +(function () { + 'use strict'; + + var ck = angular.module('horizon.dashboard.cloudkitty', ['horizon.dashboard.project.workflow']).config(config) + + config.$inject = [ + '$provide', + '$windowProvider' + ]; + + function config($provide, $windowProvider) { + + $provide.decorator("horizon.dashboard.project.workflow.launch-instance.workflow", ['$delegate', function ($delegate) { + var workflow = $delegate; + workflow.append({ + formName: 'CloudkittyForm', + templateUrl: '/dashboard/static/cloudkitty/templates/cloudkitty-step.html', + helpUrl: '/dashboard/static/cloudkitty/templates/cloudkitty-help.html', + title: 'Price' + }); + return workflow; + }]); + + } + +})(); diff --git a/cloudkittydashboard/static/cloudkitty/js/cloudkitty.spec.js b/cloudkittydashboard/static/cloudkitty/js/cloudkitty.spec.js new file mode 100644 index 0000000..284d90a --- /dev/null +++ b/cloudkittydashboard/static/cloudkitty/js/cloudkitty.spec.js @@ -0,0 +1,10 @@ +(function () { + 'use strict'; + + describe('horizon.dashboard.cloudkitty', function () { + it('should be defined', function () { + expect(angular.module('horizon.dashboard.cloudkitty')).toBeDefined(); + }); + }); + +})(); diff --git a/cloudkittydashboard/static/cloudkitty/templates/cloudkitty-help.html b/cloudkittydashboard/static/cloudkitty/templates/cloudkitty-help.html new file mode 100644 index 0000000..472037d --- /dev/null +++ b/cloudkittydashboard/static/cloudkitty/templates/cloudkitty-help.html @@ -0,0 +1,3 @@ +
+

Price for instance(s)

+
diff --git a/cloudkittydashboard/static/cloudkitty/templates/cloudkitty-step.html b/cloudkittydashboard/static/cloudkitty/templates/cloudkitty-step.html new file mode 100644 index 0000000..84be49a --- /dev/null +++ b/cloudkittydashboard/static/cloudkitty/templates/cloudkitty-step.html @@ -0,0 +1,6 @@ +
+

Price

+

+ {$ price | currency $} +

+