From aaac53f9fbead2f6026d461cfb3f400226a97c0e Mon Sep 17 00:00:00 2001 From: root Date: Sat, 17 Feb 2024 18:36:48 -0500 Subject: [PATCH] Add ARE rule button for testing. Created author, name and chain_mode fields. --- .../javascript/ui/panel/AutoRunRuleForm.js | 23 ++++++++++-- .../media/javascript/ui/panel/AutoRunTab.js | 36 ++++++++++++++++++- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/extensions/admin_ui/media/javascript/ui/panel/AutoRunRuleForm.js b/extensions/admin_ui/media/javascript/ui/panel/AutoRunRuleForm.js index 3ba7080c1..bcfc7af04 100644 --- a/extensions/admin_ui/media/javascript/ui/panel/AutoRunRuleForm.js +++ b/extensions/admin_ui/media/javascript/ui/panel/AutoRunRuleForm.js @@ -6,7 +6,7 @@ * deleteFn: callback function to delete this rule. * updateFn: callback function to update this rule. */ -AutoRunRuleForm = function(rule, deleteFn, updateFn) { +AutoRunRuleForm = function(rule, deleteFn, updateFn, addFn) { AutoRunRuleForm.superclass.constructor.call(this, { padding:'10 10 10 10', @@ -14,13 +14,32 @@ AutoRunRuleForm = function(rule, deleteFn, updateFn) { xtype: 'textfield', value: rule.name ? rule.name : '', fieldLabel: 'Name', - }], + }, + { + xtype: 'displayfield', + fieldLabel: 'Author', + value: rule.author ? rule.author : 'anonymous', + },{ + xtype: 'combo', + fieldLabel: 'Chain Mode', + store: ['sequential', 'nested-forward'], + queryMode: 'local', // Use local data. + triggerAction: 'all', // Show both options instead of just the default. + editable: false, // Disable manual text input. + forceSelection: true, + value: rule.chain_mode ? rule.chain_mode : 'sequential' + } + ], buttons: [{ text: 'Delete', handler: deleteFn }, { text: 'Save', handler: updateFn + }, + { + text: 'Add New', + handler: addFn }], border: false, closable: false diff --git a/extensions/admin_ui/media/javascript/ui/panel/AutoRunTab.js b/extensions/admin_ui/media/javascript/ui/panel/AutoRunTab.js index 9c29e1a9b..05649aa45 100644 --- a/extensions/admin_ui/media/javascript/ui/panel/AutoRunTab.js +++ b/extensions/admin_ui/media/javascript/ui/panel/AutoRunTab.js @@ -1,3 +1,21 @@ +const areNotification = { + "name": "Display an alert", + "author": "mgeeky", + "modules": [ + { + "name": "alert_dialog", + "condition": null, + "options": { + "text":"You've been BeEFed ;>" + } + } + ], + "execution_order": [0], + "execution_delay": [0], + "chain_mode": "nested-forward" +}; + + /** * Asynchronously returns the currently active rules in an array. @@ -48,6 +66,17 @@ AutoRunTab = function() { } }); + async function addRule() { + const res = fetch(`/api/autorun/rule/add?token=${token}`, { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify(areNotification) + }); + if (!res.ok) { + console.error(`Failed when adding a new rule with status ${res.status}.`); + } + } + async function updateRules() { const rules = await getCurrentRules(token); if (rules !== null) { @@ -55,7 +84,12 @@ AutoRunTab = function() { container.update(`

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

`); for (let i = 0; i < rules.length; i++) { - ruleForm = new AutoRunRuleForm(rules[i], function() {console.log('delete')}, function() {console.log('update')}); + ruleForm = new AutoRunRuleForm( + rules[i], + function() {console.log('delete')}, + function() {console.log('update')}, + addRule + ); container.add(ruleForm); } container.doLayout();