luci-mod-status: transform status page Lua template into ucode template
authorJo-Philipp Wich <jo@mein.io>
Wed, 14 Sep 2022 11:30:45 +0000 (13:30 +0200)
committerJo-Philipp Wich <jo@mein.io>
Mon, 24 Oct 2022 23:03:37 +0000 (01:03 +0200)
Transform the only Lua template of the status module into an equivalent
ucode template and make it conditionally include the legacy Lua logic
factored out in a previous commit.

Only if the ucode Lua bridge is installed and loadable, the Lua template
loading the legacy Lua status partials is included.

After this commit, luci-mod-status is free of Lua dependencies.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-mod-status/luasrc/view/admin_status/index.htm [deleted file]
modules/luci-mod-status/ucode/template/admin_status/index.ut [new file with mode: 0644]

diff --git a/modules/luci-mod-status/luasrc/view/admin_status/index.htm b/modules/luci-mod-status/luasrc/view/admin_status/index.htm
deleted file mode 100644 (file)
index 7d7a42c..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-<%#
- Copyright 2008 Steven Barth <steven@midlink.org>
- Copyright 2008-2018 Jo-Philipp Wich <jo@mein.io>
- Licensed to the public under the Apache License 2.0.
--%>
-
-<%+header%>
-
-<h2 name="content"><%:Status%></h2>
-
-<div id="view">
-       <div class="spinning"><%:Loading view…%></div>
-</div>
-
-<script type="text/javascript">//<![CDATA[
-function progressbar(query, value, max, byte)
-{
-       var pg = document.querySelector(query),
-           vn = parseInt(value) || 0,
-           mn = parseInt(max) || 100,
-           fv = byte ? String.format('%1024.2mB', value) : value,
-           fm = byte ? String.format('%1024.2mB', max) : max,
-           pc = Math.floor((100 / mn) * vn);
-
-       if (pg) {
-               pg.firstElementChild.style.width = pc + '%';
-               pg.setAttribute('title', '%s / %s (%d%%)'.format(fv, fm, pc));
-       }
-}
-
-function renderBox(title, active, childs) {
-       childs = childs || [];
-       childs.unshift(L.itemlist(E('span'), [].slice.call(arguments, 3)));
-
-       return E('div', { class: 'ifacebox' }, [
-               E('div', { class: 'ifacebox-head center ' + (active ? 'active' : '') },
-                       E('strong', title)),
-               E('div', { class: 'ifacebox-body left' }, childs)
-       ]);
-}
-
-function renderBadge(icon, title) {
-       return E('span', { class: 'ifacebadge' }, [
-               E('img', { src: icon, title: title || '' }),
-               L.itemlist(E('span'), [].slice.call(arguments, 2))
-       ]);
-}
-
-//]]></script>
-
-<div class="includes" style="display:none">
-<%-
-       local util = require "luci.util"
-       local fs = require "nixio.fs"
-
-       local incdir = util.libpath() .. "/view/admin_status/index/"
-       if fs.access(incdir) then
-               local _, inc
-               local includes = {}
-               for inc in fs.dir(incdir) do
-                       if inc:match("%.htm$") then
-                               includes[#includes + 1] = inc:gsub("%.htm$", "")
-                       end
-               end
-               for _, inc in luci.util.vspairs(includes) do
-                       include("admin_status/index/" .. inc)
-               end
-       end
--%>
-</div>
-
-<script type="text/javascript">
-       L.require('ui').then(function(ui) {
-               ui.instantiateView('status/index');
-       });
-</script>
-
-<%+footer%>
diff --git a/modules/luci-mod-status/ucode/template/admin_status/index.ut b/modules/luci-mod-status/ucode/template/admin_status/index.ut
new file mode 100644 (file)
index 0000000..4d018a3
--- /dev/null
@@ -0,0 +1,69 @@
+{#
+ Copyright 2008 Steven Barth <steven@midlink.org>
+ Copyright 2008-2022 Jo-Philipp Wich <jo@mein.io>
+ Licensed to the public under the Apache License 2.0.
+-#}
+
+{% include('header') %}
+
+<h2 name="content">{{ _('Status') }}</h2>
+
+<div id="view">
+       <div class="spinning">{{ _('Loading view…') }}</div>
+</div>
+
+<script type="text/javascript">//<![CDATA[
+function progressbar(query, value, max, byte)
+{
+       var pg = document.querySelector(query),
+           vn = parseInt(value) || 0,
+           mn = parseInt(max) || 100,
+           fv = byte ? String.format('%1024.2mB', value) : value,
+           fm = byte ? String.format('%1024.2mB', max) : max,
+           pc = Math.floor((100 / mn) * vn);
+
+       if (pg) {
+               pg.firstElementChild.style.width = pc + '%';
+               pg.setAttribute('title', '%s / %s (%d%%)'.format(fv, fm, pc));
+       }
+}
+
+function renderBox(title, active, childs) {
+       childs = childs || [];
+       childs.unshift(L.itemlist(E('span'), [].slice.call(arguments, 3)));
+
+       return E('div', { class: 'ifacebox' }, [
+               E('div', { class: 'ifacebox-head center ' + (active ? 'active' : '') },
+                       E('strong', title)),
+               E('div', { class: 'ifacebox-body left' }, childs)
+       ]);
+}
+
+function renderBadge(icon, title) {
+       return E('span', { class: 'ifacebadge' }, [
+               E('img', { src: icon, title: title || '' }),
+               L.itemlist(E('span'), [].slice.call(arguments, 2))
+       ]);
+}
+
+//]]></script>
+
+<div class="includes" style="display:none">
+{%
+       let lua_available = true;
+
+       try { require('lua'); }
+       catch(err) { lua_available = false; }
+
+       if (lua_available)
+               include('admin_status/luaindex');
+%}
+</div>
+
+<script type="text/javascript">
+       L.require('ui').then(function(ui) {
+               ui.instantiateView('status/index');
+       });
+</script>
+
+{% include('footer') %}