From 4728618896cd74f68b2b4e11f5568d4a54b14ec0 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Mon, 3 Jun 2024 11:08:02 +0200 Subject: [PATCH] luci-base: refactor network devices enumeration And make sure to return an empty list if getDevices() returns null. It happens with batadv. --- .../htdocs/luci-static/resources/tools/widgets.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js b/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js index 14948bbf0f8f..d946d0e09368 100644 --- a/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js +++ b/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js @@ -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', {