Module combobox provided. change handler not implemented yet.

This commit is contained in:
root
2024-02-28 00:38:18 -05:00
parent a47a35e7bc
commit fd4c4c1af5
2 changed files with 31 additions and 26 deletions

View File

@@ -7,22 +7,19 @@ loadModuleInfo = async function(token, moduleName) {
throw new Error(`Getting auto run rules failed with status ${searchResponse.status}`); throw new Error(`Getting auto run rules failed with status ${searchResponse.status}`);
} }
const searchData = await searchResponse.json(); const searchData = await searchResponse.json();
console.log("Search data:");
console.log(searchData);
if (typeof searchData.id === 'number') { if (typeof searchData.id === 'number') {
moduleId = searchData.id; moduleId = searchData.id;
} else { } else {
throw new Error("Searching module name failed."); 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 infoResponse = await fetch(`/api/modules/${moduleId}?token=${token}`);
const infoData = await infoResponse.json(); const infoData = await infoResponse.json();
if (!infoData) { if (!infoData) {
throw new Error(`Module with name ${moduleName} and ID ${moduleId} couldn't be retrived.`); throw new Error(`Module with name ${moduleName} and ID ${moduleId} couldn't be retrived.`);
} }
// Set the module Id incase we need it later.
infoData.id = moduleId;
return infoData; return infoData;
} catch(error) { } catch(error) {
@@ -41,36 +38,40 @@ loadModuleInfo = async function(token, moduleName) {
* moveUp: moves the module up one spot in the Auto Run execution order. * moveUp: moves the module up one spot in the Auto Run execution order.
* moveDown: moves the module down one spot in the Auto Run exection order. * moveDown: moves the module down one spot in the Auto Run exection order.
*/ */
AutoRunModuleForm = function(moduleData, deleteFn, moveUp, moveDown, ruleId, index) { AutoRunModuleForm = function(moduleData, deleteFn, moveUp, moveDown, ruleId, index, moduleList) {
const moduleTextAreaId = `rule-${ruleId}-module-textarea-${index}`; const moduleTextAreaId = `rule-${ruleId}-module-textarea-${index}`;
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: Change the module. const comboStore = new Ext.data.Store({
/* data: moduleList,
reader: new Ext.data.JsonReader({
fields: ['id', 'name'],
}),
proxy: new Ext.data.MemoryProxy(moduleList)
});
const moduleSelect = new Ext.form.ComboBox({ const moduleSelect = new Ext.form.ComboBox({
fieldLabel: 'Command Module', fieldLabel: 'Change Module',
store: [{name: 'hi', id: 1}], store: comboStore,
queryMode: 'local', // Set the queryMode to 'remote' queryMode: 'local',
displayField: 'name', displayField: 'name',
valueField: 'id', valueField: 'id',
editable: false, // Disable manual editing of the field editable: false, // Disable manual editing of the field
forceSelection: true, // Force selection from the list forceSelection: true, // Force selection from the list
//listeners: { triggerAction: 'all',
// render: function (combo) { typeAhead: true,
// combo.setValue(moduleData.name); listeners: {
// }, select: function(combo, newValue, oldValue) {
// select: function(combo, newValue, oldValue) { if (newValue) {
// if (newValue) { console.log(`Combo value selected ${newValue.name}.`);
// console.log("Combo value selected."); }
// } }
// } }
//}
}); });
*/
const moduleOptionsContainer = new Ext.Panel({ const moduleOptionsContainer = new Ext.Panel({
title: `${moduleData.name}`, title: moduleData.name,
padding: '10 10 10 10', padding: '10 10 10 10',
layout: 'form', layout: 'form',
border: false, border: false,
@@ -98,6 +99,10 @@ AutoRunModuleForm = function(moduleData, deleteFn, moveUp, moveDown, ruleId, ind
return; return;
} }
// Update the combobox default value to be this module.
// Can't use the moduleData name since it doesn't match the ID.
moduleSelect.setValue(moduleInfo.id);
for (let i = 0; i < moduleInfo.options.length; i++) { for (let i = 0; i < moduleInfo.options.length; i++) {
const inputField = generate_form_input_field( const inputField = generate_form_input_field(
moduleOptionsContainer, moduleOptionsContainer,
@@ -144,7 +149,7 @@ AutoRunModuleForm = function(moduleData, deleteFn, moveUp, moveDown, ruleId, ind
AutoRunModuleForm.superclass.constructor.call(this, { AutoRunModuleForm.superclass.constructor.call(this, {
items: [ items: [
//moduleSelect, moduleSelect,
moduleOptionsContainer, moduleOptionsContainer,
buttonContainer buttonContainer
] ]

View File

@@ -87,13 +87,13 @@ AutoRunRuleForm = function(rule, modules, deleteFn, updateFn) {
isFirstModule ? undefined : function() {reorderModule(i, 'forward')}, isFirstModule ? undefined : function() {reorderModule(i, 'forward')},
isLastModule ? undefined : function() {reorderModule(i, 'back')}, isLastModule ? undefined : function() {reorderModule(i, 'back')},
rule.id, rule.id,
i i,
modules
)); ));
} }
} }
function handleUpdateRule() { function handleUpdateRule() {
// TODO: Check if inputs are valid.
// TODO: Need to overwrite module order. // TODO: Need to overwrite module order.
const form = self.getForm(); const form = self.getForm();
const formValues = form.getValues(); const formValues = form.getValues();