1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

Feature 3717 (#164)

* F #3717 Added Cost target and real cost for a template

* F #3717 label and total value in the same line

* F #3717 units changed for cost

* F #3717 modified cost tags

* F #3717 fix error
This commit is contained in:
juanmont 2016-12-02 19:06:20 +01:00 committed by Tino Vázquez
parent 0b4a467093
commit 6d74447055
7 changed files with 166 additions and 17 deletions

View File

@ -219,6 +219,7 @@ define(function(require) {
//source https://datatables.net/plug-ins/sorting/ip-address (modified)
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"ip-address-pre": function ( a ) {
if(a.split){
var ip = a.split("<br>");
var i, item;
if(ip.length == 1){
@ -299,6 +300,7 @@ define(function(require) {
}
return x;
}else return a;
},
"ip-address-asc": function ( a, b ) {

View File

@ -96,6 +96,26 @@ define(function(require) {
//context.foundation('slider', 'reflow');
}
function convertCostNumber(number){
if(number >= 1000000){
number = (number/1000000).toFixed(2)
return number.toString()+"M";
}
else if(number >= 1000){
number = (number/1000).toFixed(2)
return number.toString()+"K";
}
return number;
}
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();
}
function _setup(context) {
var that = this;
@ -104,6 +124,29 @@ define(function(require) {
//context.foundation('slider', 'reflow');
});
context.on("change", "#MEMORY_COST", function() {
caculatedTotalMemory(context);
CapacityCreate.calculatedRealMemory(context);
});
context.on("change", "#MEMORY_UNIT_COST", function() {
caculatedTotalMemory(context);
CapacityCreate.calculatedRealMemory();
});
context.on("change", "#CPU_COST", function() {
var cpu = document.getElementById('CPU_COST').value;
document.getElementById('total_value_cpu').textContent = convertCostNumber(cpu * 24 * 30);
$(".total_cpu_cost", context).show();
CapacityCreate.calculatedRealCpu();
});
context.on("change", "#DISK_COST", function() {
var disk = document.getElementById('DISK_COST').value;
document.getElementById('total_value_disk').textContent = convertCostNumber(disk * 1024 * 24 * 30);
$(".total_disk_cost", context).show();
});
context.on("change", "#LOGO", function() {
$("#template_create_logo", context).show();
$("#template_create_logo", context).html('<span class="">' +
@ -135,7 +178,9 @@ define(function(require) {
function _retrieve(context) {
var templateJSON = WizardFields.retrieve(context);
templateJSON["DISK_COST"] = templateJSON["DISK_COST"] * 1024;
if(templateJSON["MEMORY_UNIT_COST"] == "GB")
templateJSON["MEMORY_COST"] = templateJSON["MEMORY_COST"] * 1024;
if (templateJSON["HYPERVISOR"] == 'vcenter') {
templateJSON["VCENTER_PUBLIC_CLOUD"] = {
'TYPE': 'vcenter',
@ -211,6 +256,8 @@ define(function(require) {
function _fill(context, templateJSON) {
var sunstone_template = templateJSON.SUNSTONE;
if(templateJSON["MEMORY_UNIT_COST"] =="GB")
templateJSON["MEMORY_COST"] = templateJSON["MEMORY_COST"] / 1024;
if (sunstone_template) {
if (sunstone_template["NETWORK_SELECT"] &&
sunstone_template["NETWORK_SELECT"].toUpperCase() == "NO") {

View File

@ -39,7 +39,10 @@ define(function(require) {
'html': _html,
'setup': _setup,
'fill': _fill,
'retrieve': _retrieve
'retrieve': _retrieve,
'calculatedRealMemory': _calculatedRealMemory,
'calculatedRealCpu': _calculatedRealCpu,
'totalCost': _totalCost
};
/*
@ -65,9 +68,67 @@ define(function(require) {
return Math.floor(val * 1024);
}
function convertCostNumber(number){
if(number >= 1000000){
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 >= 0 && number < 1000)
return number.toFixed(2);
else
return number;
}
function _totalCost(){
var total = document.getElementById('real_memory_cost').value + document.getElementById('real_cpu_cost').value;
document.getElementById('total_cost').textContent = "Total: "+ convertCostNumber(total);
}
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" && type == "MB")
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;
_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);
document.getElementById('real_cpu_cost').value = cpu;
_totalCost();
}
function _setup(context) {
context.on("change", "#MEMORY", function() {
_calculatedRealMemory();
});
context.on("change", "#MEMORY_GB", function() {
_calculatedRealMemory();
});
context.on("change", "#memory_unit", function() {
_calculatedRealMemory();
});
context.on("change", "#CPU", function() {
_calculatedRealCpu();
});
// MB to GB
context.on("input", "div.memory_input input", function(){
$("div.memory_gb_input input", context).val(_m2g(this.value));

View File

@ -24,20 +24,24 @@
</label>
</div>
<div class="small-12 columns">
<div class="input-group">
<div class="input-group" style="margin-bottom:0rem;">
<div class="mb_unit memory_input input-group-field">
<input type="number" min="0" step="256" wizard_field="MEMORY" id="MEMORY"/>
<input type="number" min="0" step="256" wizard_field="MEMORY" id="MEMORY"style="margin-bottom:0rem;"/>
</div>
<div class="gb_unit memory_gb_input input-group-field">
<input type="number" min="0" step="1" name="memory_gb"/>
<input id="MEMORY_GB" type="number" min="0" step="1" name="memory_gb" style="margin-bottom:0rem;"/>
</div>
<div class="input-group-button">
<select id="memory_unit" name="MEMORY_UNIT" class="mb_input_unit">
<select id="memory_unit" name="MEMORY_UNIT" class="mb_input_unit" style="margin-bottom:0rem;">
<option value="MB">{{tr "MB"}}</option>
<option value="GB" selected>{{tr "GB"}}</option>
</select>
</div>
</div>
<span style="color:gray;margin-bottom:1rem">
<span id="real_memory_cost">Cost</span>
<small>{{tr "COST"}} / {{tr "MONTH"}}</small>
</span>
</div>
</div>
</div>
@ -97,8 +101,12 @@
{{{tip (tr "Percentage of CPU divided by 100 required for the Virtual Machine. Half a processor is written 0.5.")}}}
</label>
<div class="cpu_input">
<input type="number" step="0.01" min="0" wizard_field="CPU" id="CPU"/>
<input type="number" step="0.01" min="0" wizard_field="CPU" id="CPU" style="margin-bottom:0rem;"/>
</div>
<span style="color:gray;margin-bottom:1rem">
<span id="real_cpu_cost" >Cost</span>
<small>{{tr "COST"}} / {{tr "MONTH"}}</small>
</span>
</div>
</div>
</div>

View File

@ -126,29 +126,60 @@
</div>
{{#isFeatureEnabled "showback"}}
<div class="row">
<div class="medium-6 columns">
<div class="medium-12 columns">
<fieldset>
<legend>{{tr "Cost"}}</legend>
<div class="medium-6 columns">
<legend>
{{tr "Cost"}}
<span>
<span id="total_cost">0.00</span>
<small>{{tr "COST"}} / {{tr "MONTH"}}</small>
</span>
</legend>
<div class="medium-4 columns">
<label for="MEMORY_COST">
{{tr "Memory"}}
{{{tip (tr "Cost of each MB per hour")}}}
{{{tip (tr "Cost of each MB or GB per hour")}}}
</label>
<input type="number" step="any" min="0" wizard_field="MEMORY_COST" id="MEMORY_COST"/>
<div class="input-group" style="margin-bottom:0;">
<input type="number" step="any" min="0" wizard_field="MEMORY_COST" id="MEMORY_COST"/>
<div class="input-group-button">
<select id="MEMORY_UNIT_COST" wizard_field="MEMORY_UNIT_COST" class="mb_input_unit">
<option value="MB" selected>{{tr "MB"}}</option>
<option value="GB" >{{tr "GB"}}</option>
</select>
</div>
</div>
<div class="target_cost" align="center" style="background-color:lightgrey;">
<label class="total_memory_cost" hidden="true">{{tr "TOTAL"}}</label>
<label class="total_memory_cost" style="font-size:200%;" id="total_value_memory" hidden="true"></label>
<label class="total_memory_cost" hidden="true">/{{tr "month"}}
</label>
</div>
</div>
<div class="medium-6 columns">
<div class="medium-4 columns">
<label for="CPU_COST">
{{tr "CPU"}}
{{{tip (tr "Cost of each CPU per hour")}}}
</label>
<input type="number" step="any" min="0" wizard_field="CPU_COST" id="CPU_COST"/>
<span></span>
<div class="target_cost" align="center" style="background-color:lightgrey;">
<label class="total_cpu_cost" hidden="true">{{tr "TOTAL"}}</label>
<label class="total_cpu_cost" style="font-size:200%;" id="total_value_cpu" hidden="true"></label>
<label class="total_cpu_cost" hidden="true">/{{tr "month"}}</label>
</div>
</div>
<div class="medium-6 columns left">
<div class="medium-4 columns left">
<label for="DISK_COST">
{{tr "Disk"}}
{{{tip (tr "Cost of each MB per hour")}}}
{{{tip (tr "Cost of each GB per hour")}}}
</label>
<input type="number" step="any" min="0" wizard_field="DISK_COST" id="DISK_COST"/>
<div class="target_cost" align="center" style="background-color:lightgrey;">
<label class="total_disk_cost" hidden="true">{{tr "TOTAL"}}</label>
<label class="total_disk_cost" style="font-size:200%;" id="total_value_disk" hidden="true"></label>
<label class="total_disk_cost" hidden="true">/{{tr "month"}}</label>
</div>
</div>
</fieldset>
</div>

View File

@ -146,7 +146,7 @@ define(function(require) {
}
var tmpl = WizardFields.retrieve(selectedContext);
tmpl["SIZE"] = tmpl["SIZE"] * 1024;
var dev_prefix = WizardFields.retrieveInput($('#disk_dev_prefix', selectedContext));
if (dev_prefix != undefined && dev_prefix.length) {
if (dev_prefix == "custom") {

View File

@ -64,7 +64,7 @@
<div class="row">
<div class="medium-6 columns left">
<label for="SIZE">
{{tr "Size in MB"}}
{{tr "Size in GB"}}
</label>
<input wizard_field="SIZE" type="number" id="SIZE" name="SIZE"/>
</div>