mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Handle import errors on initial load and report to user
This commit is contained in:
parent
fa532da8c7
commit
2c6cda1f27
@ -42,7 +42,8 @@
|
||||
"loadNodeCatalogs": "Loading Node catalogs",
|
||||
"loadNodes": "Loading Nodes __count__",
|
||||
"loadFlows": "Loading Flows",
|
||||
"importFlows": "Adding Flows to workspace"
|
||||
"importFlows": "Adding Flows to workspace",
|
||||
"importError": "<p>Error adding flows</p><p>__message__</p>"
|
||||
},
|
||||
"workspace": {
|
||||
"defaultName": "Flow __number__",
|
||||
@ -207,6 +208,8 @@
|
||||
"download": "Download",
|
||||
"importUnrecognised": "Imported unrecognised type:",
|
||||
"importUnrecognised_plural": "Imported unrecognised types:",
|
||||
"importDuplicate": "Imported duplicate node:",
|
||||
"importDuplicate_plural": "Imported duplicate nodes:",
|
||||
"nodesExported": "Nodes exported to clipboard",
|
||||
"nodesImported": "Imported:",
|
||||
"nodeCopied": "__count__ node copied",
|
||||
|
@ -1107,8 +1107,9 @@ RED.nodes = (function() {
|
||||
if (!options.generateIds) {
|
||||
if (!options.importMap[id]) {
|
||||
// No conflict resolution for this node
|
||||
if (nodes[id] || configNodes[id] || workspaces[id] || subflows[id] || groups[id]) {
|
||||
existingNodes.push(id);
|
||||
var existing = nodes[id] || configNodes[id] || workspaces[id] || subflows[id] || groups[id];
|
||||
if (existing) {
|
||||
existingNodes.push({existing:existing, imported:n});
|
||||
}
|
||||
} else if (options.importMap[id] === "replace") {
|
||||
nodesToReplace.push(n);
|
||||
@ -1120,7 +1121,21 @@ RED.nodes = (function() {
|
||||
})
|
||||
|
||||
if (existingNodes.length > 0) {
|
||||
var existingNodesError = new Error();
|
||||
var errorMessage = RED._("clipboard.importDuplicate",{count:existingNodes.length});
|
||||
var nodeList = $("<ul>");
|
||||
var existingNodesCount = Math.min(5,existingNodes.length);
|
||||
for (var i=0;i<existingNodesCount;i++) {
|
||||
var conflict = existingNodes[i];
|
||||
$("<li>").text(
|
||||
conflict.existing.id+
|
||||
" [ "+conflict.existing.type+ ((conflict.imported.type !== conflict.existing.type)?" | "+conflict.imported.type:"")+" ]").appendTo(nodeList)
|
||||
}
|
||||
if (existingNodesCount !== existingNodes.length) {
|
||||
$("<li>").text(RED._("deploy.confirm.plusNMore",{count:existingNodes.length-existingNodesCount})).appendTo(nodeList)
|
||||
}
|
||||
var wrapper = $("<p>").append(nodeList);
|
||||
|
||||
var existingNodesError = new Error(errorMessage+wrapper.html());
|
||||
existingNodesError.code = "import_conflict";
|
||||
existingNodesError.importConfig = identifyImportConflicts(newNodes);
|
||||
throw existingNodesError;
|
||||
|
@ -178,11 +178,21 @@ var RED = (function() {
|
||||
var currentHash = window.location.hash;
|
||||
RED.nodes.version(nodes.rev);
|
||||
loader.reportProgress(RED._("event.importFlows"),90 )
|
||||
RED.nodes.import(nodes.flows);
|
||||
RED.nodes.dirty(false);
|
||||
RED.view.redraw(true);
|
||||
if (/^#flow\/.+$/.test(currentHash)) {
|
||||
RED.workspaces.show(currentHash.substring(6));
|
||||
try {
|
||||
RED.nodes.import(nodes.flows);
|
||||
RED.nodes.dirty(false);
|
||||
RED.view.redraw(true);
|
||||
if (/^#flow\/.+$/.test(currentHash)) {
|
||||
RED.workspaces.show(currentHash.substring(6));
|
||||
}
|
||||
} catch(err) {
|
||||
RED.notify(
|
||||
RED._("event.importError", {message: err.message}),
|
||||
{
|
||||
fixed: true,
|
||||
type: 'error'
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
done();
|
||||
|
Loading…
Reference in New Issue
Block a user