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

Add import-to-new-tab option

This commit is contained in:
Nick O'Leary 2016-09-23 22:02:12 +01:00
parent d29abc2724
commit 252040f03b
5 changed files with 67 additions and 14 deletions

View File

@ -594,7 +594,7 @@ RED.nodes = (function() {
return true; return true;
} }
function importNodes(newNodesObj,createNewIds) { function importNodes(newNodesObj,createNewIds,createMissingWorkspace) {
var i; var i;
var n; var n;
var newNodes; var newNodes;
@ -668,6 +668,7 @@ RED.nodes = (function() {
var nid; var nid;
var def; var def;
var configNode; var configNode;
var missingWorkspace = null;
// Find all tabs and subflow templates // Find all tabs and subflow templates
for (i=0;i<newNodes.length;i++) { for (i=0;i<newNodes.length;i++) {
@ -736,10 +737,18 @@ RED.nodes = (function() {
} else { } else {
n.z = workspace_map[n.z]; n.z = workspace_map[n.z];
if (!workspaces[n.z]) { if (!workspaces[n.z]) {
if (createMissingWorkspace) {
if (missingWorkspace === null) {
missingWorkspace = RED.workspaces.add(null,true);
new_workspaces.push(missingWorkspace);
}
n.z = missingWorkspace.id;
} else {
n.z = activeWorkspace; n.z = activeWorkspace;
} }
} }
} }
}
existingConfigNode = RED.nodes.node(n.id); existingConfigNode = RED.nodes.node(n.id);
if (existingConfigNode) { if (existingConfigNode) {
if (n.z && existingConfigNode.z !== n.z) { if (n.z && existingConfigNode.z !== n.z) {
@ -792,16 +801,32 @@ RED.nodes = (function() {
} else { } else {
node.z = workspace_map[node.z]; node.z = workspace_map[node.z];
if (!workspaces[node.z]) { if (!workspaces[node.z]) {
if (createMissingWorkspace) {
if (missingWorkspace === null) {
missingWorkspace = RED.workspaces.add(null,true);
new_workspaces.push(missingWorkspace);
}
node.z = missingWorkspace.id;
} else {
node.z = activeWorkspace; node.z = activeWorkspace;
} }
} }
}
node.id = getID(); node.id = getID();
} else { } else {
node.id = n.id; node.id = n.id;
if (node.z == null || (!workspaces[node.z] && !subflow_map[node.z])) { if (node.z == null || (!workspaces[node.z] && !subflow_map[node.z])) {
if (createMissingWorkspace) {
if (missingWorkspace === null) {
missingWorkspace = RED.workspaces.add(null,true);
new_workspaces.push(missingWorkspace);
}
node.z = missingWorkspace.id;
} else {
node.z = activeWorkspace; node.z = activeWorkspace;
} }
} }
}
node.type = n.type; node.type = n.type;
node._def = def; node._def = def;
if (n.type.substring(0,7) === "subflow") { if (n.type.substring(0,7) === "subflow") {
@ -946,7 +971,7 @@ RED.nodes = (function() {
} }
RED.workspaces.refresh(); RED.workspaces.refresh();
return [new_nodes,new_links,new_workspaces,new_subflows]; return [new_nodes,new_links,new_workspaces,new_subflows,missingWorkspace];
} }
// TODO: supports filter.z|type // TODO: supports filter.z|type

View File

@ -63,7 +63,7 @@ RED.clipboard = (function() {
class: "primary", class: "primary",
text: RED._("common.label.import"), text: RED._("common.label.import"),
click: function() { click: function() {
RED.view.importNodes($("#clipboard-import").val()); RED.view.importNodes($("#clipboard-import").val(),$("#import-tab > a.selected").attr('id') === 'import-tab-new');
$( this ).dialog( "close" ); $( this ).dialog( "close" );
} }
} }
@ -79,7 +79,7 @@ RED.clipboard = (function() {
exportNodesDialog = exportNodesDialog =
'<div class="form-row">'+ '<div class="form-row">'+
'<label style="width:auto;margin-right: 10px;">Export to clipboard</label>'+ '<label style="width:auto;margin-right: 10px;" data-i18n="clipboard.export.copy"></label>'+
'<span id="export-range-group" class="button-group">'+ '<span id="export-range-group" class="button-group">'+
'<a id="export-range-selected" class="editor-button toggle" href="#" data-i18n="clipboard.export.selected"></a>'+ '<a id="export-range-selected" class="editor-button toggle" href="#" data-i18n="clipboard.export.selected"></a>'+
'<a id="export-range-flow" class="editor-button toggle" href="#" data-i18n="clipboard.export.current"></a>'+ '<a id="export-range-flow" class="editor-button toggle" href="#" data-i18n="clipboard.export.current"></a>'+
@ -100,6 +100,13 @@ RED.clipboard = (function() {
'<textarea style="resize: none; width: 100%; border-radius: 0px;font-family: monospace; font-size: 12px; background:#eee; padding-left: 0.5em; box-sizing:border-box;" id="clipboard-import" rows="5" placeholder="'+ '<textarea style="resize: none; width: 100%; border-radius: 0px;font-family: monospace; font-size: 12px; background:#eee; padding-left: 0.5em; box-sizing:border-box;" id="clipboard-import" rows="5" placeholder="'+
RED._("clipboard.pasteNodes")+ RED._("clipboard.pasteNodes")+
'"></textarea>'+ '"></textarea>'+
'</div>'+
'<div class="form-row">'+
'<label style="width:auto;margin-right: 10px;" data-i18n="clipboard.import.import"></label>'+
'<span id="import-tab" class="button-group">'+
'<a id="import-tab-current" class="editor-button toggle selected" href="#" data-i18n="clipboard.export.current"></a>'+
'<a id="import-tab-new" class="editor-button toggle" href="#" data-i18n="clipboard.import.newFlow"></a>'+
'</span>'+
'</div>'; '</div>';
} }
@ -123,6 +130,8 @@ RED.clipboard = (function() {
function importNodes() { function importNodes() {
dialogContainer.empty(); dialogContainer.empty();
dialogContainer.append($(importNodesDialog)); dialogContainer.append($(importNodesDialog));
dialogContainer.i18n();
$("#clipboard-dialog-ok").show(); $("#clipboard-dialog-ok").show();
$("#clipboard-dialog-cancel").show(); $("#clipboard-dialog-cancel").show();
$("#clipboard-dialog-close").hide(); $("#clipboard-dialog-close").hide();
@ -131,6 +140,15 @@ RED.clipboard = (function() {
$("#clipboard-import").keyup(validateImport); $("#clipboard-import").keyup(validateImport);
$("#clipboard-import").on('paste',function() { setTimeout(validateImport,10)}); $("#clipboard-import").on('paste',function() { setTimeout(validateImport,10)});
$("#import-tab > a").click(function(evt) {
evt.preventDefault();
if ($(this).hasClass('disabled') || $(this).hasClass('selected')) {
return;
}
$(this).parent().children().removeClass('selected');
$(this).addClass('selected');
});
dialog.dialog("option","title",RED._("clipboard.importNodes")).dialog("open"); dialog.dialog("option","title",RED._("clipboard.importNodes")).dialog("open");
} }

View File

@ -1389,7 +1389,7 @@ RED.view = (function() {
options.push({name:"delete",disabled:(moving_set.length===0 && selected_link === null),onselect:function() {deleteSelection();}}); options.push({name:"delete",disabled:(moving_set.length===0 && selected_link === null),onselect:function() {deleteSelection();}});
options.push({name:"cut",disabled:(moving_set.length===0),onselect:function() {copySelection();deleteSelection();}}); options.push({name:"cut",disabled:(moving_set.length===0),onselect:function() {copySelection();deleteSelection();}});
options.push({name:"copy",disabled:(moving_set.length===0),onselect:function() {copySelection();}}); options.push({name:"copy",disabled:(moving_set.length===0),onselect:function() {copySelection();}});
options.push({name:"paste",disabled:(clipboard.length===0),onselect:function() {importNodes(clipboard,true);}}); options.push({name:"paste",disabled:(clipboard.length===0),onselect:function() {importNodes(clipboard,false,true);}});
options.push({name:"edit",disabled:(moving_set.length != 1),onselect:function() { RED.editor.edit(mdn);}}); options.push({name:"edit",disabled:(moving_set.length != 1),onselect:function() { RED.editor.edit(mdn);}});
options.push({name:"select",onselect:function() {selectAll();}}); options.push({name:"select",onselect:function() {selectAll();}});
options.push({name:"undo",disabled:(RED.history.depth() === 0),onselect:function() {RED.history.pop();}}); options.push({name:"undo",disabled:(RED.history.depth() === 0),onselect:function() {RED.history.pop();}});
@ -2194,19 +2194,22 @@ RED.view = (function() {
* - all "selected" * - all "selected"
* - attached to mouse for placing - "IMPORT_DRAGGING" * - attached to mouse for placing - "IMPORT_DRAGGING"
*/ */
function importNodes(newNodesStr,touchImport) { function importNodes(newNodesStr,addNewFlow,touchImport) {
try { try {
var activeSubflowChanged; var activeSubflowChanged;
if (activeSubflow) { if (activeSubflow) {
activeSubflowChanged = activeSubflow.changed; activeSubflowChanged = activeSubflow.changed;
} }
var result = RED.nodes.import(newNodesStr,true); var result = RED.nodes.import(newNodesStr,true,addNewFlow);
if (result) { if (result) {
var new_nodes = result[0]; var new_nodes = result[0];
var new_links = result[1]; var new_links = result[1];
var new_workspaces = result[2]; var new_workspaces = result[2];
var new_subflows = result[3]; var new_subflows = result[3];
var new_default_workspace = result[4];
if (addNewFlow && new_default_workspace) {
RED.workspaces.show(new_default_workspace.id);
}
var new_ms = new_nodes.filter(function(n) { return n.hasOwnProperty("x") && n.hasOwnProperty("y") && n.z == RED.workspaces.active() }).map(function(n) { return {n:n};}); var new_ms = new_nodes.filter(function(n) { return n.hasOwnProperty("x") && n.hasOwnProperty("y") && n.z == RED.workspaces.active() }).map(function(n) { return {n:n};});
var new_node_ids = new_nodes.map(function(n){ return n.id; }); var new_node_ids = new_nodes.map(function(n){ return n.id; });

View File

@ -20,7 +20,7 @@ RED.workspaces = (function() {
var activeWorkspace = 0; var activeWorkspace = 0;
var workspaceIndex = 0; var workspaceIndex = 0;
function addWorkspace(ws) { function addWorkspace(ws,skipHistoryEntry) {
if (ws) { if (ws) {
workspace_tabs.addTab(ws); workspace_tabs.addTab(ws);
workspace_tabs.resize(); workspace_tabs.resize();
@ -34,10 +34,13 @@ RED.workspaces = (function() {
RED.nodes.addWorkspace(ws); RED.nodes.addWorkspace(ws);
workspace_tabs.addTab(ws); workspace_tabs.addTab(ws);
workspace_tabs.activateTab(tabId); workspace_tabs.activateTab(tabId);
if (!skipHistoryEntry) {
RED.history.push({t:'add',workspaces:[ws],dirty:RED.nodes.dirty()}); RED.history.push({t:'add',workspaces:[ws],dirty:RED.nodes.dirty()});
RED.nodes.dirty(true); RED.nodes.dirty(true);
} }
} }
return ws;
}
function deleteWorkspace(ws) { function deleteWorkspace(ws) {
if (workspace_tabs.count() == 1) { if (workspace_tabs.count() == 1) {
return; return;

View File

@ -95,6 +95,10 @@
"compact":"compact", "compact":"compact",
"formatted":"formatted", "formatted":"formatted",
"copy": "Export to clipboard" "copy": "Export to clipboard"
},
"import": {
"import": "Import to",
"newFlow": "new flow"
} }
}, },
"deploy": { "deploy": {