From 2e9b44682c234aa5311bd11d92b422027738aaf5 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Wed, 17 Jun 2015 12:27:27 +0200 Subject: [PATCH] feature #3748: Add provision dashboard templates --- src/sunstone/public/app/sunstone-config.js | 8 ++ .../provision-tab/dashboard/empty-graphs.hbs | 4 + .../provision-tab/dashboard/empty-quota.hbs | 1 + .../tabs/provision-tab/dashboard/quotas.hbs | 56 ++++++++++ .../tabs/provision-tab/dashboard/users.hbs | 64 +++++++++++ .../provision-tab/dashboard/vdc-quotas.hbs | 59 ++++++++++ .../tabs/provision-tab/dashboard/vdc-vms.hbs | 101 ++++++++++++++++++ .../app/tabs/provision-tab/dashboard/vms.hbs | 101 ++++++++++++++++++ src/sunstone/public/app/utils/accounting.js | 22 ++-- src/sunstone/public/app/utils/humanize.js | 72 +++++-------- .../public/app/utils/quotas/quota-widgets.js | 53 +++++++++ 11 files changed, 488 insertions(+), 53 deletions(-) create mode 100644 src/sunstone/public/app/tabs/provision-tab/dashboard/empty-graphs.hbs create mode 100644 src/sunstone/public/app/tabs/provision-tab/dashboard/empty-quota.hbs create mode 100644 src/sunstone/public/app/tabs/provision-tab/dashboard/quotas.hbs create mode 100644 src/sunstone/public/app/tabs/provision-tab/dashboard/users.hbs create mode 100644 src/sunstone/public/app/tabs/provision-tab/dashboard/vdc-quotas.hbs create mode 100644 src/sunstone/public/app/tabs/provision-tab/dashboard/vdc-vms.hbs create mode 100644 src/sunstone/public/app/tabs/provision-tab/dashboard/vms.hbs diff --git a/src/sunstone/public/app/sunstone-config.js b/src/sunstone/public/app/sunstone-config.js index 64952cb7ee..039c2099d2 100644 --- a/src/sunstone/public/app/sunstone-config.js +++ b/src/sunstone/public/app/sunstone-config.js @@ -43,6 +43,10 @@ define(function(require) { }, "tabTableColumns": function(tabName) { + if (!_config['view']['tabs'][tabName]) { + return []; + } + var columns = _config['view']['tabs'][tabName]['table_columns']; if (columns) { @@ -62,6 +66,10 @@ define(function(require) { }, "dashboardWidgets": function(perRow) { + if (!_config['view']['tabs']['dashboard-tab']) { + return [] + } + var widgets = _config['view']['tabs']['dashboard-tab'][perRow]; if (widgets) { diff --git a/src/sunstone/public/app/tabs/provision-tab/dashboard/empty-graphs.hbs b/src/sunstone/public/app/tabs/provision-tab/dashboard/empty-graphs.hbs new file mode 100644 index 0000000000..9cef304b11 --- /dev/null +++ b/src/sunstone/public/app/tabs/provision-tab/dashboard/empty-graphs.hbs @@ -0,0 +1,4 @@ + + +
+{{tr "There is no information available"}} \ No newline at end of file diff --git a/src/sunstone/public/app/tabs/provision-tab/dashboard/empty-quota.hbs b/src/sunstone/public/app/tabs/provision-tab/dashboard/empty-quota.hbs new file mode 100644 index 0000000000..e6d11adc9a --- /dev/null +++ b/src/sunstone/public/app/tabs/provision-tab/dashboard/empty-quota.hbs @@ -0,0 +1 @@ + 0 \ No newline at end of file diff --git a/src/sunstone/public/app/tabs/provision-tab/dashboard/quotas.hbs b/src/sunstone/public/app/tabs/provision-tab/dashboard/quotas.hbs new file mode 100644 index 0000000000..e1017615a3 --- /dev/null +++ b/src/sunstone/public/app/tabs/provision-tab/dashboard/quotas.hbs @@ -0,0 +1,56 @@ +
+
+

{{tr "Quotas"}}

+
+
+
+
+
+
+ 0 + %
+
+ 0 + %
+
+ 0 + %
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+ {{tr "RUNNING VMS"}} +
+ +
+
+ {{tr "CPU"}} +
+ +
+
+ {{tr "MEMORY"}} +
+ +
+
+
+
+
+
\ No newline at end of file diff --git a/src/sunstone/public/app/tabs/provision-tab/dashboard/users.hbs b/src/sunstone/public/app/tabs/provision-tab/dashboard/users.hbs new file mode 100644 index 0000000000..bb59f2e0ad --- /dev/null +++ b/src/sunstone/public/app/tabs/provision-tab/dashboard/users.hbs @@ -0,0 +1,64 @@ +
+
+

+ {{tr "Users"}} +

+
+
+
+
+
+
+
+
+
+
+ + + +
+ {{tr "TOTAL"}} +
+
+
+
+
+
+ + +
+
+
+
+
+
+
+
+
+ +
+
+

{{tr "CPU hours"}}

