Split node html to isolate bad nodes when loading

This commit is contained in:
Nick O'Leary 2018-05-11 22:30:57 +01:00
parent d49c7a3adb
commit 2d5980ff2a
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
4 changed files with 34 additions and 9 deletions

View File

@ -15,6 +15,25 @@
**/
(function() {
function appendNodeConfig(nodeConfig) {
var m = /<!-- --- \[red-module:(\S+)\] --- -->/.exec(nodeConfig.trim());
var moduleId;
if (m) {
moduleId = m[1];
} else {
moduleId = "unknown";
}
try {
$("body").append(nodeConfig);
} catch(err) {
RED.notify(RED._("notification.errors.failedToAppendNode",{module:moduleId, error:err.toString()}),{
type: "error",
timeout: 10000
});
console.log("["+moduleId+"] "+err.toString());
}
}
function loadNodeList() {
$.ajax({
headers: {
@ -55,7 +74,11 @@
cache: false,
url: 'nodes',
success: function(data) {
$("body").append(data);
var configs = data.trim().split(/(?=<!-- --- \[red-module:\S+\] --- -->)/);
configs.forEach(function(data) {
appendNodeConfig(data);
});
$("body").i18n();
$("#palette > .palette-spinner").hide();
$(".palette-scroll").removeClass("hide");
@ -296,7 +319,7 @@
addedTypes = addedTypes.concat(m.types);
RED.i18n.loadCatalog(id, function() {
$.get('nodes/'+id, function(data) {
$("body").append(data);
appendNodeConfig(data);
});
});
});
@ -324,7 +347,7 @@
RED.notify(RED._("palette.event.nodeEnabled", {count:msg.types.length})+typeList,"success");
} else {
$.get('nodes/'+msg.id, function(data) {
$("body").append(data);
appendNodeConfig(data);
typeList = "<ul><li>"+msg.types.join("</li><li>")+"</li></ul>";
RED.notify(RED._("palette.event.nodeAdded", {count:msg.types.length})+typeList,"success");
});

View File

@ -106,7 +106,8 @@
"lostConnectionTry": "Try now",
"cannotAddSubflowToItself": "Cannot add subflow to itself",
"cannotAddCircularReference": "Cannot add subflow - circular reference detected",
"unsupportedVersion": "Using an unsupported version of Node.js<br/>You should upgrade to the latest Node.js LTS release"
"unsupportedVersion": "<p>Using an unsupported version of Node.js</p><p>You should upgrade to the latest Node.js LTS release</p>",
"failedToAppendNode": "<p>Failed to load '__module__'</p><p>__error__</p>"
}
},
"clipboard": {

View File

@ -426,6 +426,7 @@ function getAllNodeConfigs(lang) {
var id = nodeList[i];
var config = moduleConfigs[getModule(id)].nodes[getNode(id)];
if (config.enabled && !config.err) {
result += "\n<!-- --- [red-module:"+id+"] --- -->\n";
result += config.config;
result += loader.getNodeHelp(config,lang||"en-US")||"";
//script += config.script;
@ -448,7 +449,7 @@ function getNodeConfig(id,lang) {
}
config = config.nodes[getNode(id)];
if (config) {
var result = config.config;
var result = "<!-- --- [red-module:"+id+"] --- -->\n"+config.config;
result += loader.getNodeHelp(config,lang||"en-US")
//if (config.script) {

View File

@ -364,8 +364,8 @@ describe("red/nodes/registry/registry",function() {
config: "configA",
types: [ "test-a","test-b"]
}, "0.0.1");
typeRegistry.getNodeConfig("test-module/test-name").should.eql('configAHEtest-nameLP');
typeRegistry.getAllNodeConfigs().should.eql('configAHEtest-nameLP');
typeRegistry.getNodeConfig("test-module/test-name").should.eql('<!-- --- [red-module:test-module/test-name] --- -->\nconfigAHEtest-nameLP');
typeRegistry.getAllNodeConfigs().should.eql('\n<!-- --- [red-module:test-module/test-name] --- -->\nconfigAHEtest-nameLP');
typeRegistry.addNodeSet("test-module/test-name-2",{
id: "test-module/test-name-2",
@ -376,8 +376,8 @@ describe("red/nodes/registry/registry",function() {
config: "configB",
types: [ "test-c","test-d"]
}, "0.0.1");
typeRegistry.getNodeConfig("test-module/test-name-2").should.eql('configBHEtest-name-2LP');
typeRegistry.getAllNodeConfigs().should.eql('configAHEtest-nameLPconfigBHEtest-name-2LP');
typeRegistry.getNodeConfig("test-module/test-name-2").should.eql('<!-- --- [red-module:test-module/test-name-2] --- -->\nconfigBHEtest-name-2LP');
typeRegistry.getAllNodeConfigs().should.eql('\n<!-- --- [red-module:test-module/test-name] --- -->\nconfigAHEtest-nameLP\n<!-- --- [red-module:test-module/test-name-2] --- -->\nconfigBHEtest-name-2LP');
});
});
describe('#getModuleInfo', function() {