Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Ben Hardill
2013-09-19 16:22:39 +01:00
28 changed files with 1002 additions and 184 deletions

View File

@@ -16,18 +16,20 @@
<script type="text/x-red" data-template-name="debug">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
<label for="node-input-complete"><i class="icon-list"></i> Output</label>
<select type="text" id="node-input-complete" style="display: inline-block; width: auto; vertical-align: top;">
<option value=false>Payload only</option>
<option value=true>Complete msg object</option>
</select>
</div>
<div class="form-row">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-complete" placeholder="Complete" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-complete" style="width: 70%;">Show complete msg object ?</label>
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="debug">
<p>The Debug node can be connected to the output of any node. It will display the timestamp, <b>msg.topic</b> and <b>msg.payload</b> fields of any messages it receives in the debug tab of the sidebar.
<p>The Debug node can be connected to the output of any node. It will display the timestamp, <b>msg.topic</b> and <b>msg.payload</b> fields of any messages it receives in the debug tab of the sidebar.
<br/>The sidebar can be accessed under the options drop-down in the top right corner.</p>
<p>The button to the right of the node will toggle it's output on and off so you can de-clutter the debug window.</p>
<p>If the payload is an object it will be stringified first for display and indicate that by saying "(Object) ".</p>
@@ -113,10 +115,16 @@
var sbc = document.getElementById("debug-content");
var errornotification = null;
function debugConnect() {
//console.log("debug ws connecting");
var ws = new WebSocket("ws://"+location.hostname+":"+location.port+document.location.pathname+"/debug");
ws.onopen = function() {
if (errornotification) {
errornotification.close();
errornotification = null;
}
//console.log("debug ws connected");
}
ws.onmessage = function(event) {
@@ -158,7 +166,9 @@
}
};
ws.onclose = function() {
//console.log("debug ws closed");
if (errornotification == null) {
errornotification = RED.notify("<b>Error</b>: Lost connection to server","error",true);
}
setTimeout(debugConnect,1000);
}
}

View File

@@ -19,21 +19,25 @@ var RED = require("../../red/red");
var util = require("util");
var ws = require('ws');
var events = require("events");
var debuglength = RED.settings.debugMaxLength||1000;
function DebugNode(n) {
RED.nodes.createNode(this,n);
this.name = n.name;
this.complete = n.complete;
this.active = (n.active == null)||n.active;
this.on("input",function(msg) {
if (this.active) {
if (msg.payload instanceof Buffer) {
msg.payload = "(Buffer) "+msg.payload.toString();
}
if (this.complete) {
if (this.complete == "true") {
DebugNode.send({id:this.id,name:this.name,topic:msg.topic,msg:msg,_path:msg._path});
} else {
DebugNode.send({id:this.id,name:this.name,topic:msg.topic,msg:msg.payload,_path:msg._path});
if (typeof msg.payload !== "undefined") {
DebugNode.send({id:this.id,name:this.name,topic:msg.topic,msg:msg.payload,_path:msg._path});
}
}
}
});
@@ -46,18 +50,23 @@ DebugNode.send = function(msg) {
msg.msg = msg.msg.toString();
}
else if (typeof msg.msg === 'object') {
try {
msg.msg = "(Object) "+JSON.stringify(msg.msg,null,1);
}
catch (err) {
console.log(msg.msg);
console.log(err);
msg.msg = "[Error] Can't stringify object with circular reference - see console log.";
}
var seen = [];
msg.msg = "(Object) " + JSON.stringify(msg.msg, function(key, value) {
if (typeof value === 'object' && value !== null) {
if (seen.indexOf(value) !== -1) { return "[circular]"; }
seen.push(value);
}
return value;
}," ");
seen = null;
}
else if (typeof msg.msg === "boolean") msg.msg = "(boolean) "+msg.msg.toString();
else if (msg.msg === 0) msg.msg = "0";
if (msg.msg.length > debuglength) {
msg.msg = msg.msg.substr(0,debuglength) +" ....";
}
for (var i in DebugNode.activeConnections) {
var ws = DebugNode.activeConnections[i];
try {

View File

@@ -19,10 +19,16 @@
<label for="node-input-name"><i class="icon-tag"></i> Comment</label>
<input type="text" id="node-input-name" placeholder="Comment">
</div>
<div class="form-row">
<label for="node-input-info"><i class="icon-file"></i> More</label>
<input type="hidden" id="node-input-info">
<div style="height: 250px;" class="node-text-editor" id="node-input-info-editor" ></div>
</div>
<div class="form-tips">Tip: this isn't meant for War and Peace - but useful notes can be kept here.</div>
</script>
<script type="text/x-red" data-help-name="comment">
<p>Simple comment block. More of a label really...</p>
<p>Simple comment block.</p>
</script>
<script type="text/javascript">
@@ -30,7 +36,8 @@
category: 'function',
color:"#ffffff",
defaults: {
name: {value:""}
name: {value:""},
info: {value:""}
},
inputs:0,
outputs:0,
@@ -40,6 +47,39 @@
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
$( "#node-input-outputs" ).spinner({
min:1
});
function functionDialogResize(ev,ui) {
$("#node-input-info-editor").css("height",(ui.size.height-235)+"px");
};
$( "#dialog" ).on("dialogresize", functionDialogResize);
$( "#dialog" ).one("dialogopen", function(ev) {
var size = $( "#dialog" ).dialog('option','sizeCache-function');
if (size) {
functionDialogResize(null,{size:size});
}
});
$( "#dialog" ).one("dialogclose", function(ev,ui) {
var height = $( "#dialog" ).dialog('option','height');
$( "#dialog" ).off("dialogresize",functionDialogResize);
});
var that = this;
require(["orion/editor/edit"], function(edit) {
that.editor = edit({
parent:document.getElementById('node-input-info-editor'),
lang:"text",
showLinesRuler:false,
showFoldingRuler:false,
contents: $("#node-input-info").val()
});
});
},
oneditsave: function() {
$("#node-input-info").val(this.editor.getText());
delete this.editor;
}
});
</script>