From 1d9d563f8a17ff5b312aaa0db0bc02c67fcd4319 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Thu, 1 Feb 2024 23:41:10 +0200 Subject: [PATCH] luci-app-cloudflared: simplify service status render Instead of using poll use the o.cfgvalue to render a status. Signed-off-by: Sergey Ponomarev (cherry picked from commit a5dfb9604c1b9eb7ac220ae83dc0478b0e3a58f0) --- .../resources/view/cloudflared/config.js | 36 ++++++------------- 1 file 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 = '
%s
'; - 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 = '%s'; + 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; -- 2.30.2