forked from cflurin/node-red-contrib-dsm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdsm.html
125 lines (119 loc) · 4.38 KB
/
dsm.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<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>