-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathm-queue.html
248 lines (240 loc) · 11.6 KB
/
m-queue.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!--
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.
-->
<script type="text/javascript">
RED.nodes.registerType('m-queue',{
category: 'function',
color: '#f3b567',
defaults: {
name: {value:""},
queueSelect: {value:"topic"},
controlFlag: {value:"control"},
// special queue selectors
defaultQueue: {value:"default"},
allQueues: {value:"all"},
// commands
triggerCmd: {value:"trigger"},
statusCmd: {value:"status"},
pauseCmd: {value:"pause"},
resumeCmd: {value:"resume"},
flushCmd: {value:"flush"},
resetCmd: {value:"reset"},
peekCmd: {value:"peek"},
dropCmd: {value:"drop"},
maximumCmd: {value:"maximum"},
newestCmd: {value:"newest"},
protectCmd: {value:"protect"},
deleteCmd: {value:"delete"},
// queue properties
paused: {value:false},
protect: {value:false},
keepNewestDefault: {value:false},
maxSizeDefault: {value:100},
protectDefault:{value:false},
// general defaults
persist: {value:false},
newValue: {value:"value"},
storeName: {value:RED.settings.context.default},
statusOutput: {value:false},
outputs: {value:1}
},
inputs:1,
outputs:1,
icon: "multiple-queue.png",
paletteLabel: "m–queue",
label: function() {
return this.name||"m-queue";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
var node = this
// configure storage options
RED.settings.context.stores.forEach(add)
function add(item){
$('#node-input-storeName').append(`<option value="${item}">${item}</option>`)
}
$('#node-input-storeName').val(node.storeName)
$("#node-input-persist").on("change", function(e) {
$("#node-input-storeName").prop("disabled", !$(this).prop("checked"))
});
// configure control message property names
$("#node-input-queueSelect").typedInput({
type:"msg",
types:["msg"]
});
$("#node-input-controlFlag").typedInput({
type:"msg",
types:["msg"]
});
$("#node-input-newValue").typedInput({
type:"msg",
types:["msg"]
});
// configure status output
node.outputs = $("#node-input-statusOutput").prop('checked') ? 2 : 1;
$("#node-input-statusOutput").change(function() {
node.outputs = this.checked ? 2 : 1;
});
// configure version number
const version = RED.nodes.registry.getModule("node-red-contrib-multiple-queue").version
$('#node-version').append(` ${version}`)
},
oneditsave: function () {
var node = this;
node.outputs = $("#node-input-statusOutput").prop('checked') ? 2 : 1;
}
});
</script>
<script type="text/html" data-template-name="m-queue">
<!-- queueSelect & controlFlag-->
<div class="form-row">
<label style="width:auto" for="node-input-queueSelect"><i class="fa fa-bars"></i>
Queue Selector</label>
<input type="text" id="node-input-queueSelect" placeholder="topic" style="width:20%">
<span>    </span>
<label for="node-input-controlFlag"><i class="fa fa-cog"></i> Control Flag</label>
<input type="text" id="node-input-controlFlag" placeholder="control" style="width:20%">
</div>
<!-- special queue selectors -->
<div><b>Special queue selectors (case insensitive):</b></div>
<div class="form-row">
<label style="width:auto" for="node-input-defaultQueue"><i class="fa fa-check-square-o"></i>
Default Queue</label>
<input type="text" id="node-input-defaultQueue" placeholder="default"
style="width:20%">
<span>    </span>
<label for="node-input-allQueues"><i class="fa fa-clone"></i>
All Queues</label>
<input type="text" id="node-input-allQueues" placeholder="all"
style="width:20%">
</div>
<!-- commands -->
<div><b>Command payloads (case insensitive):</b></div>
<!-- triggerCmd & statusCmd-->
<div class="form-row">
<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%">
<span>    </span>
<label for="node-input-statusCmd"><i class="fa fa-question"></i>
Status</label>
<input type="text" id="node-input-statusCmd" placeholder="status"
style="width:20%">
</div>
<!-- pauseCmd & resumeCmd -->
<div class="form-row">
<label for="node-input-pauseCmd"><i class="fa fa-pause"></i> Pause</label>
<input type="text" id="node-input-pauseCmd" placeholder="pause" style="width:20%">
<span>    </span>
<label for="node-input-resumeCmd"><i class="fa fa-play"></i> Resume</label>
<input type="text" id="node-input-resumeCmd" placeholder="resume" 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>    </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>    </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 size & keep newest -->
<div class="form-row">
<label for="node-input-maximumCmd"><i class="fa fa-exclamation"></i> Maximum</label>
<input type="text" id="node-input-maximumCmd" placeholder="maximum" style="width:20%">
<span>    </span>
<label for="node-input-newestCmd"><i class="fa fa-clock-o"></i> Newest</label>
<input type="text" id="node-input-newestCmd" placeholder="newest" style="width:20%">
</div>
<!-- protect & delete -->
<div class="form-row">
<label for="node-input-protectCmd"><i class="fa fa-shield"></i> Protect</label>
<input type="text" id="node-input-protectCmd" placeholder="protect" style="width:20%">
<span>    </span>
<label for="node-input-deleteCmd"><i class="fa fa-trash"></i> Delete</label>
<input type="text" id="node-input-deleteCmd" placeholder="delete" style="width:20%">
</div>
<!-- initial settings -->
<div><b>Default settings for all queues:</b></div>
<div class="form-row">
<label style="width:auto" for="node-input-maxSizeDefault"><i class="fa fa-exclamation-triangle"></i>
Maximum Queue Size</label>
<input type="number" id="node-input-maxSizeDefault" placeholder=100 style="width:10%">
(< 1, no limit)
</div>
<div class="form-row">
<label for="node-input-keepNewestDefault" style="width:25%; display:inline">
<input type="checkbox" id="node-input-keepNewestDefault" style="display:inline-block; width:15px; vertical-align:baseline;">
<span>Keep newest messages</span></label>
<span>    </span>
<label for="node-input-protectDefault" style="width:25%; display:inline">
<input type="checkbox" id="node-input-protectDefault" style="display:inline-block; width:15px; vertical-align:baseline;">
<span>Protect empty queues</span></label>
</div>
<!-- modify settings -->
<div><b>Modify settings for selected queue:</b></div>
<div class="form-row">
<label style="width:auto" for="node-input-newValue"><i class="fa fa-sliders"></i>
Value for Max Queue Size, Keep Newest Message, or Protect Queue</label>
<input type="text" id="node-input-newValue" placeholder="value" style="width:20%">
</div>
<!-- persistence & status output -->
<div>
<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>
<span>  </span>
<label for="node-input-statusOutput" style="width:25%; display:inline">
<input type="checkbox" id="node-input-statusOutput" style="display:inline-block;
width:15px; vertical-align:baseline;">
<span>Send status to second output</span></label>
</div>
<br/>
<!-- Name -->
<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>  </span>
<label id="node-version" style="width:auto" >Version</label>
</div>
</script>
<script type="text/html" data-help-name="m-queue">
<p>Provides multiple, independently controlled message queues.</p>
<p>Queues are created as needed and destroyed when empty, except for the <code>Default
queue</code>, which is always available. Each queue is identified by a unique <code>Name</code>
string that is used to steer messages to it by matching against the message
<code>Queue Selector</code> property. If that property is undefined,
the message is directed to the <code>Default Queue</code>.
<p>Messages with the property <code>Control Flag</code> set to <code>true</code> are
control messages, which manage the queue. The effects of these commands and the
status object reported by the node are described at
<a href="https://github.com/drmibell/node-red-contrib-multiple-queue">Github</a></p>
<p> When a queue is full, the user has the choice of keeping either the oldest or the newest messages.</p>
<p>After a re-deploy or Node-RED restart, all queues except the <code>Default Queue</code>
will be deleted 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 restore the queues and node settings to their
state prior to the re-deploy or restart. </p>
</script>