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

Make strings expandable in debug

This commit is contained in:
Nick O'Leary 2016-11-02 15:12:30 +00:00
parent f0f40a8606
commit 06ee9aa05c
4 changed files with 75 additions and 205 deletions

View File

@ -153,7 +153,7 @@ module.exports = function(RED) {
msg.format = (msg.msg === null)?"null":"undefined"; msg.format = (msg.msg === null)?"null":"undefined";
msg.msg = "(undefined)"; msg.msg = "(undefined)";
} else { } else {
msg.format = "string ["+msg.msg.length+"]"; msg.format = "string["+msg.msg.length+"]";
if (msg.msg.length > debuglength) { if (msg.msg.length > debuglength) {
msg.msg = msg.msg.substring(0,debuglength)+"..."; msg.msg = msg.msg.substring(0,debuglength)+"...";
} }

View File

@ -185,8 +185,8 @@ RED.debug = (function() {
} }
} else if (typeof value === 'string') { } else if (typeof value === 'string') {
subvalue = value; subvalue = value;
if (subvalue.length > 50) { if (subvalue.length > 30) {
subvalue = subvalue.substring(0,50)+"…"; subvalue = subvalue.substring(0,30)+"…";
} }
result = $('<span class="debug-message-object-value debug-message-type-string"></span>').html('"'+formatString(subvalue)+'"'); result = $('<span class="debug-message-object-value debug-message-type-string"></span>').html('"'+formatString(subvalue)+'"');
} else { } else {
@ -241,7 +241,16 @@ RED.debug = (function() {
if (obj === null || obj === undefined) { if (obj === null || obj === undefined) {
$('<span class="debug-message-type-null">'+obj+'</span>').appendTo(entryObj); $('<span class="debug-message-type-null">'+obj+'</span>').appendTo(entryObj);
} else if (typeof obj === 'string') { } else if (typeof obj === 'string') {
$('<span class="debug-message-type-string"></span>').html('"'+formatString(obj)+'"').appendTo(entryObj); element.addClass('collapsed');
$('<i class="fa fa-caret-right debug-message-object-handle"></i> ').prependTo(header);
$('<span class="debug-message-type-string debug-message-object-header"></span>').html('"'+formatString(obj)+'"').appendTo(entryObj);
makeExpandable(header, function() {
$('<span class="debug-message-type-meta debug-message-object-type-header"></span>').html(typeHint||'string').appendTo(header);
var row = $('<div class="debug-message-object-entry collapsed"></div>').appendTo(element);
$('<pre class="debug-message-type-string"></pre>').html(obj).appendTo(row);
});
} else if (typeof obj === 'number') { } else if (typeof obj === 'number') {
e = $('<span class="debug-message-type-number"></span>').text(""+obj).appendTo(entryObj); e = $('<span class="debug-message-type-number"></span>').text(""+obj).appendTo(entryObj);
e.click(function(evt) { e.click(function(evt) {
@ -271,6 +280,8 @@ RED.debug = (function() {
originalLength = data.length; originalLength = data.length;
} }
type = obj.type.toLowerCase(); type = obj.type.toLowerCase();
} else if (/buffer/.test(typeHint)) {
type = 'buffer';
} }
var fullLength = data.length; var fullLength = data.length;
@ -278,7 +289,26 @@ RED.debug = (function() {
$('<i class="fa fa-caret-right debug-message-object-handle"></i> ').prependTo(header); $('<i class="fa fa-caret-right debug-message-object-handle"></i> ').prependTo(header);
makeExpandable(header,function() { makeExpandable(header,function() {
if (!key) { if (!key) {
$('<span class="debug-message-type-meta debug-message-object-type-header"></span>').html(typeHint||(type+'['+originalLength+']')).appendTo(header); var headerHead = $('<span class="debug-message-type-meta debug-message-object-type-header"></span>').html(typeHint||(type+'['+originalLength+']')).appendTo(header);
if (type === 'buffer') {
// var bufferOpts = $('<span class="debug-message-buffer-opts"></span>').appendTo(headerHead);
// //dec hex string
// $('<a href="#"></a>').addClass('selected').html('dec').appendTo(bufferOpts).click(function(e) {
// $(this).addClass('selected').siblings().removeClass('selected');
// e.preventDefault();
// e.stopPropagation();
// })
// $('<a href="#"></a>').html('hex').appendTo(bufferOpts).click(function(e) {
// $(this).addClass('selected').siblings().removeClass('selected');
// e.preventDefault();
// e.stopPropagation();
// })
// $('<a href="#"></a>').html('string').appendTo(bufferOpts).click(function(e) {
// $(this).addClass('selected').siblings().removeClass('selected');
// e.preventDefault();
// e.stopPropagation();
// })
}
} }
var row; var row;
if (fullLength <= 10) { if (fullLength <= 10) {
@ -305,6 +335,9 @@ RED.debug = (function() {
})()); })());
$('<span class="debug-message-object-key"></span>').html("["+minRange+" &hellip; "+Math.min(fullLength-1,(minRange+9))+"]").appendTo(header); $('<span class="debug-message-object-key"></span>').html("["+minRange+" &hellip; "+Math.min(fullLength-1,(minRange+9))+"]").appendTo(header);
} }
if (fullLength < originalLength) {
$('<div class="debug-message-object-entry collapsed"><span class="debug-message-object-key">['+fullLength+' &hellip; '+originalLength+']</span></div>').appendTo(element);
}
} }
}); });
} }
@ -332,7 +365,7 @@ RED.debug = (function() {
} else if (typeof obj === 'object') { } else if (typeof obj === 'object') {
element.addClass('collapsed'); element.addClass('collapsed');
var keys = Object.keys(obj); var keys = Object.keys(obj);
if (keys.length > 0) { if (key || keys.length > 0) {
$('<i class="fa fa-caret-right debug-message-object-handle"></i> ').prependTo(header); $('<i class="fa fa-caret-right debug-message-object-handle"></i> ').prependTo(header);
makeExpandable(header, function() { makeExpandable(header, function() {
if (!key) { if (!key) {
@ -342,6 +375,9 @@ RED.debug = (function() {
var row = $('<div class="debug-message-object-entry collapsed"></div>').appendTo(element); var row = $('<div class="debug-message-object-entry collapsed"></div>').appendTo(element);
buildMessageElement(obj[keys[i]],keys[i],false).appendTo(row); buildMessageElement(obj[keys[i]],keys[i],false).appendTo(row);
} }
if (keys.length === 0) {
$('<div class="debug-message-object-entry debug-message-type-meta collapsed"></div>').text("empty").appendTo(element);
}
}); });
} }
if (key) { if (key) {
@ -365,36 +401,6 @@ RED.debug = (function() {
$('<span class="debug-message-type-meta">empty</span>').appendTo(headerHead); $('<span class="debug-message-type-meta">empty</span>').appendTo(headerHead);
} }
$('<span> }</span>').appendTo(headerHead); $('<span> }</span>').appendTo(headerHead);
// $('<span class="debug-message-type-meta debug-message-object-type-header"></span>').html('object').appendTo(header);
// headerHead = $('<span class="debug-message-object-header"></span>').appendTo(header);
// $('<span>{ </span>').appendTo(headerHead);
// for (i=0;i<keys.length;i++) {
// if (!key) {
// if (i < 5) {
// $('<span class="debug-message-object-key"></span>').text(keys[i]).appendTo(headerHead);
// $('<span>: </span>').appendTo(headerHead);
// buildMessageSummaryValue(obj[keys[i]]).appendTo(headerHead);
// if (i < keys.length -1) {
// $('<span>, </span>').appendTo(headerHead);
// }
// }
// if (i === 5) {
// $('<span> &hellip;</span>').appendTo(headerHead);
// }
// }
// entryObj = $('<div class="debug-message-object-entry collapsed"></div>').appendTo(element);
// var entryHeader = $('<span></span>').appendTo(entryObj);
// $('<span class="debug-message-object-key"></span>').text(keys[i]).appendTo(entryHeader);
// $('<span>: </span>').appendTo(entryHeader);
// e = $('<span class="debug-message-object-value"></span>').appendTo(entryObj);
// buildMessageElement(obj[keys[i]],keys[i]).appendTo(e);
// }
// $('<div class="debug-message-object-entry"><span class="debug-message-object-key">&hellip;</span></div>').appendTo(element);
}
if (keys.length === 0) {
$('<div class="debug-message-object-entry debug-message-type-meta collapsed"></div>').text("empty").appendTo(element);
} }
} else { } else {
$('<span class="debug-message-type-other"></span>').text(""+obj).appendTo(entryObj); $('<span class="debug-message-type-other"></span>').text(""+obj).appendTo(entryObj);
@ -402,167 +408,6 @@ RED.debug = (function() {
return element; return element;
} }
// function buildMessageElement(obj,topLevel,typeHint) {
// var i;
// var e;
// var entryObj;
// var header;
// var headerHead;
// var value,subvalue;
// var element = $('<span class="debug-message-element"></span>').toggleClass('collapsed',topLevel);
// if (Array.isArray(obj)) {
// var originalLength = obj.length;
// if (typeHint) {
// var m = /\[(\d+)\]/.exec(typeHint);
// if (m) {
// originalLength = parseInt(m[1]);
// }
// }
// var fullLength = obj.length;
// var length = Math.min(obj.length,10);
// if (!topLevel) {
// header = $('<span class="debug-message-type-meta"></span>').html(typeHint||('array['+obj.length+']')).appendTo(element);
// } else {
// header = $('<span>').appendTo(element);
// if (length > 0) {
// $('<i class="fa fa-caret-right debug-message-object-handle"></i> ').prependTo(header);
// makeExpandable(header);
// }
// $('<span class="debug-message-type-meta debug-message-object-type-header"></span>').html(typeHint||('array['+obj.length+']')).appendTo(header);
// headerHead = $('<span class="debug-message-object-header"></span>').appendTo(header);
// $('<span>[ </span>').appendTo(headerHead);
// }
// var row;
// for (i=0;i<fullLength;i++) {
// if (topLevel) {
// if (i<length) {
// buildMessageSummaryValue(obj[i]).appendTo(headerHead);
// if (i < length -1) {
// $('<span>, </span>').appendTo(headerHead);
// }
// }
// }
// if (fullLength < 10) {
// row = element;
// } else if (fullLength > 10 && (i%10) === 0) {
// var minRange = 10*Math.floor(i/10);
// row = $('<div class="debug-message-object-entry collapsed"></div>').appendTo(element);
// header = $('<span></span>').appendTo(row);
// $('<i class="fa fa-caret-right debug-message-object-handle"></i> ').appendTo(header);
// makeExpandable(header);
// $('<span class="debug-message-object-key"></span>').html("["+minRange+" &hellip; "+Math.min(fullLength-1,(minRange+9))+"]").appendTo(header);
// }
// entryObj = $('<div class="debug-message-object-entry collapsed"></div>').appendTo(row);
//
// header = $('<span></span>').appendTo(entryObj);
// if (typeof obj[i] === 'object' && obj[i] !== null) {
// $('<i class="fa fa-caret-right debug-message-object-handle"></i> ').appendTo(header);
// makeExpandable(header);
// }
// $('<span class="debug-message-object-key"></span>').text(i).appendTo(header);
//
// $('<span>: </span>').appendTo(entryObj);
// e = $('<span class="debug-message-object-value"></span>').appendTo(entryObj);
// buildMessageElement(obj[i],false).appendTo(e);
// }
// if (length < obj.length) {
// if (topLevel) {
// $('<span> &hellip;</span>').appendTo(headerHead);
// }
// //$('<div class="debug-message-object-entry"><span class="debug-message-object-key">&hellip;</span></div>').appendTo(element);
// }
// if (fullLength < originalLength) {
// row = $('<div class="debug-message-object-entry collapsed"></div>').appendTo(element);
// $('<span> &hellip;</span>').appendTo(row);
// }
// if (topLevel) {
// if (length === 0) {
// $('<span class="debug-message-type-meta">empty</span>').appendTo(headerHead);
// }
// $('<span> ]</span>').appendTo(headerHead);
// }
// } else if (obj === null || obj === undefined) {
// $('<span class="debug-message-object-value debug-message-type-null">'+obj+'</span>').appendTo(element);
// } else if (typeof obj === 'object') {
// if (obj.hasOwnProperty('type') && obj.type === 'Buffer' && obj.hasOwnProperty('data')) {
// buildMessageElement(obj.data,false,'buffer['+obj.data.length+']').appendTo(element);
//
// } else {
// var keys = Object.keys(obj);
// if (topLevel) {
// header = $('<span>').appendTo(element);
// if (keys.length > 0) {
// $('<i class="fa fa-caret-right debug-message-object-handle"></i> ').prependTo(header);
// makeExpandable(header);
// }
// } else {
// header = $('<span class="debug-message-type-meta"></span>').html('object').appendTo(element);
// }
// if (topLevel) {
// $('<span class="debug-message-type-meta debug-message-object-type-header"></span>').html('object').appendTo(header);
// headerHead = $('<span class="debug-message-object-header"></span>').appendTo(header);
// $('<span>{ </span>').appendTo(headerHead);
// }
// for (i=0;i<keys.length;i++) {
// if (topLevel) {
// if (i < 5) {
// $('<span class="debug-message-object-key"></span>').text(keys[i]).appendTo(headerHead);
// $('<span>: </span>').appendTo(headerHead);
// buildMessageSummaryValue(obj[keys[i]]).appendTo(headerHead);
// if (i < keys.length -1) {
// $('<span>, </span>').appendTo(headerHead);
// }
// }
// if (i === 5) {
// $('<span> &hellip;</span>').appendTo(headerHead);
// }
// }
// entryObj = $('<div class="debug-message-object-entry collapsed"></div>').appendTo(element);
// var entryHeader = $('<span></span>').appendTo(entryObj);
// $('<span class="debug-message-object-key"></span>').text(keys[i]).appendTo(entryHeader);
// $('<span>: </span>').appendTo(entryHeader);
// e = $('<span class="debug-message-object-value"></span>').appendTo(entryObj);
// if (typeof obj[keys[i]] === 'object' && obj[keys[i]] !== null) {
// $('<i class="fa fa-caret-right debug-message-object-handle"></i> ').prependTo(entryHeader);
// makeExpandable(entryHeader);
// }
// buildMessageElement(obj[keys[i]],false).appendTo(e);
// }
// if (keys.length === 0) {
// $('<div class="debug-message-object-entry debug-message-type-meta collapsed"></div>').text("empty").appendTo(element);
// }
// if (topLevel) {
// if (keys.length === 0) {
// $('<span class="debug-message-type-meta">empty</span>').appendTo(headerHead);
// }
// $('<span> }</span>').appendTo(headerHead);
// }
// }
// } else if (typeof obj === 'string') {
// $('<span class="debug-message-object-value debug-message-type-string"></span>').html('"'+formatString(obj)+'"').appendTo(element);
// } else if (typeof obj === 'number') {
// e = $('<span class="debug-message-object-value debug-message-type-number"></span>').text(""+obj).appendTo(element);
// e.click(function(evt) {
// var format = $(this).data('format');
// if (format === 'hex') {
// $(this).text(""+obj).data('format','dec');
// } else {
// $(this).text("0x"+(obj).toString(16)).data('format','hex');
// }
// evt.preventDefault();
// });
// } else {
// $('<span class="debug-message-object-value debug-message-type-other"></span>').text(""+obj).appendTo(element);
// }
// return element;
// }
function buildMessageBody(obj,el) {
}
function handleDebugMessage(o) { function handleDebugMessage(o) {
var msg = document.createElement("div"); var msg = document.createElement("div");

View File

@ -116,14 +116,19 @@
.debug-message-element.collapsed .debug-message-object-entry { .debug-message-element.collapsed .debug-message-object-entry {
display:none; display:none;
} }
.debug-message-element:not(.collapsed) .debug-message-object-header { .debug-message-element:not(.collapsed)>.debug-message-expandable>.debug-message-object-value>.debug-message-object-header {
display:none; display:none;
} }
.debug-message-element.collapsed .debug-message-object-type-header { .debug-message-element.collapsed .debug-message-object-type-header {
display:none; display:none;
} }
.debug-message-object-entry pre {
font-family: Menlo, monospace;
font-size: 12px;
line-height: 1.4em;
margin: 0 0 0 -1em;
}
.debug-message-type-other { color: #2033d6; } .debug-message-type-other { color: #2033d6; }
.debug-message-type-string { color: #b72828; } .debug-message-type-string { color: #b72828; }
@ -140,3 +145,23 @@
.debug-message-expandable:hover .debug-message-object-handle { .debug-message-expandable:hover .debug-message-object-handle {
color: #b72828 !important; color: #b72828 !important;
} }
.debug-message-buffer-opts a {
font-size: 9px;
color: #bbb;
border: 1px solid #bbb;
border-radius: 2px;
padding: 2px 5px;
margin-left: 5px;
}
.debug-message-buffer-opts a.selected {
background: #eee;
color: #999;
border: 1px solid #999;
}
.debug-message-buffer-opts a:hover {
text-decoration: none;
color: #999;
border: 1px solid #999;
background: #f3f3f3;
}

View File

@ -49,7 +49,7 @@ describe('debug node', function() {
}, function(msg) { }, function(msg) {
JSON.parse(msg).should.eql({ JSON.parse(msg).should.eql({
topic:"debug",data:{id:"n1",name:"Debug",msg:"test", topic:"debug",data:{id:"n1",name:"Debug",msg:"test",
format:"string [4]",property:"payload"} format:"string[4]",property:"payload"}
}); });
}, done); }, done);
}); });
@ -64,7 +64,7 @@ describe('debug node', function() {
n1.emit("input", {payload:"test"}); n1.emit("input", {payload:"test"});
}, function(msg) { }, function(msg) {
JSON.parse(msg).should.eql({ JSON.parse(msg).should.eql({
topic:"debug",data:{id:"n1",msg:"test",property:"payload",format:"string [4]"} topic:"debug",data:{id:"n1",msg:"test",property:"payload",format:"string[4]"}
}); });
count++; count++;
}, function() { }, function() {
@ -108,7 +108,7 @@ describe('debug node', function() {
n1.emit("input", {payload:"test", foo:"bar"}); n1.emit("input", {payload:"test", foo:"bar"});
}, function(msg) { }, function(msg) {
JSON.parse(msg).should.eql({ JSON.parse(msg).should.eql({
topic:"debug",data:{id:"n1",msg:"bar",property:"foo",format:"string [3]"} topic:"debug",data:{id:"n1",msg:"bar",property:"foo",format:"string[3]"}
}); });
}, done); }, done);
}); });
@ -122,7 +122,7 @@ describe('debug node', function() {
n1.emit("input", {payload:"test", foo: {bar: "bar"}}); n1.emit("input", {payload:"test", foo: {bar: "bar"}});
}, function(msg) { }, function(msg) {
JSON.parse(msg).should.eql({ JSON.parse(msg).should.eql({
topic:"debug",data:{id:"n1",msg:"bar",property:"foo.bar",format:"string [3]"} topic:"debug",data:{id:"n1",msg:"bar",property:"foo.bar",format:"string[3]"}
}); });
}, done); }, done);
}); });
@ -236,7 +236,7 @@ describe('debug node', function() {
id:"n1", id:"n1",
msg: Array(1001).join("X")+'...', msg: Array(1001).join("X")+'...',
property:"payload", property:"payload",
format:"string [1001]" format:"string[1001]"
} }
}); });
}, done); }, done);
@ -277,7 +277,7 @@ describe('debug node', function() {
}); });
}, function(msg) { }, function(msg) {
JSON.parse(msg).should.eql({ JSON.parse(msg).should.eql({
topic:"debug",data:{id:"n1",msg:"message 2",property:"payload",format:"string [9]"} topic:"debug",data:{id:"n1",msg:"message 2",property:"payload",format:"string[9]"}
}); });
}, done); }, done);
}); });