diff --git a/measurement.html b/measurement.html index b2f1ce2..1f0ed73 100644 --- a/measurement.html +++ b/measurement.html @@ -9,9 +9,7 @@ defaults: { // Define default properties - name: { value: "", required: true }, - enableLog: { value: false }, - logLevel: { value: "error" }, + name: { value: "", required: true }, // use asset category as name // Define specific properties scaling: { value: false }, @@ -31,6 +29,13 @@ model: { value: "" }, unit: { value: "" }, + //logger properties + enableLog: { value: false }, + logLevel: { value: "error" }, + + //physicalAspect + physicalAspect: { value: "" }, + }, inputs: 1, @@ -54,11 +59,11 @@ // Wait for the menu data to be ready before initializing the editor waitForMenuData(); - // --------------- Initialize the dropdowns and other specific UI elements -------------- this should be derived from the config in the future (make config based menu) + // THIS IS NODE SPECIFIC --------------- Initialize the dropdowns and other specific UI elements -------------- this should be derived from the config in the future (make config based menu) // Populate smoothing methods dropdown const smoothMethodSelect = document.getElementById('node-input-smooth_method'); const options = window.EVOLV?.nodes?.measurement?.config?.smoothing?.smoothMethod?.rules?.values || []; - console.log("Smoothing methods options:", options); + // Clear existing options smoothMethodSelect.innerHTML = ''; @@ -92,8 +97,13 @@ success = window.EVOLV.nodes.measurement.assetMenu.saveEditor(this); } + // Validate logger properties using the logger menu + if (window.EVOLV?.nodes?.measurement?.loggerMenu?.saveEditor) { + success = window.EVOLV.nodes.measurement.loggerMenu.saveEditor(node); + } + // Save basic properties - ["name", "smooth_method"].forEach( + ["smooth_method"].forEach( (field) => (node[field] = document.getElementById(`node-input-${field}`).value || "") ); @@ -106,17 +116,11 @@ (field) => (node[field] = parseFloat(document.getElementById(`node-input-${field}`).value) || 0) ); - node.logLevel = document.getElementById("node-input-logLevel").value || "info"; - node.enableLog = document.getElementById("node-input-enableLog").checked; - // Validation checks if (node.scaling && (isNaN(node.i_min) || isNaN(node.i_max))) { RED.notify("Scaling enabled, but input range is incomplete!", "error"); } - - - }, }); @@ -124,48 +128,30 @@ diff --git a/measurement.js b/measurement.js index d18ce47..e1df988 100644 --- a/measurement.js +++ b/measurement.js @@ -2,10 +2,11 @@ * Thin wrapper that registers a node with Node-RED and exposes HTTP endpoints. and loads EVOLV in a standard way */ -const nodeClass = require('./src/nodeClass.js'); +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 const { MenuManager, configManager } = require('generalFunctions'); -const nameOfNode = 'measurement'; +// 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) { @@ -17,14 +18,15 @@ module.exports = function(RED) { }); // Setup admin UIs - const menuMgr = new MenuManager(); - const cfgMgr = new configManager(); + 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 console.log(`Loading endpoint for ${nameOfNode} menu...`); - // Register the menu for the measurement node + + // 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('/measurement/menu.js', (req, res) => { try { - const script = menuMgr.createEndpoint(nameOfNode, ['asset']); + const script = menuMgr.createEndpoint(nameOfNode, ['asset','logger','position']); res.type('application/javascript').send(script); } catch (err) { res.status(500).send(`// Error generating menu: ${err.message}`); @@ -32,7 +34,8 @@ module.exports = function(RED) { }); console.log(`Loading endpoint for ${nameOfNode} config...`); - // Endpoint to get the configuration data for the measurement node + + // Endpoint to get the configuration data for the specific node RED.httpAdmin.get(`/measurement/configData.js`, (req, res) => { try { const script = cfgMgr.createEndpoint(nameOfNode); diff --git a/src/nodeClass.js b/src/nodeClass.js index 819065b..cfb6205 100644 --- a/src/nodeClass.js +++ b/src/nodeClass.js @@ -48,17 +48,17 @@ class MeasurementNode { this.config = { general: { name: uiConfig.name, - id: this.id, - unit: uiConfig.unit, + id: uiConfig.id, //need to add this later use node.uuid from a single project file thats unique per location + node-red environment + node + unit: uiConfig.unit, // add converter options later to convert to default units (need like a model that defines this which units we are going to use and then conver to those standards) logging: { enabled: uiConfig.enableLog, logLevel: uiConfig.logLevel } }, asset: { - tagCode: uiConfig.assetTagCode, + tagCode: uiConfig.assetTagCode, //need to add this later to the asset model supplier: uiConfig.supplier, - category: uiConfig.category, + category: uiConfig.category, //add later to define as the software type type: uiConfig.assetType, model: uiConfig.model, unit: uiConfig.unit @@ -77,7 +77,8 @@ class MeasurementNode { }, simulation: { enabled: uiConfig.simulator - } + }, + positionVsParent: uiConfig.position || 'atEquipment', // default to 'atEquipment' if not set }; // Utility for formatting outputs @@ -92,7 +93,7 @@ class MeasurementNode { } /** - * Bind Measurement events to Node-RED status updates. Using internal emitter. + * Bind Measurement events to Node-RED status updates. Using internal emitter. --> REMOVE LATER WE NEED ONLY COMPLETE CHILDS AND THEN CHECK FOR UPDATES */ _bindEvents() { this.source.emitter.on('mAbs', (val) => { @@ -109,7 +110,7 @@ class MeasurementNode { this.node.send([ null, null, - { topic: 'registerChild', payload: this.id, positionVsParent: 'upstream' } + { topic: 'registerChild', payload: this.id, positionVsParent: this.config.functionality.positionVsParent } ]); }, 100); }