From a03ec606967434182450cdbad81d25474eb5cd51 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 22 Nov 2018 12:56:05 +0100 Subject: luci-mod-network: move wifi overview markup and JS code into external files Signed-off-by: Jo-Philipp Wich --- .../luci-static/resources/view/network/wireless.js | 93 +++++++++++++++ .../model/cbi/admin_network/wifi_overview.lua | 76 +----------- .../luasrc/view/admin_network/wifi_overview.htm | 61 ++++++++++ .../view/admin_network/wifi_overview_status.htm | 127 --------------------- 4 files changed, 157 insertions(+), 200 deletions(-) create mode 100644 modules/luci-mod-network/htdocs/luci-static/resources/view/network/wireless.js create mode 100644 modules/luci-mod-network/luasrc/view/admin_network/wifi_overview.htm delete mode 100644 modules/luci-mod-network/luasrc/view/admin_network/wifi_overview_status.htm diff --git a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/wireless.js b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/wireless.js new file mode 100644 index 000000000..bdeb23d23 --- /dev/null +++ b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/wireless.js @@ -0,0 +1,93 @@ +function wifi_delete(ev) { + if (!confirm(_('Really delete this wireless network? The deletion cannot be undone! You might lose access to this device if you are connected via this network.'))) { + ev.preventDefault(); + return false; + } + + ev.target.previousElementSibling.value = '1'; + return true; +} + +function wifi_restart(ev) { + L.halt(); + + findParent(ev.target, '.table').querySelectorAll('[data-disabled="false"]').forEach(function(s) { + L.dom.content(s, E('em', _('Wireless is restarting...'))); + }); + + L.post(L.url('admin/network/wireless_reconnect', ev.target.getAttribute('data-radio')), L.run); +} + +var networks = [ ]; + +document.querySelectorAll('[data-network]').forEach(function(n) { + networks.push(n.getAttribute('data-network')); +}); + +L.poll(5, L.url('admin/network/wireless_status', networks.join(',')), null, + function(x, st) { + if (st) { + var rowstyle = 1; + var radiostate = { }; + + st.forEach(function(s) { + var r = radiostate[s.device.device] || (radiostate[s.device.device] = {}); + + 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], + sig = document.getElementById(iw.id + '-iw-signal'), + info = document.getElementById(iw.id + '-iw-status'), + disabled = (info && info.getAttribute('data-disabled') === 'true'); + + var p = iw.quality; + var q = 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(sig, E('span', { + class: 'ifacebadge', + title: '%s %d %s / %s: %d %s'.format(_('Signal'), iw.signal, _('dBm'), _('Noise'), iw.noise, _('dBm')) + }, [ E('img', { src: icon }), ' %d%%'.format(p) ])); + + L.itemlist(info, [ + _('SSID'), '%h'.format(iw.ssid || '?'), + _('Mode'), iw.mode, + _('BSSID'), iw.is_assoc ? iw.bssid : null, + _('Encryption'), iw.is_assoc ? iw.encryption || _('None') : null, + null, iw.is_assoc ? null : E('em', disabled ? _('Wireless is disabled') : _('Wireless is not associated')) + ], [ ' | ', E('br') ]); + } + + for (var dev in radiostate) { + var img = document.getElementById(dev + '-iw-upstate'); + if (img) img.src = L.resource('icons/wifi' + (radiostate[dev].up ? '' : '_disabled') + '.png'); + + var stat = document.getElementById(dev + '-iw-devinfo'); + L.itemlist(stat, [ + _('Channel'), '%s (%s %s)'.format(radiostate[dev].channel || '?', radiostate[dev].frequency || '?', _('GHz')), + _('Bitrate'), '%s %s'.format(radiostate[dev].bitrate || '?', _('Mbit/s')) + ], ' | '); + } + } + } +); diff --git a/modules/luci-mod-network/luasrc/model/cbi/admin_network/wifi_overview.lua b/modules/luci-mod-network/luasrc/model/cbi/admin_network/wifi_overview.lua index 3bffb3502..54720d688 100644 --- a/modules/luci-mod-network/luasrc/model/cbi/admin_network/wifi_overview.lua +++ b/modules/luci-mod-network/luasrc/model/cbi/admin_network/wifi_overview.lua @@ -64,68 +64,6 @@ function guess_wifi_hw(dev) end end -local tpl_radio = tpl.Template(nil, [[ -
-
- -
-
- <%=dev:name()%> -
-
- <%=hw%>
- -
-
-
- - - -
-
-
- - - - <% if #wnets > 0 then %> - <% for i, net in ipairs(wnets) do local disabled = (dev:get("disabled") == "1" or net:get("disabled") == "1") %> -
-
- .png" /> 0% -
-
"> - <%= disabled and translate("Wireless is disabled") or translate("Collecting data...") %> -
-
-
- <% if disabled then %> - - - <% else %> - - - <% end %> - - - - - -
-
-
- <% end %> - <% else %> -
-
- <%:No network configured on this device%> -
-
- <% end %> - -
-
-]]) - m = Map("wireless", translate("Wireless Overview")) m:chain("network") @@ -147,15 +85,10 @@ end local _, dev, net for _, dev in ipairs(ntm:get_wifidevs()) do s = m:section(TypedSection) + s.template = "admin_network/wifi_overview" s.wnets = dev:get_wifinets() - - function s.render(self, sid) - tpl_radio:render({ - hw = guess_wifi_hw(dev), - dev = dev, - wnets = self.wnets - }) - end + s.dev = dev + s.hw = guess_wifi_hw(dev) function s.cfgsections(self) local _, net, sl = nil, nil, { } @@ -208,9 +141,6 @@ for _, dev in ipairs(ntm:get_wifidevs()) do end end -s = m:section(NamedSection, "__script__") -s.template = "admin_network/wifi_overview_status" - s = m:section(NamedSection, "__assoclist__") function s.render(self, sid) diff --git a/modules/luci-mod-network/luasrc/view/admin_network/wifi_overview.htm b/modules/luci-mod-network/luasrc/view/admin_network/wifi_overview.htm new file mode 100644 index 000000000..89bb404fd --- /dev/null +++ b/modules/luci-mod-network/luasrc/view/admin_network/wifi_overview.htm @@ -0,0 +1,61 @@ +
+
+ +
+
+ <%=self.dev:name()%> +
+
+ <%=self.hw%>
+ +
+
+
+ + + +
+
+
+ + + + <% if #self.wnets > 0 then %> + <% for i, net in ipairs(self.wnets) do local disabled = (self.dev:get("disabled") == "1" or net:get("disabled") == "1") %> +
+
+ .png" /> 0% +
+
"> + <%= disabled and translate("Wireless is disabled") or translate("Collecting data...") %> +
+
+
+ <% if disabled then %> + + + <% else %> + + + <% end %> + + + + + +
+
+
+ <% end %> + <% else %> +
+
+ <%:No network configured on this device%> +
+
+ <% end %> + +
+
+ + diff --git a/modules/luci-mod-network/luasrc/view/admin_network/wifi_overview_status.htm b/modules/luci-mod-network/luasrc/view/admin_network/wifi_overview_status.htm deleted file mode 100644 index 9730bc2c9..000000000 --- a/modules/luci-mod-network/luasrc/view/admin_network/wifi_overview_status.htm +++ /dev/null @@ -1,127 +0,0 @@ -<%# - Copyright 2008-2009 Steven Barth - Copyright 2008-2018 Jo-Philipp Wich - Licensed to the public under the Apache License 2.0. --%> - - -- cgit v1.2.3