diff options
author | Martin Pecka <peckama2@fel.cvut.cz> | 2024-04-10 14:22:53 +0200 |
---|---|---|
committer | Paul Donald <itsascambutmailmeanyway+github@gmail.com> | 2024-04-27 02:10:35 +0200 |
commit | c75232d8d29ba5a9cc5c07c3fff65248f12f1b08 (patch) | |
tree | d3975d6749ac2a38fb2bb73eebc2c2ee7c6175cf /modules/luci-mod-dashboard/htdocs | |
parent | 1661b210c80102fb77f1a61d5c658c54ac339289 (diff) |
luci-mod-dashboard: Fill gateway info with the connection with lowest metric.
Signed-off-by: Martin Pecka <peckama2@fel.cvut.cz>
Diffstat (limited to 'modules/luci-mod-dashboard/htdocs')
-rw-r--r-- | modules/luci-mod-dashboard/htdocs/luci-static/resources/view/dashboard/include/10_router.js | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/modules/luci-mod-dashboard/htdocs/luci-static/resources/view/dashboard/include/10_router.js b/modules/luci-mod-dashboard/htdocs/luci-static/resources/view/dashboard/include/10_router.js index c43e2ca544..1667eca6ff 100644 --- a/modules/luci-mod-dashboard/htdocs/luci-static/resources/view/dashboard/include/10_router.js +++ b/modules/luci-mod-dashboard/htdocs/luci-static/resources/view/dashboard/include/10_router.js @@ -142,27 +142,35 @@ return baseclass.extend({ renderUpdateWanData: function(data, v6) { + var min_metric = 2000000000; + var min_metric_i = 0; for (var i = 0; i < data.length; i++) { - var ifc = data[i]; - - if (v6) { - var uptime = ifc.getUptime(); - this.params.internet.v6.uptime.value = (uptime > 0) ? '%t'.format(uptime) : '-'; - this.params.internet.v6.ipprefixv6.value = ifc.getIP6Prefix() || '-'; - this.params.internet.v6.gatewayv6.value = ifc.getGateway6Addr() || '-'; - this.params.internet.v6.protocol.value= ifc.getI18n() || E('em', _('Not connected')); - this.params.internet.v6.addrsv6.value = ifc.getIP6Addrs() || [ '-' ]; - this.params.internet.v6.dnsv6.value = ifc.getDNS6Addrs() || [ '-' ]; - this.params.internet.v6.connected.value = ifc.isUp(); - } else { - var uptime = ifc.getUptime(); - this.params.internet.v4.uptime.value = (uptime > 0) ? '%t'.format(uptime) : '-'; - this.params.internet.v4.protocol.value= ifc.getI18n() || E('em', _('Not connected')); - this.params.internet.v4.gatewayv4.value = ifc.getGatewayAddr() || '0.0.0.0'; - this.params.internet.v4.connected.value = ifc.isUp(); - this.params.internet.v4.addrsv4.value = ifc.getIPAddrs() || [ '-']; - this.params.internet.v4.dnsv4.value = ifc.getDNSAddrs() || [ '-' ]; - } + var metric = data[i].getMetric(); + if (metric < min_metric) { + min_metric = metric; + min_metric_i = i; + } + } + + var ifc = data[min_metric_i]; + + if (v6) { + var uptime = ifc.getUptime(); + this.params.internet.v6.uptime.value = (uptime > 0) ? '%t'.format(uptime) : '-'; + this.params.internet.v6.ipprefixv6.value = ifc.getIP6Prefix() || '-'; + this.params.internet.v6.gatewayv6.value = ifc.getGateway6Addr() || '-'; + this.params.internet.v6.protocol.value= ifc.getI18n() || E('em', _('Not connected')); + this.params.internet.v6.addrsv6.value = ifc.getIP6Addrs() || [ '-' ]; + this.params.internet.v6.dnsv6.value = ifc.getDNS6Addrs() || [ '-' ]; + this.params.internet.v6.connected.value = ifc.isUp(); + } else { + var uptime = ifc.getUptime(); + this.params.internet.v4.uptime.value = (uptime > 0) ? '%t'.format(uptime) : '-'; + this.params.internet.v4.protocol.value= ifc.getI18n() || E('em', _('Not connected')); + this.params.internet.v4.gatewayv4.value = ifc.getGatewayAddr() || '0.0.0.0'; + this.params.internet.v4.connected.value = ifc.isUp(); + this.params.internet.v4.addrsv4.value = ifc.getIPAddrs() || [ '-']; + this.params.internet.v4.dnsv4.value = ifc.getDNSAddrs() || [ '-' ]; } }, |