node-red-contrib-boolean-logic-ultimate
Version:
A set of Node-RED enhanced boolean logic node, flow interruption node, blinker node, invert node, filter node, with persisten values after reboot and more.
181 lines (169 loc) • 6.34 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('BooleanLogicUltimate', {
category: 'boolean logic ultimate',
color: '#ff8080',
defaults: {
name: {
value: ""
},
filtertrue: { value: "both" },
persist: { value: true },
sInitializeWith: { value: "WaitForPayload" },
triggertopic: {
value: "trigger",
required: false
},
outputtriggeredby: {
value: "all",
required: false
},
inputCount: {
value: 2,
required: true,
validate:
function (v) {
return !isNaN(parseInt(v)) && parseInt(v) >= 2;
}
},
topic: {
value: "result",
required: true,
validate:
function (v) {
return v !== undefined && v.length > 0;
}
},
restrictinputevaluation:{ value: true }
},
inputs: 1,
outputs: 3,
outputLabels: function (i) {
var ret = "";
switch (i) {
case 0:
return "AND";
break;
case 1:
return "OR";
break;
case 2
:
return "XOR";
break;
default:
break;
}
},
icon: "serial.png",
label:
function () {
let label = "";
let filtered = this.filtertrue == "both" ? "" : "f";
let trigger = "";
if (typeof this.outputtriggeredby !== "undefined") trigger = this.outputtriggeredby == "all" ? "" : "t (" + this.triggertopic + ")";
label = this.inputCount + ((filtered + trigger) == "" ? " Boolean Logic" : (filtered + trigger));
if (this.name !== undefined && this.name.length > 0) {
label += " (" + this.name + ")";
}
return label;
},
paletteLabel: function () {
return "BooleanLogicUltimate";
},
oneditprepare: function () {
// Add write and response as default for existing nodes like was default before
if (this.outputtriggeredby === 'all') {
$("#triggertopic").hide()
} else {
$("#triggertopic").show()
}
$("#node-input-outputtriggeredby").on('change', function () {
if ($("#node-input-outputtriggeredby").val() === "all") {
$("#triggertopic").hide()
} else {
$("#triggertopic").show()
}
})
// default
if (typeof this.outputtriggeredby === "undefined") {
$("#node-input-outputtriggeredby").val("all");
this.outputtriggeredby = "all";
}
// default
if (typeof this.sInitializeWith === "undefined") {
$("#node-input-sInitializeWith").val("WaitForPayload");
this.sInitializeWith = "WaitForPayload";
}
},
oneditsave: function () {
// Delete persistent state file
$.get("stateoperation_delete?nodeid=" + this.id, function (data) { });
}
});
</script>
<script type="text/x-red" data-template-name="BooleanLogicUltimate">
<div class="form-row">
<b>Boolean Logic Ultimate</b>    <span style="color:red"><i class="fa fa-question-circle"></i> <a target="_blank" href="https://github.com/Supergiovane/node-red-contrib-boolean-logic-ultimate"><u>Help online</u></a></span>
<br/>
<br/>
</div>
<div class="form-row">
<label for="node-input-inputCount"><i class="fa fa-step-forward"></i> Inputs count</label>
<input type="text" id="node-input-inputCount" placeholder="Inputs count, for example: 2">
</div>
<div class="form-tips" style="margin-top: 8px;background-color:lightgrey;text-align:center">Option above: the node waits for this number of <i>different</i> msg topics before evaluating the outputs.</div>
<br/>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
<input type="text" id="node-input-topic" placeholder="Node's own topic">
</div>
<div class="form-row">
<label for="node-input-filtertrue"><i class="fa fa-filter"></i> Filter output result</label>
<select type="text" id="node-input-filtertrue" placeholder="Filter">
<option value="both">Output both 'true' and 'false' results</option>
<option value="onlytrue">Output only 'true' results</option>
</select>
</div>
<div class="form-row">
<label for="node-input-outputtriggeredby"><i class="fa fa-filter"></i> Trigger mode</label>
<select type="text" id="node-input-outputtriggeredby" placeholder="Event">
<option value="all">All topics (will output a result whenever an input msg arrives)</option>
<option value="onlyonetopic">Single topic (still evaluates all inputs, but will output a result only if a specified topic arrives)</option>
</select>
</div>
<div class="form-row" id="triggertopic">
<label for="node-input-triggertopic"><i class="fa fa-tasks"></i> Topic that start boolean logic evaluation</label>
<input type="text" id="node-input-triggertopic" placeholder="Input topic">
</div>
<div class="form-row">
<label for="node-input-sInitializeWith"><i class="fa fa-home"></i> If input states are undefined at boot</label>
<select type="text" id="node-input-sInitializeWith" placeholder="">
<option value="WaitForPayload">Leave undefined</option>
<option value="false">Initialize all with False</option>
<option value="true">Initialize all with True</option>
</select>
</div>
<div class="form-row">
<i class="fa fa-floppy-o"></i>  
<input type="checkbox" id="node-input-persist" style="display:inline-block; width:auto; vertical-align:top;">
 <label style="width:auto" for="node-input-persist"> Remember latest input values after reboot</label>
</div>
<div class="form-row">
<i class="fa fa-gavel"></i> 
<input type="checkbox" id="node-input-restrictinputevaluation" style="display:inline-block; width:auto; vertical-align:top;">
 <label style="width:auto" for="node-input-restrictinputevaluation"> Reject non boolean (true/false) input values</label>
</div>
</script>
<script type="text/x-red" data-help-name="BooleanLogicUltimate">
<p>
SEE THE README FOR HELP CONFIGURING THE NODE
</p>
<p>
<a href="https://github.com/Supergiovane/node-red-contrib-boolean-logic-ultimate" target="_blank">Click here to learn how to configure the node.</a>
</p>
<a href="https://www.paypal.me/techtoday" target="_blank"><img src='https://img.shields.io/badge/Donate-PayPal-blue.svg?style=flat-square' width='30%'></a>
</script>