Generic updates completed for now

This commit is contained in:
znetsixe
2025-07-01 15:24:18 +02:00
parent b4803e5e9b
commit edf9b09af1
4 changed files with 17 additions and 20 deletions

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2025 Rene De Ren
Copyright (c) 2025 wbd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to use,

View File

@@ -9,7 +9,7 @@
defaults: {
// Define default properties
name: { value: "", required: true }, // use asset category as name
name: { value: "" }, // use asset category as name
// Define specific properties
scaling: { value: false },
@@ -36,6 +36,7 @@
//physicalAspect
positionVsParent: { value: "" },
positionIcon: { value: "" },
},
@@ -46,7 +47,7 @@
icon: "font-awesome/fa-tachometer",
label: function () {
return this.name || "Measurement";
return this.positionIcon + " " + this.assetType || "Measurement";
},
oneditprepare: function() {
@@ -118,6 +119,11 @@
success = window.EVOLV.nodes.measurement.loggerMenu.saveEditor(node);
}
// save position field
if (window.EVOLV?.nodes?.rotatingMachine?.positionMenu?.saveEditor) {
window.EVOLV.nodes.rotatingMachine.positionMenu.saveEditor(this);
}
// Save basic properties
["smooth_method"].forEach(
(field) => (node[field] = document.getElementById(`node-input-${field}`).value || "")

View File

@@ -1,7 +1,3 @@
/**
* Thin wrapper that registers a node with Node-RED and exposes HTTP endpoints. and loads EVOLV in a standard way
*/
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');
@@ -12,7 +8,6 @@ module.exports = function(RED) {
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);
});
@@ -21,10 +16,8 @@ module.exports = function(RED) {
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 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) => {
RED.httpAdmin.get(`/${nameOfNode}/menu.js`, (req, res) => {
try {
const script = menuMgr.createEndpoint(nameOfNode, ['asset','logger','position']);
res.type('application/javascript').send(script);
@@ -33,10 +26,8 @@ module.exports = function(RED) {
}
});
//console.log(`Loading endpoint for ${nameOfNode} config...`);
// Endpoint to get the configuration data for the specific node
RED.httpAdmin.get(`/measurement/configData.js`, (req, res) => {
RED.httpAdmin.get(`/${nameOfNode}/configData.js`, (req, res) => {
try {
const script = cfgMgr.createEndpoint(nameOfNode);
// Send the configuration data as JSON response
@@ -46,5 +37,4 @@ module.exports = function(RED) {
}
});
//console.log(`Measurement node '${nameOfNode}' registered.`);
};

View File

@@ -7,14 +7,14 @@
const { outputUtils, configManager } = require('generalFunctions');
const Specific = require("./specificClass");
/**
* Class representing a Measurement Node-RED node.
*/
class nodeClass {
/**
* Create a MeasurementNode.
* @param {object} uiConfig - Node-RED node configuration.
* @param {object} RED - Node-RED runtime API.
* @param {object} nodeInstance - The Node-RED node instance.
* @param {string} nameOfNode - The name of the node, used for
*/
constructor(uiConfig, RED, nodeInstance, nameOfNode) {
@@ -48,7 +48,7 @@ class nodeClass {
// Merge UI config over defaults
this.config = {
general: {
name: this.name,
name: uiConfig.name,
id: node.id, // node.id is for the child registration process
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: {
@@ -94,6 +94,7 @@ class nodeClass {
*/
_setupSpecificClass() {
this.source = new Specific(this.config);
this.node.source = this.source; // Store the source in the node instance for easy access
}
/**
@@ -114,7 +115,7 @@ class nodeClass {
this.node.send([
null,
null,
{ topic: 'registerChild', payload: this.config.general.id, positionVsParent: this.config?.functionality?.positionVsParent || 'atEquipment' },
{ topic: 'registerChild', payload: this.node.id , positionVsParent: this.config?.functionality?.positionVsParent || 'atEquipment' },
]);
}, 100);
}