UNPKG

@totallyinformation/node-red-contrib-events

Version:
170 lines (136 loc) 6.51 kB
<!-- Copyright (c) 2021 Julian Knight (Totally Information) 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. --> <script type="text/javascript"> /* eslint-disable strict */ // Isolate this code (function () { 'use strict' const nodeLabel = 'event-out' /** Prep for edit * @param {*} node - */ function onEditPrepare(node) { // Handle v1.0 legacy if (node.passthrough === true) $('#node-input-passthrough').val('input') //node.passthrough = 'input' else if (node.passthrough === false) $('#node-input-passthrough').val('none') //node.passthrough = 'none' // Initial state $(`#passthrough-${node.passthrough}`).attr('checked', true) // Handle change on radio inputs $('[name="passthrough"]') // If the setting changes, change the number of output ports .on('change', function passthroughChange(event) { let passthrough = event.target.id.replace('passthrough-', '') $('#node-input-passthrough').val(passthrough) if ( passthrough === 'none') node.outputs = 0 else node.outputs = 1 }) } RED.nodes.registerType(nodeLabel, { category: 'Events', color: '#E6E0F8', defaults: { name: { value: '' }, topic: { value: '' }, passthrough: { value: 'none', required:true }, outputs: { value: 0 }, }, align:'right', inputs: 1, inputLabels: 'Msg with topic property', outputs: 0, outputLabels: function (i) { return this.passthrough === 'return' ? 'msg returned from event-return node' : 'Input msg with node ID added' }, // eslint-disable-line no-unused-vars icon: 'link-out.svg', paletteLabel: nodeLabel, label: function () { return this.name || this.topic || nodeLabel }, /** Available methods: * oneditprepare: (function) called when the edit dialog is being built. * oneditsave: (function) called when the edit dialog is okayed. * oneditcancel: (function) called when the edit dialog is canceled. * oneditdelete: (function) called when the delete button in a configuration node’s edit dialog is pressed. * oneditresize: (function) called when the edit dialog is resized. * onpaletteadd: (function) called when the node type is added to the palette. * onpaletteremove: (function) called when the node type is removed from the palette. */ oneditprepare: function() { onEditPrepare(this) }, }) // ---- End of registerType() ---- // }()) </script> <script type="text/html" data-template-name="event-out"> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-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"> </div> <div class="form-row" style="border: 1px solid silver;width:auto;padding:1em;"> <input type="text" id="node-input-passthrough" style="display:none;"> <div style="padding-bottom: 1em;width:29em;"> This node has an optional output port that either passes the input msg to the output. Or it uses a <code>event-return</code> node allowing flow loops to be easily created: </div> <div> <input type="radio" id="passthrough-none" value="none" name="passthrough" style="width: auto; vertical-align: baseline;"> <label for="passthrough-none" style="min-width:20em;">No outputs.</label> </div> <div> <input type="radio" id="passthrough-input" value="input" name="passthrough" style="width: auto; vertical-align: baseline;"> <label for="passthrough-input" style="min-width:20em;">Pass input msg to output?</label> </div> <div> <input type="radio" id="passthrough-return" value="return" name="passthrough" style="width: auto; vertical-align: baseline;"> <label for="passthrough-return" style="min-width:20em;">Allow output from a <code>event-return</code> node?</label> </div> </div> </script> <script type="text/html" data-help-name="event-out"> <p> Event-driven notifications. Create an event from an input msg.topic. Any <code>event-in</code> node with a matching topic specified will receive the input msg. </p> <h3>Inputs</h3> <dl class="message-properties"> <dt class="optional">payload <span class="property-type">string | buffer</span></dt> <dd> Optionally, the payload of the message to send to all connected client browser tabs. </dd> <dt class="optional">topic <span class="property-type">string</span></dt> <dd> Optionally, the MQTT topic to use. Takes preference over the topic defined in settings.</dd> </dl> <h3>Outputs</h3> <p> If <code>passthrough</code> is set, the input message is sent to the output. </p> <h3>Node Settings</h3> <dl class="message-properties"> <dt>Name <span class="property-type">string</span></dt> <dd>A short description shown in the admin interface</dd> <dt>Topic <span class="property-type">string</span></dt> <dd>A topic name to use if the incoming msg does not contain one.</dd> <dt>passthrough <span class="property-type">string, hidden</span></dt> <dd> Set by the 3 radio buttons to one of 'none', 'input', or 'return'. <ul> <li> <b>None</b>: No output port. </li> <li> <b>Input</b>: A copy of the input msg is sent to the output. </li> <li> <b>Return</b>: The node listens for output from an <code>event-return</code> node receiving a <code>msg._eventOriginator</code> property having the same ID as this node. This allows for sub-flows and loops to be created. </li> </ul> </dd> </dl> </script>