first try to standardize

This commit is contained in:
znetsixe
2025-06-25 17:26:13 +02:00
parent b09d9e8327
commit 85eb1eb4a6
8 changed files with 1488 additions and 893 deletions

View File

@@ -1,282 +1,132 @@
<script type="module">
import * as menuUtils from "/generalFunctions/helper/menuUtils.js";
import nodeTemplates from "/generalFunctions/helper/nodeTemplates.js";
<!-- Load the dynamic menu & config endpoints -->
<script src="/rotatingMachine/menu.js"></script>
<script src="/rotatingMachine/configData.js"></script>
// Grab the asset template from nodeTemplates
const tm = nodeTemplates.asset;
RED.nodes.registerType("rotatingMachine", {
category: tm.category,
color: tm.color,
defaults: {
...tm.defaults,
machineCurve: { value: {} }, // used to interpolate values
speed: { value: 1, required: true },
startup: { value: 0, required: false },
warmup: { value: 0, required: false },
shutdown:{ value: 0, required: false },
cooldown:{ value: 0, required: false },
},
inputs: tm.inputs,
outputs: tm.outputs,
inputLabels: tm.inputLabels,
outputLabels: tm.outputLabels,
icon: tm.icon,
<script>
RED.nodes.registerType("rotatingMachine", {
category: "EVOLV",
color: "#4f8582",
defaults: {
// Define default properties
name: { value: "", required: true }, // use asset category as name ?
label: function () {
return this.name || "asset";
},
oneditprepare: function () {
const node = this;
console.log("------------ Edit Prepare for Rotating Machine Node ------------");
// specific fields of node
const elements = {
speed: document.getElementById("node-input-speed"),
startup: document.getElementById("node-input-startup"),
warmup: document.getElementById("node-input-warmup"),
shutdown: document.getElementById("node-input-shutdown"),
cooldown: document.getElementById("node-input-cooldown"),
};
// Define specific properties
speed: { value: 1, required: true },
startup: { value: 0 },
warmup: { value: 0 },
shutdown: { value: 0 },
machineCurve : { value: {}},
// Loop through tm.elements to add non-specific elements
Object.keys(tm.elements).forEach(key => {
elements[key] = document.getElementById(tm.elements[key]);
});
//define asset properties
uuid: { value: "" },
supplier: { value: "" },
category: { value: "" },
assetType: { value: "" },
model: { value: "" },
unit: { value: "" },
console.log("Elements:", elements);
//logger properties
enableLog: { value: false },
logLevel: { value: "error" },
const projecSettingstURL = tm.projectSettingsURL;
console.log("Project settings URL:", projecSettingstURL);
//physicalAspect
positionVsParent: { value: "" },
try{
// Fetch project settings
menuUtils.fetchProjectData(projecSettingstURL)
.then((projectSettings) => {
//assign to node vars
node.configUrls = projectSettings.configUrls;
const { cloudConfigURL, localConfigURL } = menuUtils.getSpecificConfigUrl("rotatingMachine",node.configUrls.cloud.taggcodeAPI);
node.configUrls.cloud.config = cloudConfigURL; // first call
node.configUrls.local.config = localConfigURL; // backup call
node.locationId = projectSettings.locationId;
node.uuid = projectSettings.uuid;
// 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);
menuUtils.fetchAndPopulateDropdowns(node.configUrls, elements, node); // function for all assets
})
}catch(e){
console.log("Error fetching project settings", e);
}
if(node.d){
//this means node is disabled
console.log("Current status of node is disabled");
}
},
oneditsave: function () {
inputs: 1,
outputs: 3,
inputLabels: ["Input"],
outputLabels: ["process", "dbase", "parent"],
icon: "font-awesome/fa-tachometer",
label: function() {
return this.name || "rotatingMachine";
},
oneditprepare: function() {
// wait for the menu scripts to load
const waitForMenuData = () => {
if (window.EVOLV?.nodes?.rotatingMachine?.initEditor) {
window.EVOLV.nodes.rotatingMachine.initEditor(this);
} else {
setTimeout(waitForMenuData, 50);
}
};
waitForMenuData();
// your existing projectsettings & asset dropdown logic can remain here
document.getElementById("node-input-speed"),
document.getElementById("node-input-startup"),
document.getElementById("node-input-warmup"),
document.getElementById("node-input-shutdown"),
document.getElementById("node-input-cooldown")
},
oneditsave: function() {
const node = this;
console.log(`------------ Saving changes to node ------------`);
console.log(`${node.uuid}`);
//save basic properties
["name", "unit", "supplier", "subType", "model"].forEach(
(field) => {
const element = document.getElementById(`node-input-${field}`);
if (element) {
node[field] = element.value || "";
}
}
);
// Save numeric and boolean properties
// save asset fields
if (window.EVOLV?.nodes?.rotatingMachine?.assetMenu?.saveEditor) {
window.EVOLV.nodes.rotatingMachine.assetMenu.saveEditor(this);
}
// save logger fields
if (window.EVOLV?.nodes?.rotatingMachine?.loggerMenu?.saveEditor) {
window.EVOLV.nodes.rotatingMachine.loggerMenu.saveEditor(this);
}
// save position field
if (window.EVOLV?.nodes?.rotatingMachine?.positionMenu?.saveEditor) {
window.EVOLV.nodes.rotatingMachine.positionMenu.saveEditor(this);
}
// …plus any custom saves for speed, startup, etc.
["speed", "startup", "warmup", "shutdown", "cooldown"].forEach(
(field) => {
const element = document.getElementById(`node-input-${field}`);
if (element) {
node[field] = Number(element.value) || 0;
}
}
(field) => (node[field] = parseFloat(document.getElementById(`node-input-${field}`).value) || 0)
);
/*
//local db
node[field] = node["modelMetadata"][field];
//central db
node[field] = node["modelMetadata"]["product_model_meta"][field];
*/
//save meta data curve central db
["machineCurve"].forEach(
(field) => {
node[field] = node.modelMetadata.product_model_meta
? node.modelMetadata.product_model_meta[field]
: node.modelMetadata[field];
//console.log(node[field]);
console.log("Machine curve saved");
}
);
const logLevelElement = document.getElementById("node-input-logLevel");
node.logLevel = logLevelElement ? logLevelElement.value || "info" : "info";
if (!node.unit) {
RED.notify("Unit selection is required.", "error");
}
if (node.subType && !node.unit) {
RED.notify("Unit must be set when specifying a subtype.", "error");
}
try{
console.log("Saving assetID and tagnumber");
console.log(node.assetTagCode);
// Fetch project settings
menuUtils.apiCall(node,node.configUrls)
.then((response) => {
console.log(" ====<<>>>> API call response", response);
//save response to node information
node.assetId = response.asset_id;
node.assetTagCode = response.asset_tag_number;
})
.catch((error) => {
console.log("Error during API call", error);
});
}catch(e){
console.log("Error saving assetID and tagnumber", e);
}
},
}
});
</script>
</script>
<!-- Main UI Template -->
<script type="text/html" data-template-name="rotatingMachine">
<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="Machine Name"
style="width:70%;"
/>
</div>
<div class="form-row">
<label for="node-input-speed"><i class="fa fa-clock-o"></i> Reaction Speed</label>
<input type="number" id="node-input-speed" placeholder="1" />
</div>
<div class="form-row">
<label for="node-input-startup"><i class="fa fa-clock-o"></i> Startup Time</label>
<input type="number" id="node-input-startup" placeholder="0" />
</div>
<div class="form-row">
<label for="node-input-warmup"><i class="fa fa-clock-o"></i> Warmup Time</label>
<input type="number" id="node-input-warmup" placeholder="0" />
</div>
<div class="form-row">
<label for="node-input-shutdown"><i class="fa fa-clock-o"></i> Shutdown Time</label>
<input type="number" id="node-input-shutdown" placeholder="0" />
</div>
<div class="form-row">
<label for="node-input-cooldown"><i class="fa fa-clock-o"></i> Cooldown Time</label>
<input type="number" id="node-input-cooldown" placeholder="0" />
</div>
<!-- Main UI Template -->
<script type="text/html" data-template-name="rotatingMachine">
<!-- Optional Extended Fields: supplier, type, subType, model -->
<hr />
<div class="form-row">
<label for="node-input-supplier"
><i class="fa fa-industry"></i> Supplier</label
>
<select id="node-input-supplier" style="width:60%;">
<option value="">(optional)</option>
</select>
</div>
<div class="form-row">
<label for="node-input-subType"
><i class="fa fa-puzzle-piece"></i> SubType</label
>
<select id="node-input-subType" style="width:60%;">
<option value="">(optional)</option>
</select>
</div>
<div class="form-row">
<label for="node-input-model"><i class="fa fa-wrench"></i> Model</label>
<select id="node-input-model" style="width:60%;">
<option value="">(optional)</option>
</select>
</div>
<div class="form-row">
<label for="node-input-unit"><i class="fa fa-balance-scale"></i> Unit</label>
<select id="node-input-unit" style="width:60%;"></select>
</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>
<!-- Machine-specific controls -->
<div class="form-row">
<label for="node-input-speed"><i class="fa fa-clock-o"></i> Reaction Speed</label>
<input type="number" id="node-input-speed" style="width:60%;" />
</div>
<div class="form-row">
<label for="node-input-startup"><i class="fa fa-clock-o"></i> Startup Time</label>
<input type="number" id="node-input-startup" style="width:60%;" />
</div>
<div class="form-row">
<label for="node-input-warmup"><i class="fa fa-clock-o"></i> Warmup Time</label>
<input type="number" id="node-input-warmup" style="width:60%;" />
</div>
<div class="form-row">
<label for="node-input-shutdown"><i class="fa fa-clock-o"></i> Shutdown Time</label>
<input type="number" id="node-input-shutdown" style="width:60%;" />
</div>
<div class="form-row">
<label for="node-input-cooldown"><i class="fa fa-clock-o"></i> Cooldown Time</label>
<input type="number" id="node-input-cooldown" style="width:60%;" />
</div>
</script>
<script type="text/html" data-help-name="rotatingMachine">
<p>
<b>Rotating Machine Node</b>: Configure the behavior of a rotating machine
used in a digital twin.
</p>
<ul>
<li><b>Supplier:</b> Select a supplier to populate machine options.</li>
<li><b>SubType:</b> Select a subtype if applicable to further categorize the asset.</li>
<li><b>Model:</b> Define the specific model for more granular asset configuration.</li>
<li><b>Unit:</b> Assign a unit to standardize measurements or operations.</li>
<li><b>Speed:</b> Reaction speed of the machine in response to inputs.</li>
<li><b>Startup:</b> Define the startup time for the machine.</li>
<li><b>Warmup:</b> Define the warmup time for the machine.</li>
<li><b>Shutdown:</b> Define the shutdown time for the machine.</li>
<li><b>Cooldown:</b> Define the cooldown time for the machine.</li>
<li><b>Enable Log:</b> Enable or disable logging for the machine.</li>
<li><b>Log Level:</b> Set the log level (Info, Debug, Warn, Error).</li>
</ul>
</script>
<!-- Asset fields injected here -->
<div id="asset-fields-placeholder"></div>
<!-- Logger fields injected here -->
<div id="logger-fields-placeholder"></div>
<!-- Position fields injected here -->
<div id="position-fields-placeholder"></div>
</script>
<script type="text/html" data-help-name="rotatingMachine">
<p><b>Rotating Machine Node</b>: Configure a rotatingmachine asset.</p>
<ul>
<li><b>Reaction Speed, Startup, Warmup, Shutdown, Cooldown:</b> timing parameters.</li>
<li><b>Supplier / SubType / Model / Unit:</b> choose via Asset menu.</li>
<li><b>Enable Log / Log Level:</b> toggle via Logger menu.</li>
<li><b>Position:</b> set Upstream / At Equipment / Downstream via Position menu.</li>
</ul>
</script>