Skip to content

Commit

Permalink
luci-base: refactor network devices enumeration
Browse files Browse the repository at this point in the history
And make sure to return an empty list if getDevices() returns null.

It happens with batadv.
  • Loading branch information
lu-zero authored and systemcrash committed Sep 14, 2024
1 parent d6d3c77 commit 4728618
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions modules/luci-base/htdocs/luci-static/resources/tools/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ function getGroups() {
});
}

function getDevices(network) {
if (network.isBridge()) {
var devices = network.getDevices();
return devices ? devices : [];
} else {
return L.toArray(network.getDevice());
}
}

var CBIZoneSelect = form.ListValue.extend({
__name__: 'CBI.ZoneSelect',

Expand Down Expand Up @@ -105,7 +114,7 @@ var CBIZoneSelect = form.ListValue.extend({
'class': 'ifacebadge' + (network.getName() == this.network ? ' ifacebadge-active' : '')
}, network.getName() + ': ');

var devices = network.isBridge() ? network.getDevices() : L.toArray(network.getDevice());
var devices = getDevices(network);

for (var k = 0; k < devices.length; k++) {
span.appendChild(E('img', {
Expand Down Expand Up @@ -246,7 +255,7 @@ var CBIZoneForwards = form.DummyValue.extend({
'class': 'ifacebadge' + (network.getName() == this.network ? ' ifacebadge-active' : '')
}, network.getName() + ': ');

var subdevs = network.isBridge() ? network.getDevices() : L.toArray(network.getDevice());
var subdevs = getDevices(network);

for (var k = 0; k < subdevs.length && subdevs[k]; k++) {
span.appendChild(E('img', {
Expand Down Expand Up @@ -339,7 +348,7 @@ var CBINetworkSelect = form.ListValue.extend({

renderIfaceBadge: function(network) {
var span = E('span', { 'class': 'ifacebadge' }, network.getName() + ': '),
devices = network.isBridge() ? network.getDevices() : L.toArray(network.getDevice());
devices = getDevices(network);

for (var j = 0; j < devices.length && devices[j]; j++) {
span.appendChild(E('img', {
Expand Down

0 comments on commit 4728618

Please sign in to comment.