1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Total cost take account the images size. Bug with NaN

commit c6374fa03722800a7371f6879780fa87c7d81261
Merge: 1cc73b25d e65750eb3
Author: Jaime Melis <jmelis@opennebula.org>
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 <acoronado@opennebula.org>
Date:   Fri Sep 29 15:42:08 2017 +0200

    NaN cost/month (update template)

commit 18f564f260c25a787e00618bc341dc3a123bd8b7
Author: abelCoronado93 <acoronado@opennebula.org>
Date:   Fri Sep 29 14:03:00 2017 +0200

    Total cost take account the images size
This commit is contained in:
Abel Coronado 2017-10-02 12:57:48 +02:00 committed by Jaime Melis
parent 1cc73b25d5
commit cb8b22410c
2 changed files with 29 additions and 16 deletions

View File

@ -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;

View File

@ -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();
});