From: Jo-Philipp Wich Date: Wed, 21 Nov 2018 20:07:34 +0000 (+0100) Subject: luci-mod-network: move interface overview JS into external file X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=f598b10c49ff5d196baea7c92a2859da70869a5f;p=oweals%2Fluci.git luci-mod-network: move interface overview JS into external file Signed-off-by: Jo-Philipp Wich --- diff --git a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/network.js b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/network.js new file mode 100644 index 000000000..acca7cf8a --- /dev/null +++ b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/network.js @@ -0,0 +1,135 @@ +function iface_reconnect(id) { + L.halt(); + L.dom.content(document.getElementById(id + '-ifc-description'), E('em', _('Interface is reconnecting...'))); + L.post(L.url('admin/network/iface_reconnect', id), L.run); +} + +function iface_delete(ev) { + if (!confirm(_('Really delete this interface? The deletion cannot be undone! You might lose access to this device if you are connected via this interface'))) { + ev.preventDefault(); + return false; + } + + ev.target.previousElementSibling.value = '1'; + return true; +} + +var networks = []; + +document.querySelectorAll('[data-network]').forEach(function(n) { + networks.push(n.getAttribute('data-network')); +}); + +function render_iface(ifc) { + return E('span', { class: 'cbi-tooltip-container' }, [ + E('img', { 'class' : 'middle', 'src': L.resource('icons/%s%s.png').format( + ifc.is_alias ? 'alias' : ifc.type, + ifc.is_up ? '' : '_disabled') }), + E('span', { 'class': 'cbi-tooltip ifacebadge large' }, [ + E('img', { 'src': L.resource('icons/%s%s.png').format( + ifc.type, ifc.is_up ? '' : '_disabled') }), + L.itemlist(E('span', { 'class': 'left' }), [ + _('Type'), ifc.typename, + _('Device'), ifc.ifname, + _('Connected'), ifc.is_up ? _('yes') : _('no'), + _('MAC'), ifc.macaddr, + _('RX'), '%.2mB (%d %s)'.format(ifc.rx_bytes, ifc.rx_packets, _('Pkts.')), + _('TX'), '%.2mB (%d %s)'.format(ifc.tx_bytes, ifc.tx_packets, _('Pkts.')) + ]) + ]) + ]); +} + +L.poll(5, L.url('admin/network/iface_status', networks.join(',')), null, + function(x, ifcs) { + if (ifcs) { + for (var idx = 0; idx < ifcs.length; idx++) { + var ifc = ifcs[idx]; + + var s = document.getElementById(ifc.id + '-ifc-devices'); + if (s) { + var c = [ render_iface(ifc) ]; + + if (ifc.subdevices && ifc.subdevices.length) + { + var sifs = [ ' (' ]; + + for (var j = 0; j < ifc.subdevices.length; j++) + sifs.push(render_iface(ifc.subdevices[j])); + + sifs.push(')'); + + c.push(E('span', {}, sifs)); + } + + c.push(E('br')); + c.push(E('small', {}, ifc.is_alias ? _('Alias of "%s"').format(ifc.is_alias) : ifc.name)); + + L.dom.content(s, c); + } + + var d = document.getElementById(ifc.id + '-ifc-description'); + if (d && ifc.proto && ifc.ifname) { + var desc = null, c = []; + + if (ifc.is_dynamic) + desc = _('Virtual dynamic interface'); + else if (ifc.is_alias) + desc = _('Alias Interface'); + + if (ifc.desc) + desc = desc ? '%s (%s)'.format(desc, ifc.desc) : ifc.desc; + + L.itemlist(d, [ + _('Protocol'), '%h'.format(desc || '?'), + _('Uptime'), ifc.is_up ? '%t'.format(ifc.uptime) : null, + _('MAC'), (!ifc.is_dynamic && !ifc.is_alias && ifc.macaddr) ? ifc.macaddr : null, + _('RX'), (!ifc.is_dynamic && !ifc.is_alias) ? '%.2mB (%d %s)'.format(ifc.rx_bytes, ifc.rx_packets, _('Pkts.')) : null, + _('TX'), (!ifc.is_dynamic && !ifc.is_alias) ? '%.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, + _('Error'), ifc.errors ? ifc.errors[0] : null, + _('Error'), ifc.errors ? ifc.errors[1] : null, + _('Error'), ifc.errors ? ifc.errors[2] : null, + _('Error'), ifc.errors ? ifc.errors[3] : null, + _('Error'), ifc.errors ? ifc.errors[4] : null, + ]); + } + else if (d && !ifc.proto) { + var e = document.getElementById(ifc.id + '-ifc-edit'); + if (e) e.disabled = true; + + var link = L.url('admin/system/packages') + '?query=luci-proto&display=available'; + L.dom.content(d, [ + E('em', _('Unsupported protocol type.')), E('br'), + E('a', { href: link }, _('Install protocol extensions...')) + ]); + } + else if (d && !ifc.ifname) { + var link = L.url('admin/network/network', ifc.name) + '?tab.network.%s=physical'.format(ifc.name); + L.dom.content(d, [ + E('em', _('Network without interfaces.')), E('br'), + E('a', { href: link }, _('Assign interfaces...')) + ]); + } + else if (d) { + L.dom.content(d, E('em' ,_('Interface not present or not connected yet.'))); + } + } + } + } +); diff --git a/modules/luci-mod-network/luasrc/model/cbi/admin_network/network.lua b/modules/luci-mod-network/luasrc/model/cbi/admin_network/network.lua index 0c0ca5263..b98086dea 100644 --- a/modules/luci-mod-network/luasrc/model/cbi/admin_network/network.lua +++ b/modules/luci-mod-network/luasrc/model/cbi/admin_network/network.lua @@ -15,59 +15,6 @@ m:chain("dhcp") m.pageaction = false -local tpl_networks = tpl.Template(nil, [[ -
-
- <% - for i, net in ipairs(netlist) do - local z = net[3] - local c = z and z:get_color() or "#EEEEEE" - local t = z and translate("Part of zone %q" % z:name()) or translate("No zone assigned") - local disabled = (net[4]:get("auto") == "0") - local dynamic = net[4]:is_dynamic() - %> -
-
-
-
- <%=net[1]:upper()%> -
-
-
- ? -
-
-
-
- <%:Collecting data...%> -
-
-
- /> - - <% if disabled then %> - - /> - <% else %> - - /> - <% end %> - - '" title="<%:Edit this interface%>" value="<%:Edit%>" id="<%=net[1]%>-ifc-edit"<%=ifattr(dynamic, "disabled", "disabled")%> /> - - - /> -
-
-
- <% end %> -
-
-
- '" /> -
-]]) - local _, net local ifaces, netlist = { }, { } @@ -102,6 +49,8 @@ table.sort(netlist, end) s = m:section(TypedSection, "interface", translate("Interface Overview")) +s.template = "admin_network/iface_overview" +s.netlist = netlist function s.cfgsections(self) local _, net, sl = nil, nil, { } @@ -113,12 +62,6 @@ function s.cfgsections(self) return sl end -function s.render(self) - tpl_networks:render({ - netlist = netlist - }) -end - o = s:option(Value, "__disable__") function o.write(self, sid, value) @@ -138,8 +81,6 @@ function o.write(self, sid, value) end -m:section(SimpleSection).template = "admin_network/iface_overview_status" - if fs.access("/etc/init.d/dsl_control") then local ok, boarddata = pcall(json.parse, fs.readfile("/etc/board.json")) local modemtype = (ok == true) diff --git a/modules/luci-mod-network/luasrc/view/admin_network/iface_overview.htm b/modules/luci-mod-network/luasrc/view/admin_network/iface_overview.htm new file mode 100644 index 000000000..4fd46e2bf --- /dev/null +++ b/modules/luci-mod-network/luasrc/view/admin_network/iface_overview.htm @@ -0,0 +1,53 @@ +
+
+ <% + for i, net in ipairs(self.netlist) do + local z = net[3] + local c = z and z:get_color() or "#EEEEEE" + local t = z and translate("Part of zone %q" % z:name()) or translate("No zone assigned") + local disabled = (net[4]:get("auto") == "0") + local dynamic = net[4]:is_dynamic() + %> +
+
+
+
+ <%=net[1]:upper()%> +
+
+
+ ? +
+
+
+
+ <%:Collecting data...%> +
+
+
+ /> + + <% if disabled then %> + + /> + <% else %> + + /> + <% end %> + + '" title="<%:Edit this interface%>" value="<%:Edit%>" id="<%=net[1]%>-ifc-edit"<%=ifattr(dynamic, "disabled", "disabled")%> /> + + + /> +
+
+
+ <% end %> +
+
+ +
+ '" /> +
+ + diff --git a/modules/luci-mod-network/luasrc/view/admin_network/iface_overview_status.htm b/modules/luci-mod-network/luasrc/view/admin_network/iface_overview_status.htm deleted file mode 100644 index 7427154a0..000000000 --- a/modules/luci-mod-network/luasrc/view/admin_network/iface_overview_status.htm +++ /dev/null @@ -1,183 +0,0 @@ -<%# - Copyright 2010-2018 Jo-Philipp Wich - Licensed to the public under the Apache License 2.0. --%> - -