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