Autorun UI elements now match command module elements.
This commit is contained in:
@@ -1,3 +1,38 @@
|
||||
|
||||
loadModuleInfo = async function(token, moduleName) {
|
||||
let moduleId = null;
|
||||
try {
|
||||
const searchResponse = await fetch(`/api/modules/search/${moduleName}?token=${token}`);
|
||||
if (!searchResponse.ok) {
|
||||
throw new Error(`Getting auto run rules failed with status ${searchResponse.status}`);
|
||||
}
|
||||
const searchData = await searchResponse.json();
|
||||
console.log("Search data:");
|
||||
console.log(searchData);
|
||||
if (typeof searchData.id === 'number') {
|
||||
moduleId = searchData.id;
|
||||
} else {
|
||||
throw new Error("Searching module name failed.");
|
||||
}
|
||||
|
||||
// DEBUG log
|
||||
console.log(`Successfully retrieved module id for ${moduleName} = ${moduleId}`);
|
||||
|
||||
const infoResponse = await fetch(`/api/modules/${moduleId}?token=${token}`);
|
||||
const infoData = await infoResponse.json();
|
||||
if (!infoData) {
|
||||
throw new Error(`Module with name ${moduleName} and ID ${moduleId} couldn't be retrived.`);
|
||||
}
|
||||
return infoData;
|
||||
|
||||
} catch(error) {
|
||||
console.error(error);
|
||||
console.error("Failed to get module information.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Form that displays fields for a module.
|
||||
*
|
||||
@@ -9,22 +44,37 @@
|
||||
AutoRunModuleForm = function(moduleData, deleteFn, moveUp, moveDown, ruleId, index) {
|
||||
const moduleTextAreaId = `rule-${ruleId}-module-textarea-${index}`;
|
||||
const chainModeComboId = `rule-${ruleId}-module-combo-${index}`;
|
||||
const token = BeefWUI.get_rest_token();
|
||||
|
||||
// TODO: Load in modules from ruby.
|
||||
/*
|
||||
const moduleSelect = new Ext.form.ComboBox({
|
||||
fieldLabel: 'Command Module',
|
||||
store: [{name: 'hi', id: 1}],
|
||||
queryMode: 'local', // Set the queryMode to 'remote'
|
||||
displayField: 'name',
|
||||
valueField: 'id',
|
||||
editable: false, // Disable manual editing of the field
|
||||
forceSelection: true, // Force selection from the list
|
||||
//listeners: {
|
||||
// render: function (combo) {
|
||||
// combo.setValue(moduleData.name);
|
||||
// },
|
||||
// select: function(combo, newValue, oldValue) {
|
||||
// if (newValue) {
|
||||
// console.log("Combo value selected.");
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
});
|
||||
*/
|
||||
|
||||
const moduleOptionsContainer = new Ext.Panel({
|
||||
padding: '5 5 5 5',
|
||||
border: false,
|
||||
title: `${moduleData.name}`,
|
||||
padding: '10 10 10 10',
|
||||
layout: 'form',
|
||||
items: [/*{
|
||||
xtype: 'combo',
|
||||
id: chainModeComboId,
|
||||
fieldLabel: 'Chain Mode',
|
||||
store: ['moduleA', 'moduleB'], // TODO: Update this to the array of commands.
|
||||
queryMode: 'local', // Use local data.
|
||||
triggerAction: 'all', // Show both options instead of just the default.
|
||||
editable: false, // Disable manual text input.
|
||||
forceSelection: true,
|
||||
value: moduleData.name,
|
||||
},*/
|
||||
border: false,
|
||||
items: [
|
||||
{
|
||||
xtype: 'displayfield',
|
||||
fieldLabel: 'Module Name',
|
||||
@@ -35,23 +85,42 @@ AutoRunModuleForm = function(moduleData, deleteFn, moveUp, moveDown, ruleId, ind
|
||||
fieldLabel: 'Module Author',
|
||||
value: moduleData.author ? moduleData.author : 'anonymous',
|
||||
}
|
||||
]
|
||||
],
|
||||
listeners: {
|
||||
afterrender: loadModule
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
if (!moduleInfo) {
|
||||
moduleOptionsContainer.update("<p>Failed to load module information.</p>");
|
||||
return;
|
||||
}
|
||||
console.log("Module data:");
|
||||
console.log(moduleData);
|
||||
for (key in moduleData.options) {
|
||||
const value = moduleData.options[key];
|
||||
const inputField = new Ext.form.TextField({
|
||||
fieldLabel: key,
|
||||
value: value ? value : '',
|
||||
});
|
||||
moduleOptionsContainer.add(inputField);
|
||||
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++) {
|
||||
console.log(JSON.stringify(moduleInfo.options[i], null, 2));
|
||||
// TODO add real autorun module value by default.
|
||||
generate_form_input_field(
|
||||
moduleOptionsContainer,
|
||||
moduleInfo.options[i],
|
||||
null,
|
||||
false,
|
||||
{session: `${moduleInfo.name}-module-${index}-field-${i}`}
|
||||
);
|
||||
};
|
||||
moduleOptionsContainer.doLayout();
|
||||
}
|
||||
loadModule();
|
||||
|
||||
const buttonContainer = new Ext.Container({
|
||||
layout: {
|
||||
@@ -79,12 +148,12 @@ AutoRunModuleForm = function(moduleData, deleteFn, moveUp, moveDown, ruleId, ind
|
||||
|
||||
|
||||
AutoRunModuleForm.superclass.constructor.call(this, {
|
||||
padding: '10 10 10 10',
|
||||
closable: false,
|
||||
items: [
|
||||
//moduleSelect,
|
||||
moduleOptionsContainer,
|
||||
buttonContainer
|
||||
]});
|
||||
]
|
||||
});
|
||||
};
|
||||
|
||||
Ext.extend(AutoRunModuleForm, Ext.Panel, {});
|
||||
Ext.extend(AutoRunModuleForm, Ext.Container, {});
|
||||
Reference in New Issue
Block a user