Skip to content

Commit

Permalink
F #911: Fix some bugs in sunstone
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Huertas Herrero authored and Ruben S. Montero committed Dec 21, 2018
1 parent 82551a7 commit 018bbfa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 51 deletions.
Expand Up @@ -245,7 +245,10 @@ define(function(require) {
var that = this;

if (!that.nics.find(nic => nic.NAME === ("NIC" + that.numberOfNics))) {
that.nics.push({"NAME": "NIC" + that.numberOfNics, "ALIAS": false});
that.nics.push({"NAME": "NIC" + that.numberOfNics,
"ALIAS": false,
"ID": that.numberOfNics,
"CONTEXT": context});
}

that.numberOfNics++;
Expand Down Expand Up @@ -296,12 +299,12 @@ define(function(require) {

function _renameTabLinks(context) {
$("#" + LINKS_CONTAINER_ID + " li", context).each(function(index) {
$("a", this).html(Locale.tr("NIC") + ' ' + index + " <i id='remove_nic_" + index + "'class='fa fa-times-circle remove-tab'></i>");
$("a", this).html(Locale.tr("NIC") + ' ' + index + " <i id='update_remove_nic_" + index + "'class='fa fa-times-circle remove-tab'></i>");

if (!that.nics.find(nic => nic.ALIAS === ("NIC" + index))) {
$("#remove_nic_" + index).show();
if (that.nics.find(nic => nic.ALIAS === ("NIC" + index))) {
$("#update_remove_nic_" + index).hide();
} else {
$("#remove_nic_" + index).hide();
$("#update_remove_nic_" + index).show();
}
})

Expand Down
Expand Up @@ -232,6 +232,7 @@ define(function(require) {
} else {
if(alias_on && !alias) {
$("#" + that.nicTabId + "_alias_parent", context).show();
$("#" + that.nicTabId + "_alias_parent", context).click();
$(".network_selection", context).hide();
$("#" + that.nicTabId + "_no_alias").hide();
} else if (alias_on && alias) {
Expand All @@ -246,19 +247,7 @@ define(function(require) {
}
});

if (alias) {
$.each(that.nics, function(index, value) {
if (value.ALIAS == alias) {
found = true;
}
});

if (found) {
$("#remove_nic_" + (alias[alias.length - 1])).hide();
} else {
$("#remove_nic_" + (alias[alias.length - 1])).show();
}
}
_hide_remove(that.nics);

$("#" + that.nicTabId + "_alias_parent", context).hide();
$(".network_selection", context).show();
Expand Down Expand Up @@ -290,29 +279,16 @@ define(function(require) {
if (!add) {
$("#" + that.nicTabId + "_alias_parent", context).append(new Option("No NIC available", "INVALID"));
$("#" + that.nicTabId + "_alias_parent", context).val("INVALID");
} else if (add && selected_nic == "INVALID") {
$("#" + that.nicTabId + "_alias_parent", context).val($("#" + that.nicTabId + "_alias_parent option:first").val());
selected_nic = $("#" + that.nicTabId + "_alias_parent", context).val();
}

$.each(that.nics, function(index, value) {
if (value.NAME == ("NIC" + that.nicId) && selected_nic != "INVALID") {
if (value.NAME == ("NIC" + that.nicId) && selected_nic && selected_nic != "INVALID") {
value.ALIAS = selected_nic;
}
});

if (selected_nic && selected_nic != "INVALID") {
$.each(that.nics, function(index, value) {
if (value.ALIAS == selected_nic) {
found = true;
}
});

if (found) {
$("#remove_nic_" + (selected_nic[selected_nic.length - 1])).hide();
} else {
$("#remove_nic_" + (selected_nic[selected_nic.length - 1])).show();
}
_hide_remove(that.nics);

$("#" + that.nicTabId + "_alias_parent", context).val(selected_nic);
}
Expand Down Expand Up @@ -510,11 +486,19 @@ define(function(require) {
});

$("#" + this.nicTabId + "interface_type", this.context).show();
$("input#" + this.nicTabId + "_interface_type", this.context).click();
$("#" + this.nicTabId + "_alias_parent", this.context).show();
$("#" + this.nicTabId + "_alias_parent", this.context).empty();
$("#" + this.nicTabId + "_alias_parent").append(new Option(nicname, nicname));
$("#" + this.nicTabId + "_alias_parent", this.context).click();
$("#" + this.nicTabId + "_interface_type", this.context).click();
$("#" + this.nicTabId + "_alias_parent", this.context).val(nicname);
$(".network_selection", this.context).hide();
}

function _hide_remove(nics) {
$.each(nics, function(index, value) {
if (that.nics.find(nic => nic.ALIAS === value.NAME)) {
$("#update_remove_nic_" + value.ID).hide();
} else {
$("#update_remove_nic_" + value.ID).show();
}
});
}
});
24 changes: 10 additions & 14 deletions src/sunstone/public/app/utils/nics-section.js
Expand Up @@ -119,7 +119,7 @@ define(function(require) {
nicId ++;
});

_hide_remove(context);
_hide_remove();
}
} catch(err) {
_generate_provision_network_accordion(
Expand Down Expand Up @@ -371,6 +371,7 @@ define(function(require) {
} else {
if(alias_on && !alias) {
$("#provision_accordion_dd_" + dd_context["dd_id"] + "_alias_parent", dd_context).show();
$("#provision_accordion_dd_" + dd_context["dd_id"] + "_alias_parent", dd_context).click();
$(".network_selection", dd_context).hide();
$("#provision_accordion_dd_" + dd_context["dd_id"] + "_no_alias", dd_context).hide();
} else if (alias_on && alias) {
Expand All @@ -384,7 +385,7 @@ define(function(require) {
}
});

_hide_remove(that.context);
_hide_remove();

$("#provision_accordion_dd_" + dd_context["dd_id"] + "_alias_parent", dd_context).hide();
$(".network_selection", dd_context).show();
Expand Down Expand Up @@ -413,19 +414,16 @@ define(function(require) {
if (!add) {
$("#provision_accordion_dd_" + dd_context["dd_id"] + "_alias_parent", dd_context).append(new Option("No NIC available", "INVALID"));
$("#provision_accordion_dd_" + dd_context["dd_id"] + "_alias_parent", dd_context).val("INVALID");
} else if (add && selected_nic == "INVALID") {
selected_nic = $("#provision_accordion_dd_" + dd_context["dd_id"] + "_alias_parent option:first").val();
$("#provision_accordion_dd_" + dd_context["dd_id"] + "_alias_parent", dd_context).val(selected_nic);
}

$.each(_nics, function(index, value) {
if (value.NAME == ("NIC" + dd_context["nic_id"])) {
if (value.NAME == ("NIC" + dd_context["nic_id"]) && selected_nic && selected_nic != "INVALID") {
value.ALIAS = selected_nic;
}
});

if (selected_nic && selected_nic != "INVALID") {
_hide_remove(that.context);
_hide_remove();

$("#provision_accordion_dd_" + dd_context["dd_id"] + "_alias_parent", dd_context).val(selected_nic);
}
Expand Down Expand Up @@ -647,20 +645,18 @@ define(function(require) {
});

$("#provision_accordion_dd_" + provision_nic_accordion_dd_id + "_interface_type_section", this.context).show();
$("input#provision_accordion_dd_" + provision_nic_accordion_dd_id + "_interface_type", this.context).click();
$("#provision_accordion_dd_" + provision_nic_accordion_dd_id + "_alias_parent", this.context).show();
$("#provision_accordion_dd_" + provision_nic_accordion_dd_id + "_alias_parent").empty();
$("#provision_accordion_dd_" + provision_nic_accordion_dd_id + "_alias_parent").append(new Option(nicname, nicname));
$("#provision_accordion_dd_" + provision_nic_accordion_dd_id + "_alias_parent", this.context).click();
$("#provision_accordion_dd_" + provision_nic_accordion_dd_id + "_interface_type", this.context).click();
$("#provision_accordion_dd_" + provision_nic_accordion_dd_id + "_alias_parent", this.context).val(nicname);
$("#provision_accordion_dd_" + provision_nic_accordion_dd_id + "_network_selection", this.context).hide();
}

function _hide_remove(context) {
function _hide_remove() {
$.each(_nics, function(index, value) {
if (_nics.find(nic => nic.ALIAS === value.NAME)) {
$("#remove_nic_" + value.DD_ID, context).hide();
$("#remove_nic_" + value.DD_ID).hide();
} else {
$("#remove_nic_" + value.DD_ID, context).show();
$("#remove_nic_" + value.DD_ID).show();
}
});
}
Expand Down

0 comments on commit 018bbfa

Please sign in to comment.