+
+
+
+ {{> ./empty-graphs}} +
+
+
+
+
+

{{tr "Memory GB hours"}}

+
+
+
+ {{> ./empty-graphs}} +
+
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/src/sunstone/public/app/tabs/provision-tab/dashboard/vdc-quotas.hbs b/src/sunstone/public/app/tabs/provision-tab/dashboard/vdc-quotas.hbs new file mode 100644 index 0000000000..e50b8b8b37 --- /dev/null +++ b/src/sunstone/public/app/tabs/provision-tab/dashboard/vdc-quotas.hbs @@ -0,0 +1,59 @@ +
+
+

{{tr "Group Quotas"}}

+
+
+
+
+
+
+ 0 + % +
+
+ 0 + % +
+
+ 0 + % +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+ {{tr "RUNNING VMS"}} +
+ +
+
+ {{tr "CPU"}} +
+ +
+
+ {{tr "MEMORY"}} +
+ +
+
+
+
+
+
\ No newline at end of file diff --git a/src/sunstone/public/app/tabs/provision-tab/dashboard/vdc-vms.hbs b/src/sunstone/public/app/tabs/provision-tab/dashboard/vdc-vms.hbs new file mode 100644 index 0000000000..d958926cb1 --- /dev/null +++ b/src/sunstone/public/app/tabs/provision-tab/dashboard/vdc-vms.hbs @@ -0,0 +1,101 @@ +
+
+

{{tr "Group Virtual Machines"}}

+
+
+
+
+
+
+
+
+
+ + +
+ {{tr "TOTAL"}} +
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+ + + +
+ {{tr "RUNNING"}} +
+
+
+
+
+ + + +
+ {{tr "DEPLOYING"}} +
+
+
+
+
+ + + +
+ {{tr "OFF"}} +
+
+
+
+
+ + + +
+ {{tr "ERROR"}} +
+
+
+
+ +
+
+

+ {{tr "CPU hours"}} +

+
+
+
{{> ./empty-graphs}}
+
+
+
+
+

+ {{tr "Memory GB hours"}} +

+
+
+
{{> ./empty-graphs}}
+
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/src/sunstone/public/app/tabs/provision-tab/dashboard/vms.hbs b/src/sunstone/public/app/tabs/provision-tab/dashboard/vms.hbs new file mode 100644 index 0000000000..7e867a14b9 --- /dev/null +++ b/src/sunstone/public/app/tabs/provision-tab/dashboard/vms.hbs @@ -0,0 +1,101 @@ +
+
+

{{tr "Virtual Machines"}}

+
+
+
+
+
+
+
+
+
+ + +
+ {{tr "TOTAL"}} +
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+ + + +
+ {{tr "RUNNING"}} +
+
+
+
+
+ + + +
+ {{tr "DEPLOYING"}} +
+
+
+
+
+ + + +
+ {{tr "OFF"}} +
+
+
+
+
+ + + +
+ {{tr "ERROR"}} +
+
+
+
+ +
+
+

+ {{tr "CPU hours"}} +

+
+
+
{{> ./empty-graphs}}
+
+
+
+
+

+ {{tr "Memory GB hours"}} +

