From 75baf8c8d118f2955e6d9a1a4165b0eca86e1bf1 Mon Sep 17 00:00:00 2001 From: Abel Coronado Date: Thu, 19 Oct 2017 15:44:04 +0200 Subject: [PATCH] Solved bug showback (#530) * Solved bug showback * '===' instead of '==' (cherry picked from commit 2f48f1fab512ad01cba597dbde29db68ad2cf777) --- .../public/app/opennebula/template.js | 11 ++- .../form-panels/instantiate.js | 2 +- .../form-panels/create/wizard-tabs/general.js | 11 ++- .../wizard-tabs/general/capacity-create.js | 74 ++++++++++--------- .../templates-tab/form-panels/instantiate.js | 2 +- 5 files changed, 56 insertions(+), 44 deletions(-) diff --git a/src/sunstone/public/app/opennebula/template.js b/src/sunstone/public/app/opennebula/template.js index 1738afb40b..35cbda7526 100644 --- a/src/sunstone/public/app/opennebula/template.js +++ b/src/sunstone/public/app/opennebula/template.js @@ -103,6 +103,7 @@ define(function(require) { var cpuCost = capacity.CPU_COST; var memoryCost = capacity.MEMORY_COST; + var memoryUnitCost = capacity.MEMORY_UNIT_COST; var diskCost = capacity.DISK_COST; if (cpuCost == undefined){ @@ -122,7 +123,11 @@ define(function(require) { } if (capacity.MEMORY) { - cost += capacity.MEMORY * memoryCost; + if (memoryUnitCost === "GB"){ + cost += (capacity.MEMORY / 1024) * memoryCost; + } else { + cost += capacity.MEMORY * memoryCost; + } } if (diskCost != 0) { @@ -134,9 +139,9 @@ define(function(require) { disks = [template_disk]; } - $.each(disks, function(i,disk){ + $.each(disks, function(i, disk){ if (disk.SIZE) { - cost += diskCost * disk.SIZE; + cost += diskCost * (disk.SIZE / 1024); } if (disk.DISK_SNAPSHOT_TOTAL_SIZE) { diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate.js b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate.js index c453016a53..3cf1be6ed6 100644 --- a/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate.js +++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate.js @@ -146,7 +146,7 @@ define(function(require) { total_cost += (cost * role.cardinality); $(".total_cost_div", context).show(); - $(".total_cost_div .cost_value", context).text( (total_cost).toFixed(2) ); + $(".total_cost_div .cost_value", context).text((total_cost).toFixed(4)); } UserInputs.vmTemplateInsert( 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 f7c35dc3f2..649f934de3 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 @@ -163,9 +163,14 @@ define(function(require) { totalGB += ivalue.SIZE / 1024; } }); - totalCostDisk = totalGB * that.disk; - CapacityCreate.totalCost(totalCostDisk); - document.getElementById('total_value_disk').textContent = convertCostNumber(totalCostDisk * 24 * 30); + var totalCostDisk = 0; + if (!isNaN(totalGB)){ + totalCostDisk = totalGB * that.disk; + document.getElementById('total_value_disk').textContent = convertCostNumber(totalCostDisk * 24 * 30); + CapacityCreate.totalCost(); + } else { + document.getElementById('total_value_disk').textContent = totalCostDisk; + } $(".total_disk_cost", context).show(); } }); 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 e33d9658e4..5b3ee16d96 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 @@ -70,67 +70,69 @@ define(function(require) { } function convertCostNumber(number){ if(number >= 1000000){ - number = (number/1000000).toFixed(2) - return number.toString()+"M"; + number = (number / 1000000).toFixed(2) + return number.toString() + "M"; } - else if(number >= 1000){ - number = (number/1000).toFixed(2) - return number.toString()+"K"; + else if (number >= 1000){ + number = (number / 1000).toFixed(2) + return number.toString() + "K"; } - else if (number >= 0 && number < 1000) + else if (number >= 0 && number < 1000){ return number.toFixed(2); - else + } + else { return number; + } } - function _totalCost(totalCostDisk=0){ - if(!this.totalCostDisk){ - this.totalCostDisk = 0; - } - var memory = document.getElementById('real_memory_cost').value; - var cpu = document.getElementById('real_cpu_cost').value; - if (totalCostDisk != 0){ - this.totalCostDisk = totalCostDisk; + function _totalCost(){ + var memory = $("#real_memory_cost").val(); + var cpu = $("#real_cpu_cost").val(); + var disk_cost = $("#total_value_disk").text(); + if (disk_cost === "") { + disk_cost = 0; + } else { + disk_cost = parseFloat(disk_cost); } - if(memory === undefined && cpu === undefined){ - 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){ - document.getElementById('total_cost').textContent = "Total: " + convertCostNumber(memory + this.totalCostDisk); + if ((memory === undefined || memory === "") && (cpu === undefined || cpu === "")){ + document.getElementById('total_cost').textContent = "Total: " + disk_cost; + } else if(memory === undefined || memory === ""){ + document.getElementById('total_cost').textContent = "Total: " + convertCostNumber(cpu + disk_cost); + } else if(cpu === undefined || cpu === ""){ + document.getElementById('total_cost').textContent = "Total: " + convertCostNumber(memory + disk_cost); } else { - document.getElementById('total_cost').textContent = "Total: " + convertCostNumber(memory + cpu + this.totalCostDisk); + document.getElementById('total_cost').textContent = "Total: " + convertCostNumber(memory + cpu + disk_cost); } } function _calculatedRealMemory(){ - var memory_cost = document.getElementById('MEMORY_COST').value; - 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") - memory = (memory/1024)*memory_cost*24*30; - else - memory = memory*memory_cost*24*30; - document.getElementById('real_memory_cost').textContent = "Cost: "+ convertCostNumber(memory); + var memory_cost = $("#MEMORY_COST").val(); + var type_cost = $("#MEMORY_UNIT_COST").val(); + var memory = $("#MEMORY").val(); + var type = $("#memory_unit").val(); + if (type_cost == "GB"){ + memory = (memory / 1024) * memory_cost * 24 * 30; + } else { + memory = memory * memory_cost * 24 * 30; + } + document.getElementById('real_memory_cost').textContent = "Cost: " + convertCostNumber(memory); document.getElementById('real_memory_cost').value = memory; document.getElementById('total_value_memory').textContent = memory; _totalCost(); } function _calculatedRealCpu(){ - var cpu_cost = document.getElementById('CPU_COST').value; - var cpu = document.getElementById('CPU').value; - cpu = cpu*cpu_cost*24*30; - document.getElementById('real_cpu_cost').textContent = "Cost: "+ convertCostNumber(cpu); + var cpu_cost = $("#CPU_COST").val(); + var cpu = $("#CPU").val(); + cpu = cpu * cpu_cost * 24 * 30; + document.getElementById('real_cpu_cost').textContent = "Cost: " + convertCostNumber(cpu); document.getElementById('real_cpu_cost').value = cpu; document.getElementById('total_value_cpu').textContent = cpu; _totalCost(); } function _setup(context) { - this.totalCostDisk = 0; context.on("change", "#MEMORY", function() { _calculatedRealMemory(); }); 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 09441ef4bc..ef92a74a34 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 @@ -515,7 +515,7 @@ define(function(require) { memoryCost = Config.onedConf.DEFAULT_COST.MEMORY_COST; } else { if (memoryUnitCost == "GB"){ - memoryCost = memoryCost / 1024 / 1024; + memoryCost = memoryCost / 1024; } }