Skip to content

Commit e250a91

Browse files
authored
Merge branch '0.18' into projects
2 parents 9558930 + 92a65dc commit e250a91

37 files changed

Lines changed: 645 additions & 886 deletions

editor/js/nodes.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,19 @@ RED.nodes = (function() {
272272
if (updatedConfigNode) {
273273
RED.workspaces.refresh();
274274
}
275+
try {
276+
if (node._def.oneditdelete) {
277+
node._def.oneditdelete.call(node);
278+
}
279+
} catch(err) {
280+
console.log("oneditdelete",node.id,node.type,err.toString());
281+
}
275282
RED.events.emit('nodes:remove',node);
276283
}
277284
}
278285
if (node && node._def.onremove) {
286+
// Deprecated: never documented but used by some early nodes
287+
console.log("Deprecated API warning: node type ",node.type," has an onremove function - should be oneditremove - please report");
279288
node._def.onremove.call(n);
280289
}
281290
return {links:removedLinks,nodes:removedNodes};

editor/js/ui/editor.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,16 @@ RED.editor = (function() {
779779
var fileName = selectIconFile.val();
780780
iconFileHidden.val(fileName);
781781
});
782+
var clear = $('<button class="editor-button editor-button-small"><i class="fa fa-times"></i></button>').appendTo(iconForm);
783+
clear.click(function(evt) {
784+
evt.preventDefault();
785+
var iconPath = RED.utils.getDefaultNodeIcon(node._def, node);
786+
selectIconModule.val(iconPath.module);
787+
moduleChange(selectIconModule, selectIconFile, iconModuleHidden, iconFileHidden, iconSets, true);
788+
selectIconFile.removeClass("input-error");
789+
selectIconFile.val(iconPath.file);
790+
iconFileHidden.val(iconPath.file);
791+
});
782792

783793
moduleChange(selectIconModule, selectIconFile, iconModuleHidden, iconFileHidden, iconSets, false);
784794
var iconFileList = iconSets[selectIconModule.val()];

