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

Save/restore tabs

This commit is contained in:
Nicholas O'Leary 2013-10-25 21:34:00 +01:00
parent f3e33f4c29
commit 3604286793
5 changed files with 115 additions and 67 deletions

View File

@ -121,7 +121,7 @@
</div><!-- /palette --> </div><!-- /palette -->
<div id="workspace"> <div id="workspace">
<ul id="workspace-tabs"><li><a href="#tab-0">main</a></li></ul> <ul id="workspace-tabs"></ul>
<div id="chart"></div> <div id="chart"></div>
</div> </div>

View File

@ -21,12 +21,20 @@ RED.nodes = function() {
var configNodes = {}; var configNodes = {};
var links = []; var links = [];
var defaultWorkspace;
var workspaces = {};
function registerType(nt,def) { function registerType(nt,def) {
node_defs[nt] = def; node_defs[nt] = def;
// TODO: too tightly coupled into palette UI // TODO: too tightly coupled into palette UI
RED.palette.add(nt,def); RED.palette.add(nt,def);
} }
function getID() {
return (1+Math.random()*4294967295).toString(16);
}
function getType(type) { function getType(type) {
return node_defs[type]; return node_defs[type];
} }
@ -87,6 +95,10 @@ RED.nodes = function() {
} }
} }
function addWorkspace(ws) {
workspaces[ws.id] = ws;
}
function getAllFlowNodes(node) { function getAllFlowNodes(node) {
var visited = {}; var visited = {};
visited[node.id] = true; visited[node.id] = true;
@ -167,6 +179,9 @@ RED.nodes = function() {
//TODO: rename this (createCompleteNodeSet) //TODO: rename this (createCompleteNodeSet)
function createCompleteNodeSet() { function createCompleteNodeSet() {
var nns = []; var nns = [];
for (var i in workspaces) {
nns.push(workspaces[i]);
}
for (var i in configNodes) { for (var i in configNodes) {
nns.push(convertNode(configNodes[i])); nns.push(convertNode(configNodes[i]));
} }
@ -194,12 +209,27 @@ RED.nodes = function() {
} }
for (var i in newNodes) { for (var i in newNodes) {
var n = newNodes[i]; var n = newNodes[i];
if (!getType(n.type)) { if (n.type != "workspace" && !getType(n.type)) {
// TODO: get this UI thing out of here! (see below as well) // TODO: get this UI thing out of here! (see below as well)
RED.notify("<strong>Failed to import nodes</strong>: unrecognised type '"+n.type+"'","error"); RED.notify("<strong>Failed to import nodes</strong>: unrecognised type '"+n.type+"'","error");
return null; return null;
} }
} }
for (var i in newNodes) {
var n = newNodes[i];
if (n.type === "workspace") {
if (defaultWorkspace == null) {
defaultWorkspace = n;
}
addWorkspace(n);
RED.view.addWorkspace(n);
}
}
if (defaultWorkspace == null) {
defaultWorkspace = { type:"workspace", id:getID(), label:"default" };
addWorkspace(defaultWorkspace);
RED.view.addWorkspace(defaultWorkspace);
}
var node_map = {}; var node_map = {};
var new_nodes = []; var new_nodes = [];
@ -207,6 +237,7 @@ RED.nodes = function() {
for (var i in newNodes) { for (var i in newNodes) {
var n = newNodes[i]; var n = newNodes[i];
if (n.type !== "workspace") {
var def = getType(n.type); var def = getType(n.type);
if (def && def.category == "config") { if (def && def.category == "config") {
if (!RED.nodes.node(n.id)) { if (!RED.nodes.node(n.id)) {
@ -219,14 +250,15 @@ RED.nodes = function() {
RED.nodes.add(configNode); RED.nodes.add(configNode);
} }
} else { } else {
if (n.z == null) {
n.z = 0;
}
var node = {x:n.x,y:n.y,z:n.z,type:0,wires:n.wires}; var node = {x:n.x,y:n.y,z:n.z,type:0,wires:n.wires};
if (createNewIds) { if (createNewIds) {
node.id = (1+Math.random()*4294967295).toString(16); node.z = RED.view.getWorkspace();
node.id = getID();
} else { } else {
node.id = n.id; node.id = n.id;
if (node.z == null || !workspaces[node.z]) {
node.z = RED.view.getWorkspace();
}
} }
node.type = n.type; node.type = n.type;
node._def = def; node._def = def;
@ -257,6 +289,7 @@ RED.nodes = function() {
new_nodes.push(node); new_nodes.push(node);
} }
} }
}
for (var i in new_nodes) { for (var i in new_nodes) {
var n = new_nodes[i]; var n = new_nodes[i];
for (var w1 in n.wires) { for (var w1 in n.wires) {
@ -288,6 +321,7 @@ RED.nodes = function() {
addLink: addLink, addLink: addLink,
remove: removeNode, remove: removeNode,
removeLink: removeLink, removeLink: removeLink,
addWorkspace: addWorkspace,
eachNode: function(cb) { eachNode: function(cb) {
for (var n in nodes) { for (var n in nodes) {
cb(nodes[n]); cb(nodes[n]);
@ -309,6 +343,7 @@ RED.nodes = function() {
getAllFlowNodes: getAllFlowNodes, getAllFlowNodes: getAllFlowNodes,
createExportableNodeSet: createExportableNodeSet, createExportableNodeSet: createExportableNodeSet,
createCompleteNodeSet: createCompleteNodeSet, createCompleteNodeSet: createCompleteNodeSet,
id: getID,
nodes: nodes, // TODO: exposed for d3 vis nodes: nodes, // TODO: exposed for d3 vis
links: links // TODO: exposed for d3 vis links: links // TODO: exposed for d3 vis
}; };

View File

@ -72,6 +72,10 @@ RED.tabs = function() {
if (options.onadd) { if (options.onadd) {
options.onadd(tab); options.onadd(tab);
} }
link.attr("title",tab.label);
if (ul.find("li.red-ui-tab").size() == 1) {
activateTab(link);
}
}, },
activateTab: activateTab, activateTab: activateTab,
resize: updateTabWidths resize: updateTabWidths

View File

@ -70,8 +70,7 @@ RED.view = function() {
var workspace_tabs = RED.tabs.create({ var workspace_tabs = RED.tabs.create({
id: "workspace-tabs", id: "workspace-tabs",
onchange: function(id) { onchange: function(id) {
console.log(id); RED.view.setWorkspace(id.slice(1));
RED.view.setWorkspace(id.split("-")[1]);
}, },
ondblclick: function(id) { ondblclick: function(id) {
console.log("DC:",id); console.log("DC:",id);
@ -87,15 +86,13 @@ RED.view = function() {
$('#workspace-menu-list').append(menuli); $('#workspace-menu-list').append(menuli);
} }
}); });
workspace_tabs.addTab({id:"tab-1",label:"Workspace 1"});
workspace_tabs.addTab({id:"tab-2",label:"Workspace 2"});
workspace_tabs.addTab({id:"tab-3",label:"Workspace 3"});
workspace_tabs.addTab({id:"tab-4",label:"Workspace 4"});
$('#btn-workspace-add').on("click",function() { $('#btn-workspace-add').on("click",function() {
var id = Math.floor(Math.random()*2000); var tabId = RED.nodes.id();
workspace_tabs.addTab({id:"tab-"+id,label:"Workspace "+id}); var ws = {type:"workspace",id:tabId,label:"Workspace "+tabId};
workspace_tabs.activateTab("tab-"+id); RED.nodes.addWorkspace(ws);
workspace_tabs.addTab(ws);
workspace_tabs.activateTab(tabId);
}); });
@ -454,6 +451,7 @@ RED.view = function() {
table += "<tr><td>Type</td><td>&nbsp;"+node.type+"</td></tr>"; table += "<tr><td>Type</td><td>&nbsp;"+node.type+"</td></tr>";
table += "<tr><td>ID</td><td>&nbsp;"+node.id+"</td></tr>"; table += "<tr><td>ID</td><td>&nbsp;"+node.id+"</td></tr>";
table += "<tr><td>WS</td><td>&nbsp;"+node.z+"</td></tr>";
table += '<tr class="blank"><td colspan="2">&nbsp;Properties</td></tr>'; table += '<tr class="blank"><td colspan="2">&nbsp;Properties</td></tr>';
for (var n in node._def.defaults) { for (var n in node._def.defaults) {
if ((n != "func")&&(n != "template")) { if ((n != "func")&&(n != "template")) {
@ -994,6 +992,13 @@ RED.view = function() {
mouse_mode = state; mouse_mode = state;
} }
}, },
addWorkspace: function(ws) {
workspace_tabs.addTab(ws);
workspace_tabs.resize();
},
getWorkspace: function() {
return activeWorkspace;
},
setWorkspace: function(z) { setWorkspace: function(z) {
activeWorkspace = z; activeWorkspace = z;
clearSelection(); clearSelection();

View File

@ -292,10 +292,12 @@ var parseConfig = function() {
missingTypes = []; missingTypes = [];
for (var i in activeConfig) { for (var i in activeConfig) {
var type = activeConfig[i].type; var type = activeConfig[i].type;
if (type != "workspace") {
var nt = node_type_registry.get(type); var nt = node_type_registry.get(type);
if (!nt && missingTypes.indexOf(type) == -1) { if (!nt && missingTypes.indexOf(type) == -1) {
missingTypes.push(type); missingTypes.push(type);
} }
}
}; };
if (missingTypes.length > 0) { if (missingTypes.length > 0) {
util.log("[red] Waiting for missing types to be registered:"); util.log("[red] Waiting for missing types to be registered:");
@ -309,6 +311,7 @@ var parseConfig = function() {
events.emit("nodes-starting"); events.emit("nodes-starting");
for (var i in activeConfig) { for (var i in activeConfig) {
var nn = null; var nn = null;
if (activeConfig[i].type != "workspace") {
var nt = node_type_registry.get(activeConfig[i].type); var nt = node_type_registry.get(activeConfig[i].type);
if (nt) { if (nt) {
try { try {
@ -323,6 +326,7 @@ var parseConfig = function() {
util.log("[red] unknown type: "+activeConfig[i].type); util.log("[red] unknown type: "+activeConfig[i].type);
} }
} }
}
// Clean up any orphaned credentials // Clean up any orphaned credentials
var deletedCredentials = false; var deletedCredentials = false;
for (var c in credentials) { for (var c in credentials) {