Compare commits

..

65 Commits

Author SHA1 Message Date
Nick O'Leary
fb0f12bb20 Bump to 0.20.0-beta.5 2019-02-08 10:41:22 +00:00
Nick O'Leary
e94b8d3e84 Update changelog 2019-02-08 10:41:01 +00:00
Nick O'Leary
8c00e1fdf4 Bump dependencies 2019-02-08 10:35:06 +00:00
Nick O'Leary
a31fa82284 Merge pull request #2056 from node-red-hitachi/update-logic-nodes-info-jp
Update Japanese info text of logic nodes
2019-02-08 09:38:17 +00:00
Nick O'Leary
5d0af45d8f Merge pull request #2055 from node-red-hitachi/update-io-nodes-info-jp
Update Japanese info text of io nodes
2019-02-08 09:38:04 +00:00
Hiroyasu Nishiyama
e9f248020e update Japanese info text of split node 2019-02-08 09:46:35 +09:00
Hiroyasu Nishiyama
a8e1058af6 fix typos in Japanese info text of range node 2019-02-08 09:35:02 +09:00
Hiroyasu Nishiyama
1a087fd799 update info text of switch node 2019-02-08 09:32:07 +09:00
Hiroyasu Nishiyama
50c81533e0 fix header level of switch node info text 2019-02-08 09:26:11 +09:00
Hiroyasu Nishiyama
5eab9aa4b1 fix typos in tcpin node info text 2019-02-08 09:14:32 +09:00
Hiroyasu Nishiyama
1970cbfe37 fix mismatched p-tag 2019-02-08 09:05:29 +09:00
Hiroyasu Nishiyama
6d736201f9 fix unmatched p-tag 2019-02-08 08:58:59 +09:00
Nick O'Leary
51ec52b573 Merge pull request #2053 from node-red-hitachi/update-node-messages-jp
Update Japanese message catalogue of core nodes
2019-02-07 22:00:55 +00:00
Nick O'Leary
d099387186 Merge pull request #2054 from node-red-hitachi/update-core-nodes-info-jp
Update Japanese info text of core nodes
2019-02-07 21:59:57 +00:00
Hiroyasu Nishiyama
3f91e4da66 update Japanese info text of template node 2019-02-07 23:35:09 +09:00
Hiroyasu Nishiyama
4124159378 update Japanese info text of function node 2019-02-07 23:24:12 +09:00
Hiroyasu Nishiyama
18f3789e29 update Japanese info text of catch node 2019-02-07 23:15:06 +09:00
Hiroyasu Nishiyama
7828af591e update Japanese message catalogue of core nodes 2019-02-07 20:03:16 +09:00
Nick O'Leary
d432dba726 Merge pull request #2052 from node-red-hitachi/update-editor-messages-jp
Update Japanese editor message catalogue
2019-02-07 09:30:13 +00:00
Nick O'Leary
72ae87857f Delete package-lock.json 2019-02-07 09:29:38 +00:00
Nick O'Leary
724acff591 Properly sanitize node names in deploy warning dialogs 2019-02-07 09:11:06 +00:00
Hiroyasu Nishiyama
482b432e2c update Japanese message catalogue for JSONata 2019-02-07 12:49:36 +09:00
Hiroyasu Nishiyama
351c0cb0a8 add missing colon 2019-02-07 12:33:36 +09:00
Hiroyasu Nishiyama
314a0fb5d6 update Japanese message catalog 2019-02-07 12:28:59 +09:00
Nick O'Leary
a301bf8bf5 Fix XSS issues in library ui code 2019-02-06 22:25:25 +00:00
Nick O'Leary
37b3601c47 Link Node - scroll to current flow in node list 2019-02-06 15:38:35 +00:00
Nick O'Leary
6e944485f0 Merge pull request #2030 from node-red-hitachi/scope-parent
Allow access of scope parent
2019-02-06 14:10:57 +00:00
Nick O'Leary
431266069e Merge pull request #2050 from node-red/subflow-props
Display parent subflow properties in subflow instance edit dialog
2019-02-06 14:06:22 +00:00
Nick O'Leary
d48a09e68b Add env type to subflow env var types
Also remove date and regex types
2019-02-06 13:58:31 +00:00
Nick O'Leary
2a8f0a4eab Display parent subflow properties in edit dialog 2019-02-05 23:08:39 +00:00
Nick O'Leary
79f3669fac Add 'catch uncaught only' mode to Catch node
Closes #1747

This was inspired by a PR from @mauriciom75 but implemented in a different way
due to some of the internal reworking done to Flow and Subflow in the dev branch
2019-02-05 14:29:50 +00:00
Nick O'Leary
aab0f2dcd5 Merge pull request #2047 from node-red-hitachi/fix-use-common-i18n-label
Fix use of i18n label
2019-02-05 08:31:38 +00:00
Nick O'Leary
a47831e278 Merge pull request #2049 from kazuhitoyokoi/dev-fixbug4outoputinsubflow
Fix direction value of subflow output
2019-02-05 08:31:04 +00:00
Kazuhito Yokoi
f1a5e8a42c Fix direction value of subflow output 2019-02-05 16:27:02 +09:00
Hiroyasu Nishiyama
723e9b3cba make $parent access without key return undefined 2019-02-05 14:47:30 +09:00
Hiroyasu Nishiyama
ff759a8074 use common i18 label for variable name placeholder 2019-02-05 13:12:21 +09:00
Nick O'Leary
4de1056d82 Tidy up HTTP Request payload to GET params work 2019-02-04 21:30:11 +00:00
Nick O'Leary
884b8da8bf Merge pull request #1981 from jonferreira/dev
Use payload properties as parameters on a GET request
2019-02-04 20:43:45 +00:00
Nick O'Leary
044ad77a4b Merge pull request #2044 from node-red-hitachi/cookie_encoding
Allow http request node to avoid encoding cookie
2019-02-04 20:39:05 +00:00
Nick O'Leary
1fe8b388a3 Allow subflow env-var list to resize with the dialog 2019-02-04 17:20:31 +00:00
Dave Conway-Jones
79fe7d684c Add parsed JSON output option to MQTT subscribe node 2019-02-04 16:35:42 +00:00
Dave Conway-Jones
c409af0ea8 Add local time display option to numerics in debug window 2019-02-04 15:51:42 +00:00
Nick O'Leary
5110eaff96 Merge branch 'dev' into pr_2042 2019-02-04 14:39:00 +00:00
Nick O'Leary
db3eee72b5 Do not convert falsey env vars to blank string
Only blank out undefined as that's what we've always done
2019-02-04 14:12:34 +00:00
Nick O'Leary
3bcff91328 Add Status Node to Subflow to allow subflow-specific status
Closes #597
2019-02-01 23:44:50 +00:00
Hiroyasu Nishiyama
e843f192ec convert subflow env vars to dict 2019-02-02 08:34:33 +09:00
Hiroki Uchikawa
f3d2053878 Make the encode option a boolean value to determine whether to encode 2019-02-01 17:15:07 +09:00
Nick O'Leary
efe8fbbd11 Better handling of multiple flow merges
Fixes #2039

Keeps better track of what was merged so a subsequent merge
properly identifies new-vs-old and doesn't remove thinks by mistake
2019-01-30 15:12:01 +00:00
Hiroyasu Nishiyama
ce507b3b52 simplified meta-data 2019-01-30 20:57:51 +09:00
Nick O'Leary
85de227003 Make Node._flow a writeable property
This is needed so an existing node constructor that does:

   Object.assign(this,config);

works when it tries to replace this._flow with config._flow.
2019-01-30 10:50:29 +00:00
Hiroki Uchikawa
7c6eb7c794 Allow http request node to change cookie value encoding 2019-01-30 19:33:23 +09:00
Hiroki Uchikawa
2037741b54 Revert cookie encoding behavior 2019-01-30 19:24:19 +09:00
Nick O'Leary
d534a8952d Do not propagate Flow.getNode to parent when called from outside flow 2019-01-29 21:49:20 +00:00
Hiroyasu Nishiyama
0b05b883cb add test cases 2019-01-30 00:04:41 +09:00
Hiroyasu Nishiyama
6937aa5ddd fix type of env values 2019-01-29 23:46:56 +09:00
Hiroyasu Nishiyama
8f6b24e0aa fixed to access last variable with same name 2019-01-29 21:46:50 +09:00
Hiroyasu Nishiyama
ba3b64a6c6 removed useless env setup & simplified env access in function node 2019-01-29 21:39:59 +09:00
Hiroyasu Nishiyama
0881c6a20b update test cases 2019-01-28 23:14:49 +09:00
Hiroyasu Nishiyama
f88a4b1791 fixed comments from @knolleary 2019-01-28 22:14:08 +09:00
Hiroyasu Nishiyama
2b43e3ee23 add placeholder for env var name 2019-01-27 21:56:13 +09:00
Hiroyasu Nishiyama
a413f3cded Add support of subflow env var 2019-01-26 23:15:20 +09:00
Hiroyasu Nishiyama
596fbfb517 allow $parent access of flow context 2019-01-16 23:10:03 +09:00
jonferreira
86bb5503ab Update 21-httprequest.html 2018-11-15 17:11:40 +00:00
jonferreira
21ce23d27d Update 21-httprequest.js 2018-11-15 17:11:27 +00:00
jonferreira
6c75baecb2 Update messages.json 2018-11-15 17:11:11 +00:00
57 changed files with 2098 additions and 186 deletions

View File

@@ -1,3 +1,33 @@
#### 0.20.0-beta.5: Beta Release
Runtime
- Bump dependencies
- Allow `$parent` access of flow context
- Make Node.\_flow a writeable property
- Do not propagate Flow.getNode to parent when called from outside flow
- Add support of subflow env var
Editor
- Properly sanitize node names in deploy warning dialogs
- Fix XSS issues in library ui code
- Add env type to subflow env var types
- Display parent subflow properties in edit dialog
- Fix direction value of subflow output
- Add Status Node to Subflow to allow subflow-specific status Closes #597
- Better handling of multiple flow merges Fixes #2039
Nodes
- Various translation updates
- Catch: Add 'catch uncaught only' mode. Closes #1747
- Link: scroll to current flow in node list
- HTTPRequest: add option to urlencode cookies
- HTTPRequest: option to use msg.payload as query params on GET. #1981
- Debug: Add local time display option to numerics in debug window
- MQTT: Add parsed JSON output option
#### 0.20.0-beta.4: Beta Release
Runtime

View File

