From bc82dfca4fa9d427d9aaa34a6cd4291845c52bca Mon Sep 17 00:00:00 2001 From: Jorge Lobo <47326048+jloboescalona2@users.noreply.github.com> Date: Wed, 25 Mar 2020 10:52:57 +0100 Subject: [PATCH] M #~: fix roles in services (#4421) Signed-off-by: Jorge Lobo --- src/sunstone/public/app/opennebula/vm.js | 36 ++++++++++--------- .../tabs/vms-tab/utils/datatable-common.js | 4 +-- src/sunstone/public/app/utils/labels/utils.js | 9 +++-- .../public/app/utils/template-utils.js | 2 +- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/sunstone/public/app/opennebula/vm.js b/src/sunstone/public/app/opennebula/vm.js index 0e17e9b48f..18356d038c 100644 --- a/src/sunstone/public/app/opennebula/vm.js +++ b/src/sunstone/public/app/opennebula/vm.js @@ -755,10 +755,10 @@ define(function(require) { // Return the IP or several IPs of a VM function ipsStr(element, divider) { var divider = divider || "
"; - var nics = element.TEMPLATE.NIC; - var pci = element.TEMPLATE.PCI; + var nics = element && element.TEMPLATE && element.TEMPLATE.NIC; + var pci = element && element.TEMPLATE && element.TEMPLATE.PCI; var ips = []; - var monitoring = element.MONITORING; + var monitoring = element && element.MONITORING; if (monitoring) { var externalIP; $.each(EXTERNAL_IP_ATTRS, function(index, IPAttr) { @@ -776,7 +776,7 @@ define(function(require) { }); } - if (nics == undefined){ + if (nics == undefined || nics == false){ nics = []; } @@ -784,7 +784,7 @@ define(function(require) { nics = [nics]; } - if (pci != undefined) { + if (pci != undefined || pci != false) { if (!$.isArray(pci)) { pci = [pci]; } @@ -865,23 +865,27 @@ define(function(require) { // returns true if the vnc button should be enabled function isVNCSupported(element) { - var graphics = element.TEMPLATE.GRAPHICS; - var state = parseInt(element.LCM_STATE); - - return (graphics && + var rtn = false; + if(element && element.TEMPLATE && element.TEMPLATE.GRAPHICS && element.LCM_STATE){ + var graphics = element.TEMPLATE.GRAPHICS; + var state = parseInt(element.LCM_STATE); + rtn = graphics && graphics.TYPE && - graphics.TYPE.toLowerCase() == "vnc" && - $.inArray(state, VNC_STATES) != -1); + graphics.TYPE.toLowerCase() == "vnc" && + $.inArray(state, VNC_STATES) != -1; + } + return rtn; } function isSPICESupported(element) { - var graphics = element.TEMPLATE.GRAPHICS; - var state = parseInt(element.LCM_STATE); - - return (graphics && + var rtn = false; + if(element && element.TEMPLATE && element.TEMPLATE.GRAPHICS && element.LCM_STATE){ + rtn = graphics && graphics.TYPE && graphics.TYPE.toLowerCase() == "spice" && - $.inArray(state, VNC_STATES) != -1); + $.inArray(state, VNC_STATES) != -1; + } + return rtn; } // returns true if the RDP button should be enabled diff --git a/src/sunstone/public/app/tabs/vms-tab/utils/datatable-common.js b/src/sunstone/public/app/tabs/vms-tab/utils/datatable-common.js index a0872291b2..81536b9208 100644 --- a/src/sunstone/public/app/tabs/vms-tab/utils/datatable-common.js +++ b/src/sunstone/public/app/tabs/vms-tab/utils/datatable-common.js @@ -187,9 +187,9 @@ define(function(require) { var type; - if (element.TEMPLATE.VROUTER_ID != undefined){ + if (element && element.TEMPLATE && element.TEMPLATE.VROUTER_ID && element.TEMPLATE.VROUTER_ID != undefined){ type = "VR"; - } else if (element.USER_TEMPLATE.SERVICE_ID != undefined){ + } else if (element && element.USER_TEMPLATE && element.USER_TEMPLATE.SERVICE_ID && element.USER_TEMPLATE.SERVICE_ID != undefined){ type = "FLOW"; } else { type = "VM"; diff --git a/src/sunstone/public/app/utils/labels/utils.js b/src/sunstone/public/app/utils/labels/utils.js index 287a367a4b..6527926fea 100644 --- a/src/sunstone/public/app/utils/labels/utils.js +++ b/src/sunstone/public/app/utils/labels/utils.js @@ -369,10 +369,13 @@ define(function (require) { } function _labelsStr(elementTemplate) { - if (elementTemplate['BODY'] && elementTemplate["BODY"][LABELS_ATTR.toLowerCase()]) { - return TemplateUtils.htmlEncode(elementTemplate["BODY"][LABELS_ATTR.toLowerCase()]); + if (elementTemplate && + elementTemplate.BODY && + elementTemplate.BODY[LABELS_ATTR.toLowerCase()] + ) { + return TemplateUtils.htmlEncode(elementTemplate.BODY[LABELS_ATTR.toLowerCase()]); } else { - return TemplateUtils.htmlEncode(elementTemplate[LABELS_ATTR]); + return TemplateUtils.htmlEncode(elementTemplate && elementTemplate[LABELS_ATTR]? elementTemplate[LABELS_ATTR] : ""); } } diff --git a/src/sunstone/public/app/utils/template-utils.js b/src/sunstone/public/app/utils/template-utils.js index 1b64dd12b4..29eb377e4e 100644 --- a/src/sunstone/public/app/utils/template-utils.js +++ b/src/sunstone/public/app/utils/template-utils.js @@ -176,7 +176,7 @@ define(function(require) { function _removeHTMLTags(string){ var rtn = string; if(rtn){ - rtn = string.replace(/<[^0-9\s=>]+>/g, ''); + rtn = String(string).replace(/<[^0-9\s=>]+>/g, ''); } return rtn; }