-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy patharray-loop.html
136 lines (130 loc) · 5.48 KB
/
array-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
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
<script type="text/x-red" data-template-name="array-loop">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="array-loop.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]array-loop.label.name">
</div>
<div class="form-row">
<label for="node-input-key"><i class="fa fa-key"></i> <span data-i18n="array-loop.label.key"></span></label>
<input type="text" id="node-input-key" data-i18n="[placeholder]array-loop.label.key">
<input type="hidden" id="node-input-keyType">
</div>
<div>
<label for="node-input-reset">
<input type="checkbox" id="node-input-reset" style="display:inline-block; width:15px; vertical-align:baseline;">
<span>
Set key variable to
<select id="resetValue-select" style="width: 120px;">
<option value="value-null">null</option>
<option value="value-undefined">undefined</option>
<option value="value-empty">empty string</option>
</select>
when exiting the loop.
<input type="hidden" id="node-input-resetValue">
</span>
</div>
<div class="form-tips" style="margin-bottom: 5px;">
<span>
Tip: Key needs to be <code>null</code>, <code>undefined</code> or empty string
when a flow reached this node for the first time.
</span>
</div>
<div class="form-row">
<label for="node-input-array"><i class="fa fa-list"></i> <span data-i18n="array-loop.label.array"></span></label>
<input type="text" id="node-input-array" data-i18n="[placeholder]array-loop.label.array">
<input type="hidden" id="node-input-arrayType">
</div>
<div class="form-tips">
<span>
Note: If you manipulate key variable or array in the loop, Node-RED may fail due to an infinite loop.
</span>
</div>
</script>
<script type="text/x-red" data-help-name="array-loop">
<p>Help flow looping until the end of the specified array.</p>
<p>If reaching the end of array, flow breaks out of loop and message is sent from the upper output port.</p>
<h3>Inputs</h3>
<dl>
<dt>Key Variable</dt>
<dd>Define whether to use for key variable which stores an array index number. Set to msg property, flow context or global context. This property must be <code>null</code>, <code>undefined</code> or empty string when a flow reached this node for the first time. If not those, key variable is not set to 0.</dd>
<dt>Array</dt>
<dd></dd>
</dl>
<h3>Output</h3>
<p>Until reaching the end of array, flow is sent to the lower output port. After that flow is sent to the upper output port ("end array" label).</p>
<dl class="message-properties">
<dt>payload <span class="property-type"></span></dt>
<dd>Until reaching the end of array, an element of the specified array is send to the lower output port.</dd>
</dl>
<h3>Details</h3>
<p>When exiting the loop, counter variable can reset by setting to <code>null</code>, <code>undefined</code> or empty string. This is useful for multi-loop.</p>
<p>Please note if you select message property, flow or global context property for inputs, if manipulate these in the loop, Node-RED may fail due to an infinite loop.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('array-loop', {
category: 'function-loop',
defaults: {
name: {
value: ""
},
key: {
value: "",
required: true,
validate: function () {
return !(this.keyType == 'msg' && this.key == 'payload');
}
},
keyType: {
value: "msg"
},
reset: {
value: false
},
resetValue: {
value: 'value-null',
required: true
},
array: {
value: "",
required: true,
validate: function () {
return !(this.arrayType == 'msg' && this.array == 'payload');
}
},
arrayType: {
value: "msg"
}
},
color: "#e2d96e",
inputs: 1,
outputs: 2,
icon: "loop.png",
label: function() {
let expression;
if (this.array) {
expression = this.arrayType + '.' + this.array;
}
return this.name || expression || 'array-loop';
},
outputLabels: ["end array", ""],
paletteLabel: 'array-loop',
oneditprepare: function() {
if ($('#node-input-key').val() === '') {
let n = this;
$('#node-input-key').val('al' + n.id.replace(/[^a-zA-Z0-9]/g, ''));
}
$('#resetValue-select').val(this.resetValue);
$("#node-input-key").typedInput({
types: ["msg", "flow", "global"],
typeField: $('#node-input-keyType')
});
$("#node-input-array").typedInput({
types: ["msg", "flow", "global"],
typeField: $('#node-input-arrayType')
});
$('#resetValue-select').on('change', function() {
let v = $(this).val();
$('#node-input-resetValue').val(v);
});
}
});
</script>