editor/js/ui/palette.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,16 +412,17 @@ RED.palette = (function() {
412412
for (var j=0;j<nodeSet.types.length;j++) {
413413
showNodeType(nodeSet.types[j]);
414414
var def = RED.nodes.getType(nodeSet.types[j]);
415-
if (def.onpaletteadd && typeof def.onpaletteadd === "function") {
415+
if (def && def.onpaletteadd && typeof def.onpaletteadd === "function") {
416416
def.onpaletteadd.call(def);
417417
}
418418
}
419419
});
420420
RED.events.on('registry:node-set-disabled', function(nodeSet) {
421+
console.log(nodeSet);
421422
for (var j=0;j<nodeSet.types.length;j++) {
422423
hideNodeType(nodeSet.types[j]);
423424
var def = RED.nodes.getType(nodeSet.types[j]);
424-
if (def.onpaletteremove && typeof def.onpaletteremove === "function") {
425+
if (def && def.onpaletteremove && typeof def.onpaletteremove === "function") {
425426
def.onpaletteremove.call(def);
426427
}
427428
}
@@ -431,7 +432,7 @@ RED.palette = (function() {
431432
for (var j=0;j<nodeSet.types.length;j++) {
432433
removeNodeType(nodeSet.types[j]);
433434
var def = RED.nodes.getType(nodeSet.types[j]);
434-
if (def.onpaletteremove && typeof def.onpaletteremove === "function") {
435+
if (def && def.onpaletteremove && typeof def.onpaletteremove === "function") {
435436
def.onpaletteremove.call(def);
436437
}
437438
}

editor/js/ui/typeSearch.js

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ RED.typeSearch = (function() {
1919
function search(val) {
2020
activeFilter = val.toLowerCase();
2121
var visible = searchResults.editableList('filter');
22+
searchResults.editableList('sort');
2223
setTimeout(function() {
2324
selected = 0;
2425
searchResults.children().removeClass('selected');
@@ -101,6 +102,23 @@ RED.typeSearch = (function() {
101102
}
102103
return (activeFilter==="")||(data.index.indexOf(activeFilter) > -1);
103104
},
105+
sort: function(A,B) {
106+
if (activeFilter === "") {
107+
return A.i - B.i;
108+
}
109+
var Ai = A.index.indexOf(activeFilter);
110+
var Bi = B.index.indexOf(activeFilter);
111+
if (Ai === -1) {
112+
return 1;
113+
}
114+
if (Bi === -1) {
115+
return -1;
116+
}
117+
if (Ai === Bi) {
118+
return sortTypeLabels(A,B);
119+
}
120+
return Ai-Bi;
121+
},
104122
addItem: function(container,i,object) {
105123
var def = object.def;
106124
object.index = object.type.toLowerCase();
@@ -225,7 +243,17 @@ RED.typeSearch = (function() {
225243
}
226244
return label;
227245
}
228-
246+
function sortTypeLabels(a,b) {
247+
var al = a.label.toLowerCase();
248+
var bl = b.label.toLowerCase();
249+
if (al < bl) {
250+
return -1;
251+
} else if (al === bl) {
252+
return 0;
253+
} else {
254+
return 1;
255+
}
256+
}
229257
function refreshTypeList() {
230258
var i;
231259
searchResults.editableList('empty');
@@ -250,27 +278,19 @@ RED.typeSearch = (function() {
250278
items.push({type:t,def: def, label:getTypeLabel(t,def)});
251279
}
252280
});
253-
items.sort(function(a,b) {
254-
var al = a.label.toLowerCase();
255-
var bl = b.label.toLowerCase();
256-
if (al < bl) {
257-
return -1;
258-
} else if (al === bl) {
259-
return 0;
260-
} else {
261-
return 1;
262-
}
263-
})
281+
items.sort(sortTypeLabels);
264282

265283
var commonCount = 0;
266284
var item;
285+
var index = 0;
267286
for(i=0;i<common.length;i++) {
268287
var itemDef = RED.nodes.getType(common[i]);
269288
if (itemDef) {
270289
item = {
271290
type: common[i],
272291
common: true,
273-
def: itemDef
292+
def: itemDef,
293+
i: index++
274294
};
275295
item.label = getTypeLabel(item.type,item.def);
276296
if (i === common.length-1) {
@@ -283,7 +303,8 @@ RED.typeSearch = (function() {
283303
item = {
284304
type:recentlyUsed[i],
285305
def: RED.nodes.getType(recentlyUsed[i]),
286-
recent: true
306+
recent: true,
307+
i: index++
287308
};
288309
item.label = getTypeLabel(item.type,item.def);
289310
if (i === recentlyUsed.length-1) {
@@ -292,6 +313,7 @@ RED.typeSearch = (function() {
292313
searchResults.editableList('addItem', item);
293314
}
294315
for (i=0;i<items.length;i++) {
316+
items[i].i = index++;
295317
searchResults.editableList('addItem', items[i]);
296318
}
297319
setTimeout(function() {

nodes/core/analysis/72-sentiment.html

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
1-
<!--
2-
Copyright JS Foundation and other contributors, http://js.foundation
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
-->
161

172
<script type="text/x-red" data-template-name="sentiment">
3+
<div class="form-row">
4+
<label for="node-input-property"><i class="fa fa-ellipsis-h"></i> <span data-i18n="node-red:common.label.property"></span></label>
5+
<input type="text" id="node-input-property" style="width:70%;"/>
6+
</div>
187
<div class="form-row">
198
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
209
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
2110
</div>
2211
</script>
2312

2413
<script type="text/x-red" data-help-name="sentiment">
25-
<p>Analyses the <code>payload</code> and adds a <code>sentiment</code> object.</p>
14+
<p>Analyses the chosen property, default <code>payload</code>, and adds a <code>sentiment</code> object.</p>
2615
<h3>Outputs</h3>
2716
<dl class="message-properties">
2817
<dt>sentiment <span class="property-type">object</span></dt>
@@ -47,6 +36,7 @@ <h3>Details</h3>
4736
color:"#E6E0F8",
4837
defaults: {
4938
name: {value:""},
39+
property: {value:"payload",required:true}
5040
},
5141
inputs:1,
5242
outputs:1,
@@ -56,6 +46,12 @@ <h3>Details</h3>
5646
},
5747
labelStyle: function() {
5848
return this.name?"node_label_italic":"";
49+
},
50+
oneditprepare: function() {
51+
if (this.property === undefined) {
52+
$("#node-input-property").val("payload");
53+
}
54+
$("#node-input-property").typedInput({default:'msg',types:['msg']});
5955
}
6056
});
6157
</script>

nodes/core/analysis/72-sentiment.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
1-
/**
2-
* Copyright JS Foundation and other contributors, http://js.foundation
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
**/
161

172
module.exports = function(RED) {
183
"use strict";
194
var sentiment = require('sentiment');
205

216
function SentimentNode(n) {
227
RED.nodes.createNode(this,n);
8+
this.property = n.property||"payload";
239
var node = this;
2410

2511
this.on("input", function(msg) {
26-
if (msg.hasOwnProperty("payload")) {
27-
sentiment(msg.payload, msg.overrides || null, function (err, result) {
12+
var value = RED.util.getMessageProperty(msg,node.property);
13+
if (value !== undefined) {
14+
sentiment(value, msg.overrides || null, function (err, result) {
2815
msg.sentiment = result;
2916
node.send(msg);
3017
});
3118
}
32-
else { node.send(msg); } // If no payload - just pass it on.
19+
else { node.send(msg); } // If no matching property - just pass it on.
3320
});
3421
}
3522
RED.nodes.registerType("sentiment",SentimentNode);

nodes/core/locales/en-US/messages.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"topic": "Topic",
66
"name": "Name",
77
"username": "Username",
8-
"password": "Password"
8+
"password": "Password",
9+
"property": "Property"
910
},
1011
"status": {
1112
"connected": "connected",
@@ -542,7 +543,7 @@
542543
"label": {
543544
"property": "Property",
544545
"rule": "rule",
545-
"repair" : "repair sequence (reconstruct parts property of outgoing messages)"
546+
"repair" : "recreate message sequences"
546547
},
547548
"and": "and",
548549
"checkall": "checking all rules",
@@ -558,7 +559,7 @@
558559
"nnull":"is not null",
559560
"head":"head",
560561
"tail":"tail",
561-
"index":"is between",
562+
"index":"index between",
562563
"exp":"JSONata exp",
563564
"else":"otherwise"
564565
},
@@ -608,7 +609,7 @@
608609
"maxout": "e.g. 255"
609610
},
610611
"scale": {
611-
"payload": "Scale msg.payload",
612+
"payload": "Scale the message property",
612613
"limit": "Scale and limit to the target range",
613614
"wrap": "Scale and wrap within the target range"
614615
},
@@ -846,7 +847,7 @@
846847
"mode":{
847848
"mode":"Mode",
848849
"auto":"automatic",
849-
"merge":"merge sequence",
850+
"merge":"merge sequences",
850851
"reduce":"reduce sequence",
851852
"custom":"manual"
852853
},
@@ -881,8 +882,8 @@
881882
"exp": "Reduce exp",
882883
"exp-value": "exp",
883884
"init": "Initial value",
884-
"right": "Evaluate in reverse order (right to left)",
885-
"fixup": "Fixup exp"
885+
"right": "Evaluate in reverse order (last to first)",
886+
"fixup": "Fix-up exp"
886887
},
887888
"errors": {
888889
"invalid-expr": "Invalid JSONata expression: __error__"
@@ -904,20 +905,19 @@
904905
"batch" : {
905906
"mode": {
906907
"label" : "Mode",
907-
"num-msgs" : "number of messages",
908-
"interval" : "interval in seconds",
909-
"concat" : "concatenate sequences"
908+
"num-msgs" : "Group by number of messages",
909+
"interval" : "Group by time interval",
910+
"concat" : "Concatenate sequences"
910911
},
911912
"count": {
912-
"label" : "Number of msgs",
913-
"overwrap" : "Overwrap",
913+
"label" : "Number of messages",
914+
"overlap" : "Overlap",
914915
"count" : "count",
915-
"invalid" : "Invalid count and overwrap"
916+
"invalid" : "Invalid count and overlap"
916917
},
917918
"interval": {
918-
"label" : "Interval (sec)",
919+
"label" : "Interval",
919920
"seconds" : "seconds",
920-
"sec" : "sec",
921921
"empty" : "send empty message when no message arrives"
922922
},
923923
"concat": {

0 commit comments

Comments
 (0)