UNPKG

node-red-contrib-dsm

Version:

A dynamic state machine node based on the finite state machine model.

126 lines (119 loc) 4.49 kB
<script type="text/x-red" data-template-name="dsm"> <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> <div class="form-row" style="margin-bottom: 0px;"> <label for="node-input-sm_config" style="width: 100% !important;"><i class="fa fa-list"></i> Config</label> <input type="hidden" id="node-input-sm_config" autofocus="autofocus"> </div> <div class="form-row node-text-editor-row"> <div style="height: 250px; min-height:150px;" class="node-text-editor" id="node-input-sm_config-editor"></div> </div> </script> <script type="text/x-red" data-help-name="dsm"> <p>A dynamic state machine node based on the finite state machine model.</p> <h3>Inputs</h3> <dl class="message-properties"> <dt>payload <span class="property-type">object</span> </dt> <dd> dsm configuration</dd> <dt class="optional">topic <span class="property-type">string</span></dt> <dd> set</dd> </dl> <dl class="message-properties"> <dt>msg <span class="property-type">object</span></dt> <dd>The triggerInput as defined in the configuration, default <code>topic</code>.</dd> </dl> <h3>Outputs</h3> <dl class="message-properties"> <dt>msg <span class="property-type">object</span></dt> <dd>The currentState added to the message as defined in the configuration, default <code>topic</code>.</dd> <dd>If the <code>globalOutput</code> is defined in the configuration, the global variable is additionally set.</dd> <dd>If the <code>flowlOutput</code> is defined in the configuration, the flow variable is additionally set.</dd> </dl> <h3>Details</h3> <p>In addition to states and transitions a <code>dsm</code> can also contain arbitrary data and methods.</p> <li><a href="https://github.com/cflurin/node-red-contrib-dsm#data-and-methods">Consult the documentation on GitHub</a></li> <p></p> <h4>A dsm configuration example</h4> <pre> { "currentState": "closed", "states": { "opened": { "close": "closed", "stop": "stopped" }, "closed": { "open": "opened", "stop": "stopped" }, "stopped": { "open": "opened", "close": "closed" } } } </pre> <h3>References</h3> <ul> <li><a href="https://en.wikipedia.org/wiki/Finite-state_machine">Finite state machine</a></li> </ul> </script> <script type="text/javascript"> RED.nodes.registerType('dsm',{ category: 'advanced', color: "#E9967A", defaults: { name: {value:""}, sm_config: {value:"", validate: RED.validators.typedInput("json")} }, inputs:1, outputs:1, icon: "switch.png", label: function() { var suffix = ""; if (this.sm_config) { suffix = " ✔"; } else { suffix = " ❖"; } return (this.name||"dsm")+suffix; }, inputLabels: "set|trigger|methods", outputLabels: "currentState|data", oneditprepare: function() { var that = this; this.editor = RED.editor.createEditor({ id: 'node-input-sm_config-editor', mode: 'ace/mode/json', value: $("#node-input-sm_config").val() }); this.editor.focus(); }, oneditsave: function() { $("#node-input-sm_config").val(this.editor.getValue()); this.editor.destroy(); delete this.editor; }, oneditcancel: function() { this.editor.destroy(); delete this.editor; }, oneditresize: function(size) { var rows = $("#dialog-form>div:not(.node-text-editor-row)"); var height = $("#dialog-form").height(); for (var i=0; i<rows.size(); i++) { height -= $(rows[i]).outerHeight(true); } var editorRow = $("#dialog-form>div.node-text-editor-row"); height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom"))); $(".node-text-editor").css("height",height+"px"); this.editor.resize(); } }); </script>