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

Add env type to subflow env var types

Also remove date and regex types
This commit is contained in:
Nick O'Leary 2019-02-06 13:58:31 +00:00
parent 2a8f0a4eab
commit d48a09e68b
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
3 changed files with 10 additions and 13 deletions

View File

@ -570,7 +570,7 @@ RED.editor = (function() {
}).appendTo(row) }).appendTo(row)
valueField.typedInput({default:'str', valueField.typedInput({default:'str',
types:['str','num','bool','json','bin','re','date'] types:['str','num','bool','json','bin','env']
}); });
valueField.typedInput('type', opt.parent?(opt.type||opt.parent.type):opt.type); valueField.typedInput('type', opt.parent?(opt.type||opt.parent.type):opt.type);

View File

@ -265,7 +265,7 @@ class Subflow extends Flow {
if (env && env.hasOwnProperty(name)) { if (env && env.hasOwnProperty(name)) {
var val = env[name]; var val = env[name];
try { try {
var ret = redUtil.evaluateNodeProperty(val.value, val.type, null, null, null); var ret = redUtil.evaluateNodeProperty(val.value, val.type, this.node, null, null);
return ret; return ret;
} }
catch (e) { catch (e) {

View File

@ -166,7 +166,7 @@ describe('subflow', function() {
n1.receive({payload:"foo"}); n1.receive({payload:"foo"});
}); });
}); });
it('should access env var of subflow instance', function(done) { it('should access env var of subflow instance', function(done) {
var flow = [ var flow = [
{id:"t0", type:"tab", label:"", disabled:false, info:""}, {id:"t0", type:"tab", label:"", disabled:false, info:""},
@ -256,13 +256,11 @@ describe('subflow', function() {
{id:"t0", type:"tab", label:"", disabled:false, info:""}, {id:"t0", type:"tab", label:"", disabled:false, info:""},
{id:"n1", x:10, y:10, z:"t0", type:"subflow:s1", {id:"n1", x:10, y:10, z:"t0", type:"subflow:s1",
env: [ env: [
{name: "KS", type: "str", value: "STR"},
{name: "KN", type: "num", value: "100"}, {name: "KN", type: "num", value: "100"},
{name: "KB", type: "bool", value: "true"}, {name: "KB", type: "bool", value: "true"},
{name: "KJ", type: "json", value: "[1,2,3]"}, {name: "KJ", type: "json", value: "[1,2,3]"},
{name: "Kb", type: "bin", value: "[65,65]"}, {name: "Kb", type: "bin", value: "[65,65]"},
{name: "KR", type: "re", value: "[A-Z]"}, {name: "Ke", type: "env", value: "KS"}
{name: "KD", type: "date", value: ""}
], ],
wires:[["n2"]]}, wires:[["n2"]]},
{id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]}, {id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]},
@ -275,10 +273,13 @@ describe('subflow', function() {
out:[{ out:[{
x:10, y:10, x:10, y:10,
wires:[ {id:"s1-n1", port:0} ] wires:[ {id:"s1-n1", port:0} ]
}] }],
env: [
{name: "KS", type: "str", value: "STR"}
]
}, },
{id:"s1-n1", x:10, y:10, z:"s1", type:"function", {id:"s1-n1", x:10, y:10, z:"s1", type:"function",
func:"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'); msg.VR = env.get('KR'); msg.VD = env.get('KD'); return msg;", 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:[]} wires:[]}
]; ];
helper.load(functionNode, flow, function() { helper.load(functionNode, flow, function() {
@ -292,14 +293,10 @@ describe('subflow', function() {
msg.should.have.property("VJ", [1,2,3]); msg.should.have.property("VJ", [1,2,3]);
msg.should.have.property("Vb"); msg.should.have.property("Vb");
should.ok(msg.Vb instanceof Buffer); should.ok(msg.Vb instanceof Buffer);
msg.should.have.property("VR"); msg.should.have.property("VE","STR");
should.ok(msg.VR instanceof RegExp);
msg.should.have.property("VD");
should.ok((typeof msg.VD) === "number");
done(); done();
} }
catch (e) { catch (e) {
console.log(e);
done(e); done(e);
} }
}); });