From 65b333b1b2151dcb2aa71d5c074d56412944661c Mon Sep 17 00:00:00 2001 From: juanmont Date: Thu, 20 Apr 2017 12:29:37 +0200 Subject: [PATCH] F #4913 (#271) * F #4913 changed code for disable or enable icons * F #4913 Added new section for vcenter information in datastore * F #4913 Added new section for vcenter information in host-tab * F #4913 Added new section for vcenter information in vms-tab * F #4913 Added new section for vcenter information in vnets-tab --- .../app/tabs/datastores-tab/panels/info.js | 31 ++++- .../tabs/datastores-tab/panels/info/html.hbs | 3 + .../public/app/tabs/hosts-tab/panels/info.js | 18 ++- .../app/tabs/hosts-tab/panels/info/html.hbs | 3 + .../public/app/tabs/vms-tab/panels/info.js | 30 +++-- .../app/tabs/vms-tab/panels/info/html.hbs | 3 + .../public/app/tabs/vnets-tab/panels/info.js | 46 ++++--- .../app/tabs/vnets-tab/panels/info/html.hbs | 5 + .../public/app/utils/panel/template-table.js | 114 ++++++++++-------- 9 files changed, 174 insertions(+), 79 deletions(-) diff --git a/src/sunstone/public/app/tabs/datastores-tab/panels/info.js b/src/sunstone/public/app/tabs/datastores-tab/panels/info.js index 0d9ffb0093..07da9e4e3b 100644 --- a/src/sunstone/public/app/tabs/datastores-tab/panels/info.js +++ b/src/sunstone/public/app/tabs/datastores-tab/panels/info.js @@ -67,9 +67,18 @@ define(function(require) { function _html() { var renameTrHTML = RenameTr.html(TAB_ID, RESOURCE, this.element.NAME); - var templateTableHTML = TemplateTable.html( - this.element.TEMPLATE, RESOURCE, - Locale.tr("Attributes")); + var strippedTemplate = {}; + var strippedTemplateVcenter = {}; + $.each(this.element.TEMPLATE, function(key, value) { + if (key.match(/^VCENTER_*/)){ + strippedTemplateVcenter[key] = value; + } + else { + strippedTemplate[key] = value; + } + }); + var templateTableHTML = TemplateTable.html(strippedTemplate, RESOURCE, Locale.tr("Attributes"), true); + var templateTableVcenterHTML = TemplateTable.html(strippedTemplateVcenter, RESOURCE, Locale.tr("Vcenter information"), false); var permissionsTableHTML = PermissionsTable.html(TAB_ID, RESOURCE, this.element); var capacityBar = DatastoreCapacityBar.html(this.element); var stateStr = OpenNebulaDatastore.stateStr(this.element.STATE); @@ -84,6 +93,7 @@ define(function(require) { 'element': this.element, 'renameTrHTML': renameTrHTML, 'templateTableHTML': templateTableHTML, + 'templateTableVcenterHTML': templateTableVcenterHTML, 'permissionsTableHTML': permissionsTableHTML, 'capacityBar': capacityBar, 'stateStr': stateStr, @@ -94,7 +104,20 @@ define(function(require) { function _setup(context) { RenameTr.setup(TAB_ID, RESOURCE, this.element.ID, context); - TemplateTable.setup(this.element.TEMPLATE, RESOURCE, this.element.ID, context); + var strippedTemplate = {}; + var strippedTemplateVcenter = {}; + $.each(this.element.TEMPLATE, function(key, value) { + if (key.match(/^VCENTER_*/)){ + strippedTemplateVcenter[key] = value; + } + else { + strippedTemplate[key] = value; + } + }); + if($.isEmptyObject(strippedTemplateVcenter)){ + $('.vcenter', context).hide(); + } + TemplateTable.setup(strippedTemplate, RESOURCE, this.element.ID, context); PermissionsTable.setup(TAB_ID, RESOURCE, this.element, context); return false; } diff --git a/src/sunstone/public/app/tabs/datastores-tab/panels/info/html.hbs b/src/sunstone/public/app/tabs/datastores-tab/panels/info/html.hbs index 987a5a47d1..442279c487 100644 --- a/src/sunstone/public/app/tabs/datastores-tab/panels/info/html.hbs +++ b/src/sunstone/public/app/tabs/datastores-tab/panels/info/html.hbs @@ -58,6 +58,9 @@ {{{permissionsTableHTML}}} +
+
{{{templateTableVcenterHTML}}}
+
{{{templateTableHTML}}}
diff --git a/src/sunstone/public/app/tabs/hosts-tab/panels/info.js b/src/sunstone/public/app/tabs/hosts-tab/panels/info.js index 52cc8a3332..3a670c94c6 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/panels/info.js +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/info.js @@ -65,12 +65,17 @@ define(function(require) { // in the template table. Unshow values are stored in the unshownTemplate // object to be used when the host info is updated. that.unshownTemplate = {}; + that.strippedTemplateVcenter = {}; that.strippedTemplate = {}; var unshownKeys = ['HOST', 'VM', 'WILDS', 'ZOMBIES', 'RESERVED_CPU', 'RESERVED_MEM']; $.each(that.element.TEMPLATE, function(key, value) { if ($.inArray(key, unshownKeys) > -1) { - that.unshownTemplate[key] = value; - } else { + that.unshownTemplate[key] = value; + } + else if (key.match(/^VCENTER_*/)){ + that.strippedTemplateVcenter[key] = value; + } + else { that.strippedTemplate[key] = value; } }); @@ -92,6 +97,10 @@ define(function(require) { this.strippedTemplate, RESOURCE, Locale.tr("Attributes")); + var templateTableVcenterHTML = TemplateTable.html( + this.strippedTemplateVcenter, + RESOURCE, + Locale.tr("Vcenter information"),false); var renameTrHTML = RenameTr.html(TAB_ID, RESOURCE, this.element.NAME); var clusterTrHTML = ClusterTr.html(this.element.CLUSTER); var permissionsTableHTML = PermissionsTable.html(TAB_ID, RESOURCE, this.element); @@ -106,6 +115,7 @@ define(function(require) { 'renameTrHTML': renameTrHTML, 'clusterTrHTML': clusterTrHTML, 'templateTableHTML': templateTableHTML, + 'templateTableVcenterHTML': templateTableVcenterHTML, 'permissionsTableHTML': permissionsTableHTML, 'cpuBars': cpuBars, 'memoryBars': memoryBars, @@ -137,6 +147,10 @@ define(function(require) { TemplateTable.setup(this.strippedTemplate, RESOURCE, this.element.ID, context, this.unshownTemplate); PermissionsTable.setup(TAB_ID, RESOURCE, this.element, context); + if($.isEmptyObject(this.strippedTemplateVcenter)){ + $('.vcenter', context).hide(); + } + //.off and .on prevent multiple clicks events $(document).off('click', '.update_reserved_hosts').on("click", '.update_reserved', function(){ var reservedCPU = parseInt(document.getElementById('change_bar_cpu_hosts').value); diff --git a/src/sunstone/public/app/tabs/hosts-tab/panels/info/html.hbs b/src/sunstone/public/app/tabs/hosts-tab/panels/info/html.hbs index 7ff53d2194..d9a0ae56d3 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/panels/info/html.hbs +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/info/html.hbs @@ -107,6 +107,9 @@ +
+
{{{templateTableVcenterHTML}}}
+
{{{templateTableHTML}}}
diff --git a/src/sunstone/public/app/tabs/vms-tab/panels/info.js b/src/sunstone/public/app/tabs/vms-tab/panels/info.js index 2784b5597a..b87f71af57 100644 --- a/src/sunstone/public/app/tabs/vms-tab/panels/info.js +++ b/src/sunstone/public/app/tabs/vms-tab/panels/info.js @@ -91,17 +91,24 @@ define(function(require) { // Get rid of the unwanted (for show) SCHED_* keys var that = this; var strippedTemplate = {}; + var strippedTemplateVcenter = {}; var unshownValues = {}; $.each(that.element.USER_TEMPLATE, function(key, value) { if (key.match(/^SCHED_*/) || key == "USER_INPUTS") { unshownValues[key] = value; - } else { + } + else if (key.match(/^VCENTER_*/)){ + strippedTemplateVcenter[key] = value; + } + else { strippedTemplate[key] = value; } }); - var templateTableHTML = TemplateTable.html(strippedTemplate, RESOURCE, Locale.tr("Attributes")); + var templateTableHTML = TemplateTable.html(strippedTemplate, RESOURCE, Locale.tr("Attributes"), true); + var templateTableVcenterHTML = TemplateTable.html(strippedTemplateVcenter, RESOURCE, Locale.tr("Vcenter information"), false); + var monitoring = $.extend({}, this.element.MONITORING); delete monitoring.CPU; @@ -127,6 +134,7 @@ define(function(require) { 'IP': IP, 'resched': resched, 'permissionsTableHTML': permissionsTableHTML, + 'templateTableVcenterHTML': templateTableVcenterHTML, 'templateTableHTML': templateTableHTML, 'monitoringTableContentHTML': monitoringTableContentHTML, 'vrouterHTML': vrouterHTML @@ -139,14 +147,22 @@ define(function(require) { // Get rid of the unwanted (for show) SCHED_* keys var that = this; var strippedTemplate = {}; + var strippedTemplateVcenter = {}; var unshownValues = {}; - $.each(that.element.USER_TEMPLATE, function(key, value) { - if (!key.match(/^SCHED_*/)) { - strippedTemplate[key] = value; - } else { + $.each(that.element.USER_TEMPLATE, function(key, value) { + if (key.match(/^SCHED_*/) || key == "USER_INPUTS") { unshownValues[key] = value; } - }) + else if (key.match(/^VCENTER_*/)){ + strippedTemplateVcenter[key] = value; + } + else { + strippedTemplate[key] = value; + } + }); + if($.isEmptyObject(strippedTemplateVcenter)){ + $('.vcenter', context).hide(); + } TemplateTable.setup(strippedTemplate, RESOURCE, this.element.ID, context, unshownValues); } diff --git a/src/sunstone/public/app/tabs/vms-tab/panels/info/html.hbs b/src/sunstone/public/app/tabs/vms-tab/panels/info/html.hbs index 05c1921b49..a645619bf4 100644 --- a/src/sunstone/public/app/tabs/vms-tab/panels/info/html.hbs +++ b/src/sunstone/public/app/tabs/vms-tab/panels/info/html.hbs @@ -81,6 +81,9 @@
{{{permissionsTableHTML}}}
+
+
{{{templateTableVcenterHTML}}}
+
{{{templateTableHTML}}}
diff --git a/src/sunstone/public/app/tabs/vnets-tab/panels/info.js b/src/sunstone/public/app/tabs/vnets-tab/panels/info.js index 0774481ef9..8bdca05a30 100644 --- a/src/sunstone/public/app/tabs/vnets-tab/panels/info.js +++ b/src/sunstone/public/app/tabs/vnets-tab/panels/info.js @@ -78,14 +78,22 @@ define(function(require) { "OUTBOUND_PEAK_BW", "OUTBOUND_PEAK_KB" ]; - var strippedTemplate = $.extend({}, this.element.TEMPLATE); - - $.each(hiddenKeys, function(i, key){ - delete strippedTemplate[key]; + var strippedTemplate = {}; + var strippedTemplateVcenter = {}; + $.each(this.element.TEMPLATE, function(key, value) { + if (!$.inArray(key, hiddenKeys) > -1) { + if (key.match(/^VCENTER_*/)){ + strippedTemplateVcenter[key] = value; + } + else { + strippedTemplate[key] = value; + } + } }); - var templateTableHTML = TemplateTable.html(strippedTemplate, RESOURCE, Locale.tr("Attributes")); + var templateTableVcenterHTML = TemplateTable.html(strippedTemplateVcenter, RESOURCE, + Locale.tr("Vcenter information"), false); //==== // TODO: move to util? @@ -114,7 +122,8 @@ define(function(require) { 'renameTrHTML': renameTrHTML, 'reservationTrHTML': reservationTrHTML, 'permissionsTableHTML': permissionsTableHTML, - 'templateTableHTML': templateTableHTML + 'templateTableHTML': templateTableHTML, + 'templateTableVcenterHTML': templateTableVcenterHTML }); } @@ -134,20 +143,25 @@ define(function(require) { "OUTBOUND_PEAK_BW", "OUTBOUND_PEAK_KB" ]; - var strippedTemplate = $.extend({}, this.element.TEMPLATE); - - $.each(hiddenKeys, function(i, key){ - delete strippedTemplate[key]; - }); - var hiddenValues = {}; - - $.each(hiddenKeys, function(i, key){ - if (that.element.TEMPLATE[key] != undefined){ - hiddenValues[key] = that.element.TEMPLATE[key]; + var strippedTemplate = {}; + var strippedTemplateVcenter = {}; + $.each(that.element.TEMPLATE, function(key, value) { + if ($.inArray(key, hiddenKeys) > -1) { + hiddenValues[key] = value; } + if (key.match(/^VCENTER_*/)){ + strippedTemplateVcenter[key] = value; + } + else { + strippedTemplate[key] = value; + } }); + if($.isEmptyObject(strippedTemplateVcenter)){ + $('.vcenter', context).hide(); + } + TemplateTable.setup(strippedTemplate, RESOURCE, this.element.ID, context, hiddenValues); //=== diff --git a/src/sunstone/public/app/tabs/vnets-tab/panels/info/html.hbs b/src/sunstone/public/app/tabs/vnets-tab/panels/info/html.hbs index 837d3d87a0..26a067264e 100644 --- a/src/sunstone/public/app/tabs/vnets-tab/panels/info/html.hbs +++ b/src/sunstone/public/app/tabs/vnets-tab/panels/info/html.hbs @@ -96,6 +96,11 @@ +
+
+ {{{templateTableVcenterHTML}}} +
+
{{{templateTableHTML}}} diff --git a/src/sunstone/public/app/utils/panel/template-table.js b/src/sunstone/public/app/utils/panel/template-table.js index e78f21e69f..116ca1599f 100644 --- a/src/sunstone/public/app/utils/panel/template-table.js +++ b/src/sunstone/public/app/utils/panel/template-table.js @@ -31,7 +31,7 @@ define(function(require) { @param {String} tableName Header of the table (i.e: Locale.tr("Attributes")) @returns {String} HTML table */ - function _html(templateJSON, resourceType, tableName) { + function _html(templateJSON, resourceType, tableName, modify=true) { var str = '\ \ @@ -41,13 +41,15 @@ define(function(require) { '\ \ ' + - fromJSONtoHTMLTable(templateJSON, resourceType) + - '\ + fromJSONtoHTMLTable(templateJSON, resourceType, undefined, undefined,modify); + if (modify) { + str += '\ \ \ \ - \ -
\
' + '; + } + str += '' return str; } @@ -359,7 +361,7 @@ define(function(require) { } // Returns an HTML string with the json keys and values - function fromJSONtoHTMLTable(templateJSON, resourceType, vectorial, ocurrence) { + function fromJSONtoHTMLTable(templateJSON, resourceType, vectorial, ocurrence, modify) { var str = "" if (!templateJSON) { return "Not defined";} var field = null; @@ -370,14 +372,15 @@ define(function(require) { templateJSON[field], resourceType, vectorial, - ocurrence); + ocurrence, + modify); } return str; } // Helper for fromJSONtoHTMLTable function - function fromJSONtoHTMLRow(field, value, resourceType, vectorial_key, ocurrence) { + function fromJSONtoHTMLRow(field, value, resourceType, vectorial_key, ocurrence, modify) { var str = ""; // value can be an array @@ -391,28 +394,32 @@ define(function(require) { if (typeof current_value == 'object') { str += '\ ' + Locale.tr(field) + '\ - \ - \ - \ - \ -  \ - \ - \ - \ - \ - ' + '; + if (modify) { + str += '\ + \ + \ +  \ + \ + \ + \ + '; + } + str += '' str += fromJSONtoHTMLTable(current_value, resourceType, field, - it); + it, + modify); } else { // if it is a single value, create the row for this occurence of the key str += fromJSONtoHTMLRow(field, current_value, resourceType, false, - it); + it, + modify); } } } else // or value can be a string @@ -425,48 +432,55 @@ define(function(require) { if (vectorial_key) { str += '\   ' + Locale.tr(field) + '\ - ' + TemplateUtils.htmlEncode(value) + '\ - \ - \ - \ -  \ - \ - \ - \ - \ - '; + ' + TemplateUtils.htmlEncode(value) + ''; + if (modify) { + str += '\ + \ + \ +  \ + \ + \ + \ + ' + } + str += ''; } else { // If it is not comming from a vectorial daddy key, it can still vectorial itself if (typeof value == 'object') { str += '\ ' + Locale.tr(field) + '\ - \ - \ - \ - \ -  \ - \ - \ - \ - ' + '; + if (modify) { + str += '\ + \ + \ +  \ + \ + \ + \ + ' + } str += fromJSONtoHTMLTable(value, resourceType, field, - ocurrence); + ocurrence, + modify); } else // or, just a single value { str += '\ ' + Locale.tr(field) + '\ - ' + TemplateUtils.htmlEncode(value) + '\ - \ - \ - \ -  \ - \ - \ - \ - \ - '; + ' + TemplateUtils.htmlEncode(value) + ''; + if (modify) { + str += '\ + \ + \ +  \ + \ + \ + \ + '; + } + str += ''; } }