mirror of
https://github.com/openwrt/luci.git
synced 2025-12-21 17:04:35 +04:00
luci-mod-status: ES6 network panel refactor
Signed-off-by: Paul Donald <newtwen+github@gmail.com>
This commit is contained in:
@@ -4,11 +4,11 @@
|
||||
'require network';
|
||||
|
||||
function progressbar(value, max, byte) {
|
||||
var vn = parseInt(value) || 0,
|
||||
mn = parseInt(max) || 100,
|
||||
fv = byte ? String.format('%1024.2mB', value) : value,
|
||||
fm = byte ? String.format('%1024.2mB', max) : max,
|
||||
pc = Math.floor((100 / mn) * vn);
|
||||
const vn = parseInt(value) || 0;
|
||||
const mn = parseInt(max) || 100;
|
||||
const fv = byte ? String.format('%1024.2mB', value) : value;
|
||||
const fm = byte ? String.format('%1024.2mB', max) : max;
|
||||
const pc = Math.floor((100 / mn) * vn);
|
||||
|
||||
return E('div', {
|
||||
'class': 'cbi-progressbar',
|
||||
@@ -17,12 +17,12 @@ function progressbar(value, max, byte) {
|
||||
}
|
||||
|
||||
function renderbox(ifc, ipv6) {
|
||||
var dev = ifc.getL3Device(),
|
||||
active = (dev && ifc.getProtocol() != 'none'),
|
||||
addrs = (ipv6 ? ifc.getIP6Addrs() : ifc.getIPAddrs()) || [],
|
||||
dnssrv = (ipv6 ? ifc.getDNS6Addrs() : ifc.getDNSAddrs()) || [],
|
||||
expires = ifc.getExpiry(),
|
||||
uptime = ifc.getUptime();
|
||||
const dev = ifc.getL3Device();
|
||||
const active = (dev && ifc.getProtocol() != 'none');
|
||||
const addrs = (ipv6 ? ifc.getIP6Addrs() : ifc.getIPAddrs()) || [];
|
||||
const dnssrv = (ipv6 ? ifc.getDNS6Addrs() : ifc.getDNSAddrs()) || [];
|
||||
const expires = ifc.getExpiry();
|
||||
const uptime = ifc.getUptime();
|
||||
|
||||
function addEntries(label, array) {
|
||||
return Array.isArray(array) ? array.flatMap((item) => [label, item]) : [label, null];
|
||||
@@ -39,7 +39,7 @@ function renderbox(ifc, ipv6) {
|
||||
_('Gateway'), ipv6 ? (ifc.getGateway6Addr() || '::') : (ifc.getGatewayAddr() || '0.0.0.0'),
|
||||
...addEntries(_('DNS'), dnssrv),
|
||||
_('Expires'), (expires != null && expires > -1) ? '%t'.format(expires) : null,
|
||||
_('Connected'), (uptime > 0) ? '%t'.format(uptime) : null
|
||||
_('Connected'), (uptime > 0) ? '%t'.format(uptime) : null,
|
||||
]),
|
||||
E('div', {}, renderBadge(
|
||||
L.resource('icons/%s.svg').format(dev ? dev.getType() : 'ethernet_disabled'), null,
|
||||
@@ -53,43 +53,39 @@ function renderbox(ifc, ipv6) {
|
||||
return baseclass.extend({
|
||||
title: _('Network'),
|
||||
|
||||
load: function() {
|
||||
load() {
|
||||
return Promise.all([
|
||||
fs.trimmed('/proc/sys/net/netfilter/nf_conntrack_count'),
|
||||
fs.trimmed('/proc/sys/net/netfilter/nf_conntrack_max'),
|
||||
network.getWANNetworks(),
|
||||
network.getWAN6Networks()
|
||||
network.getWAN6Networks(),
|
||||
]);
|
||||
},
|
||||
|
||||
render: function(data) {
|
||||
var ct_count = +data[0],
|
||||
ct_max = +data[1],
|
||||
wan_nets = data[2],
|
||||
wan6_nets = data[3];
|
||||
render([ct_count, ct_max, wan_nets, wan6_nets]) {
|
||||
|
||||
var fields = [
|
||||
_('Active Connections'), ct_max ? ct_count : null
|
||||
const fields = [
|
||||
{ label: _('Active Connections'), value: ct_max ? ct_count : null }
|
||||
];
|
||||
|
||||
var ctstatus = E('table', { 'class': 'table' });
|
||||
const ctstatus = E('table', { 'class': 'table' });
|
||||
|
||||
for (var i = 0; i < fields.length; i += 2) {
|
||||
for (const { label, value } of fields) {
|
||||
ctstatus.appendChild(E('tr', { 'class': 'tr' }, [
|
||||
E('td', { 'class': 'td left', 'width': '33%' }, [ fields[i] ]),
|
||||
E('td', { 'class': 'td left', 'width': '33%' }, [ label ]),
|
||||
E('td', { 'class': 'td left' }, [
|
||||
(fields[i + 1] != null) ? progressbar(fields[i + 1], ct_max) : '?'
|
||||
(value != null) ? progressbar(value, ct_max) : '?'
|
||||
])
|
||||
]));
|
||||
}
|
||||
|
||||
var netstatus = E('div', { 'class': 'network-status-table' });
|
||||
const netstatus = E('div', { 'class': 'network-status-table' });
|
||||
|
||||
for (var i = 0; i < wan_nets.length; i++)
|
||||
netstatus.appendChild(renderbox(wan_nets[i], false));
|
||||
for (const wan_net of wan_nets)
|
||||
netstatus.appendChild(renderbox(wan_net, false));
|
||||
|
||||
for (var i = 0; i < wan6_nets.length; i++)
|
||||
netstatus.appendChild(renderbox(wan6_nets[i], true));
|
||||
for (const wan6_net of wan6_nets)
|
||||
netstatus.appendChild(renderbox(wan6_net, true));
|
||||
|
||||
return E([
|
||||
netstatus,
|
||||
|
||||
Reference in New Issue
Block a user