From e5ba594d77eed77d31d4b9b8c0e86026eb5a5fac Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 25 Jun 2018 09:01:33 +0200 Subject: luci-base, luci-mod-admin-full: unify wifi assoclist code Merge the assoclist code of the status overview and wireless overview pages into a single shared partial template. Signed-off-by: Jo-Philipp Wich --- .../luasrc/view/admin_network/wifi_assoclist.htm | 84 ++++++++++++ .../luasrc/view/admin_network/wifi_overview.htm | 150 ++++----------------- .../luasrc/view/admin_status/index.htm | 109 +-------------- 3 files changed, 113 insertions(+), 230 deletions(-) create mode 100644 modules/luci-mod-admin-full/luasrc/view/admin_network/wifi_assoclist.htm (limited to 'modules/luci-mod-admin-full/luasrc/view') diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_network/wifi_assoclist.htm b/modules/luci-mod-admin-full/luasrc/view/admin_network/wifi_assoclist.htm new file mode 100644 index 000000000..f3e2313ee --- /dev/null +++ b/modules/luci-mod-admin-full/luasrc/view/admin_network/wifi_assoclist.htm @@ -0,0 +1,84 @@ + + +
+
+
+
<%:Network%>
+
<%:MAC-Address%>
+
<%:Host%>
+
<%:Signal%> / <%:Noise%>
+
<%:RX Rate%> / <%:TX Rate%>
+
+
+
<%:Collecting data...%>
+
+
+
diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_network/wifi_overview.htm b/modules/luci-mod-admin-full/luasrc/view/admin_network/wifi_overview.htm index 8cea5e7ea..b9602785f 100644 --- a/modules/luci-mod-admin-full/luasrc/view/admin_network/wifi_overview.htm +++ b/modules/luci-mod-admin-full/luasrc/view/admin_network/wifi_overview.htm @@ -113,28 +113,6 @@ var is_reconnecting = false; - function nowrap(s) { - return s.replace(/ /g, ' '); - } - - function wifirate(bss, rx) { - var p = rx ? 'rx_' : 'tx_', - s = '%.1f <%:Mbit/s%>, %d<%:MHz%>' - .format(bss[p+'rate'] / 1000, bss[p+'mhz']), - ht = bss[p+'ht'], vht = bss[p+'vht'], - mhz = bss[p+'mhz'], nss = bss[p+'nss'], - mcs = bss[p+'mcs'], sgi = bss[p+'short_gi']; - - if (ht || vht) { - if (vht) s += ', VHT-MCS %d'.format(mcs); - if (nss) s += ', VHT-NSS %d'.format(nss); - if (ht) s += ', MCS %s'.format(mcs); - if (sgi) s += ', <%:Short GI%>'; - } - - return s; - } - function wifi_shutdown(id, toggle) { var reconnect = (toggle.getAttribute('active') == 'false'); @@ -193,20 +171,25 @@ { if (st) { - var assoctable = document.getElementById('iw-assoclist'); - if (assoctable) - while (assoctable.firstElementChild !== assoctable.lastElementChild) - assoctable.removeChild(assoctable.lastElementChild); - - var devup = { }; var rowstyle = 1; + var radiostate = { }; + + st.forEach(function(s) { + var r = radiostate[wifidevs[s.id]] || (radiostate[wifidevs[s.id]] = {}); + + s.is_assoc = (s.bssid && s.bssid != '00:00:00:00:00:00' && s.channel && s.mode != 'Unknown' && !s.disabled); + + r.up = r.up || s.is_assoc; + r.channel = r.channel || s.channel; + r.bitrate = r.bitrate || s.bitrate; + r.frequency = r.frequency || s.frequency; + }); for( var i = 0; i < st.length; i++ ) { var iw = st[i]; - var is_assoc = (iw.bssid && iw.bssid != '00:00:00:00:00:00' && iw.channel && iw.mode != 'Unknown' && !iw.disabled); var p = iw.quality; - var q = is_assoc ? p : -1; + var q = iw.is_assoc ? p : -1; var icon; if (q < 0) @@ -222,9 +205,6 @@ else icon = "<%=resource%>/icons/signal-75-100.png"; - if (!devup[wifidevs[iw.id]]) - devup[wifidevs[iw.id]] = is_assoc; - var sig = document.getElementById(iw.id + '-iw-signal'); if (sig) sig.innerHTML = String.format( @@ -254,7 +234,7 @@ var info = document.getElementById(iw.id + '-iw-status'); if (info) { - if (is_assoc) + if (iw.is_assoc) info.innerHTML = String.format( '<%:SSID%>: %h | ' + '<%:Mode%>: %s
' + @@ -274,83 +254,23 @@ : '<%:Wireless is disabled or not associated%>' ); } - - var dev = document.getElementById(wifidevs[iw.id] + '-iw-devinfo'); - if (dev) - { - if (is_assoc) - dev.innerHTML = String.format( - '<%:Channel%>: %s (%s <%:GHz%>) | ' + - '<%:Bitrate%>: %s <%:Mbit/s%>', - iw.channel ? iw.channel : '?', - iw.frequency ? iw.frequency : '?', - iw.bitrate ? iw.bitrate : '?' - ); - else - dev.innerHTML = ''; - } - - if (assoctable) - { - var assoclist = [ ]; - for (var bssid in iw.assoclist) - { - assoclist.push(iw.assoclist[bssid]); - assoclist[assoclist.length-1].bssid = bssid; - } - - assoclist.sort(function(a, b) { a.bssid < b.bssid }); - - for (var j = 0; j < assoclist.length; j++) - { - var icon; - var q = (-1 * (assoclist[j].noise - assoclist[j].signal)) / 5; - if (q < 1) - icon = "<%=resource%>/icons/signal-0.png"; - else if (q < 2) - icon = "<%=resource%>/icons/signal-0-25.png"; - else if (q < 3) - icon = "<%=resource%>/icons/signal-25-50.png"; - else if (q < 4) - icon = "<%=resource%>/icons/signal-50-75.png"; - else - icon = "<%=resource%>/icons/signal-75-100.png"; - - var host = hosts[assoclist[j].bssid], - name = host ? (host.name || host.ipv4 || host.ipv6) : null, - hint = (host && host.name && (host.ipv4 || host.ipv6)) ? (host.ipv4 || host.ipv6) : null; - - assoctable.appendChild(E('
'.format(rowstyle), [ - E('
%h
' - .format(iw.device.name, iw.ifname)), - E('
%h
' - .format(iw.ssid || '?')), - E('
%h
' - .format(assoclist[j].bssid)), - E('
', hint ? '
%h (%h)
' - .format(name || '?', hint) : (name || '?')), - E('
%d / %d <%:dBm%>
' - .format(assoclist[j].signal, assoclist[j].noise, assoclist[j].signal - assoclist[j].noise, icon, assoclist[j].signal, assoclist[j].noise)), - E('
', [ - E('', wifirate(assoclist[j], true)), - E('
'), - E('', wifirate(assoclist[j], false)) - ]) - ])); - - rowstyle = (rowstyle == 1) ? 2 : 1; - } - } } - if (assoctable && assoctable.firstElementChild === assoctable.lastElementChild) - assoctable.appendChild(E('

<%:No information available%>
')); - - for (var dev in devup) + for (var dev in radiostate) { var img = document.getElementById(dev + '-iw-upstate'); if (img) - img.src = '<%=resource%>/icons/wifi' + (devup[dev] ? '' : '_disabled') + '.png'; + img.src = '<%=resource%>/icons/wifi' + (radiostate[dev].up ? '' : '_disabled') + '.png'; + + var stat = document.getElementById(dev + '-iw-devinfo'); + if (stat) + stat.innerHTML = String.format( + '<%:Channel%>: %s (%s <%:GHz%>) | ' + + '<%:Bitrate%>: %s <%:Mbit/s%>', + radiostate[dev].channel ? radiostate[dev].channel : '?', + radiostate[dev].frequency ? radiostate[dev].frequency : '?', + radiostate[dev].bitrate ? radiostate[dev].bitrate : '?' + ); } } } @@ -428,23 +348,7 @@

<%:Associated Stations%>

-
-
-
-
<%:Interface%>
-
<%:SSID%>
-
<%:MAC-Address%>
-
<%:Host%>
-
<%:Signal%> / <%:Noise%>
-
<%:RX Rate%> / <%:TX Rate%>
-
-
-
- <%:Collecting data...%> -
-
-
-
+ <%+admin_network/wifi_assoclist%>
<%+footer%> diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm b/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm index 7c4a5bfc9..6083a8a2c 100644 --- a/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm +++ b/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm @@ -140,24 +140,6 @@ ); } - function wifirate(bss, rx) { - var p = rx ? 'rx_' : 'tx_', - s = '%.1f <%:Mbit/s%>, %d<%:MHz%>' - .format(bss[p+'rate'] / 1000, bss[p+'mhz']), - ht = bss[p+'ht'], vht = bss[p+'vht'], - mhz = bss[p+'mhz'], nss = bss[p+'nss'], - mcs = bss[p+'mcs'], sgi = bss[p+'short_gi']; - - if (ht || vht) { - if (vht) s += ', VHT-MCS %d'.format(mcs); - if (nss) s += ', VHT-NSS %d'.format(nss); - if (ht) s += ', MCS %s'.format(mcs); - if (sgi) s += ', <%:Short GI%>'; - } - - return s; - } - function duid2mac(duid) { // DUID-LLT / Ethernet if (duid.length === 28 && duid.substr(0, 8) === '00010001') @@ -402,8 +384,6 @@ <% end %> <% if has_wifi then %> - var assoclist = [ ]; - var ws = document.getElementById('wifi_status_table'); if (ws) { @@ -420,21 +400,6 @@ { var net = dev.networks[nidx]; var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel && !net.disabled); - var num_assoc = 0; - - for (var bssid in net.assoclist) - { - var bss = net.assoclist[bssid]; - - bss.bssid = bssid; - bss.link = net.link; - bss.name = net.name; - bss.ifname = net.ifname; - bss.radio = dev.name; - - assoclist.push(bss); - num_assoc++; - } var icon; if (!is_assoc) @@ -457,7 +422,7 @@ '<%:Mode%>', net.mode, '<%:BSSID%>', is_assoc ? (net.bssid || '-') : null, '<%:Encryption%>', is_assoc ? net.encryption : null, - '<%:Associations%>', is_assoc ? (num_assoc || '-') : null, + '<%:Associations%>', is_assoc ? (net.num_assoc || '-') : null, null, is_assoc ? null : E('em', '<%:Wireless is disabled or not associated%>'))); } @@ -472,63 +437,6 @@ if (!ws.lastElementChild) ws.appendChild(E('<%:No information available%>')); } - - var ac = document.getElementById('wifi_assoc_table'); - if (ac) - { - var rows = []; - - assoclist.sort(function(a, b) { - return (a.name == b.name) - ? (a.bssid < b.bssid) - : (a.name > b.name ) - ; - }); - - for (var i = 0; i < assoclist.length; i++) - { - var icon; - var q = (-1 * (assoclist[i].noise - assoclist[i].signal)) / 5; - if (q < 1) - icon = "<%=resource%>/icons/signal-0.png"; - else if (q < 2) - icon = "<%=resource%>/icons/signal-0-25.png"; - else if (q < 3) - icon = "<%=resource%>/icons/signal-25-50.png"; - else if (q < 4) - icon = "<%=resource%>/icons/signal-50-75.png"; - else - icon = "<%=resource%>/icons/signal-75-100.png"; - - var host = hosts[assoclist[i].bssid], - name = host ? (host.name || host.ipv4 || host.ipv6) : null, - hint = (host && host.name && (host.ipv4 || host.ipv6)) ? (host.ipv4 || host.ipv6) : null; - - rows.push([ - ' %h (%h)'.format( - assoclist[i].radio, - assoclist[i].link, - assoclist[i].name, - assoclist[i].ifname), - assoclist[i].bssid, - hint ? '%h (%h)'.format(name || '?', hint) : (name || '?'), - ' %d / %d <%:dBm%>'.format( - assoclist[i].signal, - assoclist[i].noise, - assoclist[i].signal - assoclist[i].noise, - icon, - assoclist[i].signal, - assoclist[i].noise), - E('span', {}, [ - E('span', wifirate(assoclist[i], true)), - E('br'), - E('span', wifirate(assoclist[i], false)) - ]) - ]); - } - - cbi_update_table(ac, rows, '<%:No information available%>'); - } <% end %> var e; @@ -709,20 +617,7 @@

<%:Associated Stations%>

-
-
-
-
<%:Network%>
-
<%:MAC-Address%>
-
<%:Host%>
-
<%:Signal%> / <%:Noise%>
-
<%:RX Rate%> / <%:TX Rate%>
-
-
-

<%:Collecting data...%>
-
-
-
+ <%+admin_network/wifi_assoclist%>
<% end %> -- cgit v1.2.3