mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add timestamp as a default typedInput
and update Inject and change nodes to match, and add some tests.
This commit is contained in:
parent
f55f85aa14
commit
59b34c2b3f
@ -22,7 +22,8 @@
|
|||||||
num: {value:"num",label:"number",icon:"red/images/typedInput/09.png",validate:/^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/},
|
num: {value:"num",label:"number",icon:"red/images/typedInput/09.png",validate:/^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/},
|
||||||
bool: {value:"bool",label:"boolean",icon:"red/images/typedInput/bool.png",options:["true","false"]},
|
bool: {value:"bool",label:"boolean",icon:"red/images/typedInput/bool.png",options:["true","false"]},
|
||||||
json: {value:"json",label:"JSON",icon:"red/images/typedInput/json.png", validate: function(v) { try{JSON.parse(v);return true;}catch(e){return false;}}},
|
json: {value:"json",label:"JSON",icon:"red/images/typedInput/json.png", validate: function(v) { try{JSON.parse(v);return true;}catch(e){return false;}}},
|
||||||
re: {value:"re",label:"regular expression",icon:"red/images/typedInput/re.png"}
|
re: {value:"re",label:"regular expression",icon:"red/images/typedInput/re.png"},
|
||||||
|
date: {value:"date",label:"timestamp",hasValue:false}
|
||||||
};
|
};
|
||||||
var nlsd = false;
|
var nlsd = false;
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@
|
|||||||
$("#node-input-payload").typedInput({
|
$("#node-input-payload").typedInput({
|
||||||
default: 'str',
|
default: 'str',
|
||||||
typeField: $("#node-input-payloadType"),
|
typeField: $("#node-input-payloadType"),
|
||||||
types:['flow','global','str','num','bool','json',{value:"date",label:this._("inject.timestamp"),hasValue:false}]
|
types:['flow','global','str','num','bool','json','date']
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#inject-time-type-select").change(function() {
|
$("#inject-time-type-select").change(function() {
|
||||||
|
@ -149,7 +149,7 @@
|
|||||||
.appendTo(row2);
|
.appendTo(row2);
|
||||||
var propertyValue = $('<input/>',{style:"width:250px",class:"node-input-rule-property-value",type:"text"})
|
var propertyValue = $('<input/>',{style:"width:250px",class:"node-input-rule-property-value",type:"text"})
|
||||||
.appendTo(row2)
|
.appendTo(row2)
|
||||||
.typedInput({default:'str',types:['msg','flow','global','str','num','bool','json']});
|
.typedInput({default:'str',types:['msg','flow','global','str','num','bool','json','date']});
|
||||||
|
|
||||||
var row3_1 = $('<div/>').appendTo(row3);
|
var row3_1 = $('<div/>').appendTo(row3);
|
||||||
$('<div/>',{style:"display:inline-block;text-align:right; width:120px; padding-right:10px; box-sizing:border-box;"})
|
$('<div/>',{style:"display:inline-block;text-align:right; width:120px; padding-right:10px; box-sizing:border-box;"})
|
||||||
|
@ -100,6 +100,8 @@ module.exports = function(RED) {
|
|||||||
value = node.context().flow.get(rule.to);
|
value = node.context().flow.get(rule.to);
|
||||||
} else if (rule.tot === 'global') {
|
} else if (rule.tot === 'global') {
|
||||||
value = node.context().global.get(rule.to);
|
value = node.context().global.get(rule.to);
|
||||||
|
} else if (rule.tot === 'date') {
|
||||||
|
value = Date.now();
|
||||||
}
|
}
|
||||||
if (rule.t === 'change') {
|
if (rule.t === 'change') {
|
||||||
if (rule.fromt === 'msg' || rule.fromt === 'flow' || rule.fromt === 'global') {
|
if (rule.fromt === 'msg' || rule.fromt === 'flow' || rule.fromt === 'global') {
|
||||||
|
@ -222,7 +222,8 @@
|
|||||||
"num": "number",
|
"num": "number",
|
||||||
"re": "regular expression",
|
"re": "regular expression",
|
||||||
"bool": "boolean",
|
"bool": "boolean",
|
||||||
"json": "JSON"
|
"json": "JSON",
|
||||||
|
"date": "timestamp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,6 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
themeSettings = null;
|
themeSettings = null;
|
||||||
theme = settings.editorTheme;
|
theme = settings.editorTheme;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
app: function() {
|
app: function() {
|
||||||
|
@ -182,6 +182,8 @@ function evaluateNodeProperty(value, type, node, msg) {
|
|||||||
return JSON.parse(value);
|
return JSON.parse(value);
|
||||||
} else if (type === 're') {
|
} else if (type === 're') {
|
||||||
return new RegExp(value);
|
return new RegExp(value);
|
||||||
|
} else if (type === 'date') {
|
||||||
|
return Date.now();
|
||||||
} else if (type === 'msg' && msg) {
|
} else if (type === 'msg' && msg) {
|
||||||
return getMessageProperty(msg,value);
|
return getMessageProperty(msg,value);
|
||||||
} else if (type === 'flow' && node) {
|
} else if (type === 'flow' && node) {
|
||||||
|
@ -242,7 +242,6 @@ describe('change Node', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('changes the value to a number', function(done) {
|
it('changes the value to a number', function(done) {
|
||||||
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"123","tot":"num"}],"name":"changeNode","wires":[["helperNode1"]]},
|
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"123","tot":"num"}],"name":"changeNode","wires":[["helperNode1"]]},
|
||||||
{id:"helperNode1", type:"helper", wires:[]}];
|
{id:"helperNode1", type:"helper", wires:[]}];
|
||||||
@ -260,6 +259,7 @@ describe('change Node', function() {
|
|||||||
changeNode1.receive({payload:""});
|
changeNode1.receive({payload:""});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('changes the value to a js object', function(done) {
|
it('changes the value to a js object', function(done) {
|
||||||
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":'{"a":123}',"tot":"json"}],"name":"changeNode","wires":[["helperNode1"]]},
|
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":'{"a":123}',"tot":"json"}],"name":"changeNode","wires":[["helperNode1"]]},
|
||||||
{id:"helperNode1", type:"helper", wires:[]}];
|
{id:"helperNode1", type:"helper", wires:[]}];
|
||||||
@ -278,6 +278,24 @@ describe('change Node', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('sets the value of the message property to the current timestamp', function(done) {
|
||||||
|
var flow = [{"id":"changeNode1","type":"change","rules":[{"t":"set","p":"ts","pt":"msg","to":"","tot":"date"}],"name":"changeNode","wires":[["helperNode1"]]},
|
||||||
|
{id:"helperNode1", type:"helper", wires:[]}];
|
||||||
|
helper.load(changeNode, flow, function() {
|
||||||
|
var changeNode1 = helper.getNode("changeNode1");
|
||||||
|
var helperNode1 = helper.getNode("helperNode1");
|
||||||
|
var rule = helper.getNode("changeNode1").rules[0];
|
||||||
|
helperNode1.on("input", function(msg) {
|
||||||
|
try {
|
||||||
|
(Date.now() - msg.ts).should.be.approximately(0,50);
|
||||||
|
done();
|
||||||
|
} catch(err) {
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
changeNode1.receive({payload:Date.now()});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
describe('#change', function() {
|
describe('#change', function() {
|
||||||
|
@ -210,6 +210,10 @@ describe("red/util", function() {
|
|||||||
var result = util.evaluateNodeProperty('^abc$','re');
|
var result = util.evaluateNodeProperty('^abc$','re');
|
||||||
result.toString().should.eql("/^abc$/");
|
result.toString().should.eql("/^abc$/");
|
||||||
});
|
});
|
||||||
|
it('returns date',function() {
|
||||||
|
var result = util.evaluateNodeProperty('','date');
|
||||||
|
(Date.now() - result).should.be.approximately(0,50);
|
||||||
|
});
|
||||||
it('returns msg property',function() {
|
it('returns msg property',function() {
|
||||||
var result = util.evaluateNodeProperty('foo.bar','msg',{},{foo:{bar:"123"}});
|
var result = util.evaluateNodeProperty('foo.bar','msg',{},{foo:{bar:"123"}});
|
||||||
result.should.eql("123");
|
result.should.eql("123");
|
||||||
|
Loading…
Reference in New Issue
Block a user