mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Compare commits
65 Commits
0.20.0-bet
...
0.20.0-bet
Author | SHA1 | Date | |
---|---|---|---|
|
fb0f12bb20 | ||
|
e94b8d3e84 | ||
|
8c00e1fdf4 | ||
|
a31fa82284 | ||
|
5d0af45d8f | ||
|
e9f248020e | ||
|
a8e1058af6 | ||
|
1a087fd799 | ||
|
50c81533e0 | ||
|
5eab9aa4b1 | ||
|
1970cbfe37 | ||
|
6d736201f9 | ||
|
51ec52b573 | ||
|
d099387186 | ||
|
3f91e4da66 | ||
|
4124159378 | ||
|
18f3789e29 | ||
|
7828af591e | ||
|
d432dba726 | ||
|
72ae87857f | ||
|
724acff591 | ||
|
482b432e2c | ||
|
351c0cb0a8 | ||
|
314a0fb5d6 | ||
|
a301bf8bf5 | ||
|
37b3601c47 | ||
|
6e944485f0 | ||
|
431266069e | ||
|
d48a09e68b | ||
|
2a8f0a4eab | ||
|
79f3669fac | ||
|
aab0f2dcd5 | ||
|
a47831e278 | ||
|
f1a5e8a42c | ||
|
723e9b3cba | ||
|
ff759a8074 | ||
|
4de1056d82 | ||
|
884b8da8bf | ||
|
044ad77a4b | ||
|
1fe8b388a3 | ||
|
79fe7d684c | ||
|
c409af0ea8 | ||
|
5110eaff96 | ||
|
db3eee72b5 | ||
|
3bcff91328 | ||
|
e843f192ec | ||
|
f3d2053878 | ||
|
efe8fbbd11 | ||
|
ce507b3b52 | ||
|
85de227003 | ||
|
7c6eb7c794 | ||
|
2037741b54 | ||
|
d534a8952d | ||
|
0b05b883cb | ||
|
6937aa5ddd | ||
|
8f6b24e0aa | ||
|
ba3b64a6c6 | ||
|
0881c6a20b | ||
|
f88a4b1791 | ||
|
2b43e3ee23 | ||
|
a413f3cded | ||
|
596fbfb517 | ||
|
86bb5503ab | ||
|
21ce23d27d | ||
|
6c75baecb2 |
30
CHANGELOG.md
30
CHANGELOG.md
@@ -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
|
||||
|
@@ -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",
|
||||
|
@@ -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",
|
||||
|
@@ -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"
|
||||
}
|
||||
}
|
||||
|
@@ -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": "環境変数"
|
||||
}
|
||||
}
|
||||
|
@@ -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`と同じ形式です。"
|
||||
}
|
||||
}
|
||||
|
@@ -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",
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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();
|
||||
|
@@ -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);
|
||||
|
@@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@@ -261,7 +261,9 @@ RED.deploy = (function() {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
function sanitize(html) {
|
||||
return html.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")
|
||||
}
|
||||
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= [
|
||||
|
@@ -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();
|
||||
|
@@ -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 = {
|
||||
|
@@ -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) {
|
||||
|
@@ -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
|
||||
}
|
||||
})();
|
||||
|
@@ -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));
|
||||
}
|
||||
|
@@ -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});
|
||||
|
@@ -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;
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
});
|
||||
|
@@ -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() {
|
||||
|
@@ -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 () {
|
||||
|
@@ -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>
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
@@ -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'];
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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"
|
||||
|
@@ -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>
|
||||
|
@@ -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>
|
||||
|
@@ -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>
|
||||
|
@@ -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 = {
|
||||
|
@@ -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>
|
||||
|
@@ -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>1024番より小さな番号のポートをアクセスするにはrootもしくはadministrator権限が必要なシステムもあります。</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>
|
||||
|
@@ -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>のルールは、長さ0の文字列・配列・バッファ、またはプロパティを持たないオブジェクトを出力します。<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>
|
||||
|
@@ -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>
|
||||
|
@@ -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">
|
||||
|
@@ -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>
|
||||
|
@@ -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ノードの未処理メッセージを破棄しました"
|
||||
},
|
||||
|
@@ -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",
|
||||
|
@@ -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"
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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', {
|
||||
|
@@ -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("==================")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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",
|
||||
|
42
packages/node_modules/@node-red/util/lib/util.js
vendored
42
packages/node_modules/@node-red/util/lib/util.js
vendored
@@ -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);
|
||||
|
@@ -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"
|
||||
|
10
packages/node_modules/node-red/package.json
vendored
10
packages/node_modules/node-red/package.json
vendored
@@ -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",
|
||||
|
@@ -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"}];
|
||||
|
450
test/nodes/subflow/subflow_spec.js
Normal file
450
test/nodes/subflow/subflow_spec.js
Normal 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"});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
@@ -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"},
|
||||
|
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user