mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #3379 from node-red-hitachi/nr_node_path-support
add NR_NODE_PATH path support
This commit is contained in:
commit
5b428bb8e6
@ -378,6 +378,9 @@ class Subflow extends Flow {
|
||||
if (name === "NR_NODE_ID") {
|
||||
return node.id;
|
||||
}
|
||||
if (name === "NR_NODE_PATH") {
|
||||
return node._path;
|
||||
}
|
||||
}
|
||||
if (node.g) {
|
||||
const group = this.getGroupNode(node.g);
|
||||
|
@ -529,6 +529,9 @@ function getSetting(node, name, flow_) {
|
||||
if (name === "NR_NODE_ID") {
|
||||
return node.id;
|
||||
}
|
||||
if (name === "NR_NODE_PATH") {
|
||||
return node._path;
|
||||
}
|
||||
}
|
||||
var flow = (flow_ ? flow_ : (node ? node._flow : null));
|
||||
if (flow) {
|
||||
|
@ -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) {
|
||||
var flow = [{id: "n1", type: "inject", name: "NAME", topnic: "t1", payload: "NR_FLOW_NAME", payloadType: "env", wires: [["n2"]], z: "flow"},
|
||||
{id: "n2", type: "helper"},
|
||||
|
@ -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"});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user