mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
148 lines
6.1 KiB
HTML
148 lines
6.1 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.
|
|
-->
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<script type="text/x-red" data-template-name="sort">
|
|
|
|
<div class="form-row">
|
|
<label for="node-input-target"><i class="fa fa-dot-circle-o"></i> <span data-i18n="sort.target"></span></label>
|
|
<input type="text" id="node-input-target" style="width:70%;">
|
|
<input type="hidden" id="node-input-targetType">
|
|
</div>
|
|
|
|
<div class="node-row-sort-msg-key">
|
|
<div class="form-row">
|
|
<label for="node-input-msgKey"><i class="fa fa-filter"></i> <span data-i18n="sort.key"></span></label>
|
|
<input type="text" id="node-input-msgKey" style="width:70%;">
|
|
<input type="hidden" id="node-input-msgKeyType">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="node-row-sort-seq-key">
|
|
<div class="form-row">
|
|
<label for="node-input-seqKey"><i class="fa fa-filter"></i> <span data-i18n="sort.key"></span></label>
|
|
<input type="text" id="node-input-seqKey" style="width:70%;">
|
|
<input type="hidden" id="node-input-seqKeyType">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
<label><i class="fa fa-random"></i> <span data-i18n="sort.order"></span></label>
|
|
<select id="node-input-order" style="width:200px;">
|
|
<option value="ascending" data-i18n="sort.ascending"></option>
|
|
<option value="descending" data-i18n="sort.descending"></option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-row" id="node-as_num">
|
|
<label> </label>
|
|
<input type="checkbox" id="node-input-as_num" style="display: inline-block; width: auto; vertical-align: top;">
|
|
<label for="node-input-as_num" style="width: 70%;" data-i18n="sort.as-number"></label>
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
|
|
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
|
|
</div>
|
|
</script>
|
|
|
|
<script type="text/x-red" data-help-name="sort">
|
|
<p>A function that sorts message property or a sequence of messages.</p>
|
|
<p>When configured to sort message property, the node sorts array data pointed to by specified message property.</p>
|
|
<p>When configured to sort a sequence of messages, it will reorder the messages.</p>
|
|
<p>The sorting order can be:</p>
|
|
<ul>
|
|
<li><b>ascending</b>,</li>
|
|
<li><b>descending</b>.</li>
|
|
</ul>
|
|
<p>For numbers, numerical ordering can be specified by a checkbox.</p>
|
|
<p>Sort key can be element value or JSONata expression for sorting property value, or message property or JSONata expression for sorting a message sequence.<p>
|
|
<p>When sorting a message sequence, the sort node relies on the received messages to have <code>msg.parts</code> set. The split node generates this property, but can be manually created. It has the following properties:</p>
|
|
<p>
|
|
<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>
|
|
</ul>
|
|
</p>
|
|
<p><b>Note:</b> This node internally keeps messages for its operation. In order to prevent unexpected memory usage, maximum number of messages kept can be specified. Default is no limit on number of messages.
|
|
<ul>
|
|
<li><code>maxKeptMsgsCount</code> property set in <b>settings.js</b>.</li>
|
|
</ul>
|
|
</p>
|
|
</script>
|
|
|
|
<script type="text/javascript">
|
|
RED.nodes.registerType('sort',{
|
|
category: 'function',
|
|
color:"#E2D96E",
|
|
defaults: {
|
|
name: { value:"" },
|
|
order: { value:"ascending" },
|
|
as_num: { value:false },
|
|
target: { value:"payload" },
|
|
targetType: { value:"msg" },
|
|
msgKey: { value:"payload" },
|
|
msgKeyType: { value:"elem" },
|
|
seqKey: { value:"payload" },
|
|
seqKeyType: { value:"msg" }
|
|
},
|
|
inputs:1,
|
|
outputs:1,
|
|
icon: "sort.png",
|
|
label: function() {
|
|
return this.name || "sort";
|
|
},
|
|
labelStyle: function() {
|
|
return this.name ? "node_label_italic" : "";
|
|
},
|
|
oneditprepare: function() {
|
|
var seq = {
|
|
value: "seq",
|
|
label: RED._("node-red:sort.seq"),
|
|
hasValue: false
|
|
};
|
|
var elem = {
|
|
value: "elem",
|
|
label: RED._("node-red:sort.elem"),
|
|
hasValue: false
|
|
};
|
|
$("#node-input-target").typedInput({
|
|
default:'msg',
|
|
typeField: $("#node-input-targetType"),
|
|
types:['msg', seq]
|
|
});
|
|
$("#node-input-msgKey").typedInput({
|
|
default:'elem',
|
|
typeField: $("#node-input-msgKeyType"),
|
|
types:[elem, 'jsonata']
|
|
});
|
|
$("#node-input-seqKey").typedInput({
|
|
default:'msg',
|
|
typeField: $("#node-input-seqKeyType"),
|
|
types:['msg', 'jsonata']
|
|
});
|
|
$("#node-input-target").change(function(e) {
|
|
var val = $("#node-input-target").typedInput('type');
|
|
$(".node-row-sort-msg-key").toggle(val === "msg");
|
|
$(".node-row-sort-seq-key").toggle(val === "seq");
|
|
});
|
|
$("#node-input-target").change();
|
|
}
|
|
});
|
|
</script>
|