From 27607c8bb367f951fd7368e46ed60d1bc76e20f5 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 (cherry picked from commit bc82dfca4fa9d427d9aaa34a6cd4291845c52bca) --- src/sunstone/public/app/opennebula/vm.js | 38 ++++++++++--------- .../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, 30 insertions(+), 23 deletions(-) diff --git a/src/sunstone/public/app/opennebula/vm.js b/src/sunstone/public/app/opennebula/vm.js index 345e394ac2..91488d3372 100644 --- a/src/sunstone/public/app/opennebula/vm.js +++ b/src/sunstone/public/app/opennebula/vm.js @@ -754,10 +754,10 @@ define(function(require) { // Return the IP or several IPs of a VM function ipsStr(element, divider) { var divider = divider || "
"; - var nic = 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) { @@ -775,15 +775,15 @@ define(function(require) { }); } - if (nic == undefined){ - nic = []; + if (nics == undefined || nics == false){ + nics = []; } if (!$.isArray(nic)) { nic = [nic]; } - if (pci != undefined) { + if (pci != undefined || pci != false) { if (!$.isArray(pci)) { pci = [pci]; } @@ -852,23 +852,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 d530ada5a5..9a2ed1a1ee 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 @@ -97,9 +97,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 c7751d4945..07b6f3dd31 100644 --- a/src/sunstone/public/app/utils/template-utils.js +++ b/src/sunstone/public/app/utils/template-utils.js @@ -174,7 +174,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; }