menu fixes with min lines of code and standard menus - WORKING-

This commit is contained in:
znetsixe
2025-06-20 17:14:22 +02:00
parent c4f16fb36d
commit 6f63415698
4 changed files with 54 additions and 133 deletions

View File

@@ -1,11 +1,10 @@
console.log('Loading measurement.js module...');
// load helper modules from the generalFunctions folder
const { outputUtils } = require('generalFunctions');
const { outputUtils, MenuManager } = require('generalFunctions');
//internal node-red node dependencies this is the class that will handle the measurement
const Measurement = require("./dependencies/measurement/measurement");
const { menuUtils } = require('generalFunctions');
console.log('All dependencies loaded successfully');
console.log(menuUtils);
module.exports = function (RED) {
function measurement(config) {
@@ -151,9 +150,21 @@ module.exports = function (RED) {
RED.nodes.registerType("measurement", measurement);
// Create a new instance of MenuUtils for use in the html browser
let menuUtil = new menuUtils();
// Create the endpoint with one line!
menuUtil.createMenuUtilsEndpoint(RED, 'measurement', menuUtils);
const menuManager = new MenuManager();
RED.httpAdmin.get("/measurement/menu.js", (req, res) => {
try {
const script = menuManager.createEndpoint('measurement', ['asset']);
res.set('Content-Type', 'application/javascript').send(script);
} catch (error) {
console.error("Error creating measurement menu script:", error);
res.status(500).send(`// Failed to generate menu data: ${error.message}`);
}
});
console.log('Measurement node and its menu data endpoint are registered.');
};