1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00
node-red/nodes/core/logic/17-split.html

213 lines
9.6 KiB
HTML
Raw Permalink Normal View History

2016-06-04 01:40:40 +02:00
<!DOCTYPE html>
<!--
Copyright JS Foundation and other contributors, http://js.foundation
2016-06-04 01:40:40 +02:00
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">
<label for="node-input-splt"><i class="fa fa-scissors"></i> Split</label>
<input type="text" id="node-input-splt" placeholder="character to split strings on : e.g. \n">
</div>
<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">
</div>
</script>
<script type="text/x-red" data-help-name="split">
2016-06-09 12:33:40 +02:00
<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>
2016-06-10 23:51:57 +02:00
<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>
2016-06-04 01:40:40 +02:00
</script>
<script type="text/javascript">
RED.nodes.registerType('split',{
category: 'function',
color:"#E2D96E",
defaults: {
name: {value:""},
splt: {value:"\\n"}
2016-06-04 01:40:40 +02:00
},
inputs:1,
outputs:1,
2016-06-12 13:24:52 +02:00
icon: "split.png",
2016-06-04 01:40:40 +02:00
label: function() {
return this.name||"split";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
}
});
</script>
<script type="text/x-red" data-template-name="join">
<div class="form-row">
2016-06-06 22:18:20 +02:00
<label>Mode</label>
<select id="node-input-mode" style="width:200px;">
2016-06-04 01:40:40 +02:00
<option value="auto">automatic</option>
2016-06-06 22:18:20 +02:00
<option value="custom">manual</option>
2016-06-04 01:40:40 +02:00
</select>
</div>
2016-06-06 22:18:20 +02:00
<div class="node-row-custom">
<div class="form-row node-row-property">
2016-06-10 23:51:57 +02:00
<label>Combine each </label>
<input type="text" id="node-input-property" style="width:70%;">
2016-06-06 22:18:20 +02:00
<input type="hidden" id="node-input-propertyType">
</div>
<div class="form-row">
<label>to create </label>
<select id="node-input-build" style="width:200px;">
<option id="node-input-build-string" value="string">a String</option>
<option value="array">an Array</option>
2016-06-11 22:43:37 +02:00
<option value="object">a key/value Object</option>
<option value="merged">a merged Object</option>
2016-06-06 22:18:20 +02:00
</select>
</div>
<div class="form-row node-row-key">
<label style="vertical-align: top; margin-top: 7px;">using</label>
<div style="display:inline-block">
<input type="text" id="node-input-key" style="width:300px;">
<div style="margin-top: 7px;">as the property key</div>
</div>
</div>
<div class="form-row node-row-joiner">
<label for="node-input-joiner">joined using</label>
<input type="text" id="node-input-joiner" style="width: 40px">
</div>
2016-06-04 01:40:40 +02:00
2016-06-06 22:18:20 +02:00
<div class="form-row node-row-trigger">
<label style="width: auto;">Send the message:</label>
<ul>
<li style="height: 40px;">
<label style="width: 280px;" for="node-input-count">After a fixed number of messages:</label> <input id="node-input-count" placeholder="count" type="text" style="width: 75px;">
</li>
<li style="height: 40px;">
<label style="width: 280px;" for="node-input-timeout">After a timeout following the first message:</label> <input id="node-input-timeout" placeholder="seconds" type="text" style="width: 75px;">
</li>
<li style="height: 40px;">
<label style="width: auto; padding-top: 6px;">After a message with the <code>msg.complete</code> property set</label>
</li>
</ul>
</div>
2016-06-04 01:40:40 +02:00
</div>
<div class="form-tips form-tips-auto hide">This mode assumes this node is either
paired with a <i>split</i> node or the received messages will have a properly
configured <code>msg.parts</code> property.</div>
</script>
<script type="text/x-red" data-help-name="join">
<p>A function that joins a sequence of messages into a single message.</p>
2016-06-10 23:51:57 +02:00
<p>When paired with the <b>split</b> node, it will automatically join the messages
to reverse the split that was performed.</p>
2016-06-11 22:43:37 +02:00
<p>The node can join either a specific property of each received message or,
if the output type is not string, the entire message.</p>
<p>The type of the resulting message property can be:</p>
<ul>
<li>a <b>string</b> - created by joining the 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>
The other properties of the output message are taken from the last message received before the result is sent.</p>
2016-06-10 23:51:57 +02:00
<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>
2016-06-11 22:43:37 +02:00
<p>If a message is received with the <b>msg.complete</b> property set, the output message is sent.</p>
<p>The automatic behaviour relies on the received messages to have <b>msg.parts</b> set. The split node generates
this property, but can be manually created. It 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>
2016-06-04 01:40:40 +02:00
</script>
<script type="text/javascript">
RED.nodes.registerType('join',{
category: 'function',
color:"#E2D96E",
defaults: {
name: {value:""},
2016-06-06 22:18:20 +02:00
mode: {value:"auto"},
build: { value:"string"},
property: { value: "payload", validate: RED.validators.typedInput("propertyType")},
propertyType: { value:"msg"},
key: {value:"topic"},
joiner: { value:"\\n"},
2016-06-04 01:40:40 +02:00
timeout: {value:""},
2016-06-06 22:18:20 +02:00
count: {value:""}
2016-06-04 01:40:40 +02:00
},
inputs:1,
outputs:1,
icon: "join.png",
label: function() {
return this.name||"join";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
2016-06-06 22:18:20 +02:00
$("#node-input-mode").change(function(e) {
var val = $(this).val();
$(".node-row-custom").toggle(val==='custom');
$(".form-tips-auto").toggle(val==='auto');
});
$("#node-input-build").change(function(e) {
2016-06-04 01:40:40 +02:00
var val = $(this).val();
2016-06-06 22:18:20 +02:00
$(".node-row-key").toggle(val==='object');
$(".node-row-joiner").toggle(val==='string');
2016-06-04 01:40:40 +02:00
$(".node-row-trigger").toggle(val!=='auto');
2016-06-06 22:18:20 +02:00
if (val === 'string') {
$("#node-input-property").typedInput('types',['msg']);
2016-06-06 22:18:20 +02:00
} else {
$("#node-input-property").typedInput('types',['msg', {value:"full",label:"complete message",hasValue:false}]);
}
2016-06-04 01:40:40 +02:00
})
$("#node-input-property").typedInput({
typeField: $("#node-input-propertyType"),
types:['msg', {value:"full",label:"complete message",hasValue:false}]
})
$("#node-input-key").typedInput({
2016-06-10 23:51:57 +02:00
types:['msg', {value:"merge",label:"",hasValue: false}]
2016-06-04 01:40:40 +02:00
})
$("#node-input-build").change();
2016-06-06 22:18:20 +02:00
$("#node-input-mode").change();
2016-06-04 01:40:40 +02:00
}
});
</script>