not working yet need to fix child registration?

This commit is contained in:
znetsixe
2025-07-01 17:03:36 +02:00
parent e6979d06ad
commit 35eb965609
7 changed files with 1554 additions and 274 deletions

153
mgc.html
View File

@@ -11,96 +11,61 @@
#4f8582
#c4cce0
-->
<script type="text/javascript">
<script src="/machineGroupControl/menu.js"></script> <!-- Load the menu script for dynamic dropdowns -->
<script src="/machineGroupControl/configData.js"></script> <!-- Load the config script for node information -->
<script>
RED.nodes.registerType('machineGroupControl',{
category: 'digital twin',
color: '#eaf4f1',
defaults: {
name: {value:""},
enableLog: { value: false },
logLevel: { value: "error" },
},
category: "EVOLV",
color: "#eaf4f1",
defaults: {
// Define default properties
name: { value: "" },
// Logger properties
enableLog: { value: false },
logLevel: { value: "error" },
// Physical aspect
positionVsParent: { value: "" },
positionLabel: { value: "" },
positionIcon: { value: "" },
},
inputs:1,
outputs:4,
inputLabels: "Usage see manual",
outputLabels: ["process", "dbase", "upstreamParent", "downstreamParent"],
outputs:3,
inputLabels: ["Input"],
outputLabels: ["process", "dbase", "parent"],
icon: "font-awesome/fa-tachometer",
//define label function
label: function() {
return this.name || "MachineGroup controller";
label: function () {
return this.positionIcon + " " + "machineGroup";
},
oneditprepare: function() {
const node = this;
console.log("Rotating Machine Node: Edit Prepare");
const elements = {
// Basic fields
name: document.getElementById("node-input-name"),
// Logging fields
logCheckbox: document.getElementById("node-input-enableLog"),
logLevelSelect: document.getElementById("node-input-logLevel"),
rowLogLevel: document.getElementById("row-logLevel"),
};
const projecSettingstURL = "http://localhost:1880/generalFunctions/settings/projectSettings.json";
try{
// Fetch project settings
menuUtils.fetchProjectData(projecSettingstURL)
.then((projectSettings) => {
//assign to node vars
node.configUrls = projectSettings.configUrls;
const { cloudConfigURL, localConfigURL } = menuUtils.getSpecificConfigUrl("machineGroupControl",node.configUrls.cloud.taggcodeAPI);
node.configUrls.cloud.config = cloudConfigURL; // first call
node.configUrls.local.config = localConfigURL; // backup call
// Gets the ID of the active workspace (Flow)
const activeFlowId = RED.workspaces.active(); //fetches active flow id
node.processId = activeFlowId;
// UI elements
menuUtils.initBasicToggles(elements);
})
}catch(e){
console.log("Error fetching project settings", e);
// Initialize the menu data for the node
const waitForMenuData = () => {
if (window.EVOLV?.nodes?.machineGroupControl?.initEditor) {
window.EVOLV.nodes.machineGroupControl.initEditor(this);
} else {
setTimeout(waitForMenuData, 50);
}
if(node.d){
//this means node is disabled
console.log("Current status of node is disabled");
}
};
// Wait for the menu data to be ready before initializing the editor
waitForMenuData();
},
oneditsave: function(){
const node = this;
//save basic properties
["name"].forEach(
(field) => {
const element = document.getElementById(`node-input-${field}`);
if (element) {
node[field] = element.value || "";
}
// Validate logger properties using the logger menu
if (window.EVOLV?.nodes?.measurement?.loggerMenu?.saveEditor) {
success = window.EVOLV.nodes.measurement.loggerMenu.saveEditor(node);
}
);
const logLevelElement = document.getElementById("node-input-logLevel");
node.logLevel = logLevelElement ? logLevelElement.value || "info" : "info";
// save position field
if (window.EVOLV?.nodes?.rotatingMachine?.positionMenu?.saveEditor) {
window.EVOLV.nodes.rotatingMachine.positionMenu.saveEditor(this);
}
}
});
@@ -108,39 +73,13 @@
<script type="text/html" data-template-name="machineGroupControl">
<!-------------------------------------------INPUT NAME / TYPE ----------------------------------------------->
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i>Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<!-- Logger fields injected here -->
<div id="logger-fields-placeholder"></div>
<hr />
<!-- loglevel checkbox -->
<div class="form-row">
<label for="node-input-enableLog"
><i class="fa fa-cog"></i> Enable Log</label
>
<input
type="checkbox"
id="node-input-enableLog"
style="width:20px; vertical-align:baseline;"
/>
<span>Enable logging</span>
</div>
<div class="form-row" id="row-logLevel">
<label for="node-input-logLevel"><i class="fa fa-cog"></i> Log Level</label>
<select id="node-input-logLevel" style="width:60%;">
<option value="info">Info</option>
<option value="debug">Debug</option>
<option value="warn">Warn</option>
<option value="error">Error</option>
</select>
</div>
<!-- Position fields injected here -->
<div id="position-fields-placeholder"></div>
<!-------------------------------------------INPUT TRANSLATION TO OUTPUT ----------------------------------------------->
<hr />
<div class="form-tips"></div>
<b>Tip:</b> Ensure that the "Name" field is unique to easily identify the node.
Enable logging if you need detailed information for debugging purposes.