luci-base: refactor network devices enumeration

And make sure to return an empty list if getDevices() returns null.

It happens with batadv.
This commit is contained in:
Luca Barbato 2024-06-03 11:08:02 +02:00 committed by Paul Donald
parent d6d3c77df0
commit 4728618896

View File

@ -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',
@ -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', {
@ -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', {
@ -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', {