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

merge upstream changes

This commit is contained in:
Kunihiko Toumura 2019-08-02 15:15:30 +09:00
commit c4e8756210
7 changed files with 62 additions and 6 deletions

View File

@ -368,13 +368,21 @@ RED.history = (function() {
dirty: RED.nodes.dirty()
};
if (ev.nodes) {
<<<<<<< HEAD
inv_ev.movedNodes = [];
=======
var z = ev.activeWorkspace;
>>>>>>> upstream/dev
RED.nodes.filterNodes({z:ev.subflow.subflow.id}).forEach(function(n) {
n.x += ev.subflow.offsetX;
n.y += ev.subflow.offsetY;
n.z = ev.activeWorkspace;
n.dirty = true;
<<<<<<< HEAD
inv_ev.movedNodes.push(n.id);
=======
RED.nodes.moveNodeToTab(n, z);
>>>>>>> upstream/dev
});
inv_ev.subflows = [];
for (i=0;i<ev.nodes.length;i++) {

View File

@ -301,6 +301,17 @@ RED.nodes = (function() {
return {links:removedLinks,nodes:removedNodes};
}
function moveNodeToTab(node, z) {
if (nodeTabMap[node.z]) {
delete nodeTabMap[node.z][node.id];
}
if (!nodeTabMap[z]) {
nodeTabMap[z] = {};
}
nodeTabMap[z][node.id] = node;
node.z = z;
}
function removeLink(l) {
var index = links.indexOf(l);
if (index != -1) {
@ -324,7 +335,7 @@ RED.nodes = (function() {
}
function removeWorkspace(id) {
delete workspaces[id];
delete nodeTabMap[ws.id];
delete nodeTabMap[id];
workspacesOrder.splice(workspacesOrder.indexOf(id),1);
var removedNodes = [];
@ -1466,6 +1477,8 @@ RED.nodes = (function() {
remove: removeNode,
clear: clear,
moveNodeToTab: moveNodeToTab,
addLink: addLink,
removeLink: removeLink,

View File

@ -723,7 +723,7 @@ RED.subflow = (function() {
}
n.x -= offsetX;
n.y -= offsetY;
n.z = subflow.id;
RED.nodes.moveNodeToTab(n, subflow.id);
}
RED.history.push({

View File

@ -48,6 +48,7 @@
{v:"lte",t:"<=",kind:'V'},
{v:"gt",t:">",kind:'V'},
{v:"gte",t:">=",kind:'V'},
{v:"hask",t:"switch.rules.hask",kind:'V'},
{v:"btwn",t:"switch.rules.btwn",kind:'V'},
{v:"cont",t:"switch.rules.cont",kind:'V'},
{v:"regex",t:"switch.rules.regex",kind:'V'},
@ -142,6 +143,7 @@
var typeField = rule.find(".node-input-rule-type-value");
var numField = rule.find(".node-input-rule-num-value");
var expField = rule.find(".node-input-rule-exp-value");
var keyField = rule.find(".node-input-rule-key-value");
var btwnField1 = rule.find(".node-input-rule-btwn-value");
var btwnField2 = rule.find(".node-input-rule-btwn-value2");
var selectWidth;
@ -160,6 +162,8 @@
numField.typedInput("width",(newWidth-selectWidth-70));
} else if (type === "jsonata_exp") {
expField.typedInput("width",(newWidth-selectWidth-70));
} else if (type === "hask") {
keyField.typedInput("width",(newWidth-selectWidth-70));
} else if (type === "istype") {
typeField.typedInput("width",(newWidth-selectWidth-70));
} else {
@ -214,6 +218,7 @@
var btwnValueField = $('<input/>',{class:"node-input-rule-btwn-value",type:"text",style:"margin-left: 5px;"}).appendTo(row).typedInput({default:'num',types:['msg','flow','global','str','num','jsonata','env',previousValueType]});
var btwnAndLabel = $('<span/>',{class:"node-input-rule-btwn-label"}).text(" "+andLabel+" ").appendTo(row3);
var btwnValue2Field = $('<input/>',{class:"node-input-rule-btwn-value2",type:"text",style:"margin-left:2px;"}).appendTo(row3).typedInput({default:'num',types:['msg','flow','global','str','num','jsonata','env',previousValueType]});
var keyValueField = $('<input/>',{class:"node-input-rule-key-value",type:"text",style:"margin-left: 5px;"}).appendTo(row).typedInput({default:'str',types:['str','msg','flow','global','env']});
var typeValueField = $('<input/>',{class:"node-input-rule-type-value",type:"text",style:"margin-left: 5px;"}).appendTo(row)
.typedInput({default:'string',types:[
{value:"string",label:"string",hasValue:false},
@ -236,6 +241,7 @@
if ((type === "btwn") || (type === "index")) {
valueField.typedInput('hide');
expValueField.typedInput('hide');
keyValueField.typedInput('hide');
numValueField.typedInput('hide');
typeValueField.typedInput('hide');
btwnValueField.typedInput('show');
@ -243,19 +249,30 @@
btwnValueField.typedInput('hide');
btwnValue2Field.typedInput('hide');
expValueField.typedInput('hide');
keyValueField.typedInput('hide');
numValueField.typedInput('show');
typeValueField.typedInput('hide');
valueField.typedInput('hide');
} else if (type === "hask") {
btwnValueField.typedInput('hide');
btwnValue2Field.typedInput('hide');
expValueField.typedInput('hide');
keyValueField.typedInput('show');
numValueField.typedInput('hide');
typeValueField.typedInput('hide');
valueField.typedInput('hide');
} else if (type === "jsonata_exp") {
btwnValueField.typedInput('hide');
btwnValue2Field.typedInput('hide');
expValueField.typedInput('show');
keyValueField.typedInput('hide');
numValueField.typedInput('hide');
typeValueField.typedInput('hide');
valueField.typedInput('hide');
} else {
btwnValueField.typedInput('hide');
expValueField.typedInput('hide');
keyValueField.typedInput('hide');
numValueField.typedInput('hide');
typeValueField.typedInput('hide');
valueField.typedInput('hide');
@ -297,7 +314,10 @@
} else if (rule.t === "istype") {
typeValueField.typedInput('value',rule.vt);
typeValueField.typedInput('type',rule.vt);
} else if (rule.t === "jsonata_exp") {
} else if (rule.t === "hask") {
keyValueField.typedInput('value',rule.v);
keyValueField.typedInput('type',rule.vt);
}else if (rule.t === "jsonata_exp") {
expValueField.typedInput('value',rule.v);
expValueField.typedInput('type',rule.vt||'jsonata');
} else if (typeof rule.v != "undefined") {
@ -372,6 +392,9 @@
} else if (type === "istype") {
r.v = rule.find(".node-input-rule-type-value").typedInput('type');
r.vt = rule.find(".node-input-rule-type-value").typedInput('type');
} else if (type === "hask") {
r.v = rule.find(".node-input-rule-key-value").typedInput('value');
r.vt = rule.find(".node-input-rule-key-value").typedInput('type');
} else if (type === "jsonata_exp") {
r.v = rule.find(".node-input-rule-exp-value").typedInput('value');
r.vt = rule.find(".node-input-rule-exp-value").typedInput('type');

View File

@ -47,7 +47,6 @@ module.exports = function(RED) {
}
return false;
},
'istype': function(a, b) {
if (b === "array") { return Array.isArray(a); }
else if (b === "buffer") { return Buffer.isBuffer(a); }
@ -72,6 +71,9 @@ module.exports = function(RED) {
var index = parts.index;
return ((min <= index) && (index <= max));
},
'hask': function(a, b) {
return (typeof b !== "object" ) && a.hasOwnProperty(b+"");
},
'jsonata_exp': function(a, b) { return (b === true); },
'else': function(a) { return a === true; }
};

View File

@ -621,7 +621,8 @@
"tail":"tail",
"index":"index between",
"exp":"JSONata exp",
"else":"otherwise"
"else":"otherwise",
"hask":"has key"
},
"errors": {
"invalid-expr": "Invalid JSONata expression: __error__",

View File

@ -254,6 +254,16 @@ describe('switch Node', function() {
genericSwitchTest("gte", 3, true, true, 3, done);
});
it('should match if a payload has a required property', function(done) {
genericSwitchTest("hask", "a", true, true, {a:1}, done);
});
it('should not match if a payload does not have a required property', function(done) {
genericSwitchTest("hask", "a", true, false, {b:1}, done);
});
it('should not match if the key is not a string', function(done) {
genericSwitchTest("hask", 1, true, false, {a:1}, done);
});
it('should check if payload is between given values', function(done) {
twoFieldSwitchTest("btwn", "3", "5", true, true, 4, done);
});
@ -519,7 +529,6 @@ describe('switch Node', function() {
singularSwitchTest("nempty", true, false, 0, done);
});
it('should check input against a previous value', function(done) {
var flow = [{id:"switchNode1",type:"switch",name:"switchNode",property:"payload",rules:[{ "t": "gt", "v": "", "vt": "prev" }],checkall:true,outputs:1,wires:[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];