UNPKG

node-red-contrib-queue-gate

Version:
195 lines (187 loc) 9.74 kB
<!-- Copyright 2018-20 M. I. Bell Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified by Simon Walters 31 Jul 2019 to select toggle behavior: open/closed or open/queueing Modified by Colin Law 06 Apr 2020 to implement peek, drop, and status commands --> <script type="text/javascript"> RED.nodes.registerType('q-gate',{ category: 'function', color: '#f3b567', defaults: { name: {value:""}, controlTopic: {value:"control"}, defaultState: {value:"open"}, openCmd: {value:"open"}, closeCmd: {value:"close"}, toggleCmd: {value:"toggle"}, queueCmd: {value:"queue"}, defaultCmd: {value:"default"}, triggerCmd: {value:"trigger"}, flushCmd: {value:"flush"}, resetCmd: {value:"reset"}, peekCmd: {value:"peek"}, dropCmd: {value:"drop"}, statusCmd: {value:"status"}, maxQueueLength: {value:"100"}, keepNewest: {value:false}, qToggle: {value:false}, persist: {value:false}, // storeName: {value:RED.settings.context.default}, storeName: {value: RED.settings.hasOwnProperty('context') ? RED.settings.context.default : 'default'} }, inputs:1, outputs:1, icon: "queue.png", paletteLabel: "q–gate", label: function() { return this.name||"q-gate"; }, labelStyle: function() { return this.name?"node_label_italic":""; }, oneditprepare: function() { var node = this RED.settings.context.stores.forEach(add) // list context stores function add(item){ $('#node-input-storeName').append(`<option value="${item}">${item}</option>`) } $('#node-input-storeName').val(node.storeName) // disable if not checked $("#node-input-persist").on("change", function(e) { $("#node-input-storeName").prop("disabled", !$(this).prop("checked")) }); const version = RED.nodes.registry.getModule("node-red-contrib-queue-gate").version $('#node-version').append(` ${version}`) } }); </script> <script type="text/x-red" data-template-name="q-gate"> <!-- controlTopic --> <div class="form-row"> <label for="node-input-controlTopic"><i class="fa fa-cog"></i> Control Topic</label> <input type="text" id="node-input-controlTopic" placeholder="control"> </div> <!-- defaultState --> <div class="form-row"> <label for="node-input-defaultState"><i class="fa fa-refresh"></i> Default State</label> <select type="text" id="node-input-defaultState" style="width:16%"> <option value="open"> open</option> <option value="closed"> closed</option> <option value="queueing"> queueing</option> </select> <span>&emsp;</span> <label for="node-input-persist" style="width:25%; display:inline"> <input type="checkbox" id="node-input-persist" style="display:inline-block; width:15px; vertical-align:baseline;"> <span>Restore from state saved in</span></label> <select type="text" id="node-input-storeName" style="width:20%"> </select> <i class="fa fa-database"></i> </div> <br/> <!-- commands --> <div><b>Commands (case insensitive):</b></div> <br/> <div><b>Gating</b></div> <!-- openCmd & toggleCmd --> <div class="form-row"> <label for="node-input-openCmd"><i class="fa fa-circle-o"></i> Open</label> <input type="text" id="node-input-openCmd" placeholder="open" style="width:20%;"> <span>&emsp;&emsp;&emsp;&emsp;</span> <label for="node-input-toggleCmd"><i class="fa fa-arrows-v"></i> Toggle </label> <input type="text" id="node-input-toggleCmd" placeholder="toggle" style="width:20%;"> </div> <!-- closeCmd & defaultCmd --> <div class="form-row"> <label for="node-input-closeCmd"><i class="fa fa-circle"></i> Close</label> <input type="text" id="node-input-closeCmd" placeholder="close" style="width:20%;"> <span>&emsp;&emsp;&emsp;&emsp;</span> <label for="node-input-defaultCmd"><i class="fa fa-dot-circle-o"></i> Default</label> <input type="text" id="node-input-defaultCmd" placeholder="default" style="width:20%"> </div> <!-- statusCmd --> <div class="form-row"> <label for="node-input-statusCmd"><i class="fa fa-info"></i> Status</label> <input type="text" id="node-input-statusCmd" placeholder="status" style="width:20%"> </div> <br/> <div><b>Queuing</b></div> <!-- queueCmd & triggerCmd --> <div class="form-row"> <label for="node-input-queueCmd"><i class="fa fa-pause"></i> Queue</label> <input type="text" id="node-input-queueCmd" placeholder="queue" style="width:20%"> <span>&emsp;&emsp;&emsp;&emsp;</span> <label for="node-input-triggerCmd"><i class="fa fa-step-forward"></i> Trigger</label> <input type="text" id="node-input-triggerCmd" placeholder="trigger" style="width:20%"> </div> <!-- flushCmd & resetCmd --> <div class="form-row"> <label for="node-input-flushCmd"><i class="fa fa-forward"></i> Flush</label> <input type="text" id="node-input-flushCmd" placeholder="flush" style="width:20%"> <span>&emsp;&emsp;&emsp;&emsp;</span> <label for="node-input-resetCmd"><i class="fa fa-eject"></i> Reset</label> <input type="text" id="node-input-resetCmd" placeholder="reset" style="width:20%"> </div> <!-- peekCmd & dropCmd --> <div class="form-row"> <label for="node-input-peekCmd"><i class="fa fa-eye"></i> Peek</label> <input type="text" id="node-input-peekCmd" placeholder="peek" style="width:20%"> <span>&emsp;&emsp;&emsp;&emsp;</span> <label for="node-input-dropCmd"><i class="fa fa-times"></i> Drop</label> <input type="text" id="node-input-dropCmd" placeholder="drop" style="width:20%"> </div> <!-- max queue length & keep newest --> <div class="form-row"> <label for="node-input-maxQueueLength"><i class="fa fa-exclamation-triangle"></i> Max queue</label> <input type="number" id="node-input-maxQueueLength" placeholder="100" style="width:10%"> &nbsp; (< 1, no limit) <span>&emsp;&emsp;&emsp;&emsp;</span> <label for="node-input-keepNewest" style="width:25%; display:inline"> <input type="checkbox" id="node-input-keepNewest" style="display:inline-block; width:15px; vertical-align:baseline;"> <span>Keep newest messages</span></label> </div> <!-- Toggle action --> <div class="form-row"> <label for="node-input-qToggle" style="width:25%; display:inline"> <input type="checkbox" id="node-input-qToggle" style="display:inline-block; width:15px; vertical-align:baseline;"> <span>Toggle between open and queueing (default: between open and closed)</span></label> </div> <br/> <!-- Name & Version--> <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" style="width:50%"> <span>&emsp;&emsp;</span> <label id="node-version" style="width:auto" >Version</label> </div> </script> <!-- help text --> <script type="text/x-red" data-help-name="q-gate"> <p>Transmits the input message when in the <code>open</code> state, blocks it when <code>closed</code>, and adds it to the message queue when in the <code>queueing</code> state, provided the queue is not full. </p> <p> When the queue is full, the user has the choice of keeping either the oldest or the newest messages.</p> <p>Messages with the topic <code>Control Topic</code> are control messages, which change or display the state of the gate or manage the queue. Control messages setting the state are <code>open</code>, <code>close</code>, <code>toggle</code>, <code>queue</code>, and <code>default</code>. Those managing the queue are <code>trigger</code>, <code>flush</code>, <code>peek</code>, <code>drop</code>, and <code>reset</code>. The <code>status</code> command refreshes the node status. A control message payload may be a string, number, or boolean. The effects of these commands and the status object displayed by the node are described on <a href="https://github.com/drmibell/node-red-contrib-queue-gate">Github</a></p> <p>When first deployed or after a <code>default</code> command, the gate is in the state defined by <code>Default State</code>.<p> <p>After a re-deploy or Node-RED restart, the node will enter the <code>Default State</code>, unless the user has selected the <code>Restore from state saved in</code> option (checkbox) in the edit dialog and has chosen a persistent form of context storage in the adjacent dropdown list. In that case, the node will enter the state it was in prior to the re-deploy or restart and will also restore the message queue.</p> </script>