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

undo my changes to the Change node; revert to original

undo the local changes to the Change node to get back aligned with the
master tree
This commit is contained in:
Frank van de Pol 2013-12-24 20:02:30 +01:00
parent b81f251023
commit 231f8b6a4d
2 changed files with 24 additions and 20 deletions

View File

@ -34,6 +34,11 @@
<label id="node-input-t">replace with</label> <label id="node-input-t">replace with</label>
<input type="text" id="node-input-to" placeholder="that"/> <input type="text" id="node-input-to" placeholder="that"/>
</div> </div>
<div class="form-row" id="node-reg-row">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-reg" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-reg" style="width: 70%;">Use regular expressions ?</label>
</div>
<br/> <br/>
<div class="form-row"> <div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label> <label for="node-input-name"><i class="icon-tag"></i> Name</label>
@ -56,19 +61,9 @@
defaults: { defaults: {
action: {value:"change",required:true}, action: {value:"change",required:true},
property: {value:"payload"}, property: {value:"payload"},
from: {value:"",validate: function(v) { from: {value:""},
if (this.action == "change") {
try {
var re = new RegExp(this.from, "g");
return true;
} catch(err) {
RED.notify("<strong>Error</strong>: "+err.message,"error");
return false;
}
}
return true;
}},
to: {value:""}, to: {value:""},
reg: {value:false},
name: {value:""} name: {value:""}
}, },
inputs: 1, inputs: 1,
@ -81,6 +76,7 @@
return this.name ? "node_label_italic" : ""; return this.name ? "node_label_italic" : "";
}, },
oneditprepare: function() { oneditprepare: function() {
if (this.reg === null) { $("#node-input-reg").prop('checked', true); }
$("#node-input-action").change( function() { $("#node-input-action").change( function() {
var a = $("#node-input-action").val(); var a = $("#node-input-action").val();
if (a === "replace") { if (a === "replace") {
@ -89,6 +85,7 @@
$("#node-input-t").html("with value"); $("#node-input-t").html("with value");
$("#node-from-row").hide(); $("#node-from-row").hide();
$("#node-to-row").show(); $("#node-to-row").show();
$("#node-reg-row").hide();
$("#node-tip").html("Tip: expects a new property name and either a fixed value OR the full name of another msg.property eg: msg.sentiment.score"); $("#node-tip").html("Tip: expects a new property name and either a fixed value OR the full name of another msg.property eg: msg.sentiment.score");
} }
if (a === "delete") { if (a === "delete") {
@ -97,6 +94,7 @@
//$("#node-input-t").html("to"); //$("#node-input-t").html("to");
$("#node-from-row").hide(); $("#node-from-row").hide();
$("#node-to-row").hide(); $("#node-to-row").hide();
$("#node-reg-row").hide();
$("#node-tip").html("Tip: deletes the named property and all sub-properties"); $("#node-tip").html("Tip: deletes the named property and all sub-properties");
} }
if (a === "change") { if (a === "change") {
@ -105,7 +103,8 @@
$("#node-input-t").html("replace with"); $("#node-input-t").html("replace with");
$("#node-from-row").show(); $("#node-from-row").show();
$("#node-to-row").show(); $("#node-to-row").show();
$("#node-tip").html("Tip: <i>if it contains</i> can be a regex, likewise <i>replace with</i> can accept regex results. Only works on strings."); $("#node-reg-row").show();
$("#node-tip").html("Tip: If <i>contains</i> is a regex, you <b>must</b> escape any special characters. Likewise <i>replace with</i> can accept regex results. Only works on strings.");
} }
//if (a === "replace") { //if (a === "replace") {
// $("#node-input-todo").html("called"); // $("#node-input-todo").html("called");

View File

@ -22,6 +22,7 @@ function ChangeNode(n) {
this.property = n.property || ""; this.property = n.property || "";
this.from = n.from || " "; this.from = n.from || " ";
this.to = n.to || " "; this.to = n.to || " ";
this.reg = (n.reg === null || n.reg);
var node = this; var node = this;
var makeNew = function( stem, path, value ) { var makeNew = function( stem, path, value ) {
@ -35,13 +36,17 @@ function ChangeNode(n) {
this.on('input', function (msg) { this.on('input', function (msg) {
if (node.action == "change") { if (node.action == "change") {
try { var from = node.from;
node.re = new RegExp(this.from, "g"); if (node.reg === false) {
if (typeof msg[node.property] === "string") { from = from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
msg[node.property] = (msg[node.property]).replace(node.re, node.to); }
} try {
} catch(err) { node.re = new RegExp(from, "g");
this.error(err.message); } catch (e) {
node.error("Invalid regex: "+from);
}
if (typeof msg[node.property] === "string") {
msg[node.property] = (msg[node.property]).replace(node.re, node.to);
} }
} }
//else if (node.action == "replace") { //else if (node.action == "replace") {