Files
measurement/measurement.js

40 lines
1.8 KiB
JavaScript
Raw Normal View History

2025-06-25 10:43:15 +02:00
const nameOfNode = 'measurement'; // this is the name of the node, it should match the file name and the node type in Node-RED
const nodeClass = require('./src/nodeClass.js'); // this is the specific node class
2025-06-23 13:23:51 +02:00
const { MenuManager, configManager } = require('generalFunctions');
2025-06-25 10:43:15 +02:00
// This is the main entry point for the Node-RED node, it will register the node and setup the endpoints
2025-06-23 13:23:51 +02:00
module.exports = function(RED) {
// Register the node type
RED.nodes.registerType(nameOfNode, function(config) {
// Initialize the Node-RED node first
2025-05-14 10:31:50 +02:00
RED.nodes.createNode(this, config);
2025-06-23 13:23:51 +02:00
// Then create your custom class and attach it
2025-06-25 17:25:13 +02:00
this.nodeClass = new nodeClass(config, RED, this, nameOfNode);
2025-06-23 13:23:51 +02:00
});
2025-05-14 10:31:50 +02:00
2025-06-23 13:23:51 +02:00
// Setup admin UIs
2025-06-25 10:43:15 +02:00
const menuMgr = new MenuManager(); //this will handle the menu endpoints so we can load them dynamically
const cfgMgr = new configManager(); // this will handle the config endpoints so we can load them dynamically
2025-06-23 13:23:51 +02:00
2025-06-25 10:43:15 +02:00
// Register the different menu's for the measurement node (in the future we could automate this further by refering to the config)
2025-07-01 15:24:18 +02:00
RED.httpAdmin.get(`/${nameOfNode}/menu.js`, (req, res) => {
2025-06-23 13:23:51 +02:00
try {
2025-06-25 10:43:15 +02:00
const script = menuMgr.createEndpoint(nameOfNode, ['asset','logger','position']);
2025-06-23 13:23:51 +02:00
res.type('application/javascript').send(script);
} catch (err) {
res.status(500).send(`// Error generating menu: ${err.message}`);
2025-05-14 10:31:50 +02:00
}
});
2025-06-25 10:43:15 +02:00
// Endpoint to get the configuration data for the specific node
2025-07-01 15:24:18 +02:00
RED.httpAdmin.get(`/${nameOfNode}/configData.js`, (req, res) => {
2025-06-23 13:23:51 +02:00
try {
const script = cfgMgr.createEndpoint(nameOfNode);
// Send the configuration data as JSON response
res.type('application/javascript').send(script);
} catch (err) {
res.status(500).send(`// Error generating configData: ${err.message}`);
}
});
2025-05-14 10:31:50 +02:00
};