Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 3717 #164

Merged
merged 5 commits into from
Dec 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/sunstone/public/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -299,6 +300,7 @@ define(function(require) {
}

return x;
}else return a;
},

"ip-address-asc": function ( a, b ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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="">' +
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ define(function(require) {
'html': _html,
'setup': _setup,
'fill': _fill,
'retrieve': _retrieve
'retrieve': _retrieve,
'calculatedRealMemory': _calculatedRealMemory,
'calculatedRealCpu': _calculatedRealCpu,
'totalCost': _totalCost
};

/*
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down