luci-mod-status: rework interface status info
authorPaul Donald <newtwen+github@gmail.com>
Tue, 5 Nov 2024 18:06:49 +0000 (19:06 +0100)
committerPaul Donald <newtwen+github@gmail.com>
Tue, 5 Nov 2024 18:06:49 +0000 (19:06 +0100)
Signed-off-by: Paul Donald <newtwen+github@gmail.com>
modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/30_network.js

index 0d051bdeaf9f9bbae3db157c84dac997aa310589..e87aa345422b38f82e0bacbeaee9b66e804a70a8 100644 (file)
@@ -24,29 +24,20 @@ function renderbox(ifc, ipv6) {
            expires = ifc.getExpiry(),
            uptime = ifc.getUptime();
 
+       function addEntries(label, array) {
+               return Array.isArray(array) ? array.flatMap((item) => [label, item]) : [label, null];
+       }
+
        return E('div', { class: 'ifacebox' }, [
                E('div', { class: 'ifacebox-head center ' + (active ? 'active' : '') },
                        E('strong', ipv6 ? _('IPv6 Upstream') : _('IPv4 Upstream'))),
                E('div', { class: 'ifacebox-body left' }, [
                        L.itemlist(E('span'), [
                                _('Protocol'), ifc.getI18n() || E('em', _('Not connected')),
-                               _('Prefix Delegated'), ipv6 ? ifc.getIP6Prefix() : null,
-                               _('Address'), addrs[0],
-                               _('Address'), addrs[1],
-                               _('Address'), addrs[2],
-                               _('Address'), addrs[3],
-                               _('Address'), addrs[4],
-                               _('Address'), addrs[5],
-                               _('Address'), addrs[6],
-                               _('Address'), addrs[7],
-                               _('Address'), addrs[8],
-                               _('Address'), addrs[9],
+                               ...addEntries(_('Prefix Delegated'), ipv6 ? ifc.getIP6Prefixes?.() : null),
+                               ...addEntries(_('Address'), addrs),
                                _('Gateway'), ipv6 ? (ifc.getGateway6Addr() || '::') : (ifc.getGatewayAddr() || '0.0.0.0'),
-                               _('DNS') + ' 1', dnssrv[0],
-                               _('DNS') + ' 2', dnssrv[1],
-                               _('DNS') + ' 3', dnssrv[2],
-                               _('DNS') + ' 4', dnssrv[3],
-                               _('DNS') + ' 5', dnssrv[4],
+                               ...addEntries(_('DNS'), dnssrv),
                                _('Expires'), (expires != null && expires > -1) ? '%t'.format(expires) : null,
                                _('Connected'), (uptime > 0) ? '%t'.format(uptime) : null
                        ]),