2016-11-03 00:20:48 +01:00
|
|
|
/**
|
2017-01-11 16:24:33 +01:00
|
|
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
2016-11-03 00:20:48 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
**/
|
|
|
|
|
|
|
|
RED.utils = (function() {
|
|
|
|
|
|
|
|
function formatString(str) {
|
|
|
|
return str.replace(/\r?\n/g,"↵").replace(/\t/g,"→");
|
|
|
|
}
|
2016-11-27 22:51:34 +01:00
|
|
|
function sanitize(m) {
|
|
|
|
return m.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
|
|
|
|
}
|
2016-11-03 00:20:48 +01:00
|
|
|
|
|
|
|
function buildMessageSummaryValue(value) {
|
|
|
|
var result;
|
|
|
|
if (Array.isArray(value)) {
|
2018-05-11 15:05:52 +02:00
|
|
|
result = $('<span class="debug-message-object-value debug-message-type-meta"></span>').text('array['+value.length+']');
|
2016-11-03 00:20:48 +01:00
|
|
|
} else if (value === null) {
|
|
|
|
result = $('<span class="debug-message-object-value debug-message-type-null">null</span>');
|
|
|
|
} else if (typeof value === 'object') {
|
|
|
|
if (value.hasOwnProperty('type') && value.type === 'Buffer' && value.hasOwnProperty('data')) {
|
2018-05-11 15:05:52 +02:00
|
|
|
result = $('<span class="debug-message-object-value debug-message-type-meta"></span>').text('buffer['+value.length+']');
|
2016-11-03 00:20:48 +01:00
|
|
|
} else if (value.hasOwnProperty('type') && value.type === 'array' && value.hasOwnProperty('data')) {
|
2018-05-11 15:05:52 +02:00
|
|
|
result = $('<span class="debug-message-object-value debug-message-type-meta"></span>').text('array['+value.length+']');
|
2018-06-25 23:31:11 +02:00
|
|
|
} else if (value.hasOwnProperty('type') && value.type === 'function') {
|
|
|
|
result = $('<span class="debug-message-object-value debug-message-type-meta"></span>').text('function');
|
2018-06-29 11:50:07 +02:00
|
|
|
} else if (value.hasOwnProperty('type') && value.type === 'number') {
|
|
|
|
result = $('<span class="debug-message-object-value debug-message-type-number"></span>').text(value.data);
|
2016-11-03 00:20:48 +01:00
|
|
|
} else {
|
|
|
|
result = $('<span class="debug-message-object-value debug-message-type-meta">object</span>');
|
|
|
|
}
|
|
|
|
} else if (typeof value === 'string') {
|
2016-11-27 22:51:34 +01:00
|
|
|
var subvalue;
|
|
|
|
if (value.length > 30) {
|
|
|
|
subvalue = sanitize(value.substring(0,30))+"…";
|
|
|
|
} else {
|
|
|
|
subvalue = sanitize(value);
|
2016-11-03 00:20:48 +01:00
|
|
|
}
|
|
|
|
result = $('<span class="debug-message-object-value debug-message-type-string"></span>').html('"'+formatString(subvalue)+'"');
|
2018-06-29 11:50:07 +02:00
|
|
|
} else if (typeof value === 'number') {
|
|
|
|
result = $('<span class="debug-message-object-value debug-message-type-number"></span>').text(""+value);
|
2016-11-03 00:20:48 +01:00
|
|
|
} else {
|
|
|
|
result = $('<span class="debug-message-object-value debug-message-type-other"></span>').text(""+value);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2017-08-01 00:29:36 +02:00
|
|
|
function makeExpandable(el,onbuild,ontoggle,expand) {
|
2016-11-03 00:20:48 +01:00
|
|
|
el.addClass("debug-message-expandable");
|
2017-08-01 00:29:36 +02:00
|
|
|
el.prop('toggle',function() {
|
|
|
|
return function(state) {
|
|
|
|
var parent = el.parent();
|
|
|
|
if (parent.hasClass('collapsed')) {
|
|
|
|
if (state) {
|
|
|
|
if (onbuild && !parent.hasClass('built')) {
|
|
|
|
onbuild();
|
|
|
|
parent.addClass('built');
|
|
|
|
}
|
|
|
|
parent.removeClass('collapsed');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!state) {
|
|
|
|
parent.addClass('collapsed');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2016-11-03 00:20:48 +01:00
|
|
|
el.click(function(e) {
|
|
|
|
var parent = $(this).parent();
|
2017-08-01 00:29:36 +02:00
|
|
|
var currentState = !parent.hasClass('collapsed');
|
|
|
|
if ($(this).prop('toggle')(!currentState)) {
|
|
|
|
if (ontoggle) {
|
|
|
|
ontoggle(!currentState);
|
2016-11-03 00:20:48 +01:00
|
|
|
}
|
|
|
|
}
|
2017-08-01 00:29:36 +02:00
|
|
|
// if (parent.hasClass('collapsed')) {
|
|
|
|
// if (onbuild && !parent.hasClass('built')) {
|
|
|
|
// onbuild();
|
|
|
|
// parent.addClass('built');
|
|
|
|
// }
|
|
|
|
// if (ontoggle) {
|
|
|
|
// ontoggle(true);
|
|
|
|
// }
|
|
|
|
// parent.removeClass('collapsed');
|
|
|
|
// } else {
|
|
|
|
// parent.addClass('collapsed');
|
|
|
|
// if (ontoggle) {
|
|
|
|
// ontoggle(false);
|
|
|
|
// }
|
|
|
|
// }
|
2016-11-03 00:20:48 +01:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
2017-05-11 16:08:10 +02:00
|
|
|
if (expand) {
|
|
|
|
el.click();
|
|
|
|
}
|
2017-08-01 00:29:36 +02:00
|
|
|
|
2016-11-03 00:20:48 +01:00
|
|
|
}
|
2017-05-11 16:08:10 +02:00
|
|
|
|
|
|
|
var pinnedPaths = {};
|
2017-05-11 18:00:49 +02:00
|
|
|
var formattedPaths = {};
|
2017-05-11 16:08:10 +02:00
|
|
|
|
|
|
|
function addMessageControls(obj,sourceId,key,msg,rootPath,strippedKey) {
|
|
|
|
if (!pinnedPaths.hasOwnProperty(sourceId)) {
|
|
|
|
pinnedPaths[sourceId] = {}
|
|
|
|
}
|
|
|
|
var tools = $('<span class="debug-message-tools"></span>').appendTo(obj);
|
|
|
|
var copyTools = $('<span class="debug-message-tools-copy button-group"></span>').appendTo(tools);
|
2017-05-12 11:19:50 +02:00
|
|
|
if (!!key) {
|
|
|
|
var copyPath = $('<button class="editor-button editor-button-small"><i class="fa fa-terminal"></i></button>').appendTo(copyTools).click(function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
RED.clipboard.copyText(key,copyPath,"clipboard.copyMessagePath");
|
|
|
|
})
|
|
|
|
}
|
2017-05-11 16:08:10 +02:00
|
|
|
var copyPayload = $('<button class="editor-button editor-button-small"><i class="fa fa-clipboard"></i></button>').appendTo(copyTools).click(function(e) {
|
2017-05-10 16:49:12 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
RED.clipboard.copyText(msg,copyPayload,"clipboard.copyMessageValue");
|
|
|
|
})
|
2018-06-25 23:31:11 +02:00
|
|
|
if (strippedKey !== undefined && strippedKey !== '') {
|
2017-05-11 16:08:10 +02:00
|
|
|
var isPinned = pinnedPaths[sourceId].hasOwnProperty(strippedKey);
|
2017-05-10 16:49:12 +02:00
|
|
|
|
2017-05-11 16:08:10 +02:00
|
|
|
var pinPath = $('<button class="editor-button editor-button-small debug-message-tools-pin"><i class="fa fa-map-pin"></i></button>').appendTo(tools).click(function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
if (pinnedPaths[sourceId].hasOwnProperty(strippedKey)) {
|
|
|
|
delete pinnedPaths[sourceId][strippedKey];
|
|
|
|
$(this).removeClass("selected");
|
|
|
|
obj.removeClass("debug-message-row-pinned");
|
|
|
|
} else {
|
|
|
|
var rootedPath = "$"+(strippedKey[0] === '['?"":".")+strippedKey;
|
|
|
|
pinnedPaths[sourceId][strippedKey] = normalisePropertyExpression(rootedPath);
|
|
|
|
$(this).addClass("selected");
|
|
|
|
obj.addClass("debug-message-row-pinned");
|
|
|
|
}
|
|
|
|
}).toggleClass("selected",isPinned);
|
|
|
|
obj.toggleClass("debug-message-row-pinned",isPinned);
|
|
|
|
}
|
2017-05-10 16:49:12 +02:00
|
|
|
}
|
2017-05-11 16:08:10 +02:00
|
|
|
function checkExpanded(strippedKey,expandPaths,minRange,maxRange) {
|
|
|
|
if (expandPaths && expandPaths.length > 0) {
|
|
|
|
if (strippedKey === '' && minRange === undefined) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
for (var i=0;i<expandPaths.length;i++) {
|
|
|
|
var p = expandPaths[i];
|
|
|
|
if (p.indexOf(strippedKey) === 0 && (p[strippedKey.length] === "." || p[strippedKey.length] === "[") ) {
|
2016-11-03 00:20:48 +01:00
|
|
|
|
2017-05-11 16:08:10 +02:00
|
|
|
if (minRange !== undefined && p[strippedKey.length] === "[") {
|
|
|
|
var subkey = p.substring(strippedKey.length);
|
|
|
|
var m = (/\[(\d+)\]/.exec(subkey));
|
|
|
|
if (m) {
|
|
|
|
var index = parseInt(m[1]);
|
|
|
|
return minRange<=index && index<=maxRange;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-11 22:15:16 +02:00
|
|
|
function formatNumber(element,obj,sourceId,path,cycle,initialFormat) {
|
2017-11-02 17:50:35 +01:00
|
|
|
var format = (formattedPaths[sourceId] && formattedPaths[sourceId][path] && formattedPaths[sourceId][path]['number']) || initialFormat || "dec";
|
2017-05-11 18:00:49 +02:00
|
|
|
if (cycle) {
|
|
|
|
if (format === 'dec') {
|
|
|
|
if ((obj.toString().length===13) && (obj<=2147483647000)) {
|
|
|
|
format = 'dateMS';
|
|
|
|
} else if ((obj.toString().length===10) && (obj<=2147483647)) {
|
|
|
|
format = 'dateS';
|
|
|
|
} else {
|
|
|
|
format = 'hex'
|
|
|
|
}
|
|
|
|
} else if (format === 'dateMS' || format == 'dateS') {
|
|
|
|
format = 'hex';
|
|
|
|
} else {
|
|
|
|
format = 'dec';
|
|
|
|
}
|
|
|
|
formattedPaths[sourceId] = formattedPaths[sourceId]||{};
|
2017-11-02 17:50:35 +01:00
|
|
|
formattedPaths[sourceId][path] = formattedPaths[sourceId][path]||{};
|
|
|
|
formattedPaths[sourceId][path]['number'] = format;
|
2017-05-11 22:15:16 +02:00
|
|
|
} else if (initialFormat !== undefined){
|
|
|
|
formattedPaths[sourceId] = formattedPaths[sourceId]||{};
|
2017-11-02 17:50:35 +01:00
|
|
|
formattedPaths[sourceId][path] = formattedPaths[sourceId][path]||{};
|
|
|
|
formattedPaths[sourceId][path]['number'] = format;
|
2017-05-11 18:00:49 +02:00
|
|
|
}
|
|
|
|
if (format === 'dec') {
|
|
|
|
element.text(""+obj);
|
|
|
|
} else if (format === 'dateMS') {
|
|
|
|
element.text((new Date(obj)).toISOString());
|
|
|
|
} else if (format === 'dateS') {
|
|
|
|
element.text((new Date(obj*1000)).toISOString());
|
|
|
|
} else if (format === 'hex') {
|
|
|
|
element.text("0x"+(obj).toString(16));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function formatBuffer(element,button,sourceId,path,cycle) {
|
2017-11-02 17:50:35 +01:00
|
|
|
var format = (formattedPaths[sourceId] && formattedPaths[sourceId][path] && formattedPaths[sourceId][path]['buffer']) || "raw";
|
2017-05-11 18:00:49 +02:00
|
|
|
if (cycle) {
|
|
|
|
if (format === 'raw') {
|
|
|
|
format = 'string';
|
|
|
|
} else {
|
|
|
|
format = 'raw';
|
|
|
|
}
|
|
|
|
formattedPaths[sourceId] = formattedPaths[sourceId]||{};
|
2017-11-02 17:50:35 +01:00
|
|
|
formattedPaths[sourceId][path] = formattedPaths[sourceId][path]||{};
|
|
|
|
formattedPaths[sourceId][path]['buffer'] = format;
|
2017-05-11 18:00:49 +02:00
|
|
|
}
|
|
|
|
if (format === 'raw') {
|
|
|
|
button.text('raw');
|
|
|
|
element.removeClass('debug-message-buffer-string').addClass('debug-message-buffer-raw');
|
|
|
|
} else if (format === 'string') {
|
|
|
|
button.text('string');
|
|
|
|
element.addClass('debug-message-buffer-string').removeClass('debug-message-buffer-raw');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-01 00:29:36 +02:00
|
|
|
function buildMessageElement(obj,options) {
|
|
|
|
options = options || {};
|
|
|
|
var key = options.key;
|
|
|
|
var typeHint = options.typeHint;
|
|
|
|
var hideKey = options.hideKey;
|
|
|
|
var path = options.path;
|
|
|
|
var sourceId = options.sourceId;
|
|
|
|
var rootPath = options.rootPath;
|
|
|
|
var expandPaths = options.expandPaths;
|
|
|
|
var ontoggle = options.ontoggle;
|
|
|
|
var exposeApi = options.exposeApi;
|
|
|
|
|
|
|
|
var subElements = {};
|
2016-11-03 00:20:48 +01:00
|
|
|
var i;
|
|
|
|
var e;
|
|
|
|
var entryObj;
|
2017-08-01 00:29:36 +02:00
|
|
|
var expandableHeader;
|
2016-11-03 00:20:48 +01:00
|
|
|
var header;
|
|
|
|
var headerHead;
|
2016-11-27 22:51:34 +01:00
|
|
|
var value;
|
2017-05-11 16:08:10 +02:00
|
|
|
var strippedKey;
|
2017-05-12 11:19:50 +02:00
|
|
|
if (path !== undefined && rootPath !== undefined) {
|
2017-05-11 16:08:10 +02:00
|
|
|
strippedKey = path.substring(rootPath.length+(path[rootPath.length]==="."?1:0));
|
|
|
|
}
|
2016-11-03 00:20:48 +01:00
|
|
|
var element = $('<span class="debug-message-element"></span>');
|
2017-05-12 23:12:55 +02:00
|
|
|
element.collapse = function() {
|
|
|
|
element.find(".debug-message-expandable").parent().addClass("collapsed");
|
|
|
|
}
|
2017-05-10 16:49:12 +02:00
|
|
|
header = $('<span class="debug-message-row"></span>').appendTo(element);
|
2017-05-11 16:08:10 +02:00
|
|
|
if (sourceId) {
|
|
|
|
addMessageControls(header,sourceId,path,obj,rootPath,strippedKey);
|
|
|
|
}
|
2016-11-03 00:20:48 +01:00
|
|
|
if (!key) {
|
|
|
|
element.addClass("debug-message-top-level");
|
2017-05-11 16:08:10 +02:00
|
|
|
if (sourceId) {
|
|
|
|
var pinned = pinnedPaths[sourceId];
|
|
|
|
expandPaths = [];
|
|
|
|
if (pinned) {
|
|
|
|
for (var pinnedPath in pinned) {
|
|
|
|
if (pinned.hasOwnProperty(pinnedPath)) {
|
|
|
|
try {
|
|
|
|
var res = getMessageProperty({$:obj},pinned[pinnedPath]);
|
|
|
|
if (res !== undefined) {
|
|
|
|
expandPaths.push(pinnedPath);
|
|
|
|
}
|
|
|
|
} catch(err) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
expandPaths.sort();
|
|
|
|
}
|
2017-05-12 23:12:55 +02:00
|
|
|
element.clearPinned = function() {
|
|
|
|
element.find(".debug-message-row-pinned").removeClass("debug-message-row-pinned");
|
|
|
|
pinnedPaths[sourceId] = {};
|
|
|
|
}
|
2017-05-11 16:08:10 +02:00
|
|
|
}
|
2017-05-10 16:49:12 +02:00
|
|
|
} else {
|
|
|
|
if (!hideKey) {
|
|
|
|
$('<span class="debug-message-object-key"></span>').text(key).appendTo(header);
|
|
|
|
$('<span>: </span>').appendTo(header);
|
|
|
|
}
|
2016-11-03 00:20:48 +01:00
|
|
|
}
|
|
|
|
entryObj = $('<span class="debug-message-object-value"></span>').appendTo(header);
|
|
|
|
|
|
|
|
var isArray = Array.isArray(obj);
|
|
|
|
var isArrayObject = false;
|
2016-12-20 23:46:56 +01:00
|
|
|
if (obj && typeof obj === 'object' && obj.hasOwnProperty('type') && obj.hasOwnProperty('data') && ((obj.__encoded__ && obj.type === 'array') || obj.type === 'Buffer')) {
|
2016-11-03 00:20:48 +01:00
|
|
|
isArray = true;
|
|
|
|
isArrayObject = true;
|
|
|
|
}
|
|
|
|
if (obj === null || obj === undefined) {
|
|
|
|
$('<span class="debug-message-type-null">'+obj+'</span>').appendTo(entryObj);
|
2018-06-29 11:50:07 +02:00
|
|
|
} else if (obj.__encoded__ && obj.type === 'number') {
|
|
|
|
e = $('<span class="debug-message-type-number debug-message-object-header"></span>').text(obj.data).appendTo(entryObj);
|
2018-06-25 23:31:11 +02:00
|
|
|
} else if (typeHint === "function" || (obj.__encoded__ && obj.type === 'function')) {
|
|
|
|
e = $('<span class="debug-message-type-meta debug-message-object-header"></span>').text("function").appendTo(entryObj);
|
|
|
|
} else if (typeHint === "internal" || (obj.__encoded__ && obj.type === 'internal')) {
|
|
|
|
e = $('<span class="debug-message-type-meta debug-message-object-header"></span>').text("[internal]").appendTo(entryObj);
|
2016-11-03 00:20:48 +01:00
|
|
|
} else if (typeof obj === 'string') {
|
2016-11-03 00:40:17 +01:00
|
|
|
if (/[\t\n\r]/.test(obj)) {
|
|
|
|
element.addClass('collapsed');
|
|
|
|
$('<i class="fa fa-caret-right debug-message-object-handle"></i> ').prependTo(header);
|
|
|
|
makeExpandable(header, function() {
|
2018-05-11 15:05:52 +02:00
|
|
|
$('<span class="debug-message-type-meta debug-message-object-type-header"></span>').text(typeHint||'string').appendTo(header);
|
2016-11-03 00:40:17 +01:00
|
|
|
var row = $('<div class="debug-message-object-entry collapsed"></div>').appendTo(element);
|
2016-11-27 22:51:34 +01:00
|
|
|
$('<pre class="debug-message-type-string"></pre>').text(obj).appendTo(row);
|
2017-08-01 00:29:36 +02:00
|
|
|
},function(state) {if (ontoggle) { ontoggle(path,state);}}, checkExpanded(strippedKey,expandPaths));
|
2016-11-03 00:40:17 +01:00
|
|
|
}
|
2017-01-16 11:29:00 +01:00
|
|
|
e = $('<span class="debug-message-type-string debug-message-object-header"></span>').html('"'+formatString(sanitize(obj))+'"').appendTo(entryObj);
|
|
|
|
if (/^#[0-9a-f]{6}$/i.test(obj)) {
|
|
|
|
$('<span class="debug-message-type-string-swatch"></span>').css('backgroundColor',obj).appendTo(e);
|
|
|
|
}
|
2016-11-03 00:20:48 +01:00
|
|
|
|
|
|
|
} else if (typeof obj === 'number') {
|
2017-05-11 18:00:49 +02:00
|
|
|
e = $('<span class="debug-message-type-number"></span>').appendTo(entryObj);
|
|
|
|
|
2016-11-28 18:28:49 +01:00
|
|
|
if (Number.isInteger(obj) && (obj >= 0)) { // if it's a +ve integer
|
2016-11-27 22:51:34 +01:00
|
|
|
e.addClass("debug-message-type-number-toggle");
|
|
|
|
e.click(function(evt) {
|
|
|
|
evt.preventDefault();
|
2017-05-11 18:00:49 +02:00
|
|
|
formatNumber($(this), obj, sourceId, path, true);
|
2016-11-27 22:51:34 +01:00
|
|
|
});
|
|
|
|
}
|
2017-05-11 22:15:16 +02:00
|
|
|
formatNumber(e,obj,sourceId,path,false,typeHint==='hex'?'hex':undefined);
|
2017-05-11 18:00:49 +02:00
|
|
|
|
2016-11-03 00:20:48 +01:00
|
|
|
} else if (isArray) {
|
|
|
|
element.addClass('collapsed');
|
|
|
|
|
|
|
|
var originalLength = obj.length;
|
|
|
|
if (typeHint) {
|
|
|
|
var m = /\[(\d+)\]/.exec(typeHint);
|
|
|
|
if (m) {
|
|
|
|
originalLength = parseInt(m[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var data = obj;
|
|
|
|
var type = 'array';
|
|
|
|
if (isArrayObject) {
|
|
|
|
data = obj.data;
|
|
|
|
if (originalLength === undefined) {
|
|
|
|
originalLength = data.length;
|
|
|
|
}
|
2017-01-16 18:43:39 +01:00
|
|
|
if (data.__encoded__) {
|
|
|
|
data = data.data;
|
|
|
|
}
|
2016-11-03 00:20:48 +01:00
|
|
|
type = obj.type.toLowerCase();
|
|
|
|
} else if (/buffer/.test(typeHint)) {
|
|
|
|
type = 'buffer';
|
|
|
|
}
|
|
|
|
var fullLength = data.length;
|
|
|
|
|
2017-05-22 21:13:39 +02:00
|
|
|
if (originalLength > 0) {
|
2016-11-03 00:20:48 +01:00
|
|
|
$('<i class="fa fa-caret-right debug-message-object-handle"></i> ').prependTo(header);
|
|
|
|
var arrayRows = $('<div class="debug-message-array-rows"></div>').appendTo(element);
|
|
|
|
element.addClass('debug-message-buffer-raw');
|
2017-05-22 21:13:39 +02:00
|
|
|
}
|
|
|
|
if (key) {
|
2018-05-11 15:05:52 +02:00
|
|
|
headerHead = $('<span class="debug-message-type-meta"></span>').text(typeHint||(type+'['+originalLength+']')).appendTo(entryObj);
|
2017-05-22 21:13:39 +02:00
|
|
|
} else {
|
|
|
|
headerHead = $('<span class="debug-message-object-header"></span>').appendTo(entryObj);
|
|
|
|
$('<span>[ </span>').appendTo(headerHead);
|
|
|
|
var arrayLength = Math.min(originalLength,10);
|
|
|
|
for (i=0;i<arrayLength;i++) {
|
|
|
|
buildMessageSummaryValue(data[i]).appendTo(headerHead);
|
|
|
|
if (i < arrayLength-1) {
|
|
|
|
$('<span>, </span>').appendTo(headerHead);
|
2017-05-11 18:00:49 +02:00
|
|
|
}
|
|
|
|
}
|
2017-05-22 21:13:39 +02:00
|
|
|
if (originalLength > arrayLength) {
|
|
|
|
$('<span> …</span>').appendTo(headerHead);
|
|
|
|
}
|
|
|
|
if (arrayLength === 0) {
|
|
|
|
$('<span class="debug-message-type-meta">empty</span>').appendTo(headerHead);
|
|
|
|
}
|
|
|
|
$('<span> ]</span>').appendTo(headerHead);
|
|
|
|
}
|
|
|
|
if (originalLength > 0) {
|
2017-05-11 18:00:49 +02:00
|
|
|
|
2016-11-03 00:20:48 +01:00
|
|
|
makeExpandable(header,function() {
|
|
|
|
if (!key) {
|
2018-05-11 15:05:52 +02:00
|
|
|
headerHead = $('<span class="debug-message-type-meta debug-message-object-type-header"></span>').text(typeHint||(type+'['+originalLength+']')).appendTo(header);
|
2016-11-03 00:20:48 +01:00
|
|
|
}
|
|
|
|
if (type === 'buffer') {
|
|
|
|
var stringRow = $('<div class="debug-message-string-rows"></div>').appendTo(element);
|
|
|
|
var sr = $('<div class="debug-message-object-entry collapsed"></div>').appendTo(stringRow);
|
|
|
|
var stringEncoding = "";
|
|
|
|
try {
|
|
|
|
stringEncoding = String.fromCharCode.apply(null, new Uint16Array(data))
|
|
|
|
} catch(err) {
|
|
|
|
console.log(err);
|
|
|
|
}
|
2016-11-27 22:51:34 +01:00
|
|
|
$('<pre class="debug-message-type-string"></pre>').text(stringEncoding).appendTo(sr);
|
2016-11-03 00:20:48 +01:00
|
|
|
var bufferOpts = $('<span class="debug-message-buffer-opts"></span>').appendTo(headerHead);
|
2018-05-11 15:05:52 +02:00
|
|
|
var switchFormat = $('<a href="#"></a>').addClass('selected').text('raw').appendTo(bufferOpts).click(function(e) {
|
2016-11-03 00:20:48 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2017-05-11 18:00:49 +02:00
|
|
|
formatBuffer(element,$(this),sourceId,path,true);
|
|
|
|
});
|
|
|
|
formatBuffer(element,switchFormat,sourceId,path,false);
|
|
|
|
|
2016-11-03 00:20:48 +01:00
|
|
|
}
|
|
|
|
var row;
|
|
|
|
if (fullLength <= 10) {
|
|
|
|
for (i=0;i<fullLength;i++) {
|
|
|
|
row = $('<div class="debug-message-object-entry collapsed"></div>').appendTo(arrayRows);
|
2017-08-01 00:29:36 +02:00
|
|
|
subElements[path+"["+i+"]"] = buildMessageElement(
|
|
|
|
data[i],
|
|
|
|
{
|
|
|
|
key: ""+i,
|
|
|
|
typeHint: type==='buffer'?'hex':false,
|
|
|
|
hideKey: false,
|
|
|
|
path: path+"["+i+"]",
|
|
|
|
sourceId: sourceId,
|
|
|
|
rootPath: rootPath,
|
|
|
|
expandPaths: expandPaths,
|
|
|
|
ontoggle: ontoggle,
|
|
|
|
exposeApi: exposeApi
|
|
|
|
}
|
|
|
|
).appendTo(row);
|
2016-11-03 00:20:48 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i=0;i<fullLength;i+=10) {
|
|
|
|
var minRange = i;
|
|
|
|
row = $('<div class="debug-message-object-entry collapsed"></div>').appendTo(arrayRows);
|
|
|
|
header = $('<span></span>').appendTo(row);
|
|
|
|
$('<i class="fa fa-caret-right debug-message-object-handle"></i> ').appendTo(header);
|
|
|
|
makeExpandable(header, (function() {
|
|
|
|
var min = minRange;
|
|
|
|
var max = Math.min(fullLength-1,(minRange+9));
|
|
|
|
var parent = row;
|
|
|
|
return function() {
|
|
|
|
for (var i=min;i<=max;i++) {
|
|
|
|
var row = $('<div class="debug-message-object-entry collapsed"></div>').appendTo(parent);
|
2017-08-01 00:29:36 +02:00
|
|
|
subElements[path+"["+i+"]"] = buildMessageElement(
|
|
|
|
data[i],
|
|
|
|
{
|
|
|
|
key: ""+i,
|
|
|
|
typeHint: type==='buffer'?'hex':false,
|
|
|
|
hideKey: false,
|
|
|
|
path: path+"["+i+"]",
|
|
|
|
sourceId: sourceId,
|
|
|
|
rootPath: rootPath,
|
|
|
|
expandPaths: expandPaths,
|
|
|
|
ontoggle: ontoggle,
|
|
|
|
exposeApi: exposeApi
|
|
|
|
|
|
|
|
}
|
|
|
|
).appendTo(row);
|
2016-11-03 00:20:48 +01:00
|
|
|
}
|
|
|
|
}
|
2017-08-01 00:29:36 +02:00
|
|
|
})(),
|
|
|
|
(function() { var path = path+"["+i+"]"; return function(state) {if (ontoggle) { ontoggle(path,state);}}})(),
|
|
|
|
checkExpanded(strippedKey,expandPaths,minRange,Math.min(fullLength-1,(minRange+9))));
|
2016-11-03 00:20:48 +01:00
|
|
|
$('<span class="debug-message-object-key"></span>').html("["+minRange+" … "+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+' … '+originalLength+']</span></div>').appendTo(arrayRows);
|
|
|
|
}
|
|
|
|
}
|
2017-08-01 00:29:36 +02:00
|
|
|
},
|
|
|
|
function(state) {if (ontoggle) { ontoggle(path,state);}},
|
|
|
|
checkExpanded(strippedKey,expandPaths));
|
2016-11-03 00:20:48 +01:00
|
|
|
}
|
|
|
|
} else if (typeof obj === 'object') {
|
|
|
|
element.addClass('collapsed');
|
|
|
|
var keys = Object.keys(obj);
|
|
|
|
if (key || keys.length > 0) {
|
|
|
|
$('<i class="fa fa-caret-right debug-message-object-handle"></i> ').prependTo(header);
|
|
|
|
makeExpandable(header, function() {
|
|
|
|
if (!key) {
|
2018-05-11 15:05:52 +02:00
|
|
|
$('<span class="debug-message-type-meta debug-message-object-type-header"></span>').text('object').appendTo(header);
|
2016-11-03 00:20:48 +01:00
|
|
|
}
|
|
|
|
for (i=0;i<keys.length;i++) {
|
|
|
|
var row = $('<div class="debug-message-object-entry collapsed"></div>').appendTo(element);
|
2017-05-10 16:49:12 +02:00
|
|
|
var newPath = path;
|
2018-02-14 00:42:22 +01:00
|
|
|
if (newPath !== undefined) {
|
2017-07-26 16:47:19 +02:00
|
|
|
if (/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(keys[i])) {
|
|
|
|
newPath += (newPath.length > 0?".":"")+keys[i];
|
|
|
|
} else {
|
|
|
|
newPath += "[\""+keys[i].replace(/"/,"\\\"")+"\"]"
|
|
|
|
}
|
2017-05-10 16:49:12 +02:00
|
|
|
}
|
2017-08-01 00:29:36 +02:00
|
|
|
subElements[newPath] = buildMessageElement(
|
|
|
|
obj[keys[i]],
|
|
|
|
{
|
|
|
|
key: keys[i],
|
|
|
|
typeHint: false,
|
|
|
|
hideKey: false,
|
|
|
|
path: newPath,
|
|
|
|
sourceId: sourceId,
|
|
|
|
rootPath: rootPath,
|
|
|
|
expandPaths: expandPaths,
|
|
|
|
ontoggle: ontoggle,
|
|
|
|
exposeApi: exposeApi
|
|
|
|
|
|
|
|
}
|
|
|
|
).appendTo(row);
|
2016-11-03 00:20:48 +01:00
|
|
|
}
|
|
|
|
if (keys.length === 0) {
|
|
|
|
$('<div class="debug-message-object-entry debug-message-type-meta collapsed"></div>').text("empty").appendTo(element);
|
|
|
|
}
|
2017-08-01 00:29:36 +02:00
|
|
|
},
|
|
|
|
function(state) {if (ontoggle) { ontoggle(path,state);}},
|
|
|
|
checkExpanded(strippedKey,expandPaths));
|
2016-11-03 00:20:48 +01:00
|
|
|
}
|
|
|
|
if (key) {
|
2018-05-11 15:05:52 +02:00
|
|
|
$('<span class="debug-message-type-meta"></span>').text('object').appendTo(entryObj);
|
2016-11-03 00:20:48 +01:00
|
|
|
} else {
|
|
|
|
headerHead = $('<span class="debug-message-object-header"></span>').appendTo(entryObj);
|
|
|
|
$('<span>{ </span>').appendTo(headerHead);
|
|
|
|
var keysLength = Math.min(keys.length,5);
|
|
|
|
for (i=0;i<keysLength;i++) {
|
|
|
|
$('<span class="debug-message-object-key"></span>').text(keys[i]).appendTo(headerHead);
|
|
|
|
$('<span>: </span>').appendTo(headerHead);
|
|
|
|
buildMessageSummaryValue(obj[keys[i]]).appendTo(headerHead);
|
|
|
|
if (i < keysLength-1) {
|
|
|
|
$('<span>, </span>').appendTo(headerHead);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (keys.length > keysLength) {
|
|
|
|
$('<span> …</span>').appendTo(headerHead);
|
|
|
|
}
|
|
|
|
if (keysLength === 0) {
|
|
|
|
$('<span class="debug-message-type-meta">empty</span>').appendTo(headerHead);
|
|
|
|
}
|
|
|
|
$('<span> }</span>').appendTo(headerHead);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$('<span class="debug-message-type-other"></span>').text(""+obj).appendTo(entryObj);
|
|
|
|
}
|
2017-08-01 00:29:36 +02:00
|
|
|
if (exposeApi) {
|
|
|
|
element.prop('expand', function() { return function(targetPath, state) {
|
|
|
|
if (path === targetPath) {
|
2017-08-03 10:58:25 +02:00
|
|
|
if (header.prop('toggle')) {
|
|
|
|
header.prop('toggle')(state);
|
|
|
|
}
|
|
|
|
} else if (subElements[targetPath] && subElements[targetPath].prop('expand') ) {
|
2017-08-01 00:29:36 +02:00
|
|
|
subElements[targetPath].prop('expand')(targetPath,state);
|
2017-08-04 15:23:28 +02:00
|
|
|
} else {
|
|
|
|
for (var p in subElements) {
|
|
|
|
if (subElements.hasOwnProperty(p)) {
|
|
|
|
if (targetPath.indexOf(p) === 0) {
|
|
|
|
if (subElements[p].prop('expand') ) {
|
|
|
|
subElements[p].prop('expand')(targetPath,state);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-01 00:29:36 +02:00
|
|
|
}
|
|
|
|
}});
|
|
|
|
}
|
2016-11-03 00:20:48 +01:00
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
2017-05-11 16:08:10 +02:00
|
|
|
function normalisePropertyExpression(str) {
|
|
|
|
// This must be kept in sync with validatePropertyExpression
|
|
|
|
// in editor/js/ui/utils.js
|
2017-01-06 12:23:19 +01:00
|
|
|
|
|
|
|
var length = str.length;
|
2017-01-06 22:58:17 +01:00
|
|
|
if (length === 0) {
|
2017-05-11 16:08:10 +02:00
|
|
|
throw new Error("Invalid property expression: zero-length");
|
2017-01-06 22:58:17 +01:00
|
|
|
}
|
2017-05-11 16:08:10 +02:00
|
|
|
var parts = [];
|
2017-01-06 12:23:19 +01:00
|
|
|
var start = 0;
|
|
|
|
var inString = false;
|
|
|
|
var inBox = false;
|
|
|
|
var quoteChar;
|
|
|
|
var v;
|
|
|
|
for (var i=0;i<length;i++) {
|
|
|
|
var c = str[i];
|
|
|
|
if (!inString) {
|
|
|
|
if (c === "'" || c === '"') {
|
|
|
|
if (i != start) {
|
2017-05-11 16:08:10 +02:00
|
|
|
throw new Error("Invalid property expression: unexpected "+c+" at position "+i);
|
2017-01-06 12:23:19 +01:00
|
|
|
}
|
|
|
|
inString = true;
|
|
|
|
quoteChar = c;
|
|
|
|
start = i+1;
|
|
|
|
} else if (c === '.') {
|
2017-05-11 16:08:10 +02:00
|
|
|
if (i===0) {
|
|
|
|
throw new Error("Invalid property expression: unexpected . at position 0");
|
|
|
|
}
|
|
|
|
if (start != i) {
|
|
|
|
v = str.substring(start,i);
|
|
|
|
if (/^\d+$/.test(v)) {
|
|
|
|
parts.push(parseInt(v));
|
|
|
|
} else {
|
|
|
|
parts.push(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i===length-1) {
|
|
|
|
throw new Error("Invalid property expression: unterminated expression");
|
2017-01-06 12:23:19 +01:00
|
|
|
}
|
2017-01-06 15:32:37 +01:00
|
|
|
// Next char is first char of an identifier: a-z 0-9 $ _
|
|
|
|
if (!/[a-z0-9\$\_]/i.test(str[i+1])) {
|
2017-05-11 16:08:10 +02:00
|
|
|
throw new Error("Invalid property expression: unexpected "+str[i+1]+" at position "+(i+1));
|
2017-01-06 12:23:19 +01:00
|
|
|
}
|
|
|
|
start = i+1;
|
|
|
|
} else if (c === '[') {
|
|
|
|
if (i === 0) {
|
2017-05-11 16:08:10 +02:00
|
|
|
throw new Error("Invalid property expression: unexpected "+c+" at position "+i);
|
|
|
|
}
|
|
|
|
if (start != i) {
|
|
|
|
parts.push(str.substring(start,i));
|
2017-01-06 12:23:19 +01:00
|
|
|
}
|
|
|
|
if (i===length-1) {
|
2017-05-11 16:08:10 +02:00
|
|
|
throw new Error("Invalid property expression: unterminated expression");
|
2017-01-06 12:23:19 +01:00
|
|
|
}
|
|
|
|
// Next char is either a quote or a number
|
|
|
|
if (!/["'\d]/.test(str[i+1])) {
|
2017-05-11 16:08:10 +02:00
|
|
|
throw new Error("Invalid property expression: unexpected "+str[i+1]+" at position "+(i+1));
|
2017-01-06 12:23:19 +01:00
|
|
|
}
|
|
|
|
start = i+1;
|
|
|
|
inBox = true;
|
|
|
|
} else if (c === ']') {
|
|
|
|
if (!inBox) {
|
2017-05-11 16:08:10 +02:00
|
|
|
throw new Error("Invalid property expression: unexpected "+c+" at position "+i);
|
2017-01-06 12:23:19 +01:00
|
|
|
}
|
|
|
|
if (start != i) {
|
|
|
|
v = str.substring(start,i);
|
2017-05-11 16:08:10 +02:00
|
|
|
if (/^\d+$/.test(v)) {
|
|
|
|
parts.push(parseInt(v));
|
|
|
|
} else {
|
|
|
|
throw new Error("Invalid property expression: unexpected array expression at position "+start);
|
2017-01-06 12:23:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
start = i+1;
|
|
|
|
inBox = false;
|
|
|
|
} else if (c === ' ') {
|
2017-05-11 16:08:10 +02:00
|
|
|
throw new Error("Invalid property expression: unexpected ' ' at position "+i);
|
2017-01-06 12:23:19 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (c === quoteChar) {
|
|
|
|
if (i-start === 0) {
|
2017-05-11 16:08:10 +02:00
|
|
|
throw new Error("Invalid property expression: zero-length string at position "+start);
|
2017-01-06 12:23:19 +01:00
|
|
|
}
|
2017-05-11 16:08:10 +02:00
|
|
|
parts.push(str.substring(start,i));
|
|
|
|
// If inBox, next char must be a ]. Otherwise it may be [ or .
|
2017-01-06 12:23:19 +01:00
|
|
|
if (inBox && !/\]/.test(str[i+1])) {
|
2017-05-11 16:08:10 +02:00
|
|
|
throw new Error("Invalid property expression: unexpected array expression at position "+start);
|
2017-01-06 12:23:19 +01:00
|
|
|
} else if (!inBox && i+1!==length && !/[\[\.]/.test(str[i+1])) {
|
2017-05-11 16:08:10 +02:00
|
|
|
throw new Error("Invalid property expression: unexpected "+str[i+1]+" expression at position "+(i+1));
|
2017-01-06 12:23:19 +01:00
|
|
|
}
|
|
|
|
start = i+1;
|
|
|
|
inString = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (inBox || inString) {
|
2017-05-11 16:08:10 +02:00
|
|
|
throw new Error("Invalid property expression: unterminated expression");
|
|
|
|
}
|
|
|
|
if (start < length) {
|
|
|
|
parts.push(str.substring(start));
|
|
|
|
}
|
|
|
|
return parts;
|
|
|
|
}
|
|
|
|
|
|
|
|
function validatePropertyExpression(str) {
|
|
|
|
try {
|
|
|
|
var parts = normalisePropertyExpression(str);
|
|
|
|
return true;
|
|
|
|
} catch(err) {
|
2017-01-06 12:23:19 +01:00
|
|
|
return false;
|
|
|
|
}
|
2017-05-11 16:08:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getMessageProperty(msg,expr) {
|
|
|
|
var result = null;
|
|
|
|
var msgPropParts;
|
|
|
|
|
|
|
|
if (typeof expr === 'string') {
|
|
|
|
if (expr.indexOf('msg.')===0) {
|
|
|
|
expr = expr.substring(4);
|
|
|
|
}
|
|
|
|
msgPropParts = normalisePropertyExpression(expr);
|
|
|
|
} else {
|
|
|
|
msgPropParts = expr;
|
|
|
|
}
|
|
|
|
var m;
|
|
|
|
msgPropParts.reduce(function(obj, key) {
|
|
|
|
result = (typeof obj[key] !== "undefined" ? obj[key] : undefined);
|
|
|
|
if (result === undefined && obj.hasOwnProperty('type') && obj.hasOwnProperty('data')&& obj.hasOwnProperty('length')) {
|
|
|
|
result = (typeof obj.data[key] !== "undefined" ? obj.data[key] : undefined);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}, msg);
|
|
|
|
return result;
|
2017-01-06 12:23:19 +01:00
|
|
|
}
|
|
|
|
|
2017-11-30 14:13:35 +01:00
|
|
|
function separateIconPath(icon) {
|
|
|
|
var result = {module: "", file: ""};
|
|
|
|
if (icon) {
|
|
|
|
var index = icon.indexOf('/');
|
|
|
|
if (index !== -1) {
|
|
|
|
result.module = icon.slice(0, index);
|
|
|
|
result.file = icon.slice(index + 1);
|
|
|
|
} else {
|
|
|
|
result.file = icon;
|
|
|
|
}
|
2017-01-18 14:06:22 +01:00
|
|
|
}
|
2017-11-30 14:13:35 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getDefaultNodeIcon(def,node) {
|
2017-01-18 14:06:22 +01:00
|
|
|
var icon_url;
|
2018-03-22 06:14:09 +01:00
|
|
|
if (node && node.type === "subflow") {
|
|
|
|
icon_url = "node-red/subflow.png";
|
|
|
|
} else if (typeof def.icon === "function") {
|
2017-01-18 14:06:22 +01:00
|
|
|
try {
|
|
|
|
icon_url = def.icon.call(node);
|
|
|
|
} catch(err) {
|
|
|
|
console.log("Definition error: "+def.type+".icon",err);
|
|
|
|
icon_url = "arrow-in.png";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
icon_url = def.icon;
|
|
|
|
}
|
2017-11-30 14:13:35 +01:00
|
|
|
|
|
|
|
var iconPath = separateIconPath(icon_url);
|
|
|
|
if (!iconPath.module) {
|
2018-02-15 16:33:19 +01:00
|
|
|
if (def.set) {
|
|
|
|
iconPath.module = def.set.module;
|
|
|
|
} else {
|
|
|
|
// Handle subflow instance nodes that don't have def.set
|
|
|
|
iconPath.module = "node-red";
|
|
|
|
}
|
2017-11-30 14:13:35 +01:00
|
|
|
}
|
|
|
|
return iconPath;
|
|
|
|
}
|
|
|
|
|
2018-03-14 05:51:50 +01:00
|
|
|
function isIconExists(iconPath) {
|
|
|
|
var iconSets = RED.nodes.getIconSets();
|
|
|
|
var iconFileList = iconSets[iconPath.module];
|
|
|
|
if (iconFileList && iconFileList.indexOf(iconPath.file) !== -1) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-30 14:13:35 +01:00
|
|
|
function getNodeIcon(def,node) {
|
|
|
|
if (def.category === 'config') {
|
|
|
|
return "icons/node-red/cog.png"
|
|
|
|
} else if (node && node.type === 'tab') {
|
|
|
|
return "icons/node-red/subflow.png"
|
|
|
|
} else if (node && node.type === 'unknown') {
|
|
|
|
return "icons/node-red/alert.png"
|
|
|
|
} else if (node && node.icon) {
|
|
|
|
var iconPath = separateIconPath(node.icon);
|
2018-03-14 05:51:50 +01:00
|
|
|
if (isIconExists(iconPath)) {
|
2017-11-30 14:13:35 +01:00
|
|
|
return "icons/" + node.icon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var iconPath = getDefaultNodeIcon(def, node);
|
2018-03-14 05:51:50 +01:00
|
|
|
if (def.category === 'subflows') {
|
|
|
|
if (!isIconExists(iconPath)) {
|
|
|
|
return "icons/node-red/subflow.png";
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 14:13:35 +01:00
|
|
|
return "icons/"+iconPath.module+"/"+iconPath.file;
|
2017-01-18 14:06:22 +01:00
|
|
|
}
|
|
|
|
|
2016-11-22 13:57:08 +01:00
|
|
|
function getNodeLabel(node,defaultLabel) {
|
|
|
|
defaultLabel = defaultLabel||"";
|
2017-05-22 12:35:45 +02:00
|
|
|
var l;
|
|
|
|
if (node.type === 'tab') {
|
|
|
|
l = node.label || defaultLabel
|
|
|
|
} else {
|
|
|
|
l = node._def.label;
|
|
|
|
try {
|
|
|
|
l = (typeof l === "function" ? l.call(node) : l)||defaultLabel;
|
|
|
|
} catch(err) {
|
|
|
|
console.log("Definition error: "+node.type+".label",err);
|
|
|
|
l = defaultLabel;
|
|
|
|
}
|
2016-11-22 13:57:08 +01:00
|
|
|
}
|
|
|
|
return RED.text.bidi.enforceTextDirectionWithUCC(l);
|
|
|
|
}
|
|
|
|
|
2018-01-22 14:46:11 +01:00
|
|
|
function addSpinnerOverlay(container,contain) {
|
|
|
|
var spinner = $('<div class="projects-dialog-spinner "><img src="red/images/spin.svg"/></div>').appendTo(container);
|
|
|
|
if (contain) {
|
|
|
|
spinner.addClass('projects-dialog-spinner-contain');
|
|
|
|
}
|
|
|
|
return spinner;
|
|
|
|
}
|
|
|
|
|
2018-06-25 23:31:11 +02:00
|
|
|
function decodeObject(payload,format) {
|
|
|
|
if ((format === 'number') && (payload === "NaN")) {
|
|
|
|
payload = Number.NaN;
|
2018-06-29 11:50:07 +02:00
|
|
|
} else if ((format === 'number') && (payload === "Infinity")) {
|
|
|
|
payload = Infinity;
|
|
|
|
} else if ((format === 'number') && (payload === "-Infinity")) {
|
|
|
|
payload = -Infinity;
|
2018-06-25 23:31:11 +02:00
|
|
|
} else if (format === 'Object' || /^array/.test(format) || format === 'boolean' || format === 'number' ) {
|
|
|
|
payload = JSON.parse(payload);
|
|
|
|
} else if (/error/i.test(format)) {
|
|
|
|
payload = JSON.parse(payload);
|
|
|
|
payload = (payload.name?payload.name+": ":"")+payload.message;
|
|
|
|
} else if (format === 'null') {
|
|
|
|
payload = null;
|
|
|
|
} else if (format === 'undefined') {
|
|
|
|
payload = undefined;
|
|
|
|
} else if (/^buffer/.test(format)) {
|
|
|
|
var buffer = payload;
|
|
|
|
payload = [];
|
|
|
|
for (var c = 0; c < buffer.length; c += 2) {
|
|
|
|
payload.push(parseInt(buffer.substr(c, 2), 16));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return payload;
|
|
|
|
}
|
|
|
|
|
2018-07-10 12:41:46 +02:00
|
|
|
function parseContextKey(key) {
|
|
|
|
var parts = {};
|
|
|
|
var m = /^#:\((\S+?)\)::(.*)$/.exec(key);
|
|
|
|
if (m) {
|
|
|
|
parts.store = m[1];
|
|
|
|
parts.key = m[2];
|
|
|
|
} else {
|
|
|
|
parts.key = key;
|
|
|
|
if (RED.settings.context) {
|
|
|
|
parts.store = RED.settings.context.default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return parts;
|
|
|
|
}
|
2018-06-25 23:31:11 +02:00
|
|
|
|
2016-11-03 00:20:48 +01:00
|
|
|
return {
|
|
|
|
createObjectElement: buildMessageElement,
|
2017-05-11 16:08:10 +02:00
|
|
|
getMessageProperty: getMessageProperty,
|
|
|
|
normalisePropertyExpression: normalisePropertyExpression,
|
2017-01-18 14:06:22 +01:00
|
|
|
validatePropertyExpression: validatePropertyExpression,
|
2017-11-30 14:13:35 +01:00
|
|
|
separateIconPath: separateIconPath,
|
|
|
|
getDefaultNodeIcon: getDefaultNodeIcon,
|
2016-11-22 13:57:08 +01:00
|
|
|
getNodeIcon: getNodeIcon,
|
2017-05-10 16:49:12 +02:00
|
|
|
getNodeLabel: getNodeLabel,
|
2018-06-25 23:31:11 +02:00
|
|
|
addSpinnerOverlay: addSpinnerOverlay,
|
2018-07-10 12:41:46 +02:00
|
|
|
decodeObject: decodeObject,
|
|
|
|
parseContextKey: parseContextKey
|
2016-11-03 00:20:48 +01:00
|
|
|
}
|
|
|
|
})();
|