@ralphwetzel/node-red-mcu-gate
Version:
Node that implements a gate open only when the flow runs on an MCU
75 lines (62 loc) • 2.05 kB
HTML
<!---
// *****
//
// @ralphwetzel/node-red-mcu-gate
//
// Copyright 2023 / Ralph Wetzel
// License: MIT
//
// *****
-->
<script type="text/html" data-template-name="mcu-gate">
<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>
</script>
<script type="text/javascript">
RED.nodes.registerType('mcu-gate',{
category: 'MCU',
color: '#7090c9',
defaults: {
name: {value:""},
l: {value: true}
},
inputs:1,
outputs:1,
showLabel: false,
paletteLabel: "MCU gate",
icon: function() {
return this._mcu?.mcu == true ? "font-awesome/fa-play-circle" : "font-awesome/fa-ban";
},
label: function() {
let status = (this._mcu?.mcu == true) ? "Open" : "Closed"
return this.name||status;
},
onadd: function() {
// ensure no label is shown per default
let node = this;
// this is where the editor tracks the state
node.l = false;
},
oneditsave: function() {
let node = this;
// this hack ensures that the show-label status is applied propperly,
// even despite we're initially showing no label!
// get the show-label status
let status = $("#node-input-show-label").prop('checked');
// wait until the client has done it's job ... deleting node.l
setTimeout(() => {
if (node) {
// set node.l as required...
node.l = status;
// ... & redraw the canvas!
RED.view.redraw();
}
}, 250);
}
});
</script>
<script type="text/html" data-help-name="mcu-gate">
<p>Node that implements a gate open only when the flow runs on an MCU.</p>
</script>