From cb8b22410c7d751e4d95f9df010591afa51d6ec9 Mon Sep 17 00:00:00 2001 From: Abel Coronado Date: Mon, 2 Oct 2017 12:57:48 +0200 Subject: [PATCH] Total cost take account the images size. Bug with NaN commit c6374fa03722800a7371f6879780fa87c7d81261 Merge: 1cc73b25d e65750eb3 Author: Jaime Melis Date: Mon Oct 2 12:24:07 2017 +0200 Merge branch 'bug-cost-image' of https://github.com/abelCoronado93/one into abelCoronado93-bug-cost-image commit e65750eb3d45c4e7cfc4f2a57847fccf5620e851 Author: abelCoronado93 Date: Fri Sep 29 15:42:08 2017 +0200 NaN cost/month (update template) commit 18f564f260c25a787e00618bc341dc3a123bd8b7 Author: abelCoronado93 Date: Fri Sep 29 14:03:00 2017 +0200 Total cost take account the images size --- .../form-panels/create/wizard-tabs/general.js | 39 +++++++++++++------ .../wizard-tabs/general/capacity-create.js | 6 +-- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js index 8ff5dd47b1..365b107de2 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js @@ -26,6 +26,7 @@ define(function(require) { var Config = require('sunstone-config'); var UserInputs = require('utils/user-inputs'); var UniqueId = require('utils/unique-id'); + var OpenNebula = require('opennebula'); /* TEMPLATES @@ -140,18 +141,33 @@ define(function(require) { }); context.on("change", "#DISK_COST", function() { - var disk = parseFloat(document.getElementById('DISK_COST').value); - that.templateDISKS = JSON.parse(localStorage.getItem("disksJSON")); - if (that.templateDISKS){ - var totalGB = 0; - $.each(that.templateDISKS, function(key, value){ - totalGB += value.SIZE / 1024; - }); - totalCostDisk = totalGB * disk; - CapacityCreate.totalCost(totalCostDisk); + that.disk = parseFloat(document.getElementById('DISK_COST').value); + if(!isNaN(that.disk)){ + that.templateDISKS = JSON.parse(localStorage.getItem("disksJSON")); + if (that.templateDISKS){ + OpenNebula.Image.list({ + timeout: true, + success: function(request, obj_files){ + var totalGB = 0; + $.each(that.templateDISKS, function(ikey, ivalue){ + if (ivalue.IMAGE_ID){ + $.each(obj_files, function(jkey, jvalue){ + if (ivalue.IMAGE_ID == jvalue.IMAGE.ID){ + totalGB += jvalue.IMAGE.SIZE / 1024; + } + }); + } else { + totalGB += ivalue.SIZE / 1024; + } + }); + totalCostDisk = totalGB * that.disk; + CapacityCreate.totalCost(totalCostDisk); + document.getElementById('total_value_disk').textContent = convertCostNumber(that.disk * 24 * 30); + $(".total_disk_cost", context).show(); + } + }); + } } - document.getElementById('total_value_disk').textContent = convertCostNumber(disk * 24 * 30); - $(".total_disk_cost", context).show(); }); context.on("change", "#LOGO", function() { @@ -243,7 +259,6 @@ define(function(require) { } function _fill(context, templateJSON) { - var that = this; that.templateDISKS = $.extend(true, {}, templateJSON.DISK); localStorage.setItem("disksJSON", JSON.stringify(that.templateDISKS)); var sunstone_template = templateJSON.SUNSTONE; diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create.js index 9e94cf9e28..7cf30bc9d6 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create.js @@ -31,8 +31,6 @@ define(function(require) { var TemplateHTML = require('hbs!./capacity-create/html'); - this.totalCostDisk = 0; - /* CONSTRUCTOR */ @@ -93,7 +91,7 @@ define(function(require) { } if(memory === undefined && cpu === undefined){ - document.getElementById('total_cost').textContent = "Total: 0.00"; + document.getElementById('total_cost').textContent = "Total: " + this.totalCostDisk; } else if(memory === undefined){ document.getElementById('total_cost').textContent = "Total: " + convertCostNumber(cpu + this.totalCostDisk); } else if(cpu === undefined){ @@ -127,7 +125,7 @@ define(function(require) { } function _setup(context) { - + this.totalCostDisk = 0; context.on("change", "#MEMORY", function() { _calculatedRealMemory(); });