Files
pumpingStation/pumpingStation.js

52 lines
2.2 KiB
JavaScript
Raw Normal View History

2025-10-14 08:36:45 +02:00
const nameOfNode = 'pumpingStation'; // this is the name of the node, it should match the file name and the node type in Node-RED
2025-10-07 18:05:54 +02:00
const nodeClass = require('./src/nodeClass.js'); // this is the specific node class
const { MenuManager, configManager } = require('generalFunctions');
// This is the main entry point for the Node-RED node, it will register the node and setup the endpoints
module.exports = function(RED) {
// Register the node type
RED.nodes.registerType(nameOfNode, function(config) {
// Initialize the Node-RED node first
RED.nodes.createNode(this, config);
// Then create your custom class and attach it
this.nodeClass = new nodeClass(config, RED, this, nameOfNode);
});
// Setup admin UIs
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
// Register the different menu's for the measurement node (in the future we could automate this further by refering to the config)
RED.httpAdmin.get(`/${nameOfNode}/menu.js`, (req, res) => {
try {
2025-10-14 08:36:45 +02:00
const script = menuMgr.createEndpoint(nameOfNode, ['logger','position']);
2025-10-07 18:05:54 +02:00
res.type('application/javascript').send(script);
} catch (err) {
res.status(500).send(`// Error generating menu: ${err.message}`);
}
});
// Endpoint to get the configuration data for the specific node
RED.httpAdmin.get(`/${nameOfNode}/configData.js`, (req, res) => {
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}`);
}
});
// Editor.js — extracted SVG basin-diagram + oneditprepare/oneditsave logic.
RED.httpAdmin.get(`/${nameOfNode}/editor.js`, (req, res) => {
try {
const fs = require('fs');
const path = require('path');
const script = fs.readFileSync(path.join(__dirname, 'src/editor.js'), 'utf8');
res.type('application/javascript').send(script);
} catch (err) {
res.status(500).send(`// Error loading editor.js: ${err.message}`);
}
});
2025-10-07 18:05:54 +02:00
};