From e3e6ae7b610312e5e6db2ca2f86f7018b3dcd411 Mon Sep 17 00:00:00 2001 From: juanmont Date: Thu, 14 Sep 2017 12:27:49 +0200 Subject: [PATCH] B #5368: Solved bug with costs --- .../form-panels/create/wizard-tabs/general.js | 18 ++++-------------- .../wizard-tabs/general/capacity-create.js | 2 +- .../templates-tab/form-panels/instantiate.js | 6 +++--- src/sunstone/public/app/utils/disks-resize.js | 3 ++- 4 files changed, 10 insertions(+), 19 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 700db328e6..43166c2a8e 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 @@ -98,20 +98,18 @@ define(function(require) { } function convertCostNumber(number){ if(number >= 1000000){ - number = (number/1000000).toFixed(2) + number = (number/1000000).toFixed(6) return number.toString()+"M"; } else if(number >= 1000){ - number = (number/1000).toFixed(2) + number = (number/1000).toFixed(6) return number.toString()+"K"; } - return number; + return number.toFixed(6); } function caculatedTotalMemory(context){ var memory = document.getElementById('MEMORY_COST').value; var type = document.getElementById('MEMORY_UNIT_COST').value; - if(type == "GB") - memory *= 1024; memory = memory * 24 * 30; //24 hours and 30 days document.getElementById('total_value_memory').textContent = convertCostNumber(memory); $(".total_memory_cost", context).show(); @@ -143,7 +141,7 @@ define(function(require) { context.on("change", "#DISK_COST", function() { var disk = document.getElementById('DISK_COST').value; - document.getElementById('total_value_disk').textContent = convertCostNumber(disk * 1024 * 24 * 30); + document.getElementById('total_value_disk').textContent = convertCostNumber(disk * 24 * 30); $(".total_disk_cost", context).show(); }); @@ -182,14 +180,6 @@ define(function(require) { function _retrieve(context) { var templateJSON = WizardFields.retrieve(context); - if(templateJSON["DISK_COST"]){ - templateJSON["DISK_COST"] = templateJSON["DISK_COST"] * 1024; - } - else{ - delete templateJSON["MEMORY_UNIT_COST"]; - } - if(templateJSON["MEMORY_UNIT_COST"] == "GB") - templateJSON["MEMORY_COST"] = templateJSON["MEMORY_COST"] * 1024; if (templateJSON["HYPERVISOR"] == 'vcenter') { templateJSON["VCENTER_TEMPLATE_REF"] = WizardFields.retrieveInput($("#vcenter_template_ref", context)); templateJSON["VCENTER_CCR_REF"] = WizardFields.retrieveInput($("#vcenter_ccr_ref", context)); 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 1ceabe1d43..37db057ce0 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 @@ -102,7 +102,7 @@ define(function(require) { var type_cost = document.getElementById('MEMORY_UNIT_COST').value; var memory = document.getElementById('MEMORY').value; var type = document.getElementById('memory_unit').value; - if(type_cost == "GB" && type == "MB") + if(type_cost == "GB") memory = (memory/1024)*memory_cost*24*30; else memory = memory*memory_cost*24*30; diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js index f51556eba1..b59a7663f1 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js @@ -210,7 +210,7 @@ define(function(require) { if (total != 0 && Config.isFeatureEnabled("showback")) { $(".total_cost_div", $(this)).show(); - $(".total_cost_div .cost_value", $(this)).text( (capacity_val + disk_val).toFixed(2) ); + $(".total_cost_div .cost_value", $(this)).text( (capacity_val + disk_val).toFixed(6) ); } }); } @@ -505,7 +505,7 @@ define(function(require) { memoryCost = Config.onedConf.DEFAULT_COST.MEMORY_COST; } else { if (memoryUnitCost == "GB"){ - memoryCost = memoryCost / 1024; + memoryCost = memoryCost / 1024 / 1024; } } @@ -523,7 +523,7 @@ define(function(require) { cost += cpuCost * values.CPU; } - $(".cost_value", capacityContext).html(cost.toFixed(2)); + $(".cost_value", capacityContext).html(cost.toFixed(6)); _calculateCost(context); }); diff --git a/src/sunstone/public/app/utils/disks-resize.js b/src/sunstone/public/app/utils/disks-resize.js index 01ba1e6b78..db25e4804d 100644 --- a/src/sunstone/public/app/utils/disks-resize.js +++ b/src/sunstone/public/app/utils/disks-resize.js @@ -30,6 +30,7 @@ define(function(require){ function _calculateCost(context, disk_cost, callback){ var cost = 0; + disk_cost = disk_cost / 1024 / 1024; $(".diskContainer", context).each(function(){ var size = 0; @@ -50,7 +51,7 @@ define(function(require){ cost += $(this).data('disk_snapshot_total_cost'); }); - $(".cost_value", context).text(cost.toFixed(2)); + $(".cost_value", context).text(cost.toFixed(6)); if(callback != undefined){ callback();