+
+
+
{{> ./empty-graphs}}
+
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/src/sunstone/public/app/utils/accounting.js b/src/sunstone/public/app/utils/accounting.js index 0a01f4c775..4f9c7cb247 100644 --- a/src/sunstone/public/app/utils/accounting.js +++ b/src/sunstone/public/app/utils/accounting.js @@ -299,44 +299,46 @@ define(function(require) { //-------------------------------------------------------------------------- // TODO: Allow to change group by dynamically, instead of calling oned again - + var group_by_fn; + var group_by_name; + var group_by_prefix; switch ($("#acct_group_by", context).val()){ case "user": - var group_by_fn = function(history){ + group_by_fn = function(history){ return history.VM.UID; } - var group_by_name = function(history){ + group_by_name = function(history){ return history.VM.UNAME; } - var group_by_prefix = Locale.tr("User"); + group_by_prefix = Locale.tr("User"); break; case "group": - var group_by_fn = function(history){ + group_by_fn = function(history){ return history.VM.GID; } - var group_by_name = function(history){ + group_by_name = function(history){ return history.VM.GNAME; } - var group_by_prefix = Locale.tr("Group"); + group_by_prefix = Locale.tr("Group"); break; case "vm": - var group_by_fn = function(history){ + group_by_fn = function(history){ return history.OID; } - var group_by_name = function(history){ + group_by_name = function(history){ return history.VM.NAME; } - var group_by_prefix = Locale.tr("VM"); + group_by_prefix = Locale.tr("VM"); break; } diff --git a/src/sunstone/public/app/utils/humanize.js b/src/sunstone/public/app/utils/humanize.js index ac9c8dd884..6337885fa9 100644 --- a/src/sunstone/public/app/utils/humanize.js +++ b/src/sunstone/public/app/utils/humanize.js @@ -1,10 +1,5 @@ define(function(require) { - var EXTERNAL_IPS_ATTRS = [ - 'GUEST_IP', - 'AWS_IP_ADDRESS', - 'AZ_IPADDRESS', - 'SL_PRIMARYIPADDRESS' - ] + var Locale = require('utils/locale'); /* CONSTRUCTOR @@ -19,7 +14,7 @@ define(function(require) { 'prettyTime': _prettyTime, 'prettyTimeAxis': _prettyTimeAxis, 'prettyPrintJSON': _prettyPrintJSON, - 'ipsStr': _ipsStr + 'prettyTimeAgo': _format_date } /* @@ -214,45 +209,36 @@ define(function(require) { return str; } - // Return the IP or several IPs of a VM - function _ipsStr(vm, divider) { - var divider = divider || "
" - var nic = vm.TEMPLATE.NIC; - var ips = []; + function _format_date(unix_timestamp) { + var difference_in_seconds = (Math.round((new Date()).getTime() / 1000)) - unix_timestamp, + current_date = new Date(unix_timestamp * 1000), minutes, hours; - if (nic != undefined) { - if (!$.isArray(nic)) { - nic = [nic]; + if(difference_in_seconds < 60) { + return difference_in_seconds + "s" + " ago"; + } else if (difference_in_seconds < 60*60) { + minutes = Math.floor(difference_in_seconds/60); + return minutes + "m" + " ago"; + } else if (difference_in_seconds < 60*60*24) { + hours = Math.floor(difference_in_seconds/60/60); + return hours + "h" + " ago"; + } else if (difference_in_seconds > 60*60*24){ + if(current_date.getYear() !== new Date().getYear()) + return current_date.getDay() + " " + Locale.months[current_date.getMonth()].substr(0,3) + " " + _fourdigits(current_date.getYear()); + else { + return current_date.getDay() + " " + Locale.months[current_date.getMonth()].substr(0,3); } - - $.each(nic, function(index, value) { - if (value.IP) { - ips.push(value.IP); - } - - if (value.IP6_GLOBAL) { - ips.push(value.IP6_GLOBAL); - } - - if (value.IP6_ULA) { - ips.push(value.IP6_ULA); - } - }); } - var template = vm.TEMPLATE; - var externalIP; - $.each(EXTERNAL_IPS_ATTRS, function(index, IPAttr) { - externalIP = template[IPAttr]; - if (externalIP && ($.inArray(externalIP, ips) == -1)) { - ips.push(externalIP); - } - }) + return difference_in_seconds; - if (ips.length > 0) { - return ips.join(divider); - } else { - return '--'; - } - }; + function _fourdigits(number) { + return (number < 1000) ? number + 1900 : number;} + + //function _plural(number) { + // if(parseInt(number) === 1) { + // return ""; + // } + // return "s"; + //} + } }) diff --git a/src/sunstone/public/app/utils/quotas/quota-widgets.js b/src/sunstone/public/app/utils/quotas/quota-widgets.js index 9d54c9ae29..8601fc671b 100644 --- a/src/sunstone/public/app/utils/quotas/quota-widgets.js +++ b/src/sunstone/public/app/utils/quotas/quota-widgets.js @@ -1033,6 +1033,56 @@ define(function(require) { return html; } + function _quotaInfo(usage, limit, default_limit, not_html){ + var int_usage = parseInt(usage, 10); + var int_limit = _quotaIntLimit(limit, default_limit); + return _quotaBaseInfo(int_usage, int_limit, null, not_html); + } + + function _quotaMBInfo(usage, limit, default_limit, not_html){ + var int_usage = parseInt(usage, 10); + var int_limit = _quotaIntLimit(limit, default_limit); + + info_str = Humanize.size(int_usage * 1024)+' / ' + +((int_limit >= 0) ? Humanize.size(int_limit * 1024) : '-') + + return _quotaBaseInfo(int_usage, int_limit, info_str, not_html); + } + + function _quotaFloatInfo(usage, limit, default_limit, not_html){ + var float_usage = parseFloat(usage, 10); + var float_limit = _quotaFloatLimit(limit, default_limit); + return _quotaBaseInfo(float_usage, float_limit, null, not_html); + } + + function _quotaBaseInfo(usage, limit, info_str, not_html){ + percentage = 0; + + if (limit > 0){ + percentage = Math.floor((usage / limit) * 100); + + if (percentage > 100){ + percentage = 100; + } + } else if (limit == 0 && usage > 0){ + percentage = 100; + } + + info_str = info_str || ( usage+' / '+((limit >= 0) ? limit : '-') ); + + if (not_html) { + return { + "percentage": percentage, + "str": info_str + } + } else { + html = ''+info_str+'
'; + + return html; + } + } + function _quotaBar(usage, limit, default_limit){ var int_usage = parseInt(usage, 10); var int_limit = _quotaIntLimit(limit, default_limit); @@ -1176,5 +1226,8 @@ define(function(require) { 'dialogHTML': _quotas_tmpl, 'setupQuotasDialog': _setupQuotasDialog, 'populateQuotasDialog': _populateQuotasDialog, + 'quotaFloatInfo': _quotaFloatInfo, + 'quotaMBInfo': _quotaMBInfo, + 'quotaInfo': _quotaInfo }; });