1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge branch 'dev' of github.com:node-red/node-red into dev

This commit is contained in:
Nick O'Leary 2022-01-26 17:46:47 +00:00
commit bd6e35fea2
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
5 changed files with 79 additions and 3 deletions

View File

@ -53,10 +53,22 @@ RED.search = (function() {
} }
l = l||n.label||n.name||n.id||""; l = l||n.label||n.name||n.id||"";
var properties = ['id','type','name','label','info']; var properties = ['id','type','name','label','info'];
if (n._def && n._def.defaults) { const node_def = n && n._def;
properties = properties.concat(Object.keys(n._def.defaults)); if (node_def) {
if (node_def.defaults) {
properties = properties.concat(Object.keys(node_def.defaults));
}
if (n.type !== "group" && node_def.paletteLabel && node_def.paletteLabel !== node_def.type) {
try {
const label = ("" + (typeof node_def.paletteLabel === "function" ? node_def.paletteLabel.call(node_def) : node_def.paletteLabel)).toLowerCase();
if(label && label !== (""+node_def.type).toLowerCase()) {
indexProperty(n, l, label);
}
} catch(err) {
console.warn(`error indexing ${l}`, err);
}
}
} }
for (var i=0;i<properties.length;i++) { for (var i=0;i<properties.length;i++) {
if (n.hasOwnProperty(properties[i])) { if (n.hasOwnProperty(properties[i])) {

View File

@ -378,6 +378,9 @@ class Subflow extends Flow {
if (name === "NR_NODE_ID") { if (name === "NR_NODE_ID") {
return node.id; return node.id;
} }
if (name === "NR_NODE_PATH") {
return node._path;
}
} }
if (node.g) { if (node.g) {
const group = this.getGroupNode(node.g); const group = this.getGroupNode(node.g);

View File

@ -529,6 +529,9 @@ function getSetting(node, name, flow_) {
if (name === "NR_NODE_ID") { if (name === "NR_NODE_ID") {
return node.id; return node.id;
} }
if (name === "NR_NODE_PATH") {
return node._path;
}
} }
var flow = (flow_ ? flow_ : (node ? node._flow : null)); var flow = (flow_ ? flow_ : (node ? node._flow : null));
if (flow) { if (flow) {

View File

@ -142,6 +142,25 @@ describe('inject node', function() {
}); });
}); });
it('inject path of node as environment variable ', function (done) {
var flow = [{id: "n1", type: "inject", name: "NAME", topnic: "t1", payload: "NR_NODE_PATH", payloadType: "env", wires: [["n2"]], z: "flow"},
{id: "n2", type: "helper"}];
helper.load(injectNode, flow, function () {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function (msg) {
try {
msg.should.have.property("payload", "flow/n1");
done();
} catch (err) {
done(err);
}
});
n1.receive({});
});
});
it('inject name of flow as environment variable ', function (done) { it('inject name of flow as environment variable ', function (done) {
var flow = [{id: "n1", type: "inject", name: "NAME", topnic: "t1", payload: "NR_FLOW_NAME", payloadType: "env", wires: [["n2"]], z: "flow"}, var flow = [{id: "n1", type: "inject", name: "NAME", topnic: "t1", payload: "NR_FLOW_NAME", payloadType: "env", wires: [["n2"]], z: "flow"},
{id: "n2", type: "helper"}, {id: "n2", type: "helper"},

View File

@ -567,4 +567,43 @@ describe('subflow', function() {
}); });
}); });
it('should access NR_NODE_PATH env var within 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: [], 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 = env.get('NR_NODE_PATH'); 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("payload", "t0/n1/s1-n1");
done();
}
catch (e) {
console.log(e);
done(e);
}
});
n1.receive({payload:"foo"});
});
});
}); });