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

revert change to editor change detector, and redo function node valid

code "flag" to report as non-boolean.
This commit is contained in:
dceejay 2015-05-08 15:31:48 +01:00
parent 052302b3e7
commit 5ffde21d83
3 changed files with 9 additions and 11 deletions

View File

@ -230,7 +230,7 @@ RED.editor = (function() {
newValue = input.val(); newValue = input.val();
} }
if (newValue != null) { if (newValue != null) {
if (editing_node[d].toString() != newValue.toString()) { if (editing_node[d] != newValue) {
if (editing_node._def.defaults[d].type) { if (editing_node._def.defaults[d].type) {
if (newValue == "_ADD_") { if (newValue == "_ADD_") {
newValue = ""; newValue = "";

View File

@ -22,7 +22,7 @@
<div class="form-row" style="margin-bottom: 0px;"> <div class="form-row" style="margin-bottom: 0px;">
<label for="node-input-func"><i class="fa fa-wrench"></i> Function</label> <label for="node-input-func"><i class="fa fa-wrench"></i> Function</label>
<input type="hidden" id="node-input-func" autofocus="autofocus"> <input type="hidden" id="node-input-func" autofocus="autofocus">
<input type="hidden" id="node-input-valid"> <input type="hidden" id="node-input-noerr">
</div> </div>
<div class="form-row node-text-editor-row"> <div class="form-row node-text-editor-row">
<div style="height: 250px;" class="node-text-editor" id="node-input-func-editor" ></div> <div style="height: 250px;" class="node-text-editor" id="node-input-func-editor" ></div>
@ -74,7 +74,7 @@
name: {value:""}, name: {value:""},
func: {value:"\nreturn msg;"}, func: {value:"\nreturn msg;"},
outputs: {value:1}, outputs: {value:1},
valid: {value:true,required:true} noerr: {value:0,required:true,validate:function(v){ return ((!v) || (v === 0)) ? true : false; }}
}, },
inputs:1, inputs:1,
outputs:1, outputs:1,
@ -130,12 +130,13 @@
}, },
oneditsave: function() { oneditsave: function() {
var annot = this.editor.getSession().getAnnotations(); var annot = this.editor.getSession().getAnnotations();
this.valid = true; this.noerr = 0;
$("#node-input-noerr").val(0);
for (var k=0; k < annot.length; k++) { for (var k=0; k < annot.length; k++) {
//console.log(annot[k].type,":",annot[k].text, "on line", annot[k].row); //console.log(annot[k].type,":",annot[k].text, "on line", annot[k].row);
if (annot[k].type === "error") { if (annot[k].type === "error") {
$("#node-input-valid").val(false); $("#node-input-noerr").val(annot.length);
this.valid = false; this.noerr = annot.length;
} }
} }
$("#node-input-func").val(this.editor.getValue()); $("#node-input-func").val(this.editor.getValue());

View File

@ -19,7 +19,6 @@ module.exports = function(RED) {
var util = require("util"); var util = require("util");
var vm = require("vm"); var vm = require("vm");
function sendResults(node,_msgid,msgs) { function sendResults(node,_msgid,msgs) {
if (msgs == null) { if (msgs == null) {
return; return;
@ -43,9 +42,8 @@ module.exports = function(RED) {
if (msgCount>0) { if (msgCount>0) {
node.send(msgs); node.send(msgs);
} }
} }
function FunctionNode(n) { function FunctionNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
var node = this; var node = this;
@ -99,7 +97,7 @@ module.exports = function(RED) {
context.msg = msg; context.msg = msg;
this.script.runInContext(context); this.script.runInContext(context);
sendResults(this,msg._msgid,context.results); sendResults(this,msg._msgid,context.results);
var duration = process.hrtime(start); var duration = process.hrtime(start);
var converted = Math.floor((duration[0]* 1e9 + duration[1])/10000)/100; var converted = Math.floor((duration[0]* 1e9 + duration[1])/10000)/100;
this.metric("duration", msg, converted); this.metric("duration", msg, converted);
@ -126,7 +124,6 @@ module.exports = function(RED) {
this.error(err); this.error(err);
} }
} }
RED.nodes.registerType("function",FunctionNode); RED.nodes.registerType("function",FunctionNode);
RED.library.register("functions"); RED.library.register("functions");
} }