diff options
author | Sergey Ponomarev <stokito@gmail.com> | 2024-02-01 23:41:10 +0200 |
---|---|---|
committer | Paul Donald <itsascambutmailmeanyway@gmail.com> | 2024-02-07 15:47:10 +0100 |
commit | a5dfb9604c1b9eb7ac220ae83dc0478b0e3a58f0 (patch) | |
tree | 6fa508686780dc6e1937089218772c4ec9f83962 /applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/config.js | |
parent | b8a4328fcfa77621258d210dffc091353fcb1989 (diff) |
luci-app-cloudflared: simplify service status render
Instead of using poll use the o.cfgvalue to render a status.
Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Diffstat (limited to 'applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/config.js')
-rw-r--r-- | applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/config.js | 36 |
1 files changed, 10 insertions, 26 deletions
diff --git a/applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/config.js b/applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/config.js index d473a2536d..241ed6486a 100644 --- a/applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/config.js +++ b/applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/config.js @@ -5,9 +5,7 @@ 'use strict'; 'require form'; -'require poll'; 'require rpc'; -'require uci'; 'require view'; var callServiceList = rpc.declare({ @@ -27,26 +25,15 @@ function getServiceStatus() { }); } -function renderStatus(isRunning) { - var spanTemp = '<label class="cbi-value-title">Status</label><div class="cbi-value-field"><em><span style="color:%s">%s</span></em></div>'; - var renderHTML; - if (isRunning) { - renderHTML = String.format(spanTemp, 'green', _('Running')); - } else { - renderHTML = String.format(spanTemp, 'red', _('Not Running')); - } - - return renderHTML; -} - return view.extend({ load: function () { return Promise.all([ - uci.load('cloudflared') + getServiceStatus() ]); }, render: function (data) { + let isRunning = data[0]; var m, s, o; m = new form.Map('cloudflared', _('Cloudflare Zero Trust Tunnel'), @@ -59,18 +46,15 @@ return view.extend({ s = m.section(form.NamedSection, 'config', 'cloudflared'); - o = s.option(form.DummyValue, 'service_status', _('Status')); - o.load = function () { - poll.add(function () { - return L.resolveDefault(getServiceStatus()).then(function (res) { - var view = document.getElementById('cbi-cloudflared-config-service_status'); - if (view) { - view.innerHTML = renderStatus(res); - } - }); - }); + o = s.option(form.DummyValue, '_status', _('Status')); + o.rawhtml = true; + o.cfgvalue = function(section_id) { + var span = '<b><span style="color:%s">%s</span></b>'; + var renderHTML = isRunning ? + String.format(span, 'green', _('Running')) : + String.format(span, 'red', _('Not Running')); + return renderHTML; }; - o.value = _('Collecting data...'); o = s.option(form.Flag, 'enabled', _('Enable')); o.rmempty = false; |