Edit Autorun rules in UI with dynamic input fields for modules.

This commit is contained in:
root
2024-02-26 00:35:12 -05:00
parent e25529a76b
commit a47a35e7bc
3 changed files with 13 additions and 17 deletions

View File

@@ -46,7 +46,7 @@ AutoRunModuleForm = function(moduleData, deleteFn, moveUp, moveDown, ruleId, ind
const chainModeComboId = `rule-${ruleId}-module-combo-${index}`; const chainModeComboId = `rule-${ruleId}-module-combo-${index}`;
const token = BeefWUI.get_rest_token(); const token = BeefWUI.get_rest_token();
// TODO: Load in modules from ruby. // TODO: Change the module.
/* /*
const moduleSelect = new Ext.form.ComboBox({ const moduleSelect = new Ext.form.ComboBox({
fieldLabel: 'Command Module', fieldLabel: 'Command Module',
@@ -84,40 +84,35 @@ AutoRunModuleForm = function(moduleData, deleteFn, moveUp, moveDown, ruleId, ind
xtype: 'displayfield', xtype: 'displayfield',
fieldLabel: 'Module Author', fieldLabel: 'Module Author',
value: moduleData.author ? moduleData.author : 'anonymous', value: moduleData.author ? moduleData.author : 'anonymous',
} },
], ],
listeners: { listeners: {
afterrender: loadModule afterrender: loadModule
} }
}); });
async function loadModule() { async function loadModule() {
// TODO: Need to query module option types so that not everything is given a textfield.
const moduleInfo = await loadModuleInfo(token, moduleData.name); const moduleInfo = await loadModuleInfo(token, moduleData.name);
if (!moduleInfo) { if (!moduleInfo) {
moduleOptionsContainer.update("<p>Failed to load module information.</p>"); moduleOptionsContainer.update("<p>Failed to load module information.</p>");
return; return;
} }
console.log("Module data:");
console.log(moduleData);
console.log("Module info:");
console.log(JSON.stringify(moduleInfo, null, 2));
console.log("Module options, should be an array:");
console.log(moduleInfo.options);
//genNewAutoRunModulePanel(moduleOptionsContainer, moduleInfo, ruleId);
for (let i = 0; i < moduleInfo.options.length; i++) { for (let i = 0; i < moduleInfo.options.length; i++) {
console.log(JSON.stringify(moduleInfo.options[i], null, 2)); const inputField = generate_form_input_field(
// TODO add real autorun module value by default.
generate_form_input_field(
moduleOptionsContainer, moduleOptionsContainer,
moduleInfo.options[i], moduleInfo.options[i],
null, moduleData.options[moduleInfo.options[i].name],
false, false,
{session: `${moduleInfo.name}-module-${index}-field-${i}`} {session: `${moduleInfo.name}-module-${index}-field-${i}`}
); );
// Ensure any changes to the element are reflected in the newRule object.
// When the user saves the rule the whole newRule object will be saved,
// including any changes made to these input fields.
inputField.on('change', function(_inputF, newValue, oldValue) {
moduleData.options[moduleInfo.options[i].name] = newValue;
});
}; };
moduleOptionsContainer.doLayout(); moduleOptionsContainer.doLayout();
} }

View File

@@ -29,6 +29,7 @@ AutoRunRuleForm = function(rule, modules, deleteFn, updateFn) {
const newRule = JSON.parse(JSON.stringify(rule)); const newRule = JSON.parse(JSON.stringify(rule));
newRule.modules = JSON.parse(newRule['modules']); newRule.modules = JSON.parse(newRule['modules']);
newRule.execution_delay = JSON.parse(newRule['execution_delay']); newRule.execution_delay = JSON.parse(newRule['execution_delay']);
newRule.execution_order = JSON.parse(newRule['execution_order']);
const moduleContainer = new Ext.Container({ const moduleContainer = new Ext.Container({
style: { style: {
padding: '10 10 10 10', padding: '10 10 10 10',

View File

@@ -110,7 +110,7 @@ function generate_form_input_field(form, input, value, disabled, zombie) {
console.log("Before adding input field to form values input field."); console.log("Before adding input field to form values input field.");
form.add(input_field); form.add(input_field);
return input_field;
}; };
function get_dynamic_payload_details(payload, zombie) { function get_dynamic_payload_details(payload, zombie) {