Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

197 Zeilen
8.2KB

  1. <script type="text/javascript">
  2. RED.nodes.registerType('BooleanLogicUltimate',{
  3. category: 'boolean logic ultimate',
  4. color: '#ff8080',
  5. defaults: {
  6. name: {
  7. value: ""
  8. },
  9. filtertrue: {value:"both"},
  10. persist: {value:true},
  11. triggertopic: {
  12. value: "trigger",
  13. required: false
  14. },
  15. outputtriggeredby:{
  16. value:"all",
  17. required: false},
  18. inputCount: {
  19. value: 2,
  20. required: true,
  21. validate:
  22. function(v) {
  23. return !isNaN( parseInt( v ) ) && parseInt( v ) >= 2;
  24. }
  25. },
  26. topic: {
  27. value: "result",
  28. required: true,
  29. validate:
  30. function(v) {
  31. return v !== undefined && v.length > 0;
  32. }
  33. }
  34. },
  35. inputs:1,
  36. outputs:3,
  37. outputLabels: function(i) {
  38. var ret="";
  39. switch (i) {
  40. case 0:
  41. return "AND";
  42. break;
  43. case 1:
  44. return "OR";
  45. break;
  46. case 2
  47. :
  48. return "XOR";
  49. break;
  50. default:
  51. break;
  52. }
  53. },
  54. icon: "serial.png",
  55. label:
  56. function() {
  57. let label = "";
  58. let filtered=this.filtertrue=="both" ? "" : " |T" ;
  59. let trigger="";
  60. if(typeof this.outputtriggeredby !== "undefined") trigger=this.outputtriggeredby=="all" ? "" : " |TRIG (" + this.triggertopic+")";
  61. label= this.inputCount + ((filtered+trigger)==""?" Boolean Logic":(filtered+trigger));
  62. if( this.name !== undefined && this.name.length > 0 ) {
  63. label += " (" + this.name + ")";
  64. }
  65. return label;
  66. },
  67. paletteLabel: function() {
  68. return "Boolean Logic Ultimate";
  69. },
  70. oneditprepare: function () {
  71. // Add write and response as default for existing nodes like was default before
  72. if (this.outputtriggeredby === 'all') {
  73. $("#triggertopic").hide()
  74. }else
  75. {
  76. $("#triggertopic").show()
  77. }
  78. $("#node-input-outputtriggeredby").on('change',function() {
  79. if ($("#node-input-outputtriggeredby").val()==="all") {
  80. $("#triggertopic").hide()
  81. }else{
  82. $("#triggertopic").show()
  83. }
  84. })
  85. // default
  86. if(typeof this.outputtriggeredby === "undefined")
  87. {
  88. $("#node-input-outputtriggeredby").val("all");
  89. this.outputtriggeredby="all";
  90. }
  91. },
  92. oneditsave: function () {
  93. // Delete persistent state file
  94. $.get( "stateoperation_delete?nodeid=" +this.id, function( data ) {});
  95. }
  96. });
  97. </script>
  98. <script type="text/x-red" data-template-name="BooleanLogicUltimate">
  99. <div class="form-row">
  100. <label for="node-input-inputCount"><i class="fa fa-indent"></i> Number of different topics to evaluate</label>
  101. <input type="text" id="node-input-inputCount" placeholder="Number of different topics to consider">
  102. </div>
  103. <div class="form-row">
  104. <label for="node-input-name"><i class="icon-tag"></i> Name</label>
  105. <input type="text" id="node-input-name" placeholder="Name">
  106. </div>
  107. <div class="form-row">
  108. <label for="node-input-topic"><i class="fa fa-tasks"></i> Node topic</label>
  109. <input type="text" id="node-input-topic" placeholder="Node's own topic">
  110. </div>
  111. <div class="form-row">
  112. <label for="node-input-filtertrue"><i class="fa fa-filter"></i> Filter output result</label>
  113. <select type="text" id="node-input-filtertrue" placeholder="Filter">
  114. <option value="both">Output both 'true' and 'false' results</option>
  115. <option value="onlytrue">Output only 'true' results</option>
  116. </select>
  117. </div>
  118. <div class="form-row">
  119. <label for="node-input-outputtriggeredby"><i class="fa fa-filter"></i> Trigger mode</label>
  120. <select type="text" id="node-input-outputtriggeredby" placeholder="Event">
  121. <option value="all">All topics</option>
  122. <option value="onlyonetopic">Single topic + only eval others</option>
  123. </select>
  124. </div>
  125. <div class="form-row" id="triggertopic">
  126. <label for="node-input-triggertopic"><i class="fa fa-tasks"></i> Topic that start boolean logic evaluation</label>
  127. <input type="text" id="node-input-triggertopic" placeholder="Input topic">
  128. </div>
  129. <div class="form-row">
  130. <i class="fa fa-floppy-o"></i>
  131. <label style="width:auto" for="node-input-persist"> Remember latest input values after reboot</label> <input type="checkbox" id="node-input-persist" style="display:inline-block; width:auto; vertical-align:top;">
  132. <div id="helpallga"><i> If checked, the input values are retained <br /> after a node-red reboot.<br/>If you reboot your node-red, <br />you don't need to wait all inputs <br />to arrive and initialize the node, <br />before the node can output a payload.</div>
  133. </div>
  134. </script>
  135. <script type="text/x-red" data-help-name="BooleanLogicUltimate">
  136. <p>The node performs Boolean logic on the incoming payloads.<br/>
  137. <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>
  138. The node performs 3 checks (<b>AND,OR,XOR</b>) on the incoming boolean payloads and outputs the result at the same time, as follow:<br/>
  139. - Output "AND": true or false<br/>
  140. - Output "OR": true or false<br/>
  141. - Output "XOR": true or false<br/>
  142. <br/>
  143. Changing the topic is usually only needed when chaining multiple boolean nodes after each other becuse the topics will then all be the same when delivered to the nodes further down the chain.<br/>
  144. <br/>
  145. The node expects a fixed number of topics (configured in the settings) on which it will operate. It will only output a value
  146. when it has seen the expected number of topics. If it ever sees more than the configured number of topics it will log a message then reset its state and start over.<br/>
  147. <br/><br/>
  148. <b>Filter output result</b><br />
  149. <ol>
  150. <li>Output both 'true' and 'false' results: Standard behaviour, the node will output <b>true</b> and <b>false</b> whenever it receives an input and calculate the boolean logics as output.</li>
  151. <li>Output only 'true' results: whenever the node receives an input, it outputs a payload <b>true</b> only if the result of the logic is true. <b>False</b> results are filtered out.</li>
  152. </ol>
  153. <b>filtered</b>: shown on label, means that the node will pass out only <code>true</code> values (Output only 'true' results). <br/>
  154. <br/><br/>
  155. <b>Trigger mode</b><br />
  156. The node can acts ad a standard boolean logic or as single topic triggered boolean logic.<br/>
  157. As single topic triggered boolean logic, the node will evaluate the inputs (and thus will output a payload) only if a specified topic input arrives.<br/>
  158. In a coding perspectives, it acts as follows:<br/>
  159. <code>
  160. if (msg.topic == specified topic)<br/>
  161. {<br/>
  162. If (all other inputs are true) -> outputs true otherwise false<br/>
  163. }<br/>
  164. </code>
  165. <ol>
  166. <li>All topics: standard behaviour, the node will output <b>true</b> and <b>false</b> by evaluating all inputs. Each input change will trigger the node output.</li>
  167. <li>Single topic + only eval others: <u>only whenever the node receives a msg input with the <b>specified topic</b> (having payload = true)</u>, it starts the evaluation of all other inputs as well and outputs the evaluated payload. If the node receives a msg input other than the <b>specified topic</b>), it only retains it's value for the boolean evaluation.</li>
  168. </ol>
  169. Example of trigger mode = Single topic + eval other inputs: <b>SEE THE README FOR AN EXAMPLE</b>
  170. <br/><br/>
  171. <b>Remember latest input values after reboot</b><br />
  172. If checked, the input values are retained after a node-red reboot. That means, that if you reboot your node-red, you don't need to wait all inputs to arrive and initialize the node, before the node can output a payload.<br/>
  173. Every time you modify the node's config, <b>the retained values are cleared</b>.<br/>
  174. <br/>
  175. All incoming msg.payloads are converted into a boolean value according to the following rules (this applies to all boolean logic nodes):
  176. <ol>
  177. <li>Boolean values are taken as-is.</li>
  178. <li>For numbers, 0 evaluates to false, all other numbers evaluates to true.</li>
  179. <li>Strings are converted to numbers if they match the format of a decimal value, then the same rule as for numbers are applied. If it does not match, it evaluates to false. Also, the string "true" evaluates to true.</li>
  180. </ol>
  181. <br>
  182. The XOR operation operates in a one, and only one mode, i.e. (A ^ B) ^ C ... ^ n
  183. </p>
  184. </script>