From 4bd7f4ba429eee697fb5f75c4ece5d03cc9514f5 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 23 Nov 2018 15:47:44 +0100 Subject: luci-mod-network: move wifi and iface status JS into external files Signed-off-by: Jo-Philipp Wich --- .../resources/view/network/iface_status.js | 44 ++++++++++++++ .../resources/view/network/wifi_status.js | 59 ++++++++++++++++++ .../luasrc/view/admin_network/iface_status.htm | 62 ++----------------- .../luasrc/view/admin_network/wifi_status.htm | 71 ++-------------------- 4 files changed, 111 insertions(+), 125 deletions(-) create mode 100644 modules/luci-mod-network/htdocs/luci-static/resources/view/network/iface_status.js create mode 100644 modules/luci-mod-network/htdocs/luci-static/resources/view/network/wifi_status.js diff --git a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/iface_status.js b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/iface_status.js new file mode 100644 index 000000000..1852f179f --- /dev/null +++ b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/iface_status.js @@ -0,0 +1,44 @@ +requestAnimationFrame(function() { + document.querySelectorAll('[data-iface-status]').forEach(function(container) { + var network = container.getAttribute('data-iface-status'), + icon = container.querySelector('img'), + info = container.querySelector('span'); + + L.poll(5, L.url('admin/network/iface_status', network), null, function(xhr, ifaces) { + var ifc = Array.isArray(ifaces) ? ifaces[0] : null; + if (!ifc) { + alert('No ifc!'); + return; + } + + L.itemlist(info, [ + _('Device'), ifc.ifname, + _('Uptime'), ifc.is_up ? '%t'.format(ifc.uptime) : null, + _('MAC'), ifc.ifname ? ifc.macaddr : null, + _('RX'), ifc.ifname ? '%.2mB (%d %s)'.format(ifc.rx_bytes, ifc.rx_packets, _('Pkts.')) : null, + _('TX'), ifc.ifname ? '%.2mB (%d %s)'.format(ifc.tx_bytes, ifc.tx_packets, _('Pkts.')) : null, + _('IPv4'), ifc.ipaddrs ? ifc.ipaddrs[0] : null, + _('IPv4'), ifc.ipaddrs ? ifc.ipaddrs[1] : null, + _('IPv4'), ifc.ipaddrs ? ifc.ipaddrs[2] : null, + _('IPv4'), ifc.ipaddrs ? ifc.ipaddrs[3] : null, + _('IPv4'), ifc.ipaddrs ? ifc.ipaddrs[4] : null, + _('IPv6'), ifc.ip6addrs ? ifc.ip6addrs[0] : null, + _('IPv6'), ifc.ip6addrs ? ifc.ip6addrs[1] : null, + _('IPv6'), ifc.ip6addrs ? ifc.ip6addrs[2] : null, + _('IPv6'), ifc.ip6addrs ? ifc.ip6addrs[3] : null, + _('IPv6'), ifc.ip6addrs ? ifc.ip6addrs[4] : null, + _('IPv6'), ifc.ip6addrs ? ifc.ip6addrs[5] : null, + _('IPv6'), ifc.ip6addrs ? ifc.ip6addrs[6] : null, + _('IPv6'), ifc.ip6addrs ? ifc.ip6addrs[7] : null, + _('IPv6'), ifc.ip6addrs ? ifc.ip6addrs[8] : null, + _('IPv6'), ifc.ip6addrs ? ifc.ip6addrs[9] : null, + _('IPv6-PD'), ifc.ip6prefix, + null, ifc.ifname ? null : E('em', _('Interface not present or not connected yet.')) + ]); + + icon.src = L.resource('icons/%s%s.png').format(ifc.type, ifc.is_up ? '' : '_disabled'); + }); + + L.run(); + }); +}); diff --git a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/wifi_status.js b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/wifi_status.js new file mode 100644 index 000000000..7e14d999b --- /dev/null +++ b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/wifi_status.js @@ -0,0 +1,59 @@ +requestAnimationFrame(function() { + document.querySelectorAll('[data-wifi-status]').forEach(function(container) { + var ifname = container.getAttribute('data-wifi-status'), + small = container.querySelector('small'), + info = container.querySelector('span'); + + L.poll(5, L.url('admin/network/wireless_status', ifname), null, function(xhr, iws) { + var iw = Array.isArray(iws) ? iws[0] : null; + if (!iw) + return; + + var is_assoc = (iw.bssid && iw.bssid != '00:00:00:00:00:00' && iw.channel && !iw.disabled); + var p = iw.quality; + var q = iw.disabled ? -1 : p; + + var icon; + if (q < 0) + icon = L.resource('icons/signal-none.png'); + else if (q == 0) + icon = L.resource('icons/signal-0.png'); + else if (q < 25) + icon = L.resource('icons/signal-0-25.png'); + else if (q < 50) + icon = L.resource('icons/signal-25-50.png'); + else if (q < 75) + icon = L.resource('icons/signal-50-75.png'); + else + icon = L.resource('icons/signal-75-100.png'); + + L.dom.content(small, [ + E('img', { + src: icon, + title: '%s: %d %s / %s: %d %s'.format( + _('Signal'), iw.signal, _('dBm'), + _('Noise'), iw.noise, _('dBm')) + }), + '\u00a0', E('br'), '%d%%\u00a0'.format(p) + ]); + + L.itemlist(info, [ + _('Mode'), iw.mode, + _('SSID'), '%h'.format(iw.ssid || '?'), + _('BSSID'), is_assoc ? iw.bssid : null, + _('Encryption'), is_assoc ? iw.encryption || _('None') : null, + _('Channel'), is_assoc ? '%d (%.3f %s)'.format(iw.channel, iw.frequency || 0, _('GHz')) : null, + _('Tx-Power'), is_assoc ? '%d %s'.format(iw.txpower, _('dBm')) : null, + _('Signal'), is_assoc ? '%d %s'.format(iw.signal, _('dBm')) : null, + _('Noise'), is_assoc ? '%d %s'.format(iw.noise, _('dBm')) : null, + _('Bitrate'), is_assoc ? '%.1f %s'.format(iw.bitrate || 0, _('Mbit/s')) : null, + _('Country'), is_assoc ? iw.country : null + ], [ ' | ', E('br'), E('br'), E('br'), E('br'), E('br'), ' | ', E('br'), ' | ' ]); + + if (!is_assoc) + L.dom.append(info, E('em', iw.disabled ? _('Wireless is disabled') : _('Wireless is not associated'))); + }); + + L.run(); + }); +}); diff --git a/modules/luci-mod-network/luasrc/view/admin_network/iface_status.htm b/modules/luci-mod-network/luasrc/view/admin_network/iface_status.htm index 34be35dd2..a75b2755c 100644 --- a/modules/luci-mod-network/luasrc/view/admin_network/iface_status.htm +++ b/modules/luci-mod-network/luasrc/view/admin_network/iface_status.htm @@ -1,66 +1,12 @@ <%+cbi/valueheader%> - - - +> - <%:Collecting data...%> + <%:Collecting data...%> + + <%+cbi/valuefooter%> diff --git a/modules/luci-mod-network/luasrc/view/admin_network/wifi_status.htm b/modules/luci-mod-network/luasrc/view/admin_network/wifi_status.htm index bfad3d080..93ae2f51f 100644 --- a/modules/luci-mod-network/luasrc/view/admin_network/wifi_status.htm +++ b/modules/luci-mod-network/luasrc/view/admin_network/wifi_status.htm @@ -1,77 +1,14 @@ <%+cbi/valueheader%> - - - +>   - <%:Collecting data...%> + <%:Collecting data...%> + + <%+cbi/valuefooter%> -- cgit v1.2.3