node-red/nodes/core/logic/17-split.html

283 lines
13 KiB
HTML

<!--
Copyright JS Foundation and other contributors, http://js.foundation
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/x-red" data-template-name="split">
<div class="form-row"><span data-i18n="[html]split.intro"></span></div>
<div class="form-row"><span data-i18n="[html]split.strBuff"></span></div>
<div class="form-row">
<label for="node-input-splt" style="padding-left:10px; margin-right:-10px;" data-i18n="split.splitUsing"></label>
<input type="text" id="node-input-splt" style="width:70%">
<input type="hidden" id="node-input-spltType">
</div>
<div class="form-row">
<input type="checkbox" id="node-input-stream" style="margin-left:10px; vertical-align:top; width:auto;">
<label for="node-input-stream" style="width:auto;" data-i18n="split.stream"></label>
</div>
<div class="form-row"><span data-i18n="[html]split.array"></span></div>
<div class="form-row">
<label for="node-input-arraySplt" style="padding-left:10px; margin-right:-10px;" data-i18n="split.splitUsing"></label>
<input type="text" id="node-input-arraySplt" style="width:70%">
<input type="hidden" id="node-input-arraySpltType">
</div>
<div class="form-row"><span data-i18n="[html]split.object"></span></div>
<div class="form-row" style="padding-left: 10px"><span data-i18n="[html]split.objectSend"></span></div>
<div class="form-row">
<input type="checkbox" id="node-input-addname" style="margin-left:10px; vertical-align:baseline; width:auto;">
<label for="node-input-addname" style="width:auto;" data-i18n="split.addname"></label>
<input type="text" id="node-input-addfname" style="width:70%">
</div>
<hr/>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
</div>
</script>
<script type="text/x-red" data-help-name="split">
<p>A function that splits <code>msg.payload</code> into multiple messages.</p>
<p>The behaviour is determined by the type of <code>msg.payload</code>:</p>
<ul>
<li><b>string</b> - a message is sent for each part of the string after it is split using the specified character, by default a newline (<code>\n</code>).
<li><b>array</b> - a message is sent for each element of the array</li>
<li><b>object</b> - a message is sent for each key/value pair of the object. <code>msg.parts.key</code> is set to the key of the property.</li>
</ul>
<p>Each message is sent with the <code>msg.parts</code> property set. This is
an object that provides any subsequent <i>join</i> node the necessary information
for it to reassemble the messages back into a single one. The object has the following
properties:</p>
<ul>
<li><b>id</b> - an identifier for the group of messages</li>
<li><b>index</b> - the position within the group</li>
<li><b>count</b> - the total number of messages in the group</li>
<li><b>type</b> - the type of message - string/array/object</li>
<li><b>ch</b> - for a string, the character used to split</li>
<li><b>key</b> - for an object, the key of the property this message was created from</li>
</ul>
</script>
<script type="text/javascript">
RED.nodes.registerType('split',{
category: 'function',
color:"#E2D96E",
defaults: {
name: {value:""},
splt: {value:"\\n"},
spltType: {value:"str"},
arraySplt: {value:1},
arraySpltType: {value:"len"},
stream: {value:false},
addname: {value:false},
addfname: {value:"topic"}
},
inputs:1,
outputs:1,
icon: "split.png",
label: function() {
return this.name||"split";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
$("#node-input-splt").typedInput({
default: 'str',
typeField: $("#node-input-spltType"),
types:[
'str',
'bin',
{value:"len", label:RED._("node-red:split.splitLength"),validate:/^\d+$/}
]
});
if (this.arraySplt === undefined) {
$("#node-input-arraySplt").val(1);
}
$("#node-input-arraySplt").typedInput({
default: 'len',
typeField: $("#node-input-arraySpltType"),
types:[
{value:"len", label:RED._("node-red:split.splitLength"),validate:/^\d+$/}
]
});
$("#node-input-addfname").typedInput({
typeField: $("#node-input-fnameType"),
types:['msg']
});
}
});
</script>
<script type="text/x-red" data-template-name="join">
<div class="form-row">
<label data-i18n="join.mode.mode"></label>
<select id="node-input-mode" style="width:200px;">
<option value="auto" data-i18n="join.mode.auto"></option>
<option value="custom" data-i18n="join.mode.custom"></option>
</select>
</div>
<div class="node-row-custom">
<div class="form-row node-row-property">
<label data-i18n="join.combine"> </label>
<input type="text" id="node-input-property" style="width:70%;">
<input type="hidden" id="node-input-propertyType">
</div>
<div class="form-row">
<label data-i18n="join.create"></label>
<select id="node-input-build" style="width:70%;">
<option id="node-input-build-string" value="string" data-i18n="join.type.string"></option>
<option value="array" data-i18n="join.type.array"></option>
<option value="object" data-i18n="join.type.object"></option>
<option value="merged" data-i18n="join.type.merged"></option>
</select>
</div>
<div class="form-row node-row-key">
<label style="vertical-align:top; margin-top:7px;" data-i18n="join.using"></label>
<div style="display:inline-block">
<input type="text" id="node-input-key" style="width:252px;"> <span data-i18n="join.key"></span>
</div>
</div>
<div class="form-row node-row-joiner">
<label for="node-input-joiner" data-i18n="join.joinedUsing"></label>
<input type="text" id="node-input-joiner" style="width:40px">
</div>
<div class="form-row node-row-trigger" id="trigger-row">
<label style="width:auto;" data-i18n="join.send"></label>
<ul>
<li>
<label style="width:280px;" for="node-input-count" data-i18n="join.afterCount"></label> <input id="node-input-count" data-i18n="[placeholder]join.count" type="text" style="width:75px;">
</li>
<li style="list-style-type:none;">
<input type="checkbox" id="node-input-accumulate" style="display:inline-block; width:20px; list-style-type:none; margin-left:20px; vertical-align:top;"> <span data-i18n="join.subsequent"></span>
</li>
<li>
<label style="width:280px;" for="node-input-timeout" data-i18n="join.afterTimeout"></label> <input id="node-input-timeout" data-i18n="[placeholder]join.seconds" type="text" style="width:75px;">
</li>
<li>
<label style="width:auto; padding-top:6px;" data-i18n="[html]join.complete"></label>
</li>
</ul>
</div>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
</div>
<div class="form-tips form-tips-auto hide" data-i18n="[html]join.tip"></div>
</script>
<script type="text/x-red" data-help-name="join">
<p>Joins sequences of messages into a single message.</p>
<p>When paired with the <b>split</b> node, it will automatically join the messages
to reverse the split that was performed.</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt class="optional">parts<span class="property-type">object</span></dt>
<dd>To automatically join a sequence of messages, they should all have
this property set. The <b>split</b> node generates this property but it
can be manually created. It has the following properties:
<ul>
<li><code>id</code> - an identifier for the group of messages</li>
<li><code>index</code> - the position within the group</li>
<li><code>count</code> - the total number of messages in the group</li>
<li><code>type</code> - the type of message - string/array/object</li>
<li><code>ch</code> - for a string, the character used to split</li>
<li><code>key</code> - for an object, the key of the property this message was created from</li>
<li><code>len</code> - for an array, the length of each array section</li>
</ul>
</dd>
<dt class="optional">complete</dt>
<dd>If set, the node will send its output message in its current state.</dd>
</dl>
<h3>Details</h3>
<p>When configured to join in manual mode, the node is able to join sequences
of messages in a variety of ways.</p>
<ul>
<li>a <b>string</b> - created by joining the selected property of each message with the specified join character.</li>
<li>an <b>array</b>.</li>
<li>a <b>key/value object</b> - created by using a property of each message to determine the key under which
the required value is stored.</li>
<li>a <b>merged object</b> - created by merging the property of each message under a single object.</li>
</ul>
<p>The other properties of the output message are taken from the last message received before the result is sent.</p>
<p>A <i>count</i> can be set for how many messages should be received before generating the output message.</p>
<p>A <i>timeout</i> can be set to trigger sending the new message using whatever has been received so far.</p>
<p>If a message is received with the <b>msg.complete</b> property set, the output message is sent.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('join',{
category: 'function',
color:"#E2D96E",
defaults: {
name: {value:""},
mode: {value:"auto"},
build: { value:"string"},
property: { value:"payload", validate:RED.validators.typedInput("propertyType")},
propertyType: { value:"msg"},
key: {value:"topic"},
joiner: { value:"\\n"},
accumulate: { value:"false" },
//topic: { value:""},
timeout: {value:""},
count: {value:""}
},
inputs:1,
outputs:1,
icon: "join.png",
label: function() {
return this.name||"join";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
$("#node-input-mode").change(function(e) {
var val = $(this).val();
$(".node-row-custom").toggle(val==='custom');
$(".form-tips-auto").toggle(val==='auto');
if (val === "auto") {
$("#node-input-accumulate").attr('checked', false);
}
});
$("#node-input-build").change(function(e) {
var val = $(this).val();
$(".node-row-key").toggle(val==='object');
$(".node-row-joiner").toggle(val==='string');
$(".node-row-trigger").toggle(val!=='auto');
if (val === 'string') {
$("#node-input-property").typedInput('types',['msg']);
} else {
$("#node-input-property").typedInput('types',['msg', {value:"full",label:"complete message",hasValue:false}]);
}
});
$("#node-input-property").typedInput({
typeField: $("#node-input-propertyType"),
types:['msg', {value:"full", label:"complete message", hasValue:false}]
});
$("#node-input-key").typedInput({
types:['msg', {value:"merge", label:"", hasValue:false}]
});
$("#node-input-build").change();
$("#node-input-mode").change();
}
});
</script>