-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathwhile-loop.html
99 lines (96 loc) · 3.97 KB
/
while-loop.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
<script type="text/x-red" data-template-name="while-loop">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="while-loop.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]while-loop.label.name">
</div>
<div class="form-row">
<label for="node-input-condi"><i class="fa fa-question"></i> <span data-i18n="while-loop.label.condi"></span></label>
<input type="text" id="node-input-condi" data-i18n="[placeholder]while-loop.label.condi" autofocus>
</div>
<div class="form-tips">
<span>
Note: Pay attention to the condition expression, otherwise Node-RED may fail due to an infinite loop.
</span>
</div>
<div>
<label for="node-input-limit">
<input type="checkbox" id="node-input-limit" style="display:inline-block; width:15px; vertical-align:baseline;">
<span>
Break out of the loop after looping more than
<input type="text" id="node-input-limitTime" placeholder="10000" style="width:50px; height:28px;">
times.
</span>
</div>
<div class="form-row">
<label for="node-input-time"><i class="fa fa-tag"></i> <span data-i18n="while-loop.label.time"></span></label>
<input type="text" id="node-input-time" data-i18n="[placeholder]while-loop.label.time">
<input type="hidden" id="node-input-timeType">
</div>
</script>
<script type="text/x-red" data-help-name="while-loop">
<p>Help flow looping if the condition is true.</p>
<p>If condition expression results in false or loop time exceeds the specified value, flow breaks out of loop and message is sent from the upper output port.</p>
<h3>Inputs</h3>
<dl>
<dt>Condition Expression</dt>
<dd>If this condition expression results in true, the flow loops. In this expression, you can use msg, flow context and global context.</dd>
<dt>Time Variable</dt>
<dd>This variable stores loop times. If you check, flow exits loop when this variable exceeds the specified value.</dd>
</dl>
<h3>Outputs</h3>
<p>If the condition is true, flow is sent to the lower output port ("true" label). If false, flow is sent to the upper output port ("false" label).</p>
<h3>Details</h3>
<p>Please pay attention to the condition expression, otherwise Node-RED may fail due to an infinite loop.</p>
<p>Flow and global context can be accessed using <code>flow.get("key")</code> and <code>global.get("key")</code>.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('while-loop', {
category: 'function-loop',
defaults: {
name: {
value: ''
},
condi: {
value: '',
required: true
},
limit: {
value: false
},
limitTime: {
value: 10000,
},
time: {
value: '',
required: function () {
return this.limit;
},
validate: function () {
return !(this.timeType == 'msg' && this.time == 'payload');
}
},
timeType: {
value: 'msg'
}
},
color: '#e2d96e',
inputs: 1,
outputs: 2,
icon: 'loop.png',
label: function() {
return this.name || this.condi || 'while-loop';
},
outputLabels: ['false', 'true'],
paletteLabel: 'while-loop',
oneditprepare: function() {
if ($('#node-input-time').val() === '') {
let n = this;
$('#node-input-time').val('wl' + n.id.replace(/[^a-zA-Z0-9]/g, ''));
}
$('#node-input-time').typedInput({
types: ['msg', 'flow', 'global'],
typeField: $('#node-input-timeType')
});
}
});
</script>