From 459a99dce44427e390827fdcd965a457ce320c5f Mon Sep 17 00:00:00 2001 From: root Date: Fri, 16 Feb 2024 00:17:33 -0500 Subject: [PATCH] Query the list of ARE rules on render. Display the count. --- .../media/javascript/ui/panel/AutoRunTab.js | 65 ++++++++++++++++--- 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/extensions/admin_ui/media/javascript/ui/panel/AutoRunTab.js b/extensions/admin_ui/media/javascript/ui/panel/AutoRunTab.js index f06f44e8b..547c916ea 100644 --- a/extensions/admin_ui/media/javascript/ui/panel/AutoRunTab.js +++ b/extensions/admin_ui/media/javascript/ui/panel/AutoRunTab.js @@ -1,18 +1,67 @@ +/** + * Asynchronously returns the currently active rules in an array. + * Empty array means no rules are active. + * null if there was an error. + */ +getCurrentRules = async function(token) { + console.log(`token = ${token}`); + + try { + var res = await fetch(`/api/autorun/rule/list/all?token=${token}`) + console.log(res.body); + console.log("Successfully retrieved active rules."); + if (res.body.success === true && Array.isArray(res.body.rules)) { + console.log(res.body.rules); + return res.body.rules; + } else { + console.log("No active rules."); + return []; + } + } catch(error) { + console.error(error); + console.error("Failed to get rules."); + return null; + } +} + AutoRunTab = function() { + // RESTful API token. + var token = BeefWUI.get_rest_token(); - autoRunHtml = " \ -
\ -

My custom panel :)

\ -
\ - "; + // Setup container element. + var container = new Ext.Panel({ + style: { + font: '11px tahoma,arial,helvetica,sans-serif', + width: '500px' + }, + html: "

Loading Auto Run rules...

", + listeners: { + afterrender: updateRules + } + }); + + async function updateRules() { + const rules = await getCurrentRules(token); + if (rules !== null) { + console.log(`

Number of Auto Run rules enabled: ${rules.length}.

`); + container.update(`

Number of Auto Run rules enabled: ${rules.length}.

`); + + //ruleTitle = document.createElement('h4'); + //ruleTitle.innerHTML = "Rule title 1"; + //container.appendChild(ruleTitle); + } else { + container.update("

Failed to load Auto Run rules.

"); + } + } AutoRunTab.superclass.constructor.call(this, { - region:'center', + region: 'center', padding:'10 10 10 10', - html: autoRunHtml, + items: [container], autoScroll: true, - border: false + border: false, + closable: false }); };