-
Notifications
You must be signed in to change notification settings - Fork 1
/
sequence-detector.html
151 lines (140 loc) · 6.72 KB
/
sequence-detector.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<script type="text/x-red" data-template-name="sequence-detector">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
</div>
<div class="form-row">
<label for="node-input-watch"><i class="fa fa-search"></i> Watch</span></label>
<select id="node-input-watch" style="width:180px;">
<option value="topic">Topic</option>
<option value="payload">Payload</option>
<option value="both">Both</option>
</select>
</div>
<div class="form-row" style="position: relative; margin-bottom: 0px;">
<label for="node-input-sequence"><i class="fa fa-ellipsis-h"></i> Sequence</span></label>
<input type="hidden" id="node-input-sequence" autofocus="autofocus">
</div>
<div class="form-row node-text-editor-row">
<div style="height:250px;" class="node-text-editor" id="node-input-sequence-editor"></div>
</div>
<div class="form-row">
<label for="node-input-timeout"><i class="fa fa-hourglass-end"></i> <span>timeout</span></label>
<input type="number" id="node-input-timeout"></input>
</div>
<div class="form-row">
<label for="node-input-matchMessage"><i class="fa fa-envelope"></i> <span>Match Payload</span></label>
<input type="text" id="node-input-matchMessage"></input>
</div>
<div class="form-row">
<label for="node-input-resetMessage"><i class="fa fa-envelope"></i> <span>Reset Payload</span></label>
<input type="text" id="node-input-resetMessage"></input>
</div>
<div class="form-row">
<label for="node-input-timeoutMessage"><i class="fa fa-envelope"></i> <span>Timeout Payload</span></label>
<input type="text" id="node-input-timeoutMessage"></input>
</div>
</script>
<script type="text/x-red" data-help-name="sequence-detector">
<p>Inspects all incoming messages in order and matches against the configured sequence.</p>
<h3>Inputs</h3>
<dl class="message-properties">
Either the payload, topic, or both can be inspected for sequence detection using the <code>watch</code> config option.
<dt>payload
<span class="property-type">string</span>
</dt>
<dd> the payload of the message to inspect. </dd>
<dt class="optional">topic <span class="property-type">string</span></dt>
<dd> the topic to inspect.</dd>
</dl>
<h3>Outputs</h3>
<ol class="node-ports">
<li>Match output
<dl class="message-properties">
<dt>payload <span class="property-type">string</span></dt>
<dd>the message payload sent when the full sequence is detected in exact order. The output is <code>match</code>.</dd>
</dl>
</li>
<li>Reset Output
<dl class="message-properties">
<dt>payload <span class="property-type">string</span></dt>
<dd>the message payload sent when the sequence detector resets and starts looking for the first element of the sequence again. The output is <code>reset</code>.</dd>
<dd>the message payload sent when the sequence detector reached the timeout limit and starts looking for the first element of the sequence again. The output is <code>timeout</code>.</dd>
</dl>
<p><code>match</code>, <code>reset</code>, and <code>timeout</code> output message payloads can be configured.</p>
</li>
</ol>
<h3>Details</h3>
<p><code>msg.payload</code> or <code>msg.topic</code> or both can be used.
Messages will be inspected and if a series of messages matches the configured sequence in the exact order,
a <code>match</code> message will be sent. </p>
<p>If any message breaks the sequence, the detector will reset and start to look for the configured sequence from the first element of the sequence again.
A <code>reset</code> message will be sent.</p>
<p>If the configured timeout elapsed, and <code>timeout</code> message will be sent.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('sequence-detector',{
color:"#E2D96E",
category: 'function',
defaults: {
name: {value:"Sequence Detector"},
watch: {value:"topic"},
sequence: {value:"event1\nevent2\n"},
timeout: {value:"3000"},
matchMessage: {value:"match"},
resetMessage: {value:"reset"},
timeoutMessage: {value:"timeout"}
},
inputs:1,
outputs:2,
icon: "font-awesome/fa-ellipsis-h",
paletteLabel: function() {
return "detector";
},
label: function() {
return this.name || "sequence-detector";
},
outputLabels: ["match","reset"],
oneditprepare: function() {
//console.log(this._("node-red-local-decoder/decoder:decoder.label.sequence"));
var that = this;
// $("#node-input-field").typedInput({
// default: 'msg',
// types: ['msg','flow','global'],
// typeField: $("#node-input-fieldType")
// });
this.editor = RED.editor.createEditor({
id: 'node-input-sequence-editor',
mode: 'ace/mode/handlebars',
value: $("#node-input-sequence").val()
});
// RED.library.create({
// url:"sequences", // where to get the data from
// type:"sequence", // the type of object the library is for
// editor:that.editor, // the field name the main text body goes to
// fields:['name','outputs']
// });
this.editor.focus();
},
oneditsave: function() {
$("#node-input-sequence").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>