mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Let change node set type if total match
remove unnecessary 2 step move when not required. add test for moving sub property up to main property
This commit is contained in:
@@ -35,9 +35,11 @@
|
||||
<li><b>Set</b> - set a property. The value can be a variety of different types, or
|
||||
can be taken from an existing message or context property.</li>
|
||||
<li><b>Change</b> - search & replace parts of the property. If regular expressions
|
||||
are enabled, the <b>replace with</b> property can include capture groups, for example <code>$1</code></li>
|
||||
are enabled, the <b>replace with</b> property can include capture groups, for
|
||||
example <code>$1</code>. Replace will only change the <b>type</b> if there
|
||||
is a complete match.</li>
|
||||
<li><b>Delete</b> - delete a property.</li>
|
||||
<li><b>Move</b> - move or rename a property. Equivalent to set and delete in one operation.
|
||||
<li><b>Move</b> - move or rename a property.
|
||||
</ul>
|
||||
</script>
|
||||
|
||||
@@ -135,7 +137,7 @@
|
||||
|
||||
var selectField = $('<select/>',{class:"node-input-rule-type",style:"width:110px; margin-right:10px;"}).appendTo(row1);
|
||||
var selectOptions = [{v:"set",l:set},{v:"change",l:change},{v:"delete",l:del},{v:"move",l:move}];
|
||||
for (var i=0;i<4;i++) {
|
||||
for (var i=0; i<4; i++) {
|
||||
selectField.append($("<option></option>").val(selectOptions[i].v).text(selectOptions[i].l));
|
||||
}
|
||||
|
||||
@@ -241,7 +243,7 @@
|
||||
this.rules = [rule];
|
||||
}
|
||||
|
||||
for (var i=0;i<this.rules.length;i++) {
|
||||
for (var i=0; i<this.rules.length; i++) {
|
||||
var rule = this.rules[i];
|
||||
$("#node-input-rule-container").editableList('addItem',rule);
|
||||
}
|
||||
@@ -277,7 +279,7 @@
|
||||
oneditresize: function(size) {
|
||||
var rows = $("#dialog-form>div:not(.node-input-rule-container-row)");
|
||||
var height = size.height;
|
||||
for (var i=0;i<rows.size();i++) {
|
||||
for (var i=0; i<rows.size(); i++) {
|
||||
height -= $(rows[i]).outerHeight(true);
|
||||
}
|
||||
var editorRow = $("#dialog-form>div.node-input-rule-container-row");
|
||||
|
@@ -152,7 +152,7 @@ module.exports = function(RED) {
|
||||
} else if (rule.t === 'change') {
|
||||
current = RED.util.getMessageProperty(msg,property);
|
||||
if (typeof current === 'string') {
|
||||
if ((fromType === 'num' || fromType === 'bool') && current === fromValue) {
|
||||
if ((fromType === 'num' || fromType === 'bool' || fromType === 'str') && current === fromValue) {
|
||||
// str representation of exact from number/boolean
|
||||
// only replace if they match exactly
|
||||
RED.util.setMessageProperty(msg,property,value);
|
||||
@@ -170,7 +170,8 @@ module.exports = function(RED) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
var target;
|
||||
if (rule.pt === 'flow') {
|
||||
target = node.context().flow;
|
||||
@@ -185,7 +186,7 @@ module.exports = function(RED) {
|
||||
} else if (rule.t === 'change') {
|
||||
current = target.get(msg,property);
|
||||
if (typeof current === 'string') {
|
||||
if ((fromType === 'num' || fromType === 'bool') && current === fromValue) {
|
||||
if ((fromType === 'num' || fromType === 'bool' || fromType === 'str') && current === fromValue) {
|
||||
// str representation of exact from number/boolean
|
||||
// only replace if they match exactly
|
||||
target.set(property,value);
|
||||
@@ -211,14 +212,14 @@ module.exports = function(RED) {
|
||||
if (valid) {
|
||||
var node = this;
|
||||
this.on('input', function(msg) {
|
||||
for (var i=0;i<this.rules.length;i++) {
|
||||
for (var i=0; i<this.rules.length; i++) {
|
||||
if (this.rules[i].t === "move") {
|
||||
var r = this.rules[i];
|
||||
if (r.to.indexOf(r.pt) !== -1) {
|
||||
if ((r.tot !== r.pt) || (r.p.indexOf(r.to) !== -1)) {
|
||||
msg = applyRule(msg,{t:"set", p:r.to, pt:r.tot, to:r.p, tot:r.pt});
|
||||
applyRule(msg,{t:"delete", p:r.p, pt:r.pt});
|
||||
}
|
||||
else { // 2 step move if we are moving to a child
|
||||
else { // 2 step move if we are moving from a child
|
||||
msg = applyRule(msg,{t:"set", p:"_temp_move", pt:r.tot, to:r.p, tot:r.pt});
|
||||
applyRule(msg,{t:"delete", p:r.p, pt:r.pt});
|
||||
msg = applyRule(msg,{t:"set", p:r.to, pt:r.tot, to:"_temp_move", tot:r.pt});
|
||||
|
Reference in New Issue
Block a user