@@ -1,6 +1,6 @@
{
"name": "node-red",
"version": "0.20.0-beta.4",
"version": "0.20.0-beta.5",
"description": "A visual tool for wiring the Internet of Things",
"homepage": "http://nodered.org",
"license": "Apache-2.0",
@@ -24,7 +24,7 @@
}
],
"dependencies": {
"ajv": "6.7.0",
"ajv": "6.8.1",
"basic-auth": "2.0.1",
"bcryptjs": "2.4.3",
"body-parser": "1.18.3",
@@ -41,7 +41,7 @@
"fs.notify": "0.0.4",
"hash-sum": "1.0.2",
"https-proxy-agent": "2.2.1",
"i18next": "13.1.0",
"i18next": "14.1.1",
"is-utf8": "0.2.1",
"js-yaml": "3.12.1",
"json-stringify-safe": "5.0.1",

View File

@@ -1,6 +1,6 @@
{
"name": "@node-red/editor-api",
"version": "0.20.0-beta.4",
"version": "0.20.0-beta.5",
"license": "Apache-2.0",
"main": "./lib/index.js",
"repository": {
@@ -16,8 +16,8 @@
}
],
"dependencies": {
"@node-red/util": "0.20.0-beta.4",
"@node-red/editor-client": "0.20.0-beta.4",
"@node-red/util": "0.20.0-beta.5",
"@node-red/editor-client": "0.20.0-beta.5",
"bcryptjs": "2.4.3",
"body-parser": "1.18.3",
"clone": "2.1.2",

View File

@@ -273,9 +273,14 @@
"editSubflowProperties": "edit properties",
"input": "inputs:",
"output": "outputs:",
"status": "status node",
"deleteSubflow": "delete subflow",
"info": "Description",
"category": "Category",
"env": {
"restore": "Restore to subflow default",
"remove": "Remove environment variable"
},
"errors": {
"noNodesSelected": "<strong>Cannot create subflow</strong>: no nodes selected",
"multipleInputsToSelection": "<strong>Cannot create subflow</strong>: multiple inputs to selection"
@@ -375,7 +380,7 @@
},
"event": {
"nodeAdded": "Node added to palette:",
"nodeAdded_plural": "Nodes added to palette",
"nodeAdded_plural": "Nodes added to palette:",
"nodeRemoved": "Node removed from palette:",
"nodeRemoved_plural": "Nodes removed from palette:",
"nodeEnabled": "Node enabled:",
@@ -901,6 +906,7 @@
"editor-tab": {
"properties": "Properties",
"description": "Description",
"appearance": "Appearance"
"appearance": "Appearance",
"env": "Environment Variables"
}
}

View File

@@ -273,9 +273,14 @@
"editSubflowProperties": "プロパティを編集",
"input": "入力:",
"output": "出力:",
"status": "ステータスノード",
"deleteSubflow": "サブフローを削除",
"info": "詳細",
"category": "カテゴリ",
"env": {
"restore": "デフォルト値に戻す",
"remove": "環境変数を削除"
},
"errors": {
"noNodesSelected": "<strong>サブフローを作成できません</strong>: ノードが選択されていません",
"multipleInputsToSelection": "<strong>サブフローを作成できません</strong>: 複数の入力が選択されています"
@@ -375,7 +380,7 @@
},
"event": {
"nodeAdded": "ノードをパレットへ追加しました:",
"nodeAdded_plural": "ノードをパレットへ追加しました",
"nodeAdded_plural": "ノードをパレットへ追加しました:",
"nodeRemoved": "ノードをパレットから削除しました:",
"nodeRemoved_plural": "ノードをパレットから削除しました:",
"nodeEnabled": "ノードを有効化しました:",
@@ -901,6 +906,7 @@
"editor-tab": {
"properties": "プロパティ",
"description": "説明",
"appearance": "外観"
"appearance": "外観",
"env": "環境変数"
}
}

View File

@@ -218,5 +218,17 @@
"$env": {
"args": "arg",
"desc": "環境変数の値を返します。\n\n本関数はNode-REDの定義関数です。"
},
"$eval": {
"args": "expr [, context]",
"desc": "JSONリテラルもしくはJSONata式を表す`expr`を評価します。評価の際には現在のコンテクストをコンテクストして用います。"
},
"$formatInteger": {
"args": "number, picture",
"desc": "`number`を`picture`指定に従って文字列に変換します。`picture`文字列は数値の変換方法をXPath F&O 3.1仕様の`fn:format-integer`に従って定義します。"
},
"$parseInteger": {
"args": "string, picture",
"desc": "`picture`文字列の指定に従って、`string`パラメータを整数(JSON数値)に変換します。`picture`文字列は`$formatInteger`と同じ形式です。"
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@node-red/editor-client",
"version": "0.20.0-beta.4",
"version": "0.20.0-beta.5",
"license": "Apache-2.0",
"repository": {
"type": "git",

View File

@@ -125,14 +125,20 @@ RED.history = (function() {
});
}
}
if (ev.subflow && ev.subflow.hasOwnProperty('instances')) {
ev.subflow.instances.forEach(function(n) {
var node = RED.nodes.node(n.id);
if (node) {
node.changed = n.changed;
node.dirty = true;
}
});
if (ev.subflow) {
if (ev.subflow.hasOwnProperty('instances')) {
ev.subflow.instances.forEach(function(n) {
var node = RED.nodes.node(n.id);
if (node) {
node.changed = n.changed;
node.dirty = true;
}
});
}
if (ev.subflow.hasOwnProperty('status')) {
subflow = RED.nodes.subflow(ev.subflow.id);
subflow.status = ev.subflow.status;
}
}
if (subflow) {
RED.nodes.filterNodes({type:"subflow:"+subflow.id}).forEach(function(n) {
@@ -232,6 +238,11 @@ RED.history = (function() {
}
});
}
if (ev.subflow.hasOwnProperty('status')) {
if (ev.subflow.status) {
delete ev.node.status;
}
}
RED.editor.validateNode(ev.node);
RED.nodes.filterNodes({type:"subflow:"+ev.node.id}).forEach(function(n) {
n.inputs = ev.node.in.length;
@@ -290,6 +301,7 @@ RED.history = (function() {
RED.workspaces.order(ev.order);
}
}
Object.keys(modifiedTabs).forEach(function(id) {
var subflow = RED.nodes.subflow(id);
if (subflow) {
@@ -303,6 +315,7 @@ RED.history = (function() {
RED.palette.refresh();
RED.workspaces.refresh();
RED.sidebar.config.refresh();
RED.subflow.refresh();
}
}

View File

@@ -358,7 +358,10 @@ RED.nodes = (function() {
}
subflows[sf.id] = sf;
RED.nodes.registerType("subflow:"+sf.id, {
defaults:{name:{value:""}},
defaults:{
name:{value:""},
env:{value:[]}
},
icon: function() { return sf.icon||"subflow.png" },
category: sf.category || "subflows",
inputs: sf.in.length,
@@ -369,6 +372,16 @@ RED.nodes = (function() {
paletteLabel: function() { return RED.nodes.subflow(sf.id).name },
inputLabels: function(i) { return sf.inputLabels?sf.inputLabels[i]:null },
outputLabels: function(i) { return sf.outputLabels?sf.outputLabels[i]:null },
oneditresize: function(size) {
var rows = $("#dialog-form>div:not(.node-input-env-container-row)");
var height = size.height;
for (var i=0; i<rows.size(); i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-input-env-container-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$("#node-input-env-container").editableList('height',height-80);
},
set:{
module: "node-red"
}
@@ -535,6 +548,7 @@ RED.nodes = (function() {
node.category = n.category;
node.in = [];
node.out = [];
node.env = n.env;
n.in.forEach(function(p) {
var nIn = {x:p.x,y:p.y,wires:[]};
@@ -571,6 +585,18 @@ RED.nodes = (function() {
node.icon = n.icon;
}
}
if (n.status) {
node.status = {x: n.status.x, y: n.status.y, wires:[]};
links.forEach(function(d) {
if (d.target === n.status) {
if (d.source.type != "subflow") {
node.status.wires.push({id:d.source.id, port:d.sourcePort})
} else {
node.status.wires.push({id:n.id, port:0})
}
}
});
}
return node;
}
@@ -851,6 +877,12 @@ RED.nodes = (function() {
output.i = i;
output.id = getID();
});
if (n.status) {
n.status.type = "subflow";
n.status.direction = "status";
n.status.z = n.id;
n.status.id = getID();
}
new_subflows.push(n);
addSubflow(n,createNewIds);
}
@@ -1018,6 +1050,7 @@ RED.nodes = (function() {
node.name = n.name;
node.outputs = subflow.out.length;
node.inputs = subflow.in.length;
node.env = n.env;
} else {
if (!node._def) {
if (node.x && node.y) {
@@ -1189,6 +1222,19 @@ RED.nodes = (function() {
});
delete output.wires;
});
if (n.status) {
n.status.wires.forEach(function(wire) {
var link;
if (subflow_map[wire.id] && subflow_map[wire.id].id == n.id) {
link = {source:n.in[wire.port], sourcePort:wire.port,target:n.status};
} else {
link = {source:node_map[wire.id]||subflow_map[wire.id], sourcePort:wire.port,target:n.status};
}
addLink(link);
new_links.push(link);
});
delete n.status.wires;
}
}
RED.workspaces.refresh();

View File

@@ -327,6 +327,14 @@
},
length: function() {
return this.element.children().length;
},
show: function(item) {
var items = this.element.children().filter(function(f) {
return item === $(this).find(".red-ui-editableList-item-content").data('data');
});
if (items.length > 0) {
this.uiContainer.scrollTop(this.uiContainer.scrollTop()+items.position().top)
}
}
});
})(jQuery);

View File

@@ -171,6 +171,13 @@
} else {
return this._data;
}
},
show: function(id) {
for (var i=0;i<this._data.length;i++) {
if (this._data[i].id === id) {
this._topList.editableList('show',this._data[i]);
}
}
}
});

View File

@@ -261,7 +261,9 @@ RED.deploy = (function() {
}
return list;
}
function sanitize(html) {
return html.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")
}
function restart() {
var startTime = Date.now();
$(".deploy-button-content").css('opacity',0);
@@ -353,7 +355,7 @@ RED.deploy = (function() {
if (hasUnknown && !ignoreDeployWarnings.unknown) {
showWarning = true;
notificationMessage = "<p>"+RED._('deploy.confirm.unknown')+"</p>"+
'<ul class="node-dialog-configm-deploy-list"><li>'+cropList(unknownNodes).join("</li><li>")+"</li></ul><p>"+
'<ul class="node-dialog-configm-deploy-list"><li>'+cropList(unknownNodes).map(function(n) { return sanitize(n) }).join("</li><li>")+"</li></ul><p>"+
RED._('deploy.confirm.confirm')+
"</p>";
@@ -373,7 +375,7 @@ RED.deploy = (function() {
invalidNodes.sort(sortNodeInfo);
notificationMessage = "<p>"+RED._('deploy.confirm.improperlyConfigured')+"</p>"+
'<ul class="node-dialog-configm-deploy-list"><li>'+cropList(invalidNodes.map(function(A) { return (A.tab?"["+A.tab+"] ":"")+A.label+" ("+A.type+")"})).join("</li><li>")+"</li></ul><p>"+
'<ul class="node-dialog-configm-deploy-list"><li>'+cropList(invalidNodes.map(function(A) { return sanitize( (A.tab?"["+A.tab+"] ":"")+A.label+" ("+A.type+")")})).join("</li><li>")+"</li></ul><p>"+
RED._('deploy.confirm.confirm')+
"</p>";
notificationButtons= [

View File

@@ -687,7 +687,7 @@ RED.diff = (function() {
diff: remoteDiff
}
}
var selectState = "";
if (conflicted) {
@@ -1158,19 +1158,19 @@ RED.diff = (function() {
}
});
return {
var diff = {
currentConfig: currentConfig,
newConfig: newConfig,
added: added,
deleted: deleted,
changed: changed,
moved: moved
}
};
return diff;
}
function resolveDiffs(localDiff,remoteDiff) {
var conflicted = {};
var resolutions = {};
var diff = {
localDiff: localDiff,
remoteDiff: remoteDiff,
@@ -1348,7 +1348,7 @@ RED.diff = (function() {
if (node) {
nodeChangedStates[id] = node.changed;
}
localChangedStates[id] = true;
localChangedStates[id] = 1;
newConfig.push(remoteDiff.newConfig.all[id]);
}
} else {
@@ -1363,7 +1363,7 @@ RED.diff = (function() {
nodeChangedStates[id] = node.changed;
}
if (!localDiff.added.hasOwnProperty(id)) {
localChangedStates[id] = true;
localChangedStates[id] = 2;
newConfig.push(remoteDiff.newConfig.all[id]);
}
}
@@ -1376,24 +1376,42 @@ RED.diff = (function() {
}
function mergeDiff(diff) {
//console.log(diff);
var appliedDiff = applyDiff(diff);
var newConfig = appliedDiff.config;
var nodeChangedStates = appliedDiff.nodeChangedStates;
var localChangedStates = appliedDiff.localChangedStates;
var isDirty = RED.nodes.dirty();
var historyEvent = {
t:"replace",
config: RED.nodes.createCompleteNodeSet(),
changed: nodeChangedStates,
dirty: RED.nodes.dirty(),
dirty: isDirty,
rev: RED.nodes.version()
}
RED.history.push(historyEvent);
var originalFlow = RED.nodes.originalFlow();
// originalFlow is what the editor things it loaded
// - add any newly added nodes from remote diff as they are now part of the record
for (var id in diff.remoteDiff.added) {
if (diff.remoteDiff.added.hasOwnProperty(id)) {
if (diff.remoteDiff.newConfig.all.hasOwnProperty(id)) {
originalFlow.push(JSON.parse(JSON.stringify(diff.remoteDiff.newConfig.all[id])));
}
}
}
RED.nodes.clear();
var imported = RED.nodes.import(newConfig);
// Restore the original flow so subsequent merge resolutions can properly
// identify new-vs-old
RED.nodes.originalFlow(originalFlow);
imported[0].forEach(function(n) {
if (nodeChangedStates[n.id] || localChangedStates[n.id]) {
n.changed = true;
@@ -1402,11 +1420,16 @@ RED.diff = (function() {
RED.nodes.version(diff.remoteDiff.rev);
if (isDirty) {
RED.nodes.dirty(true);
}
RED.view.redraw(true);
RED.palette.refresh();
RED.workspaces.refresh();
RED.sidebar.config.refresh();
}
function showTestFlowDiff(index) {
if (index === 1) {
var localFlow = RED.nodes.createCompleteNodeSet();

View File

@@ -540,7 +540,150 @@ RED.editor = (function() {
return label;
}
function buildEditForm(container,formId,type,ns) {
function buildEnvForm(container, node) {
var env_container = $('#node-input-env-container');
env_container
.css({
'min-height':'150px',
'min-width':'450px'
})
.editableList({
addItem: function(container, i, opt) {
var row = $('<div/>').appendTo(container);
if (opt.parent) {
$('<div/>', {
class:"uneditable-input",
style: "margin-left: 5px; width: calc(40% - 8px)",
}).appendTo(row).text(opt.name);
} else {
$('<input/>', {
class: "node-input-env-name",
type: "text",
style: "margin-left: 5px; width: calc(40% - 8px)",
placeholder: RED._("common.label.name")
}).appendTo(row).val(opt.name);
}
var valueField = $('<input/>',{
class: "node-input-env-value",
type: "text",
style: "margin-left: 5px; width: calc(60% - 8px)"
}).appendTo(row)
valueField.typedInput({default:'str',
types:['str','num','bool','json','bin','env']
});
valueField.typedInput('type', opt.parent?(opt.type||opt.parent.type):opt.type);
valueField.typedInput('value', opt.parent?(opt.value||opt.parent.value):opt.value);
var actionButton = $('<a/>',{href:"#",class:"red-ui-editableList-item-remove editor-button editor-button-small"}).appendTo(container);
$('<i/>',{class:"fa "+(opt.parent?"fa-reply":"fa-remove")}).appendTo(actionButton);
container.parent().addClass("red-ui-editableList-item-removable");
if (opt.parent) {
if (opt.value && (opt.value !== opt.parent.value || opt.type !== opt.parent.type)) {
actionButton.show();
} else {
actionButton.hide();
}
var restoreTip = RED.popover.tooltip(actionButton,RED._("subflow.env.restore"));
valueField.change(function(evt) {
var newType = valueField.typedInput('type');
var newValue = valueField.typedInput('value');
if (newType === opt.parent.type && newValue === opt.parent.value) {
actionButton.hide();
} else {
actionButton.show();
}
})
actionButton.click(function(evt) {
evt.preventDefault();
restoreTip.close();
valueField.typedInput('type', opt.parent.type);
valueField.typedInput('value', opt.parent.value);
})
} else {
var removeTip = RED.popover.tooltip(actionButton,RED._("subflow.env.remove"));
actionButton.click(function(evt) {
evt.preventDefault();
removeTip.close();
container.parent().addClass("red-ui-editableList-item-deleting")
container.fadeOut(300, function() {
env_container.editableList('removeItem',opt);
});
});
}
},
sortable: false,
removable: false
});
var parentEnv = {};
var envList = [];
if (/^subflow:/.test(node.type)) {
var subflowDef = RED.nodes.subflow(node.type.substring(8));
if (subflowDef.env) {
subflowDef.env.forEach(function(env) {
var item = {
name:env.name,
parent: {
type: env.type,
value: env.value
}
}
envList.push(item);
parentEnv[env.name] = item;
})
}
}
if (node.env) {
for (var i = 0; i < node.env.length; i++) {
var env = node.env[i];
if (parentEnv.hasOwnProperty(env.name)) {
parentEnv[env.name].type = env.type;
parentEnv[env.name].value = env.value;
} else {
envList.push({
name: env.name,
type: env.type,
value: env.value
});
}
}
}
envList.forEach(function(env) {
env_container.editableList('addItem', env);
})
}
function exportEnvList(list) {
if (list) {
var env = [];
list.each(function(i) {
var entry = $(this);
var item = entry.data('data');
var name = item.parent?item.name:entry.find(".node-input-env-name").val();
var valueInput = entry.find(".node-input-env-value");
var value = valueInput.typedInput("value");
var type = valueInput.typedInput("type");
if (!item.parent || (item.parent.value !== value || item.parent.type !== type)) {
var item = {
name: name,
type: type,
value: value
};
env.push(item);
}
});
return env;
}
return null;
}
function isSameEnv(env0, env1) {
return (JSON.stringify(env0) === JSON.stringify(env1));
}
function buildEditForm(container,formId,type,ns,node) {
var dialogForm = $('<form id="'+formId+'" class="form-horizontal" autocomplete="off"></form>').appendTo(container);
dialogForm.html($("script[data-template-name='"+type+"']").html());
ns = ns||"node-red";
@@ -561,6 +704,11 @@ RED.editor = (function() {
}
$(this).attr("data-i18n",keys.join(";"));
});
if ((type === "subflow") || (type === "subflow-template")) {
buildEnvForm(dialogForm, node);
}
// Add dummy fields to prevent 'Enter' submitting the form in some
// cases, and also prevent browser auto-fill of password
// Add in reverse order as they are prepended...
@@ -1268,6 +1416,16 @@ RED.editor = (function() {
}
}
if (type === "subflow") {
var old_env = editing_node.env;
var new_env = exportEnvList($("#node-input-env-container").editableList("items"));
if (!isSameEnv(old_env, new_env)) {
editing_node.env = new_env;
changes.env = editing_node.env;
changed = true;
}
}
if (changed) {
var wasChanged = editing_node.changed;
editing_node.changed = true;
@@ -1373,7 +1531,7 @@ RED.editor = (function() {
content: $('<div>', {class:"editor-tray-content"}).appendTo(editorContent).hide(),
iconClass: "fa fa-cog"
};
buildEditForm(nodePropertiesTab.content,"dialog-form",type,ns);
buildEditForm(nodePropertiesTab.content,"dialog-form",type,ns,node);
editorTabs.addTab(nodePropertiesTab);
if (!node._def.defaults || !node._def.defaults.hasOwnProperty('info')) {
@@ -1986,6 +2144,14 @@ RED.editor = (function() {
changed = true;
}
var old_env = editing_node.env;
var new_env = exportEnvList($("#node-input-env-container").editableList("items"));
if (!isSameEnv(old_env, new_env)) {
editing_node.env = new_env;
changes.env = editing_node.env;
changed = true;
}
RED.palette.refresh();
if (changed) {
@@ -2024,9 +2190,17 @@ RED.editor = (function() {
}
}
],
resize: function(dimensions) {
$(".editor-tray-content").height(dimensions.height - 50);
var form = $(".editor-tray-content form").height(dimensions.height - 50 - 40);
resize: function(size) {
// $(".editor-tray-content").height(size.height - 50);
// var form = $(".editor-tray-content form").height(size.height - 50 - 40);
var rows = $("#dialog-form>div:not(.node-input-env-container-row)");
var height = size.height;
for (var i=0; i<rows.size(); i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-input-env-container-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$("#node-input-env-container").editableList('height',height-80);
},
open: function(tray) {
var trayFooter = tray.find(".editor-tray-footer");
@@ -2063,7 +2237,7 @@ RED.editor = (function() {
content: $('<div>', {class:"editor-tray-content"}).appendTo(editorContent).hide(),
iconClass: "fa fa-cog"
};
buildEditForm(nodePropertiesTab.content,"dialog-form","subflow-template");
buildEditForm(nodePropertiesTab.content,"dialog-form","subflow-template", undefined, editing_node);
editorTabs.addTab(nodePropertiesTab);
var descriptionTab = {

View File

@@ -45,7 +45,7 @@ RED.library = (function() {
a = document.createElement("a");
a.href="#";
var label = i.replace(/^@.*\//,"").replace(/^node-red-contrib-/,"").replace(/^node-red-node-/,"").replace(/-/," ").replace(/_/," ");
a.innerHTML = label;
a.innerText = label;
li.appendChild(a);
li.appendChild(buildMenu(data.d[i],root+(root!==""?"/":"")+i));
ul.appendChild(li);
@@ -58,7 +58,7 @@ RED.library = (function() {
li = document.createElement("li");
a = document.createElement("a");
a.href="#";
a.innerHTML = data.f[i];
a.innerText = data.f[i];
a.flowName = root+(root!==""?"/":"")+data.f[i];
a.onclick = function() {
$.get('library/flows/'+this.flowName, function(data) {
@@ -125,8 +125,8 @@ RED.library = (function() {
li.onclick = (function () {
var dirName = v;
return function(e) {
var bcli = $('<li class="active"><span class="divider">/</span> <a href="#">'+dirName+'</a></li>');
$("a",bcli).click(function(e) {
var bcli = $('<li class="active"><span class="divider">/</span> </li>');
$('<a href="#"></a>').text(dirName).appendTo(bcli).click(function(e) {
$(this).parent().nextAll().remove();
$.getJSON("library/"+options.url+root+dirName,function(data) {
$("#node-select-library").children().first().replaceWith(buildFileList(root+dirName+"/",data));
@@ -141,12 +141,13 @@ RED.library = (function() {
});
}
})();
li.innerHTML = '<i class="fa fa-folder"></i> '+v+"</i>";
$('<i class="fa fa-folder"></i>').appendTo(li);
$('<span>').text(" "+v).appendTo(li);
ul.appendChild(li);
} else {
// file
li = buildFileListItem(v);
li.innerHTML = v.name;
li.innerText = v.name;
li.onclick = (function() {
var item = v;
return function(e) {

View File

@@ -16,34 +16,36 @@
RED.subflow = (function() {
var _subflowEditTemplate = '<script type="text/x-red" data-template-name="subflow">'+
'<div class="form-row"><label for="node-input-name" data-i18n="[append]editor:common.label.name"><i class="fa fa-tag"></i> </label><input type="text" id="node-input-name"></div>'+
'<div class="form-row" style="margin-bottom: 0px;"><label style="width: auto;" data-i18n="[append]editor:editor-tab.env"><i class="fa fa-th-list"></i> </label></div>'+
'<div class="form-row node-input-env-container-row"><ol id="node-input-env-container"></ol></div>'+
'</script>';
var _subflowEditTemplate = '<script type="text/x-red" data-template-name="subflow"><div class="form-row"><label for="node-input-name" data-i18n="[append]editor:common.label.name"><i class="fa fa-tag"></i> </label><input type="text" id="node-input-name"></div></script>';
var _subflowTemplateEditTemplate = '<script type="text/x-red" data-template-name="subflow-template">'+
'<div class="form-row"><i class="fa fa-tag"></i> <label for="subflow-input-name" data-i18n="common.label.name"></label><input type="text" id="subflow-input-name"></div>'+
'<div class="form-row"><i class="fa fa-folder-o"></i> <label for="subflow-input-category" data-i18n="editor:subflow.category"></label><select style="width: 250px;" id="subflow-input-category"></select><input style="display:none; margin-left: 10px; width:calc(100% - 250px)" type="text" id="subflow-input-custom-category"></div>'+
'<div class="form-row" style="margin-bottom: 0px;"><label style="width: auto;" data-i18n="[append]editor:editor-tab.env"><i class="fa fa-th-list"></i> </label></div>'+
'<div class="form-row node-input-env-container-row"><ol id="node-input-env-container"></ol></div>'+
'<div class="form-row form-tips" id="subflow-dialog-user-count"></div>'+
'</script>';
function getSubflow() {
return RED.nodes.subflow(RED.workspaces.active());
}
function findAvailableSubflowIOPosition(subflow,isInput) {
var pos = {x:50,y:30};
if (!isInput) {
pos.x += 110;
}
for (var i=0;i<subflow.out.length+subflow.in.length;i++) {
var port;
if (i < subflow.out.length) {
port = subflow.out[i];
} else {
port = subflow.in[i-subflow.out.length];
}
var ports = [].concat(subflow.out).concat(subflow.in);
if (subflow.status) {
ports.push(subflow.status);
}
ports.sort(function(A,B) {
return A.x-B.x;
});
for (var i=0; i<ports.length; i++) {
var port = ports[i];
if (port.x == pos.x && port.y == pos.y) {
pos.x += 55;
i=0;
}
}
return pos;
@@ -191,6 +193,61 @@ RED.subflow = (function() {
return {subflowOutputs: removedSubflowOutputs, links: removedLinks}
}
function addSubflowStatus() {
var subflow = RED.nodes.subflow(RED.workspaces.active());
if (subflow.status) {
return;
}
var position = findAvailableSubflowIOPosition(subflow,false);
var statusNode = {
type:"subflow",
direction:"status",
z:subflow.id,
x:position.x,
y:position.y,
id:RED.nodes.id()
};
subflow.status = statusNode;
subflow.dirty = true;
var wasDirty = RED.nodes.dirty();
var wasChanged = subflow.changed;
subflow.changed = true;
var result = refresh(true);
var historyEvent = {
t:'edit',
node:subflow,
dirty:wasDirty,
changed:wasChanged,
subflow: { status: true }
};
RED.history.push(historyEvent);
RED.view.select();
RED.nodes.dirty(true);
RED.view.redraw();
$("#workspace-subflow-status").prop("checked",!!subflow.status);
$("#workspace-subflow-status").parent().parent().toggleClass("active",!!subflow.status);
}
function removeSubflowStatus() {
var subflow = RED.nodes.subflow(RED.workspaces.active());
if (!subflow.status) {
return;
}
var subflowRemovedLinks = [];
RED.nodes.eachLink(function(l) {
if (l.target.type == "subflow" && l.target.z == subflow.id && l.target.direction == "status") {
subflowRemovedLinks.push(l);
}
});
subflowRemovedLinks.forEach(function(l) { RED.nodes.removeLink(l)});
delete subflow.status;
$("#workspace-subflow-status").prop("checked",!!subflow.status);
$("#workspace-subflow-status").parent().parent().toggleClass("active",!!subflow.status);
return { links: subflowRemovedLinks }
}
function refresh(markChange) {
var activeSubflow = RED.nodes.subflow(RED.workspaces.active());
refreshToolbar(activeSubflow);
@@ -219,12 +276,17 @@ RED.subflow = (function() {
}
}
}
function refreshToolbar(activeSubflow) {
if (activeSubflow) {
$("#workspace-subflow-input-add").toggleClass("active", activeSubflow.in.length !== 0);
$("#workspace-subflow-input-remove").toggleClass("active",activeSubflow.in.length === 0);
$("#workspace-subflow-output .spinner-value").text(activeSubflow.out.length);
$("#workspace-subflow-status").prop("checked",!!activeSubflow.status);
$("#workspace-subflow-status").parent().parent().toggleClass("active",!!activeSubflow.status);
}
}
@@ -232,22 +294,32 @@ RED.subflow = (function() {
var toolbar = $("#workspace-toolbar");
toolbar.empty();
// Edit properties
$('<a class="button" id="workspace-subflow-edit" href="#" data-i18n="[append]subflow.editSubflowProperties"><i class="fa fa-pencil"></i> </a>').appendTo(toolbar);
// Inputs
$('<span style="margin-left: 5px;" data-i18n="subflow.input"></span> '+
'<div style="display: inline-block;" class="button-group">'+
'<a id="workspace-subflow-input-remove" class="button active" href="#">0</a>'+
'<a id="workspace-subflow-input-add" class="button" href="#">1</a>'+
'</div>').appendTo(toolbar);
// Outputs
$('<span style="margin-left: 5px;" data-i18n="subflow.output"></span> <div id="workspace-subflow-output" style="display: inline-block;" class="button-group spinner-group">'+
'<a id="workspace-subflow-output-remove" class="button" href="#"><i class="fa fa-minus"></i></a>'+
'<div class="spinner-value">3</div>'+
'<a id="workspace-subflow-output-add" class="button" href="#"><i class="fa fa-plus"></i></a>'+
'</div>').appendTo(toolbar);
// Status
$('<span class="button-group"><span class="button" style="padding:0"><label for="workspace-subflow-status"><input id="workspace-subflow-status" type="checkbox"> <span data-i18n="subflow.status"></span></label></span></span>').appendTo(toolbar);
// $('<a class="button disabled" id="workspace-subflow-add-input" href="#" data-i18n="[append]subflow.input"><i class="fa fa-plus"></i> </a>').appendTo(toolbar);
// $('<a class="button" id="workspace-subflow-add-output" href="#" data-i18n="[append]subflow.output"><i class="fa fa-plus"></i> </a>').appendTo(toolbar);
// Delete
$('<a class="button" id="workspace-subflow-delete" href="#" data-i18n="[append]subflow.deleteSubflow"><i class="fa fa-trash"></i> </a>').appendTo(toolbar);
toolbar.i18n();
@@ -274,6 +346,7 @@ RED.subflow = (function() {
RED.view.redraw(true);
}
});
$("#workspace-subflow-output-add").click(function(event) {
event.preventDefault();
addSubflowOutput();
@@ -283,6 +356,7 @@ RED.subflow = (function() {
event.preventDefault();
addSubflowInput();
});
$("#workspace-subflow-input-remove").click(function(event) {
event.preventDefault();
var wasDirty = RED.nodes.dirty();
@@ -307,6 +381,33 @@ RED.subflow = (function() {
}
});
$("#workspace-subflow-status").change(function(evt) {
if (this.checked) {
addSubflowStatus();
} else {
var currentStatus = activeSubflow.status;
var wasChanged = activeSubflow.changed;
var result = removeSubflowStatus();
if (result) {
activeSubflow.changed = true;
var wasDirty = RED.nodes.dirty();
RED.history.push({
t:'delete',
links:result.links,
changed: wasChanged,
dirty:wasDirty,
subflow: {
id: activeSubflow.id,
status: currentStatus
}
});
RED.view.select();
RED.nodes.dirty(true);
RED.view.redraw();
}
}
})
$("#workspace-subflow-edit").click(function(event) {
RED.editor.editSubflow(RED.nodes.subflow(RED.workspaces.active()));
event.preventDefault();
@@ -328,6 +429,7 @@ RED.subflow = (function() {
$("#chart").css({"margin-top": "40px"});
$("#workspace-toolbar").show();
}
function hideWorkspaceToolbar() {
$("#workspace-toolbar").hide().empty();
$("#chart").css({"margin-top": "0"});
@@ -373,6 +475,7 @@ RED.subflow = (function() {
subflows: [activeSubflow]
}
}
function init() {
RED.events.on("workspace:change",function(event) {
var activeSubflow = RED.nodes.subflow(event.workspace);
@@ -436,6 +539,7 @@ RED.subflow = (function() {
}
return x;
}
function convertToSubflow() {
var selection = RED.view.selection();
if (!selection.nodes) {
@@ -451,7 +555,6 @@ RED.subflow = (function() {
var candidateOutputs = [];
var candidateInputNodes = {};
var boundingBox = [selection.nodes[0].x,
selection.nodes[0].y,
selection.nodes[0].x,
@@ -467,8 +570,8 @@ RED.subflow = (function() {
Math.max(boundingBox[3],n.y)
]
}
var offsetX = snapToGrid(boundingBox[0] - 180);
var offsetY = snapToGrid(boundingBox[1] - 60);
var offsetX = snapToGrid(boundingBox[0] - 200);
var offsetY = snapToGrid(boundingBox[1] - 80);
var center = [
@@ -540,7 +643,7 @@ RED.subflow = (function() {
}}),
out: candidateOutputs.map(function(v,i) { var index = i; return {
type:"subflow",
direction:"in",
direction:"out",
x:snapToGrid(v.source.x+(v.source.w/2)+80 - offsetX),
y:snapToGrid(v.source.y - offsetY),
z:subflowId,
@@ -643,8 +746,6 @@ RED.subflow = (function() {
RED.view.redraw(true);
}
return {
init: init,
createSubflow: createSubflow,
@@ -652,6 +753,7 @@ RED.subflow = (function() {
removeSubflow: removeSubflow,
refresh: refresh,
removeInput: removeSubflowInput,
removeOutput: removeSubflowOutput
removeOutput: removeSubflowOutput,
removeStatus: removeSubflowStatus
}
})();

View File

@@ -192,6 +192,14 @@ RED.utils = (function() {
format = 'hex'
}
} else if (format === 'dateMS' || format == 'dateS') {
if ((obj.toString().length===13) && (obj<=2147483647000)) {
format = 'dateML';
} else if ((obj.toString().length===10) && (obj<=2147483647)) {
format = 'dateL';
} else {
format = 'hex'
}
} else if (format === 'dateML' || format == 'dateL') {
format = 'hex';
} else {
format = 'dec';
@@ -210,6 +218,12 @@ RED.utils = (function() {
element.text((new Date(obj)).toISOString());
} else if (format === 'dateS') {
element.text((new Date(obj*1000)).toISOString());
} else if (format === 'dateML') {
var dd = new Date(obj);
element.text(dd.toLocaleString() + " [UTC" + ( dd.getTimezoneOffset()/-60 <=0?"":"+" ) + dd.getTimezoneOffset()/-60 +"]");
} else if (format === 'dateL') {
var ddl = new Date(obj*1000);
element.text(ddl.toLocaleString() + " [UTC" + ( ddl.getTimezoneOffset()/-60 <=0?"":"+" ) + ddl.getTimezoneOffset()/-60 +"]");
} else if (format === 'hex') {
element.text("0x"+(obj).toString(16));
}

View File

@@ -1261,6 +1261,13 @@ RED.view = (function() {
moving_set.push({n:n});
}
});
if (activeSubflow.status) {
activeSubflow.status.selected = (activeSubflow.status.x > x && activeSubflow.status.x < x2 && activeSubflow.status.y > y && activeSubflow.status.y < y2);
if (activeSubflow.status.selected) {
activeSubflow.status.dirty = true;
moving_set.push({n:activeSubflow.status});
}
}
}
updateSelection();
lasso.remove();
@@ -1367,6 +1374,13 @@ RED.view = (function() {
moving_set.push({n:n});
}
});
if (activeSubflow.status) {
if (!activeSubflow.status.selected) {
activeSubflow.status.selected = true;
activeSubflow.status.dirty = true;
moving_set.push({n:activeSubflow.status});
}
}
}
selected_link = null;
@@ -1552,6 +1566,7 @@ RED.view = (function() {
var removedLinks = [];
var removedSubflowOutputs = [];
var removedSubflowInputs = [];
var removedSubflowStatus = undefined;
var subflowInstances = [];
var startDirty = RED.nodes.dirty();
@@ -1573,6 +1588,8 @@ RED.view = (function() {
removedSubflowOutputs.push(node);
} else if (node.direction === "in") {
removedSubflowInputs.push(node);
} else if (node.direction === "status") {
removedSubflowStatus = node;
}
node.dirty = true;
}
@@ -1590,12 +1607,19 @@ RED.view = (function() {
removedLinks = removedLinks.concat(result.links);
}
}
if (removedSubflowStatus) {
result = RED.subflow.removeStatus();
if (result) {
removedLinks = removedLinks.concat(result.links);
}
}
var instances = RED.subflow.refresh(true);
if (instances) {
subflowInstances = instances.instances;
}
moving_set = [];
if (removedNodes.length > 0 || removedSubflowOutputs.length > 0 || removedSubflowInputs.length > 0) {
if (removedNodes.length > 0 || removedSubflowOutputs.length > 0 || removedSubflowInputs.length > 0 || removedSubflowStatus) {
RED.nodes.dirty(true);
}
}
@@ -1651,10 +1675,14 @@ RED.view = (function() {
subflowOutputs:removedSubflowOutputs,
subflowInputs:removedSubflowInputs,
subflow: {
id: activeSubflow?activeSubflow.id:undefined,
instances: subflowInstances
},
dirty:startDirty
};
if (removedSubflowStatus) {
historyEvent.subflow.status = removedSubflowStatus;
}
}
RED.history.push(historyEvent);
@@ -2420,6 +2448,49 @@ RED.view = (function() {
inGroup.append("svg:text").attr("class","port_label").attr("x",18).attr("y",20).style("font-size","10px").text("input");
var subflowStatus = nodeLayer.selectAll(".subflowstatus").data(activeSubflow.status?[activeSubflow.status]:[],function(d,i){ return d.id;});
subflowStatus.exit().remove();
var statusGroup = subflowStatus.enter().insert("svg:g").attr("class","node subflowstatus").attr("transform",function(d) { return "translate("+(d.x-20)+","+(d.y-20)+")"});
statusGroup.each(function(d,i) {
d.w=40;
d.h=40;
});
statusGroup.append("rect").attr("class","subflowport").attr("rx",8).attr("ry",8).attr("width",40).attr("height",40)
// TODO: This is exactly the same set of handlers used for regular nodes - DRY
.on("mouseup",nodeMouseUp)
.on("mousedown",nodeMouseDown)
.on("touchstart",function(d) {
var obj = d3.select(this);
var touch0 = d3.event.touches.item(0);
var pos = [touch0.pageX,touch0.pageY];
startTouchCenter = [touch0.pageX,touch0.pageY];
startTouchDistance = 0;
touchStartTime = setTimeout(function() {
showTouchMenu(obj,pos);
},touchLongPressTimeout);
nodeMouseDown.call(this,d)
})
.on("touchend", function(d) {
clearTimeout(touchStartTime);
touchStartTime = null;
if (RED.touch.radialMenu.active()) {
d3.event.stopPropagation();
return;
}
nodeMouseUp.call(this,d);
});
statusGroup.append("g").attr('transform','translate(-5,15)').append("rect").attr("class","port").attr("rx",3).attr("ry",3).attr("width",10).attr("height",10)
.on("mousedown", function(d,i){portMouseDown(d,PORT_TYPE_INPUT,0);} )
.on("touchstart", function(d,i){portMouseDown(d,PORT_TYPE_INPUT,0);} )
.on("mouseup", function(d,i){portMouseUp(d,PORT_TYPE_INPUT,0);})
.on("touchend",function(d,i){portMouseUp(d,PORT_TYPE_INPUT,0);} )
.on("mouseover",function(d){portMouseOver(d3.select(this),d,PORT_TYPE_INPUT,0);})
.on("mouseout",function(d){portMouseOut(d3.select(this),d,PORT_TYPE_INPUT,0);});
statusGroup.append("svg:text").attr("class","port_label").attr("x",22).attr("y",20).style("font-size","10px").text("status");
subflowOutputs.each(function(d,i) {
if (d.dirty) {
var output = d3.select(this);
@@ -2439,9 +2510,22 @@ RED.view = (function() {
d.dirty = false;
}
});
subflowStatus.each(function(d,i) {
if (d.dirty) {
var output = d3.select(this);
output.selectAll(".subflowport").classed("node_selected",function(d) { return d.selected; })
output.selectAll(".port_index").text(function(d){ return d.i+1});
output.attr("transform", function(d) { return "translate(" + (d.x-d.w/2) + "," + (d.y-d.h/2) + ")"; });
dirtyNodes[d.id] = d;
d.dirty = false;
}
});
} else {
nodeLayer.selectAll(".subflowoutput").remove();
nodeLayer.selectAll(".subflowinput").remove();
nodeLayer.selectAll(".subflowstatus").remove();
}
var node = nodeLayer.selectAll(".nodegroup").data(activeNodes,function(d){return d.id});

View File

@@ -33,6 +33,15 @@
transition: right 0.2s ease;
overflow: hidden;
label {
padding: 1px 8px;
margin: 0;
font-size: 12px;
}
input[type="checkbox"] {
margin: 0 3px 0 0 ;
padding: 0;
}
.button {
@include workspace-button;
margin-right: 10px;

View File

@@ -7,6 +7,10 @@
<option value="target" data-i18n="catch.scope.selected"></options>
</select>
</div>
<div class="form-row node-input-uncaught-row">
<input type="checkbox" id="node-input-uncaught" style="display: inline-block; width: auto; vertical-align: top; margin-left: 30px; margin-right: 5px;">
<label for="node-input-uncaught" style="width: auto" data-i18n="catch.label.uncaught"></label>
</div>
<div class="form-row node-input-target-row" style="display: none;">
<div id="node-input-catch-target-container-div" style="min-height: 100px;position: relative; box-sizing: border-box; border-radius: 2px; height: 180px; border: 1px solid #ccc;overflow:hidden; ">
<div style="box-sizing: border-box; line-height: 20px; font-size: 0.8em; border-bottom: 1px solid #ddd; height: 20px;">
@@ -64,13 +68,20 @@
color:"#e49191",
defaults: {
name: {value:""},
scope: {value:null}
scope: {value:null},
uncaught: {value:false}
},
inputs:0,
outputs:1,
icon: "alert.png",
label: function() {
return this.name||(this.scope?this._("catch.catchNodes",{number:this.scope.length}):this._("catch.catch"));
if (this.name) {
return this.name;
}
if (this.scope) {
return this._("catch.catchNodes",{number:this.scope.length});
}
return this.uncaught?this._("catch.catchUncaught"):this._("catch.catch")
},
labelStyle: function() {
return this.name?"node_label_italic":"";
@@ -210,8 +221,10 @@
if (scope === "target") {
createNodeList();
$(".node-input-target-row").show();
$(".node-input-uncaught-row").hide();
} else {
$(".node-input-target-row").hide();
$(".node-input-uncaught-row").show();
}
node.resize();
});
@@ -227,6 +240,7 @@
if (scope === 'all') {
this.scope = null;
} else {
$("#node-input-uncaught").prop("checked",false);
var node = this;
node.scope = [];
$(".node-input-target-node-checkbox").each(function(n) {

View File

@@ -21,6 +21,7 @@ module.exports = function(RED) {
RED.nodes.createNode(this,n);
var node = this;
this.scope = n.scope;
this.uncaught = n.uncaught;
this.on("input",function(msg) {
this.send(msg);
});

View File

@@ -54,7 +54,7 @@
flowMap[activeSubflow.id] = {
id: activeSubflow.id,
class: 'palette-header',
label: "Subflow : "+(activeSubflow.name || activeSubflow.id),
label: "Subflow : "+(activeSubflow.name || activeSubflow.id)+(node.z===ws.id ? " *":""),
expanded: true,
children: []
};
@@ -64,8 +64,8 @@
flowMap[ws.id] = {
id: ws.id,
class: 'palette-header',
label: (ws.label || ws.id),
expanded: ws.id === node.z,
label: (ws.label || ws.id)+(node.z===ws.id ? " *":""),
expanded: true,
children: []
}
flows.push(flowMap[ws.id])
@@ -88,7 +88,10 @@
}
});
flows = flows.filter(function(f) { return f.children.length > 0 })
treeList.treeList('data',flows)
treeList.treeList('data',flows);
setTimeout(function() {
treeList.treeList('show',node.z);
},100);
}
function resizeNodeList() {

View File

@@ -158,9 +158,8 @@ module.exports = function(RED) {
},
env: {
get: function(envVar) {
// For now, just return the env var. This will eventually
// also return project settings and subflow instance properties
return process.env[envVar]
var flow = node._flow;
return flow.getSetting(envVar);
}
},
setTimeout: function () {

View File

@@ -34,6 +34,7 @@
<option value="auto" data-i18n="mqtt.output.auto"></option>
<option value="buffer" data-i18n="mqtt.output.buffer"></option>
<option value="utf8" data-i18n="mqtt.output.string"></option>
<option value="json" data-i18n="mqtt.output.json"></option>
<option value="base64" data-i18n="mqtt.output.base64"></option>
</select>
</div>

View File

@@ -399,16 +399,23 @@ module.exports = function(RED) {
if (this.topic) {
node.brokerConn.register(this);
this.brokerConn.subscribe(this.topic,this.qos,function(topic,payload,packet) {
if (node.datatype =="buffer") {
if (node.datatype === "buffer") {
// payload = payload;
} else if (node.datatype =="base64") {
} else if (node.datatype === "base64") {
payload = payload.toString('base64');
} else if (node.datatype =="utf8") {
} else if (node.datatype === "utf8") {
payload = payload.toString('utf8');
} else if (node.datatype === "json") {
if (isUtf8(payload)) {
payload = payload.toString();
try { payload = JSON.parse(payload); }
catch(e) { node.error(RED._("mqtt.errors.invalid-json-parse"),{payload:payload, topic:topic, qos:packet.qos, retain:packet.retain}); return; }
}
else { node.error((RED._("mqtt.errors.invalid-json-string")),{payload:payload, topic:topic, qos:packet.qos, retain:packet.retain}); return; }
} else {
if (isUtf8(payload)) { payload = payload.toString(); }
}
var msg = {topic:topic,payload:payload, qos: packet.qos, retain: packet.retain};
var msg = {topic:topic, payload:payload, qos:packet.qos, retain:packet.retain};
if ((node.brokerConn.broker === "localhost")||(node.brokerConn.broker === "127.0.0.1")) {
msg._topic = topic;
}

View File

@@ -25,11 +25,17 @@
<option value="use" data-i18n="httpin.setby"></option>
</select>
</div>
<div class="form-row">
<label for="node-input-url"><i class="fa fa-globe"></i> <span data-i18n="httpin.label.url"></span></label>
<input id="node-input-url" type="text" placeholder="http://">
</div>
<div class="form-row node-input-paytoqs-row">
<input type="checkbox" id="node-input-paytoqs" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-paytoqs" style="width: auto" data-i18n="httpin.label.paytoqs"></label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-usetls" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-usetls" style="width: auto" data-i18n="httpin.use-tls"></label>
@@ -84,6 +90,7 @@
name: {value:""},
method:{value:"GET"},
ret: {value:"txt"},
paytoqs: {value: false},
url:{value:"",validate:function(v) { return (v.trim().length === 0) || (v.indexOf("://") === -1) || (v.trim().indexOf("http") === 0)} },
tls: {type:"tls-config",required: false},
proxy: {type:"http proxy",required: false}
@@ -114,6 +121,13 @@
$('#node-input-password').val('');
}
});
$("#node-input-method").change(function() {
if ($(this).val() == "GET") {
$(".node-input-paytoqs-row").show();
} else {
$(".node-input-paytoqs-row").hide();
}
});
if (this.credentials.user || this.credentials.has_password) {
$('#node-input-useAuth').prop('checked', true);
} else {

View File

@@ -28,6 +28,7 @@ module.exports = function(RED) {
var nodeUrl = n.url;
var isTemplatedUrl = (nodeUrl||"").indexOf("{{") != -1;
var nodeMethod = n.method || "GET";
var paytoqs = n.paytoqs;
if (n.tls) {
var tlsNode = RED.nodes.getNode(n.tls);
}
@@ -148,16 +149,9 @@ module.exports = function(RED) {
};
}
if (opts.headers.hasOwnProperty('cookie')) {
var cookies = cookie.parse(opts.headers.cookie);
var cookies = cookie.parse(opts.headers.cookie, {decode:String});
for (var name in cookies) {
if (cookies.hasOwnProperty(name)) {
if (cookies[name] === null) {
// This case clears a cookie for HTTP In/Response nodes.
// Ignore for this node.
} else {
opts.jar.setCookie(name + '=' + cookies[name], url);
}
}
opts.jar.setCookie(cookie.serialize(name, cookies[name], {encode:String}), url);
}
delete opts.headers.cookie;
}
@@ -168,9 +162,15 @@ module.exports = function(RED) {
// This case clears a cookie for HTTP In/Response nodes.
// Ignore for this node.
} else if (typeof msg.cookies[name] === 'object') {
opts.jar.setCookie(name + '=' + msg.cookies[name].value, url);
if(msg.cookies[name].encode === false){
// If the encode option is false, the value is not encoded.
opts.jar.setCookie(cookie.serialize(name, msg.cookies[name].value, {encode: String}), url);
} else {
// The value is encoded by encodeURIComponent().
opts.jar.setCookie(cookie.serialize(name, msg.cookies[name].value), url);
}
} else {
opts.jar.setCookie(name + '=' + msg.cookies[name], url);
opts.jar.setCookie(cookie.serialize(name, msg.cookies[name]), url);
}
}
}
@@ -207,6 +207,25 @@ module.exports = function(RED) {
}
opts.body = payload;
}
if (method == 'GET' && typeof msg.payload !== "undefined" && paytoqs) {
if (typeof msg.payload === "object") {
try {
if (opts.url.indexOf("?") !== -1) {
opts.url += (opts.url.endsWith("?")?"":"&") + querystring.stringify(msg.payload);
} else {
opts.url += "?" + querystring.stringify(msg.payload);
}
} catch(err) {
node.error(RED._("httpin.errors.invalid-payload"),msg);
return;
}
} else {
node.error(RED._("httpin.errors.invalid-payload"),msg);
return;
}
}
// revert to user supplied Capitalisation if needed.
if (opts.headers.hasOwnProperty('content-type') && (ctSet !== 'content-type')) {
opts.headers[ctSet] = opts.headers['content-type'];

View File

@@ -94,7 +94,7 @@ module.exports = function(RED) {
this.error(RED._("change.errors.invalid-expr",{error:e.message}));
}
} else if (rule.tot === 'env') {
rule.to = RED.util.evaluateNodeProperty(rule.to,'env');
rule.to = RED.util.evaluateNodeProperty(rule.to,'env',node);
}
}

View File

@@ -32,7 +32,8 @@
halt. This node can be used to catch those errors and handle them with a
dedicated flow.</p>
<p>By default, the node will catch errors thrown by any node on the same tab. Alternatively
it can be targetted at specific nodes.</p>
it can be targetted at specific nodes, or configured to only catch errors that
have not already been caught by a 'targeted' catch node.</p>
<p>When an error is thrown, all matching catch nodes will receive the message.</p>
<p>If an error is thrown within a subflow, the error will get handled by any
catch nodes within the subflow. If none exists, the error will be propagated

View File

@@ -72,13 +72,15 @@
"catch": {
"catch": "catch: all",
"catchNodes": "catch: __number__",
"catchUncaught": "catch: uncaught",
"label": {
"source": "Catch errors from",
"node": "node",
"type": "type",
"selectAll": "select all",
"sortByLabel": "sort by label",
"sortByType": "sort by type"
"sortByType": "sort by type",
"uncaught": "Ignore errors handled by other Catch nodes"
},
"scope": {
"all": "all nodes",
@@ -353,7 +355,8 @@
"buffer": "a Buffer",
"string": "a String",
"base64": "a Base64 encoded string",
"auto": "auto-detect"
"auto": "auto-detect (string or buffer)",
"json": "a parsed JSON object"
},
"true": "true",
"false": "false",
@@ -362,7 +365,9 @@
"not-defined": "topic not defined",
"missing-config": "missing broker configuration",
"invalid-topic": "Invalid topic specified",
"nonclean-missingclientid": "No client ID set, using clean session"
"nonclean-missingclientid": "No client ID set, using clean session",
"invalid-json-string": "Invalid JSON string",
"invalid-json-parse": "Failed to parse JSON string"
}
},
"httpin": {
@@ -374,7 +379,8 @@
"upload": "Accept file uploads?",
"status": "Status code",
"headers": "Headers",
"other": "other"
"other": "other",
"paytoqs" : "Append msg.payload as query string parameters"
},
"setby": "- set by msg.method -",
"basicauth": "Use basic authentication",
@@ -402,7 +408,8 @@
"deprecated-call":"Deprecated call to __method__",
"invalid-transport":"non-http transport requested",
"timeout-isnan": "Timeout value is not a valid number, ignoring",
"timeout-isnegative": "Timeout value is negative, ignoring"
"timeout-isnegative": "Timeout value is negative, ignoring",
"invalid-payload": "Invalid payload"
},
"status": {
"requesting": "requesting"

View File

@@ -29,7 +29,7 @@
</dl>
<h3>詳細</h3>
<p>メッセージの処理中にノードがエラーを送出した場合フロー実行は基本的に停止しますこのノードを使うとエラーをキャッチして対応するフローで処理させることができます</p>
<p>デフォルトでは同じタブの全てのノードが送出したエラーをキャッチします特定のノードをキャッチ対象とすることも可能です</p>
<p>デフォルトでは同じタブの全てのノードが送出したエラーをキャッチします特定のノードをキャッチ対象とする対象catchードで補足されていないエラーのみ補足するように指定することも可能です</p>
<p>エラー発生時にはマッチするすべてのcatchードがメッセージを受け取ります</p>
<p>サブフロー内でエラーが送出された場合まずサブフロー内のcatchードで処理されます対応するノードが存在しない場合にはそのサブフローが配置されたタブにエラーを伝播して処理します</p>
<p>メッセージが<code>error</code><code>error</code><code>_error</code></p>

View File

@@ -46,4 +46,6 @@
<li><code>node.id</code> - ID</li>
<li><code>node.name</code> - </li>
</ul>
<h4>環境変数の利用</h4>
<p>環境変数は<code>env.get("MY_ENV_VAR")</code></p>
</script>

View File

@@ -42,6 +42,8 @@
<p>というメッセージを受信した場合</p>
<pre>こんにちは山田さん今日は月曜日です</pre>
<p>というプロパティが生成されます</p>
<p>フローコンテキストもしくはグローバルコンテキストのプロパティ値を使うこともできますそれぞれ<code>{{flow.名前}}</code><code>{{global.}}</code></p>
<p>フローコンテキストもしくはグローバルコンテキストのプロパティ値を使うこともできますそれぞれ<code>{{flow.名前}}</code><code>{{global.}}</code>(<code>store</code>)<code>{{flow[store].}}</code>
<code>{{global[store].名前}}</code>
</p>
<p><b>: </b>デフォルトでは、<i>mustache</i>形式は置換対象のHTML要素をエスケープしますこれを抑止するには<code>{{{三重}}}</code>使</p>
</script>

View File

@@ -58,7 +58,7 @@
<h3>詳細</h3>
<p><code>statusCode</code><code>headers</code>使</p>
<h4>クッキーの処理</h4>
<p><code>cookies</code>/使<p>
<p><code>cookies</code>/使</p>
<p>以下の例では2つのクッキーを設定しています1つ目は<code>name</code><code>nick</code>2<code>session</code><code>1234</code>15</p>
<pre>
msg.cookies = {

View File

@@ -55,7 +55,7 @@
<h4>複数のHTTPリクエストードの利用</h4>
<p>同一フローで本ノードを複数利用するためには<code>msg.headers</code><code>msg.headers</code>2<code>msg.headers</code><code>{}</code>
<h4>クッキーの扱い</h4>
<p>ノードに<code>cookies</code>/<code>value</code><p>
<p>ノードに<code>cookies</code>/<code>value</code></p>
<p>リクエストに対して返却されたクッキーは<code>responseCookies</code></p>
<h4>要素タイプの扱い</h4>
<p><code>msg.payload</code><code>msg.payload</code>JSON</p>

View File

@@ -15,7 +15,7 @@
-->
<script type="text/x-red" data-help-name="tcp in">
<p>TCPからの入力を行いますリモートTCPポートに接続するか外部からのコネクションを受け付けます</p>
<p>TCPからの入力を行いますリモートTCPポートに接続するか外部からのコネクションを受け付けます</p>
<p><b>: </b>1024rootadministrator</p>
</script>
@@ -30,6 +30,6 @@
<script type="text/x-red" data-help-name="tcp request">
<p>シンプルなTCPリクエストード<code>msg.payload</code>TCP</p>
<p>サーバに接続"リクエスト"送信"レスポンス"受信を行います固定長の文字数指定文字へのマッチ最初のリプライの到着から指定した時間待つデータの到着待ちデータ送信を行いリプライを待たず接続を即時解除などから動作を選択できます</p>
<p>レスポンスはバッファ形式で<code>msg.payload</code>toString()使</p>
<p>レスポンスはバッファ形式で<code>msg.payload</code>.toString()使</p>
<p>TCPホストのポート番号設定を空にした場合<code>msg.host</code><code>msg.port</code></p>
</script>

View File

@@ -20,7 +20,7 @@
<p>受信したメッセージに対し指定されたルールを順に評価しマッチしたルールに対応する出力ポートにメッセージを送出します</p>
<p>最初にルールがマッチしたところで評価を止めることも可能です</p>
<p>評価ルールにはメッセージプロパティフローコンテキスト/グローバルコンテキストのプロパティJSONata式の評価結果が利用できます</p>
<h3>ルール</h3>
<h4>ルール</h4>
<p>振り分けルールは以下の4つに分類されます</p>
<ol>
<li><b>(value)</b> - </li>
@@ -29,11 +29,11 @@
<li><b>その他</b> - </li>
</ol>
<h3>注釈</h3>
<h4>注釈</h4>
<p><code>is true/false</code><code>is null</code></p>
<p><code>is empty</code><code>null</code><code>undefined</code></p>
<h3>メッセージ列の扱い</h3>
<h4>メッセージ列の扱い</h4>
<p>switchードは入力メッセージの列に関する情報を保持する<code>msg.parts</code></p>
<p><b>メッセージ列の補正</b>switch<b>settings.js</b><code>nodeMessageBufferMaxLength</code></p>
</script>

View File

@@ -29,5 +29,5 @@
<dt>移動</dt>
<dd>プロパティの移動または名前の変更を行います</dd>
</dl>
<p>expressionには<a href="http://jsonata.org/" target="_new">JSONata</a></p>
<p>JSONata式には<a href="http://jsonata.org/" target="_new">JSONata</a></p>
</script>

View File

@@ -19,7 +19,7 @@
<h3>入力</h3>
<dl class="message-properties">
<dt>payload<span class="property-type">数値</span></dt>
<dd>数値以外の場合は数値に変換します変換不能な場合はラーとなります</dd>
<dd>数値を指定します数値以外を指定した場合は数値に変換します変換不能な場合はラーとなります</dd>
</dl>
<h3>出力</h3>
<dl class="message-properties">

View File

@@ -97,7 +97,8 @@
<p>出力メッセージのその他のプロパティはメッセージを送信する直前のメッセージをコピーします</p>
<p><i>合計値</i></p>
<p><i></i></p>
<p><code>msg.complete</code></p>
<p><code>msg.complete</code></p>
<p><code>msg.reset</code></p>
<h4>列の集約モード</h4>
<p>列の集約モードを選択するとメッセージ列を構成する各々のメッセージに対して式を適用し集約した値を用いて一つのメッセージを構成します</p>

View File

@@ -62,7 +62,7 @@
"on": "曜日",
"onstart": "Node-RED起動の",
"onceDelay": "秒後、以下を行う",
"tip": "<b>注釈:</b> 「指定した時間間隔、日時」と「指定した日時」はcronを使用します。詳細はードの「情報」を確認してください。",
"tip": "<b>注釈:</b> 「指定した時間間隔、日時」と「指定した日時」はcronを使用します。<br/>「時間感覚」'には596時間より小さな値を指定します。<br/>詳細はノードの「情報」を確認してください。",
"success": "inject処理を実行しました: __label__",
"errors": {
"failed": "inject処理が失敗しました。詳細はログを確認してください。",
@@ -70,15 +70,17 @@
}
},
"catch": {
"catch": "catch all",
"catchNodes": "catch (__number__)",
"catch": "catch: 全て",
"catchNodes": "catch: __number__",
"catchUncaught": "catch: 未補足",
"label": {
"source": "エラー取得元",
"node": "ノード",
"type": "型",
"selectAll": "全て選択",
"sortByLabel": "ノード名で並べ替え",
"sortByType": "型で並べ替え"
"sortByType": "型で並べ替え",
"uncaught": "Catchードで処理済みのエラーを無視"
},
"scope": {
"all": "全てのノード",
@@ -86,8 +88,8 @@
}
},
"status": {
"status": "status (all)",
"statusNodes": "status (__number__)",
"status": "status: 全て",
"statusNodes": "status: __number__",
"label": {
"source": "状態取得元",
"node": "ノード",
@@ -263,7 +265,7 @@
},
"error": {
"buffer": "バッファ上限の1000メッセージを超えました",
"buffer1": "バッファ上限の1000メッセージを超えました"
"buffer1": "バッファ上限の10000メッセージを超えました"
}
},
"trigger": {
@@ -353,7 +355,8 @@
"buffer": "バイナリバッファ",
"string": "文字列",
"base64": "Base64文字列",
"auto": "自動判定"
"auto": "自動判定(文字列もしくはバイナリバッファ)",
"json": "JSONオブジェクト"
},
"true": "する",
"false": "しない",
@@ -362,7 +365,9 @@
"not-defined": "トピックが設定されていません",
"missing-config": "ブローカが設定されていません",
"invalid-topic": "不正なトピックが設定されています",
"nonclean-missingclientid": "「セッションの初期化」使用時に、クライアントIDが設定されていません"
"nonclean-missingclientid": "「セッションの初期化」使用時に、クライアントIDが設定されていません",
"invalid-json-string": "不正なJSON文字列",
"invalid-json-parse": "JSON文字列のパースに失敗しました"
}
},
"httpin": {
@@ -374,7 +379,8 @@
"upload": "ファイルのアップロード",
"status": "状態コード",
"headers": "ヘッダ",
"other": "その他"
"other": "その他",
"paytoqs" : "msg.payloadをクエリパラメータに追加"
},
"setby": "- msg.methodに定義 -",
"basicauth": "ベーシック認証を使用",
@@ -402,7 +408,8 @@
"deprecated-call": "非推奨の呼び出しです __method__",
"invalid-transport": "httpでないトランスポートが要求されました",
"timeout-isnan": "タイムアウト値が数値ではないため無視します",
"timeout-isnegative": "タイムアウト値が負数のため無視します"
"timeout-isnegative": "タイムアウト値が負数のため無視します",
"invalid-payload": "不正なペイロード"
},
"status": {
"requesting": "要求中"
@@ -432,7 +439,8 @@
"errors": {
"connect-error": "ws接続でエラーが発生しました: ",
"send-error": "送信中にエラーが発生しました: ",
"missing-conf": "サーバ設定が不足しています"
"missing-conf": "サーバ設定が不足しています",
"duplicate-path": "同じパスに対して2つのWebSocketリスナは指定できません: __path__"
}
},
"watch": {
@@ -849,7 +857,7 @@
"appendfail": "ファイルの追記処理が失敗しました: __error__",
"createfail": "ファイルの作成処理が失敗しました: __error__"
},
"tip": "注釈: 「ファイル名」フルパスを設定する必要があります。"
"tip": "注釈: 「ファイル名」フルパスを設定しない場合は、Node-REDプロセスの実行ディレクトリからの相対パスとなります。"
},
"split": {
"split": "split",
@@ -920,7 +928,7 @@
"ascending": "昇順",
"descending": "降順",
"as-number": "数値として比較",
"invalid-exp": "sortードで不正なJSONata式が指定されました",
"invalid-exp": "sortードで不正なJSONata式が指定されました: __message__",
"too-many": "sortードの未処理メッセージの数が許容数を超えました",
"clear": "sortードの未処理メッセージを破棄しました"
},

View File

@@ -1,6 +1,6 @@
{
"name": "@node-red/nodes",
"version": "0.20.0-beta.4",
"version": "0.20.0-beta.5",
"license": "Apache-2.0",
"repository": {
"type": "git",
@@ -15,7 +15,7 @@
}
],
"dependencies": {
"ajv": "6.7.0",
"ajv": "6.8.1",
"body-parser": "1.18.3",
"cheerio": "0.22.0",
"cookie-parser": "1.4.3",

View File

@@ -1,6 +1,6 @@
{
"name": "@node-red/registry",
"version": "0.20.0-beta.4",
"version": "0.20.0-beta.5",
"license": "Apache-2.0",
"main": "./lib/index.js",
"repository": {
@@ -16,7 +16,7 @@
}
],
"dependencies": {
"@node-red/util": "0.20.0-beta.4",
"@node-red/util": "0.20.0-beta.5",
"semver": "5.6.0",
"uglify-js": "3.4.9",
"when": "3.7.8"

View File

@@ -38,7 +38,11 @@ function Node(n) {
// Make this a non-enumerable property as it may cause
// circular references. Any existing code that tries to JSON serialise
// the object (such as dashboard) will not like circular refs
Object.defineProperty(this,'_flow', {value: n._flow, })
// The value must still be writable in the case that a node does:
// Object.assign(this,config)
// as part of its constructure - config._flow will overwrite this._flow
// which we can tolerate as they are the same object.
Object.defineProperty(this,'_flow', {value: n._flow, enumerable: false, writable: true })
}
this.updateWires(n.wires);
}

View File

@@ -18,6 +18,7 @@ var clone = require("clone");
var log = require("@node-red/util").log;
var util = require("@node-red/util").util;
var memory = require("./memory");
var flows;
var settings;
@@ -47,6 +48,7 @@ function logUnknownStore(name) {
}
function init(_settings) {
flows = require("../flows");
settings = _settings;
contexts = {};
stores = {};
@@ -198,8 +200,24 @@ function getContextStorage(storage) {
}
}
function followParentContext(parent, key) {
if (key === "$parent") {
return [parent, undefined];
}
else if (key.startsWith("$parent.")) {
var len = "$parent.".length;
var new_key = key.substring(len);
var ctx = parent;
while (ctx && new_key.startsWith("$parent.")) {
ctx = ctx.$parent;
new_key = new_key.substring(len);
}
return [ctx, new_key];
}
return null;
}
function createContext(id,seed) {
function createContext(id,seed,parent) {
// Seed is only set for global context - sourced from functionGlobalContext
var scope = id;
var obj = seed || {};
@@ -254,6 +272,21 @@ function createContext(id,seed) {
if (!storage) {
storage = keyParts.store || "_";
}
var result = followParentContext(parent, key);
if (result) {
var [ctx, new_key] = result;
if (ctx && new_key) {
return ctx.get(new_key, storage, callback);
}
else {
if (callback) {
return callback(undefined);
}
else {
return undefined;
}
}
}
} else {
if (!storage) {
storage = "_";
@@ -321,6 +354,19 @@ function createContext(id,seed) {
if (!storage) {
storage = keyParts.store || "_";
}
var result = followParentContext(parent, key);
if (result) {
var [ctx, new_key] = result;
if (ctx && new_key) {
return ctx.set(new_key, value, storage, callback);
}
else {
if (callback) {
return callback();
}
return undefined;
}
}
} else {
if (!storage) {
storage = "_";
@@ -361,10 +407,36 @@ function createContext(id,seed) {
}
}
});
if (parent) {
Object.defineProperty(obj, "$parent", {
value: parent
});
}
return obj;
}
function getContext(localId,flowId) {
function createRootContext() {
var obj = {};
Object.defineProperties(obj, {
get: {
value: function(key, storage, callback) {
return undefined;
}
},
set: {
value: function(key, value, storage, callback) {
}
},
keys: {
value: function(storage, callback) {
return undefined;
}
}
});
return obj;
}
function getContext(localId,flowId,parent) {
var contextId = localId;
if (flowId) {
contextId = localId+":"+flowId;
@@ -372,10 +444,19 @@ function getContext(localId,flowId) {
if (contexts.hasOwnProperty(contextId)) {
return contexts[contextId];
}
var newContext = createContext(contextId);
var newContext = createContext(contextId,undefined,parent);
if (flowId) {
var node = flows.get(flowId);
var parent = undefined;
if (node && node.type.startsWith("subflow:")) {
parent = node.context().flow;
}
else {
parent = createRootContext();
}
var flowContext = getContext(flowId,undefined,parent);
Object.defineProperty(newContext, 'flow', {
value: getContext(flowId)
value: flowContext
});
}
Object.defineProperty(newContext, 'global', {

View File

@@ -212,6 +212,21 @@ class Flow {
}
}
}
this.catchNodes.sort(function(A,B) {
if (A.scope && !B.scope) {
return -1;
} else if (!A.scope && B.scope) {
return 1;
} else if (A.scope && B.scope) {
return 0;
} else if (A.uncaught && !B.uncaught) {
return 1;
} else if (!A.uncaught && B.uncaught) {
return -1;
}
return 0;
});
if (activeCount > 0) {
this.trace("------------------|--------------|-----------------");
}
@@ -265,7 +280,6 @@ class Flow {
return Promise.all(promises);
}
/**
* Update the flow definition. This doesn't change anything that is running.
* This should be called after `stop` and before `start`.
@@ -281,11 +295,13 @@ class Flow {
/**
* Get a node instance from this flow. If the node is not known to this
* flow, pass the request up to the parent.
* @param {[type]} id [description]
* @param {String} id [description]
* @param {Boolean} cancelBubble if true, prevents the flow from passing the request to the parent
* This stops infinite loops when the parent asked this Flow for the
* node to begin with.
* @return {[type]} [description]
*/
getNode(id) {
// console.log('getNode',id,!!this.activeNodes[id])
getNode(id, cancelBubble) {
if (!id) {
return undefined;
}
@@ -298,7 +314,10 @@ class Flow {
// TEMP: this is a subflow internal node within this flow
return this.activeNodes[id];
}
return this.parent.getNode(id);
if (!cancelBubble) {
return this.parent.getNode(id);
}
return undefined;
}
/**
@@ -415,10 +434,20 @@ class Flow {
}
handled = true;
} else {
var handledByUncaught = false;
this.catchNodes.forEach(function(targetCatchNode) {
if (targetCatchNode.scope && targetCatchNode.scope.indexOf(reportingNode.id) === -1) {
return;
}
if (!targetCatchNode.scope && targetCatchNode.uncaught && !handledByUncaught) {
if (handled) {
// This has been handled by a !uncaught catch node
return;
}
// This is an uncaught error
handledByUncaught = true;
}
var errorMessage;
if (msg) {
errorMessage = redUtil.cloneMessage(msg);
@@ -461,6 +490,7 @@ class Flow {
}
console.log("==================")
}
}
/**

View File

@@ -17,11 +17,14 @@
const clone = require("clone");
const Flow = require('./Flow').Flow;
const util = require("util");
const redUtil = require("@node-red/util").util;
const flowUtil = require("./util");
var Log;
/**
* This class represents a subflow - which is handled as a special type of Flow
*/
@@ -37,7 +40,6 @@ class Subflow extends Flow {
* @param {[type]} subflowInstance [description]
*/
constructor(parent,globalFlow,subflowDef,subflowInstance) {
// console.log(subflowDef);
// console.log("CREATE SUBFLOW",subflowDef.id,subflowInstance.id);
// console.log("SubflowInstance\n"+JSON.stringify(subflowInstance," ",2));
// console.log("SubflowDef\n"+JSON.stringify(subflowDef," ",2));
@@ -90,6 +92,15 @@ class Subflow extends Flow {
this.subflowDef = subflowDef;
this.subflowInstance = subflowInstance;
this.node_map = node_map;
var env = [];
if (this.subflowDef.env) {
this.subflowDef.env.forEach(e => { env[e.name] = e; });
}
if (this.subflowInstance.env) {
this.subflowInstance.env.forEach(e => { env[e.name] = e; });
}
this.env = env;
}
/**
@@ -104,6 +115,40 @@ class Subflow extends Flow {
var self = this;
// Create a subflow node to accept inbound messages and route appropriately
var Node = require("../Node");
if (this.subflowDef.status) {
var subflowStatusConfig = {
id: this.subflowInstance.id+":status",
type: "subflow-status",
z: this.subflowInstance.id,
_flow: this.parent
}
this.statusNode = new Node(subflowStatusConfig);
this.statusNode.on("input", function(msg) {
if (msg.payload !== undefined) {
if (typeof msg.payload === "string") {
// if msg.payload is a String, use it as status text
self.node.status({text:msg.payload})
return;
} else if (Object.prototype.toString.call(msg.payload) === "[object Object]") {
if (msg.payload.hasOwnProperty('text') || msg.payload.hasOwnProperty('fill') || msg.payload.hasOwnProperty('shape') || Object.keys(msg.payload).length === 0) {
// msg.payload is an object that looks like a status object
self.node.status(msg.payload);
return;
}
}
// Anything else - inspect it and use as status text
var text = util.inspect(msg.payload);
if (text.length > 32) { text = text.substr(0,32) + "..."; }
self.node.status({text:text});
} else if (msg.status !== undefined) {
// if msg.status exists
self.node.status(msg.status)
}
})
}
var subflowInstanceConfig = {
id: this.subflowInstance.id,
type: this.subflowInstance.type,
@@ -164,15 +209,14 @@ class Subflow extends Flow {
self.node._updateWires(subflowInstanceConfig.wires);
}
}
}
};
// Wire the subflow outputs
if (this.subflowDef.out) {
var modifiedNodes = {};
for (var i=0;i<this.subflowDef.out.length;i++) {
// i: the output index
// This is what this Output is wired to
wires = this.subflowDef.out[i].wires;
var wires = this.subflowDef.out[i].wires;
for (var j=0;j<wires.length;j++) {
if (wires[j].id === this.subflowDef.id) {
// A subflow input wired straight to a subflow output
@@ -180,7 +224,6 @@ class Subflow extends Flow {
this.node._updateWires(subflowInstanceConfig.wires);
} else {
var node = self.node_map[wires[j].id];
modifiedNodes[node.id] = node;
if (!node._originalWires) {
node._originalWires = clone(node.wires);
}
@@ -189,9 +232,72 @@ class Subflow extends Flow {
}
}
}
if (this.subflowDef.status) {
var subflowStatusId = this.statusNode.id;
wires = this.subflowDef.status.wires;
for (var j=0;j<wires.length;j++) {
if (wires[j].id === this.subflowDef.id) {
// A subflow input wired straight to a subflow output
subflowInstanceConfig.wires[wires[j].port].push(subflowStatusId);
this.node._updateWires(subflowInstanceConfig.wires);
} else {
var node = self.node_map[wires[j].id];
if (!node._originalWires) {
node._originalWires = clone(node.wires);
}
node.wires[wires[j].port] = (node.wires[wires[j].port]||[]);
node.wires[wires[j].port].push(subflowStatusId);
}
}
}
super.start(diff);
}
/**
* Get environment variable of subflow
* @param {String} name name of env var
* @return {Object} val value of env var
*/
getSetting(name) {
var env = this.env;
if (env && env.hasOwnProperty(name)) {
var val = env[name];
try {
var ret = redUtil.evaluateNodeProperty(val.value, val.type, this.node, null, null);
return ret;
}
catch (e) {
this.error(e);
return undefined;
}
}
var parent = this.parent;
if (parent) {
var val = parent.getSetting(name);
return val;
}
return undefined;
}
/**
* Get a node instance from this subflow.
* If the subflow has a status node, check for that, otherwise use
* the super-class function
* @param {String} id [description]
* @param {Boolean} cancelBubble if true, prevents the flow from passing the request to the parent
* This stops infinite loops when the parent asked this Flow for the
* node to begin with.
* @return {[type]} [description]
*/
getNode(id, cancelBubble) {
if (this.statusNode && this.statusNode.id === id) {
return this.statusNode;
}
return super.getNode(id,cancelBubble);
}
/**
* Handle a status event from a node within this flow.
* @param {Node} node The original node that triggered the event
@@ -205,10 +311,14 @@ class Subflow extends Flow {
handleStatus(node,statusMessage,reportingNode,muteStatus) {
let handled = super.handleStatus(node,statusMessage,reportingNode,muteStatus);
if (!handled) {
// No status node on this subflow caught the status message.
// Pass up to the parent with this subflow's instance as the
// reporting node
handled = this.parent.handleStatus(node,statusMessage,this.node,true);
if (!this.statusNode || node === this.node) {
// No status node on this subflow caught the status message.
// AND there is no Subflow Status node - so the user isn't
// wanting to manage status messages themselves
// Pass up to the parent with this subflow's instance as the
// reporting node
handled = this.parent.handleStatus(node,statusMessage,this.node,true);
}
}
return handled;
@@ -234,7 +344,6 @@ class Subflow extends Flow {
return handled;
}
}

View File

@@ -207,11 +207,11 @@ function setFlows(_config,type,muteLog,forceStart) {
function getNode(id) {
var node;
if (activeNodesToFlow[id] && activeFlows[activeNodesToFlow[id]]) {
return activeFlows[activeNodesToFlow[id]].getNode(id);
return activeFlows[activeNodesToFlow[id]].getNode(id,true);
}
for (var flowId in activeFlows) {
if (activeFlows.hasOwnProperty(flowId)) {
node = activeFlows[flowId].getNode(id);
node = activeFlows[flowId].getNode(id,true);
if (node) {
return node;
}

View File

@@ -1,6 +1,6 @@
{
"name": "@node-red/runtime",
"version": "0.20.0-beta.4",
"version": "0.20.0-beta.5",
"license": "Apache-2.0",
"main": "./lib/index.js",
"repository": {
@@ -16,8 +16,8 @@
}
],
"dependencies": {
"@node-red/registry": "0.20.0-beta.4",
"@node-red/util": "0.20.0-beta.4",
"@node-red/registry": "0.20.0-beta.5",
"@node-red/util": "0.20.0-beta.5",
"clone": "2.1.2",
"express": "4.16.4",
"fs-extra": "7.0.1",

View File

@@ -413,6 +413,23 @@ function setObjectProperty(msg,prop,value,createMissing) {
}
}
/**
* Get value of environment variable.
* @param {Node} node - accessing node
* @param {String} name - name of variable
* @return {String} value of env var
*/
function getSetting(node, name) {
if (node && node._flow) {
var flow = node._flow;
if (flow) {
return flow.getSetting(name);
}
}
return process.env[name];
}
/**
* Checks if a String contains any Environment Variable specifiers and returns
* it with their values substituted in place.
@@ -420,24 +437,28 @@ function setObjectProperty(msg,prop,value,createMissing) {
* For example, if the env var `WHO` is set to `Joe`, the string `Hello ${WHO}!`
* will return `Hello Joe!`.
* @param {String} value - the string to parse
* @param {Node} node - the node evaluating the property
* @return {String} The parsed string
* @memberof @node-red/util_util
*/
function evaluateEnvProperty(value) {
function evaluateEnvProperty(value, node) {
var result;
if (/^\${[^}]+}$/.test(value)) {
// ${ENV_VAR}
value = value.substring(2,value.length-1);
value = process.env.hasOwnProperty(value)?process.env[value]:""
var name = value.substring(2,value.length-1);
result = getSetting(node, name);
} else if (!/\${\S+}/.test(value)) {
// ENV_VAR
value = process.env.hasOwnProperty(value)?process.env[value]:""
result = getSetting(node, value);
} else {
// FOO${ENV_VAR}BAR
value = value.replace(/\${([^}]+)}/g, function(match, v) {
return process.env.hasOwnProperty(v)?process.env[v]:""
return value.replace(/\${([^}]+)}/g, function(match, name) {
var val = getSetting(node, name);
return (val === undefined)?"":val;
});
}
return value;
return (result === undefined)?"":result;
}
@@ -513,7 +534,7 @@ function evaluateNodeProperty(value, type, node, msg, callback) {
var expr = prepareJSONataExpression(value,node);
result = evaluateJSONataExpression(expr,msg);
} else if (type === 'env') {
result = evaluateEnvProperty(value);
result = evaluateEnvProperty(value, node);
}
if (callback) {
callback(null,result);
@@ -540,8 +561,9 @@ function prepareJSONataExpression(value,node) {
expr.assign('globalContext',function(val) {
return node.context().global.get(val);
});
expr.assign('env', function(val) {
return process.env[val];
expr.assign('env', function(name) {
var val = getSetting(node, name);
return (val ? val : "");
})
expr.registerFunction('clone', cloneMessage, '<(oa)-:o>');
expr._legacyMode = /(^|[^a-zA-Z0-9_'"])msg([^a-zA-Z0-9_'"]|$)/.test(value);

View File

@@ -1,6 +1,6 @@
{
"name": "@node-red/util",
"version": "0.20.0-beta.4",
"version": "0.20.0-beta.5",
"license": "Apache-2.0",
"repository": {
"type": "git",
@@ -16,7 +16,7 @@
],
"dependencies": {
"clone": "2.1.2",
"i18next": "13.1.0",
"i18next": "14.1.1",
"json-stringify-safe": "5.0.1",
"jsonata": "1.6.4",
"when": "3.7.8"

View File

@@ -1,6 +1,6 @@
{
"name": "node-red",
"version": "0.20.0-beta.4",
"version": "0.20.0-beta.5",
"description": "A visual tool for wiring the Internet of Things",
"homepage": "http://nodered.org",
"license": "Apache-2.0",
@@ -31,10 +31,10 @@
"flow"
],
"dependencies": {
"@node-red/editor-api": "0.20.0-beta.4",
"@node-red/runtime": "0.20.0-beta.4",
"@node-red/util": "0.20.0-beta.4",
"@node-red/nodes": "0.20.0-beta.4",
"@node-red/editor-api": "0.20.0-beta.5",
"@node-red/runtime": "0.20.0-beta.5",
"@node-red/util": "0.20.0-beta.5",
"@node-red/nodes": "0.20.0-beta.5",
"basic-auth": "2.0.1",
"bcryptjs": "2.4.3",
"express": "4.16.4",

View File

@@ -120,7 +120,7 @@ describe('HTTP Request Node', function() {
before(function(done) {
testApp = express();
testApp.use(bodyParser.raw({type:"*/*"}));
testApp.use(cookieParser());
testApp.use(cookieParser(undefined,{decode:String}));
testApp.get('/statusCode204', function(req,res) { res.status(204).end();});
testApp.get('/text', function(req, res){ res.send('hello'); });
testApp.get('/redirectToText', function(req, res){ res.status(302).set('Location', getTestURL('/text')).end(); });
@@ -138,8 +138,7 @@ describe('HTTP Request Node', function() {
}, 50);
});
testApp.get('/checkCookie', function(req, res){
var value = req.cookies.data;
res.send(value);
res.send(req.cookies);
});
testApp.get('/setCookie', function(req, res){
res.cookie('data','hello');
@@ -219,6 +218,12 @@ describe('HTTP Request Node', function() {
res.cookie('redirectReturn','return1');
res.status(200).end();
});
testApp.get('/getQueryParams', function(req,res) {
res.json({
query:req.query,
url: req.originalUrl
});
})
startServer(function(err) {
if (err) {
done(err);
@@ -237,7 +242,6 @@ describe('HTTP Request Node', function() {
});
});
beforeEach(function() {
preEnvHttpProxyLowerCase = process.env.http_proxy;
preEnvHttpProxyUpperCase = process.env.HTTP_PROXY;
@@ -971,7 +975,31 @@ describe('HTTP Request Node', function() {
});
});
it('should append query params to url - obj', function(done) {
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",paytoqs:true,ret:"obj",url:getTestURL('/getQueryParams')},
{id:"n2", type:"helper"}];
helper.load(httpRequestNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('payload',{
query:{a:'1',b:'2',c:'3'},
url: '/getQueryParams?a=1&b=2&c=3'
});
msg.should.have.property('statusCode',200);
msg.should.have.property('headers');
done();
} catch(err) {
done(err);
}
});
n1.receive({payload:{a:1,b:2,c:3}});
});
});
});
describe('HTTP header', function() {
it('should receive cookie', function(done) {
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",url:getTestURL('/setCookie')},
@@ -1001,7 +1029,7 @@ describe('HTTP Request Node', function() {
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('payload','abc');
msg.payload.should.have.property('data','abc');
msg.should.have.property('statusCode',200);
done();
} catch(err) {
@@ -1012,6 +1040,26 @@ describe('HTTP Request Node', function() {
});
});
it('should send multiple cookies with string', function(done) {
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",url:getTestURL('/checkCookie')},
{id:"n2", type:"helper"}];
helper.load(httpRequestNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.payload.should.have.property('data','abc');
msg.payload.should.have.property('foo','bar');
msg.should.have.property('statusCode',200);
done();
} catch(err) {
done(err);
}
});
n1.receive({payload:"foo", cookies:{data:'abc',foo:'bar'}});
});
});
it('should send cookie with object data', function(done) {
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",url:getTestURL('/checkCookie')},
{id:"n2", type:"helper"}];
@@ -1020,7 +1068,7 @@ describe('HTTP Request Node', function() {
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('payload','abc');
msg.payload.should.have.property('data','abc');
msg.should.have.property('statusCode',200);
done();
} catch(err) {
@@ -1031,6 +1079,86 @@ describe('HTTP Request Node', function() {
});
});
it('should send multiple cookies with object data', function(done) {
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",url:getTestURL('/checkCookie')},
{id:"n2", type:"helper"}];
helper.load(httpRequestNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.payload.should.have.property('data','abc');
msg.payload.should.have.property('foo','bar');
msg.should.have.property('statusCode',200);
done();
} catch(err) {
done(err);
}
});
n1.receive({payload:"foo", cookies:{data:{value:'abc'},foo:{value:'bar'}}});
});
});
it('should encode cookie value', function(done) {
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",url:getTestURL('/checkCookie')},
{id:"n2", type:"helper"}];
helper.load(httpRequestNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var value = ';,/?:@ &=+$#';
n2.on("input", function(msg) {
try {
msg.payload.should.have.property('data',encodeURIComponent(value));
msg.should.have.property('statusCode',200);
done();
} catch(err) {
done(err);
}
});
n1.receive({payload:"foo", cookies:{data:value}});
});
});
it('should encode cookie object', function(done) {
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",url:getTestURL('/checkCookie')},
{id:"n2", type:"helper"}];
helper.load(httpRequestNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var value = ';,/?:@ &=+$#';
n2.on("input", function(msg) {
try {
msg.payload.should.have.property('data',encodeURIComponent(value));
msg.should.have.property('statusCode',200);
done();
} catch(err) {
done(err);
}
});
n1.receive({payload:"foo", cookies:{data:{value:value, encode:true}}});
});
});
it('should not encode cookie when encode option is false', function(done) {
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",url:getTestURL('/checkCookie')},
{id:"n2", type:"helper"}];
helper.load(httpRequestNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var value = '!#$%&\'()*+-./:<>?@[]^_`{|}~';
n2.on("input", function(msg) {
try {
msg.payload.should.have.property('data',value);
msg.should.have.property('statusCode',200);
done();
} catch(err) {
done(err);
}
});
n1.receive({payload:"foo", cookies:{data:{value:value, encode:false}}});
});
});
it('should send cookie by msg.headers', function(done) {
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",url:getTestURL('/checkCookie')},
{id:"n2", type:"helper"}];
@@ -1039,7 +1167,7 @@ describe('HTTP Request Node', function() {
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('payload','abc');
msg.payload.should.have.property('data','abc');
msg.should.have.property('statusCode',200);
done();
} catch(err) {
@@ -1050,6 +1178,26 @@ describe('HTTP Request Node', function() {
});
});
it('should send multiple cookies by msg.headers', function(done) {
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",url:getTestURL('/checkCookie')},
{id:"n2", type:"helper"}];
helper.load(httpRequestNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.payload.should.have.property('data','abc');
msg.payload.should.have.property('foo','bar');
msg.should.have.property('statusCode',200);
done();
} catch(err) {
done(err);
}
});
n1.receive({payload:"foo", cookies:{boo:'123'}, headers:{'cookie':'data=abc; foo=bar;'}});
});
});
it('should convert all HTTP headers into lower case', function(done) {
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"POST",ret:"obj",url:getTestURL('/postInspect')},
{id:"n2", type:"helper"}];

View File

@@ -0,0 +1,450 @@
/**
* 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.
**/
var should = require("should");
var functionNode = require("nr-test-utils").require("@node-red/nodes/core/core/80-function.js");
var helper = require("node-red-node-test-helper");
// Notice:
// - nodes should have x, y, z property when defining subflow.
describe('subflow', function() {
before(function(done) {
helper.startServer(done);
});
after(function(done) {
helper.stopServer(done);
});
afterEach(function() {
helper.unload();
});
it('should define subflow', function(done) {
var flow = [
{id:"t1", type:"tab"},
{id:"n1", z:"t1", type:"subflow:s1", wires:[["n2"]]},
{id:"n2", z:"t1", type:"helper", wires:[]},
// Subflow
{id:"s1", type:"subflow", name:"Subflow", info:"",
in:[{wires:[ {id:"s1-n1"} ]}],
out:[{wires:[ {id:"s1-n1", port:0} ]}]},
{id:"s1-n1", z:"s1", type:"function",
func:"return msg;", wires:[]}
];
helper.load(functionNode, flow, function() {
done();
});
});
it('should pass data to/from subflow', function(done) {
var flow = [
{id:"t0", type:"tab", label:"", disabled:false, info:""},
{id:"n1", x:10, y:10, z:"t0", type:"subflow:s1", wires:[["n2"]]},
{id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]},
// Subflow
{id:"s1", type:"subflow", name:"Subflow", info:"",
in:[{
x:10, y:10,
wires:[ {id:"s1-n1"} ]
}],
out:[{
x:10, y:10,
wires:[ {id:"s1-n1", port:0} ]
}]
},
{id:"s1-n1", x:10, y:10, z:"s1", type:"function",
func:"msg.payload = msg.payload+'bar'; return msg;", wires:[]}
];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.property("payload", "foobar");
done();
});
n1.receive({payload:"foo"});
});
});
it('should pass data to/from nested subflow', function(done) {
var flow = [
{id:"t0", type:"tab", label:"", disabled:false, info:""},
{id:"n1", x:10, y:10, z:"t0", type:"subflow:s1", wires:[["n2"]]},
{id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]},
// Subflow1
{id:"s1", type:"subflow", name:"Subflow1", info:"",
in:[{
x:10, y:10,
wires:[ {id:"s1-n1"} ]
}],
out:[{
x:10, y:10,
wires:[ {id:"s1-n2", port:0} ]
}]
},
{id:"s1-n1", x:10, y:10, z:"s1", type:"subflow:s2",
wires:[["s1-n2"]]},
{id:"s1-n2", x:10, y:10, z:"s1", type:"function",
func:"msg.payload = msg.payload+'baz'; return msg;", wires:[]},
// Subflow2
{id:"s2", type:"subflow", name:"Subflow2", info:"",
in:[{
x:10, y:10,
wires:[ {id:"s2-n1"} ]
}],
out:[{
x:10, y:10,
wires:[ {id:"s2-n1", port:0} ]
}]
},
{id:"s2-n1", x:10, y:10, z:"s2", type:"function",
func:"msg.payload=msg.payload+'bar'; return msg;", wires:[]}
];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.property("payload", "foobarbaz");
done();
});
n1.receive({payload:"foo"});
});
});
it('should access env var of subflow template', function(done) {
var flow = [
{id:"t0", type:"tab", label:"", disabled:false, info:""},
{id:"n1", x:10, y:10, z:"t0", type:"subflow:s1", wires:[["n2"]]},
{id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]},
// Subflow
{id:"s1", type:"subflow", name:"Subflow", info:"",
env: [
{name: "K", type: "str", value: "V"}
],
in:[{
x:10, y:10,
wires:[ {id:"s1-n1"} ]
}],
out:[{
x:10, y:10,
wires:[ {id:"s1-n1", port:0} ]
}]
},
{id:"s1-n1", x:10, y:10, z:"s1", type:"function",
func:"msg.V = env.get('K'); return msg;",
wires:[]}
];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property("V", "V");
done();
}
catch (e) {
console.log(e);
done(e);
}
});
n1.receive({payload:"foo"});
});
});
it('should access env var of subflow instance', function(done) {
var flow = [
{id:"t0", type:"tab", label:"", disabled:false, info:""},
{id:"n1", x:10, y:10, z:"t0", type:"subflow:s1",
env: [
{name: "K", type: "str", value: "V"}
],
wires:[["n2"]]},
{id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]},
// Subflow
{id:"s1", type:"subflow", name:"Subflow", info:"",
in:[{
x:10, y:10,
wires:[ {id:"s1-n1"} ]
}],
out:[{
x:10, y:10,
wires:[ {id:"s1-n1", port:0} ]
}]
},
{id:"s1-n1", x:10, y:10, z:"s1", type:"function",
func:"msg.V = env.get('K'); return msg;",
wires:[]}
];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property("V", "V");
done();
}
catch (e) {
console.log(e);
done(e);
}
});
n1.receive({payload:"foo"});
});
});
it('should access last env var with same name', function(done) {
var flow = [
{id:"t0", type:"tab", label:"", disabled:false, info:""},
{id:"n1", x:10, y:10, z:"t0", type:"subflow:s1",
env: [
{name: "K", type: "str", value: "V0"},
{name: "X", type: "str", value: "VX"},
{name: "K", type: "str", value: "V1"}
],
wires:[["n2"]]},
{id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]},
// Subflow
{id:"s1", type:"subflow", name:"Subflow", info:"",
in:[{
x:10, y:10,
wires:[ {id:"s1-n1"} ]
}],
out:[{
x:10, y:10,
wires:[ {id:"s1-n1", port:0} ]
}]
},
{id:"s1-n1", x:10, y:10, z:"s1", type:"function",
func:"msg.V = env.get('K'); return msg;",
wires:[]}
];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property("V", "V1");
done();
}
catch (e) {
console.log(e);
done(e);
}
});
n1.receive({payload:"foo"});
});
});
it('should access typed value of env var', function(done) {
var flow = [
{id:"t0", type:"tab", label:"", disabled:false, info:""},
{id:"n1", x:10, y:10, z:"t0", type:"subflow:s1",
env: [
{name: "KN", type: "num", value: "100"},
{name: "KB", type: "bool", value: "true"},
{name: "KJ", type: "json", value: "[1,2,3]"},
{name: "Kb", type: "bin", value: "[65,65]"},
{name: "Ke", type: "env", value: "KS"}
],
wires:[["n2"]]},
{id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]},
// Subflow
{id:"s1", type:"subflow", name:"Subflow", info:"",
in:[{
x:10, y:10,
wires:[ {id:"s1-n1"} ]
}],
out:[{
x:10, y:10,
wires:[ {id:"s1-n1", port:0} ]
}],
env: [
{name: "KS", type: "str", value: "STR"}
]
},
{id:"s1-n1", x:10, y:10, z:"s1", type:"function",
func:"msg.VE = env.get('Ke'); msg.VS = env.get('KS'); msg.VN = env.get('KN'); msg.VB = env.get('KB'); msg.VJ = env.get('KJ'); msg.Vb = env.get('Kb'); return msg;",
wires:[]}
];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property("VS", "STR");
msg.should.have.property("VN", 100);
msg.should.have.property("VB", true);
msg.should.have.property("VJ", [1,2,3]);
msg.should.have.property("Vb");
should.ok(msg.Vb instanceof Buffer);
msg.should.have.property("VE","STR");
done();
}
catch (e) {
done(e);
}
});
n1.receive({payload:"foo"});
});
});
it('should overwrite env var of subflow template by env var of subflow instance', function(done) {
var flow = [
{id:"t0", type:"tab", label:"", disabled:false, info:""},
{id:"n1", x:10, y:10, z:"t0", type:"subflow:s1",
env: [
{name: "K", type: "str", value: "V"}
],
wires:[["n2"]]},
{id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]},
// Subflow
{id:"s1", type:"subflow", name:"Subflow", info:"",
env: [
{name: "K", type: "str", value: "TV"}
],
in:[{
x:10, y:10,
wires:[ {id:"s1-n1"} ]
}],
out:[{
x:10, y:10,
wires:[ {id:"s1-n1", port:0} ]
}]
},
{id:"s1-n1", x:10, y:10, z:"s1", type:"function",
func:"msg.V = env.get('K'); return msg;",
wires:[]}
];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property("V", "V");
done();
}
catch (e) {
console.log(e);
done(e);
}
});
n1.receive({payload:"foo"});
});
});
it('should access env var of parent subflow template', function(done) {
var flow = [
{id:"t0", type:"tab", label:"", disabled:false, info:""},
{id:"n1", x:10, y:10, z:"t0", type:"subflow:s1", wires:[["n2"]]},
{id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]},
// Subflow1
{id:"s1", type:"subflow", name:"Subflow1", info:"",
env: [
{name: "K", type: "str", value: "V"},
],
in:[{
x:10, y:10,
wires:[ {id:"s1-n1"} ]
}],
out:[{
x:10, y:10,
wires:[ {id:"s1-n2", port:0} ]
}]
},
{id:"s1-n1", x:10, y:10, z:"s1", type:"subflow:s2",
wires:[["s1-n2"]]},
{id:"s1-n2", x:10, y:10, z:"s1", type:"function",
func:"return msg;", wires:[]},
// Subflow2
{id:"s2", type:"subflow", name:"Subflow2", info:"",
in:[{
x:10, y:10,
wires:[ {id:"s2-n1"} ]
}],
out:[{
x:10, y:10,
wires:[ {id:"s2-n1", port:0} ]
}]
},
{id:"s2-n1", x:10, y:10, z:"s2", type:"function",
func:"msg.V = env.get('K'); return msg;",
wires:[]}
];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.property("V", "V");
done();
});
n1.receive({payload:"foo"});
});
});
it('should access env var of parent subflow instance', function(done) {
var flow = [
{id:"t0", type:"tab", label:"", disabled:false, info:""},
{id:"n1", x:10, y:10, z:"t0", type:"subflow:s1",
env: [
{name: "K", type: "str", value: "V"}
],
wires:[["n2"]]},
{id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]},
// Subflow1
{id:"s1", type:"subflow", name:"Subflow1", info:"",
in:[{
x:10, y:10,
wires:[ {id:"s1-n1"} ]
}],
out:[{
x:10, y:10,
wires:[ {id:"s1-n2", port:0} ]
}]
},
{id:"s1-n1", x:10, y:10, z:"s1", type:"subflow:s2",
wires:[["s1-n2"]]},
{id:"s1-n2", x:10, y:10, z:"s1", type:"function",
func:"return msg;", wires:[]},
// Subflow2
{id:"s2", type:"subflow", name:"Subflow2", info:"",
in:[{
x:10, y:10,
wires:[ {id:"s2-n1"} ]
}],
out:[{
x:10, y:10,
wires:[ {id:"s2-n1", port:0} ]
}]
},
{id:"s2-n1", x:10, y:10, z:"s2", type:"function",
func:"msg.V = env.get('K'); return msg;",
wires:[]}
];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.property("V", "V");
done();
});
n1.receive({payload:"foo"});
});
});
});

View File

@@ -225,7 +225,48 @@ describe('context', function() {
});
})
describe("$parent", function() {
it('should get undefined for $parent without key', function() {
var context0 = Context.get("0","flowA");
var context1 = Context.get("1","flowB", context0);
var parent = context1.get("$parent");
should.equal(parent, undefined);
});
it('should get undefined for $parent of root', function() {
var context0 = Context.get("0","flowA");
var context1 = Context.get("1","flowB", context0);
var parent = context1.get("$parent.$parent.K");
should.equal(parent, undefined);
});
it('should get value in $parent', function() {
var context0 = Context.get("0","flowA");
var context1 = Context.get("1","flowB", context0);
context0.set("K", "v");
var v = context1.get("$parent.K");
should.equal(v, "v");
});
it('should set value in $parent', function() {
var context0 = Context.get("0","flowA");
var context1 = Context.get("1","flowB", context0);
context1.set("$parent.K", "v");
var v = context0.get("K");
should.equal(v, "v");
});
it('should not contain $parent in keys', function() {
var context0 = Context.get("0","flowA");
var context1 = Context.get("1","flowB", context0);
var parent = context1.get("$parent");
context0.set("K0", "v0");
context1.set("K1", "v1");
var keys = context1.keys();
keys.should.have.length(1);
keys[0].should.equal("K1");
});
});
});

View File

@@ -113,6 +113,7 @@ describe('Flow', function() {
Node.call(this,n);
var node = this;
this.scope = n.scope;
this.uncaught = n.uncaught;
this.foo = n.foo;
this.handled = 0;
this.messages = [];
@@ -159,6 +160,7 @@ describe('Flow', function() {
Object.keys(flow.getActiveNodes()).length.should.equal(0);
});
});
describe('#start',function() {
it("instantiates an initial configuration and stops it",function(done) {
var config = flowUtils.parseConfig([
@@ -414,6 +416,70 @@ describe('Flow', function() {
});
describe('#getNode',function() {
it("gets a node known to the flow",function(done) {
var config = flowUtils.parseConfig([
{id:"t1",type:"tab"},
{id:"1",x:10,y:10,z:"t1",type:"test",foo:"a",wires:["2"]},
{id:"2",x:10,y:10,z:"t1",type:"test",foo:"a",wires:["3"]},
{id:"3",x:10,y:10,z:"t1",type:"test",foo:"a",wires:[]},
{id:"4",z:"t1",type:"test",foo:"a"}
]);
var flow = Flow.create({},config,config.flows["t1"]);
flow.start();
Object.keys(flow.getActiveNodes()).should.have.length(4);
flow.getNode('1').should.have.a.property('id','1');
flow.stop().then(() => { done() });
});
it("passes to parent if node not known locally",function(done) {
var config = flowUtils.parseConfig([
{id:"t1",type:"tab"},
{id:"1",x:10,y:10,z:"t1",type:"test",foo:"a",wires:["2"]},
{id:"2",x:10,y:10,z:"t1",type:"test",foo:"a",wires:["3"]},
{id:"3",x:10,y:10,z:"t1",type:"test",foo:"a",wires:[]},
{id:"4",z:"t1",type:"test",foo:"a"}
]);
var flow = Flow.create({
getNode: id => { return {id:id}}
},config,config.flows["t1"]);
flow.start();
Object.keys(flow.getActiveNodes()).should.have.length(4);
flow.getNode('1').should.have.a.property('id','1');
flow.getNode('parentNode').should.have.a.property('id','parentNode');
flow.stop().then(() => { done() });
});
it("does not pass to parent if cancelBubble set",function(done) {
var config = flowUtils.parseConfig([
{id:"t1",type:"tab"},
{id:"1",x:10,y:10,z:"t1",type:"test",foo:"a",wires:["2"]},
{id:"2",x:10,y:10,z:"t1",type:"test",foo:"a",wires:["3"]},
{id:"3",x:10,y:10,z:"t1",type:"test",foo:"a",wires:[]},
{id:"4",z:"t1",type:"test",foo:"a"}
]);
var flow = Flow.create({
getNode: id => { return {id:id}}
},config,config.flows["t1"]);
flow.start();
Object.keys(flow.getActiveNodes()).should.have.length(4);
flow.getNode('1').should.have.a.property('id','1');
should.not.exist(flow.getNode('parentNode',true));
flow.stop().then(() => { done() });
});
});
describe("#handleStatus",function() {
it("passes a status event to the adjacent status node",function(done) {
var config = flowUtils.parseConfig([
@@ -497,7 +563,6 @@ describe('Flow', function() {
});
describe("#handleError",function() {
it("passes an error event to the adjacent catch node",function(done) {
var config = flowUtils.parseConfig([
@@ -506,14 +571,15 @@ describe('Flow', function() {
{id:"2",x:10,y:10,z:"t1",type:"test",wires:["3"]},
{id:"3",x:10,y:10,z:"t1",type:"test",foo:"a",wires:[]},
{id:"sn",x:10,y:10,z:"t1",type:"catch",foo:"a",wires:[]},
{id:"sn2",x:10,y:10,z:"t1",type:"catch",foo:"a",wires:[]}
{id:"sn2",x:10,y:10,z:"t1",type:"catch",foo:"a",wires:[]},
{id:"sn3",x:10,y:10,z:"t1",type:"catch",uncaught:true,wires:[]}
]);
var flow = Flow.create({},config,config.flows["t1"]);
flow.start();
var activeNodes = flow.getActiveNodes();
Object.keys(activeNodes).should.have.length(5);
Object.keys(activeNodes).should.have.length(6);
flow.handleError(config.flows["t1"].nodes["1"],"my-error",{a:"foo"});
@@ -538,6 +604,9 @@ describe('Flow', function() {
statusMessage.error.source.should.have.a.property("type","test");
statusMessage.error.source.should.have.a.property("name","a");
// Node sn3 has uncaught:true - so should not get called
currentNodes["sn3"].should.have.a.property("handled",0);
flow.stop().then(function() {
done();
@@ -550,14 +619,16 @@ describe('Flow', function() {
{id:"2",x:10,y:10,z:"t1",type:"test",wires:["3"]},
{id:"3",x:10,y:10,z:"t1",type:"test",foo:"a",wires:[]},
{id:"sn",x:10,y:10,z:"t1",type:"catch",scope:["2"],foo:"a",wires:[]},
{id:"sn2",x:10,y:10,z:"t1",type:"catch",scope:["1"],foo:"a",wires:[]}
{id:"sn2",x:10,y:10,z:"t1",type:"catch",scope:["1"],foo:"a",wires:[]},
{id:"sn3",x:10,y:10,z:"t1",type:"catch",uncaught:true,wires:[]},
{id:"sn4",x:10,y:10,z:"t1",type:"catch",uncaught:true,wires:[]}
]);
var flow = Flow.create({},config,config.flows["t1"]);
flow.start();
var activeNodes = flow.getActiveNodes();
Object.keys(activeNodes).should.have.length(5);
Object.keys(activeNodes).should.have.length(7);
flow.handleError(config.flows["t1"].nodes["1"],"my-error",{a:"foo"});
@@ -572,13 +643,29 @@ describe('Flow', function() {
statusMessage.error.source.should.have.a.property("type","test");
statusMessage.error.source.should.have.a.property("name","a");
// Node sn3/4 have uncaught:true - so should not get called
currentNodes["sn3"].should.have.a.property("handled",0);
currentNodes["sn4"].should.have.a.property("handled",0);
// Inject error that sn1/2 will ignore - so should get picked up by sn3
flow.handleError(config.flows["t1"].nodes["3"],"my-error-2",{a:"foo-2"});
currentNodes["sn"].should.have.a.property("handled",0);
currentNodes["sn2"].should.have.a.property("handled",1);
currentNodes["sn3"].should.have.a.property("handled",1);
currentNodes["sn4"].should.have.a.property("handled",1);
statusMessage = currentNodes["sn3"].messages[0];
statusMessage.should.have.a.property("error");
statusMessage.error.should.have.a.property("message","my-error-2");
statusMessage.error.should.have.a.property("source");
statusMessage.error.source.should.have.a.property("id","3");
statusMessage.error.source.should.have.a.property("type","test");
flow.stop().then(function() {
done();
});
});
it("moves any existing error object sideways",function(done){
var config = flowUtils.parseConfig([
{id:"t1",type:"tab"},

View File

@@ -67,10 +67,12 @@ describe('Subflow', function() {
this.foo = n.foo;
this.handled = 0;
this.stopped = false;
this.received = null;
currentNodes[node.id] = node;
this.on('input',function(msg) {
// console.log(this.id,msg.payload);
node.handled++;
node.received = msg.payload;
node.send(msg);
});
this.on('close',function() {
@@ -170,6 +172,35 @@ describe('Subflow', function() {
}
util.inherits(TestAsyncNode,Node);
var TestEnvNode = function(n) {
Node.call(this,n);
this._index = createCount++;
this.scope = n.scope;
this.foo = n.foo;
var node = this;
this.stopped = false;
this.received = null;
currentNodes[node.id] = node;
this.on('input',function(msg) {
var flow = node._flow;
var val = flow.getSetting("__KEY__");
node.received = val;
node.send({payload: val});
});
this.on('close',function() {
node.stopped = true;
stoppedNodes[node.id] = node;
delete currentNodes[node.id];
});
this.__updateWires = this.updateWires;
this.updateWires = function(newWires) {
rewiredNodes[node.id] = node;
node.newWires = newWires;
node.__updateWires(newWires);
};
}
util.inherits(TestEnvNode,Node);
before(function() {
getType = sinon.stub(typeRegistry,"get",function(type) {
if (type=="test") {
@@ -178,6 +209,8 @@ describe('Subflow', function() {
return TestErrorNode;
} else if (type=="testStatus"){
return TestStatusNode;
} else if (type=="testEnv"){
return TestEnvNode;
} else {
return TestAsyncNode;
}
@@ -265,7 +298,6 @@ describe('Subflow', function() {
done();
});
});
it("instantiates a subflow inside a subflow and stops it",function(done) {
var config = flowUtils.parseConfig([
{id:"t1",type:"tab"},
@@ -419,7 +451,6 @@ describe('Subflow', function() {
done();
});
});
it("passes a status event to the subflow's parent tab status node - targetted scope",function(done) {
var config = flowUtils.parseConfig([
{id:"t1",type:"tab"},
@@ -457,9 +488,164 @@ describe('Subflow', function() {
done();
});
});
});
describe("status node", function() {
it("emits a status event when a message is passed to a subflow-status node - msg.payload as string", function(done) {
var config = flowUtils.parseConfig([
{id:"t1",type:"tab"},
{id:"1",x:10,y:10,z:"t1",type:"test",name:"a",wires:["2"]},
{id:"2",x:10,y:10,z:"t1",type:"subflow:sf1",wires:["3"]},
{id:"3",x:10,y:10,z:"t1",type:"test",foo:"a",wires:[]},
{
id:"sf1",
type:"subflow",
name:"Subflow 2",
info:"",
in:[{wires:[{id:"sf1-1"}]}],
out:[{wires:[{id:"sf1-1",port:0}]}],
status:{wires:[{id:"sf1-1", port:0}]}
},
{id:"sf1-1",type:"test",name:"test","z":"sf1",x:166,y:99,"wires":[[]]},
{id:"sn",x:10,y:10,z:"t1",type:"status",foo:"a",wires:[]}
]);
var flow = Flow.create({},config,config.flows["t1"]);
flow.start();
var activeNodes = flow.getActiveNodes();
activeNodes["1"].receive({payload:"test-payload"});
currentNodes["sn"].should.have.a.property("handled",1);
var statusMessage = currentNodes["sn"].messages[0];
statusMessage.should.have.a.property("status");
statusMessage.status.should.have.a.property("text","test-payload");
statusMessage.status.should.have.a.property("source");
statusMessage.status.source.should.have.a.property("id","2");
statusMessage.status.source.should.have.a.property("type","subflow:sf1");
flow.stop().then(function() {
done();
});
});
it("emits a status event when a message is passed to a subflow-status node - msg.payload as status obj", function(done) {
var config = flowUtils.parseConfig([
{id:"t1",type:"tab"},
{id:"1",x:10,y:10,z:"t1",type:"test",name:"a",wires:["2"]},
{id:"2",x:10,y:10,z:"t1",type:"subflow:sf1",wires:["3"]},
{id:"3",x:10,y:10,z:"t1",type:"test",foo:"a",wires:[]},
{
id:"sf1",
type:"subflow",
name:"Subflow 2",
info:"",
in:[{wires:[{id:"sf1-1"}]}],
out:[{wires:[{id:"sf1-1",port:0}]}],
status:{wires:[{id:"sf1-1", port:0}]}
},
{id:"sf1-1",type:"test",name:"test","z":"sf1",x:166,y:99,"wires":[[]]},
{id:"sn",x:10,y:10,z:"t1",type:"status",foo:"a",wires:[]}
]);
var flow = Flow.create({},config,config.flows["t1"]);
flow.start();
var activeNodes = flow.getActiveNodes();
activeNodes["1"].receive({payload:{text:"payload-obj"}});
currentNodes["sn"].should.have.a.property("handled",1);
var statusMessage = currentNodes["sn"].messages[0];
statusMessage.should.have.a.property("status");
statusMessage.status.should.have.a.property("text","payload-obj");
statusMessage.status.should.have.a.property("source");
statusMessage.status.source.should.have.a.property("id","2");
statusMessage.status.source.should.have.a.property("type","subflow:sf1");
flow.stop().then(function() {
done();
});
});
it("emits a status event when a message is passed to a subflow-status node - msg.status", function(done) {
var config = flowUtils.parseConfig([
{id:"t1",type:"tab"},
{id:"1",x:10,y:10,z:"t1",type:"test",name:"a",wires:["2"]},
{id:"2",x:10,y:10,z:"t1",type:"subflow:sf1",wires:["3"]},
{id:"3",x:10,y:10,z:"t1",type:"test",foo:"a",wires:[]},
{
id:"sf1",
type:"subflow",
name:"Subflow 2",
info:"",
in:[{wires:[{id:"sf1-1"}]}],
out:[{wires:[{id:"sf1-1",port:0}]}],
status:{wires:[{id:"sf1-1", port:0}]}
},
{id:"sf1-1",type:"test",name:"test","z":"sf1",x:166,y:99,"wires":[[]]},
{id:"sn",x:10,y:10,z:"t1",type:"status",foo:"a",wires:[]}
]);
var flow = Flow.create({},config,config.flows["t1"]);
flow.start();
var activeNodes = flow.getActiveNodes();
activeNodes["1"].receive({status:{text:"status-obj"}});
currentNodes["sn"].should.have.a.property("handled",1);
var statusMessage = currentNodes["sn"].messages[0];
statusMessage.should.have.a.property("status");
statusMessage.status.should.have.a.property("text","status-obj");
statusMessage.status.should.have.a.property("source");
statusMessage.status.source.should.have.a.property("id","2");
statusMessage.status.source.should.have.a.property("type","subflow:sf1");
flow.stop().then(function() {
done();
});
});
it("does not emit a regular status event if it contains a subflow-status node", function(done) {
var config = flowUtils.parseConfig([
{id:"t1",type:"tab"},
{id:"1",x:10,y:10,z:"t1",type:"test",name:"a",wires:["2"]},
{id:"2",x:10,y:10,z:"t1",type:"subflow:sf1",wires:["3"]},
{id:"3",x:10,y:10,z:"t1",type:"test",foo:"a",wires:[]},
{
id:"sf1",
type:"subflow",
name:"Subflow 2",
info:"",
in:[{wires:[{id:"sf1-1"}]}],
out:[{wires:[{id:"sf1-1",port:0}]}],
status:{wires:[]}
},
{id:"sf1-1",type:"testStatus",name:"test-status-node","z":"sf1",x:166,y:99,"wires":[[]]},
{id:"sn",x:10,y:10,z:"t1",type:"status",foo:"a",wires:[]}
]);
var flow = Flow.create({},config,config.flows["t1"]);
flow.start();
var activeNodes = flow.getActiveNodes();
activeNodes["1"].receive({payload:"test-payload"});
currentNodes["sn"].should.have.a.property("handled",0);
flow.stop().then(function() {
done();
});
});
})
describe("#handleError",function() {
it("passes an error event to the subflow's parent tab catch node - all scope",function(done) {
var config = flowUtils.parseConfig([
@@ -493,7 +679,6 @@ describe('Subflow', function() {
done();
});
});
it("passes an error event to the subflow's parent tab catch node - targetted scope",function(done) {
var config = flowUtils.parseConfig([
{id:"t1",type:"tab"},
@@ -530,7 +715,146 @@ describe('Subflow', function() {
});
});
});
describe("#env var", function() {
// should be changed according to internal env var representation
function setEnv(node, key, val) {
var flow = node._flow;
if (flow) {
var env = flow.env;
if (!env) {
env = flow.env = {};
}
env[key] = {
name: key,
type: "str",
value: val
};
}
}
it("can access process env var", function(done) {
var config = flowUtils.parseConfig([
{id:"t1",type:"tab"},
{id:"1",x:10,y:10,z:"t1",type:"test",foo:"t1.1",wires:["2"]},
{id:"2",x:10,y:10,z:"t1",type:"subflow:sf1",wires:["3"]},
{id:"3",x:10,y:10,z:"t1",type:"test",foo:"t1.3",wires:[]},
{id:"sf1",type:"subflow",name:"Subflow 2",info:"",
"in":[ {wires:[{id:"sf1-1"}]} ],
"out":[ {wires:[{id:"sf1-2",port:0}]} ]},
{id:"sf1-1",type:"test",z:"sf1",foo:"sf1.1",x:166,y:99,wires:[["sf1-2"]]},
{id:"sf1-2",type:"testEnv",z:"sf1",foo:"sf1-cn",x:166,y:99,wires:[[]]}
]);
var flow = Flow.create({
getSetting: k=> process.env[k],
handleError: (a,b,c) => { console.log(a,b,c); }
},config,config.flows["t1"]);
flow.start();
process.env["__KEY__"] = "__VAL__";
currentNodes["1"].receive({payload: "test"});
currentNodes["3"].should.have.a.property("received", "__VAL__");
flow.stop().then(function() {
done();
});
});
it("can access subflow env var", function(done) {
var config = flowUtils.parseConfig([
{id:"t1",type:"tab"},
{id:"1",x:10,y:10,z:"t1",type:"test",foo:"t1.1",wires:["2"]},
{id:"2",x:10,y:10,z:"t1",type:"subflow:sf1",wires:["3"]},
{id:"3",x:10,y:10,z:"t1",type:"test",foo:"t1.3",wires:[]},
{id:"sf1",type:"subflow",name:"Subflow 2",info:"",
"in":[ {wires:[{id:"sf1-1"}]} ],
"out":[ {wires:[{id:"sf1-2",port:0}]} ]},
{id:"sf1-1",type:"test",z:"sf1",foo:"sf1.1",x:166,y:99,wires:[["sf1-2"]]},
{id:"sf1-2",type:"testEnv",z:"sf1",foo:"sf1.2",x:166,y:99,wires:[[]]}
]);
var flow = Flow.create({
getSetting: k=> process.env[k],
handleError: (a,b,c) => { console.log(a,b,c); }
},config,config.flows["t1"]);
flow.start();
var testenv_node = null;
for (var n in currentNodes) {
var node = currentNodes[n];
if (node.type === "testEnv") {
testenv_node = node;
break;
}
}
process.env["__KEY__"] = "__VAL0__";
setEnv(testenv_node, "__KEY__", "__VAL1__");
currentNodes["1"].receive({payload: "test"});
currentNodes["3"].should.have.a.property("received", "__VAL1__");
flow.stop().then(function() {
done();
});
});
it("can access nested subflow env var", function(done) {
var config = flowUtils.parseConfig([
{id:"t1",type:"tab"},
{id:"1",x:10,y:10,z:"t1",type:"test",foo:"t1.1",wires:["2"]},
{id:"2",x:10,y:10,z:"t1",type:"subflow:sf1",wires:["3"]},
{id:"3",x:10,y:10,z:"t1",type:"test",foo:"t1.3",wires:[]},
{id:"sf1",type:"subflow",name:"Subflow 1",info:"",
in:[{wires:[{id:"sf1-1"}]}],
out:[{wires:[{id:"sf1-2",port:0}]}]},
{id:"sf2",type:"subflow",name:"Subflow 2",info:"",
in:[{wires:[{id:"sf2-1"}]}],
out:[{wires:[{id:"sf2-2",port:0}]}]},
{id:"sf1-1",type:"test",z:"sf1",foo:"sf1.1",x:166,y:99,wires:[["sf1-2"]]},
{id:"sf1-2",type:"subflow:sf2",z:"sf1",x:166,y:99,wires:[[]]},
{id:"sf2-1",type:"test",z:"sf2",foo:"sf2.1",x:166,y:99,wires:[["sf2-2"]]},
{id:"sf2-2",type:"testEnv",z:"sf2",foo:"sf2.2",x:166,y:99,wires:[[]]},
]);
var flow = Flow.create({
getSetting: k=> process.env[k],
handleError: (a,b,c) => { console.log(a,b,c); }
},config,config.flows["t1"]);
flow.start();
var node_sf1_1 = null;
var node_sf2_1 = null;
var testenv_node = null;
for (var n in currentNodes) {
var node = currentNodes[n];
if (node.foo === "sf1.1") {
node_sf1_1 = node;
}
if (node.foo === "sf2.1") {
node_sf2_1 = node;
}
}
process.env["__KEY__"] = "__VAL0__";
currentNodes["1"].receive({payload: "test"});
currentNodes["3"].should.have.a.property("received", "__VAL0__");
setEnv(node_sf1_1, "__KEY__", "__VAL1__");
currentNodes["1"].receive({payload: "test"});
currentNodes["3"].should.have.a.property("received", "__VAL1__");
setEnv(node_sf2_1, "__KEY__", "__VAL2__");
currentNodes["1"].receive({payload: "test"});
currentNodes["3"].should.have.a.property("received", "__VAL2__");
flow.stop().then(function() {
done();
});
});
});
});