diff --git a/src/sunstone/public/app/opennebula/vm.js b/src/sunstone/public/app/opennebula/vm.js index 90917d9286..05649020a5 100644 --- a/src/sunstone/public/app/opennebula/vm.js +++ b/src/sunstone/public/app/opennebula/vm.js @@ -401,7 +401,6 @@ define(function(require) { "VROUTER_IP", "VROUTER_IP6_GLOBAL", "VROUTER_IP6_ULA", - "EXTERNAL_IP", ]; var EXTERNAL_NETWORK_ATTRIBUTES = [ @@ -999,7 +998,7 @@ define(function(require) { }, []) } - // Return the IP or several IPs of a VM + // Return the IP or several IPs of a VM function ipsStr(element, options) { options = $.extend({ defaultValue: '--', @@ -1025,91 +1024,98 @@ define(function(require) { }).join(options.divider) || options.defaultValue }; - // Return a dropdown with all the + // Return a dropdown with all the IPs function ipsDropdown(element, divider) { - var ipsHtml = this.ipsStr(element, { divider, groupStrFunction: groupByIpsDropdown }); - var ips = ipsHtml.split("
"); - var html = ""; + var ipsHtml = this.ipsStr(element, { divider, groupStrFunction: groupByIpsDropdown, forceGroup: true }); + var ips = []; - // If its generated by groupByIpsDropdown - if (~ipsHtml.indexOf("li")){ - ips = []; - $.each($.parseHTML(ipsHtml), function() { - ips.push($( this ).text()); - }); - ipsHtml = ""; - } - - // If it has less than "numIPs" IPs - var numIPs = 2; - if ((ips.length < numIPs)) return ipsHtml; - - // Take the first x - var insideHtml = ""; - for (let i = 0; i < numIPs-1; i++) { - insideHtml += ips.shift(); - if (i != numIPs-2){insideHtml+="
";} - } - - // Format the other IPs inside a dropdown - if (ips.length){ - html += ""; - } - - return html; + $.each($.parseHTML(ipsHtml), function() { + ips.push($( this ).text()); + }); + var firstIP = ipsHtml.split("")[0] + ipsHtml = ipsHtml.split("")[1] + ipsHtml = + ""; + return ipsHtml; }; - function groupByIpsDropdown(element = {}, nics = []) { - // Show the first IP two times for the dropdown. - var copy_nics = Object.assign([], nics); + function orderNICs(nics){ + // The external IPs must be first + var external_nics = []; + var non_external_nics = []; - var first_nic = Object.assign({}, nics[0]); + nics.forEach(function(nic){ + if (nic.EXTERNAL_IP && nic.EXTERNAL_IP.toLowerCase() === "yes") + external_nics.push(nic); + else + non_external_nics.push(nic); + }); + + return external_nics.concat(non_external_nics); + } + + function groupByIpsDropdown(element = {}, nics = []) { + var all_nics = orderNICs(nics); + + // Show the first IP two times for the dropdown. + var copy_nics = Object.assign([], all_nics); + + var first_nic = Object.assign({}, all_nics[0]); delete first_nic["EXTERNAL_IP"]; delete first_nic["ALIAS_IDS"]; copy_nics.unshift(first_nic); + var first = true; + var identation = "    "; return copy_nics.reduce(function(column, nic) { - if (nic.EXTERNAL_IP && String(nic.EXTERNAL_IP).toLowerCase() !== 'yes') { - column.append($("
  • ").append( - $("") - .css("color", "gray") - .html(" " + nic.NIC_ID + ": " + nic.EXTERNAL_IP) - )) + if (first){ + if (nic.IP || (nic.IP6_ULA && nic.IP6_GLOBAL)) { + var ip = nic.IP || nic.IP6_ULA + " " + identation + nic.IP6_GLOBAL; + column.append(nic.NIC_ID + ": " + ip + ""); + } + first=false; } - - if (nic.IP || (nic.IP6_ULA && nic.IP6_GLOBAL)) { - var identation = "    "; - var ip = nic.IP || nic.IP6_ULA + " " + identation + nic.IP6_GLOBAL; + else{ + if (nic.IP || (nic.IP6_ULA && nic.IP6_GLOBAL)) { + var ip = nic.IP || nic.IP6_ULA + " " + identation + nic.IP6_GLOBAL; + + var nicSection = $("").css("color", "gray").html(nic.NIC_ID + ": " + ip); - var nicSection = nic.NIC_ID - ? $("
  • ").append($("").css("color", "gray").html(nic.NIC_ID + ": " + ip)) - : $("
  • ").append("
  • ").html("-") ; - - column.append(nicSection) - - if (nic.ALIAS_IDS) { - nic.ALIAS_IDS.split(",").forEach(function(aliasId) { - var templateAlias = Array.isArray(element.TEMPLATE.NIC_ALIAS) - ? element.TEMPLATE.NIC_ALIAS - : [element.TEMPLATE.NIC_ALIAS]; - - var alias = templateAlias.find(function(alias) { - return alias.NIC_ID === aliasId; + if (nic.EXTERNAL_IP && String(nic.EXTERNAL_IP).toLowerCase() === 'yes') { + nicSection.css("font-weight", "bold"); + } + + column.append($("
  • ").append(nicSection)); + + if (nic.ALIAS_IDS) { + nic.ALIAS_IDS.split(",").forEach(function(aliasId) { + var templateAlias = Array.isArray(element.TEMPLATE.NIC_ALIAS) + ? element.TEMPLATE.NIC_ALIAS + : [element.TEMPLATE.NIC_ALIAS]; + + var alias = templateAlias.find(function(alias) { + return alias.NIC_ID === aliasId; + }); + + if (alias) { + var alias_ip = alias.IP || alias.IP6_ULA + " " + identation + "> " + alias.IP6_GLOBAL; + + column.append($("
  • ").append($("").css({ + "color": "gray", + "font-style": "italic", + }).html(identation + "> " + alias_ip))); + } }); - - if (alias) { - var alias_ip = alias.IP || alias.IP6_ULA + " " + identation + "> " + alias.IP6_GLOBAL; - - column.append($("
  • ").append($("").css({ - "color": "gray", - "font-style": "italic", - }).html(identation + "> " + alias_ip))); - } - }); + } } } @@ -1118,21 +1124,26 @@ define(function(require) { }; function groupByIpsStr(element = {}, nics = []) { + + var all_nics = orderNICs(nics); + var identation = "    "; - return nics.reduce(function(column, nic) { - if (nic.EXTERNAL_IP && String(nic.EXTERNAL_IP).toLowerCase() !== 'yes') { - column.append($("

    ") - .css("margin-bottom", 0) - .html(nic.NIC_ID + ": " + nic.EXTERNAL_IP) - ) - } - + return all_nics.reduce(function(column, nic) { if (nic.IP || (nic.IP6_ULA && nic.IP6_GLOBAL)) { var ip = nic.IP || nic.IP6_ULA + "
    " + identation + nic.IP6_GLOBAL - column.append($("

    ").css("margin-bottom", 0).html(nic.NIC_ID + ": " + ip)) + var nicSection = $("

    ") + .css("color", "gray") + .css("margin-bottom", 0) + .html(nic.NIC_ID + ": " + ip); + if (nic.EXTERNAL_IP && String(nic.EXTERNAL_IP).toLowerCase() === 'yes'){ + nicSection.css("font-weight","bold"); + } + + column.append(nicSection); + if (nic.ALIAS_IDS) { nic.ALIAS_IDS.split(",").forEach(function(aliasId) { var templateAlias = Array.isArray(element.TEMPLATE.NIC_ALIAS)