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

Add sidebar menu and migrate existing panels to new api

This commit is contained in:
Nick O'Leary 2015-07-03 10:07:40 +01:00
parent 6cfa4976fe
commit 6359b90352
9 changed files with 139 additions and 63 deletions

View File

@ -160,7 +160,10 @@ var RED = (function() {
function loadEditor() { function loadEditor() {
RED.menu.init({id:"btn-sidemenu", RED.menu.init({id:"btn-sidemenu",
options: [ options: [
{id:"menu-item-sidebar",label:RED._("menu.label.sidebar"),toggle:true,onselect:RED.sidebar.toggleSidebar, selected: true}, {id:"menu-item-sidebar-menu",label:RED._("menu.label.sidebar.sidebar"),options:[
{id:"menu-item-sidebar",label:RED._("menu.label.sidebar.show"),toggle:true,onselect:RED.sidebar.toggleSidebar, selected: true},
null
]},
{id:"menu-item-status",label:RED._("menu.label.displayStatus"),toggle:true,onselect:toggleStatus, selected: true}, {id:"menu-item-status",label:RED._("menu.label.displayStatus"),toggle:true,onselect:toggleStatus, selected: true},
null, null,
{id:"menu-item-import",label:RED._("menu.label.import"),options:[ {id:"menu-item-import",label:RED._("menu.label.import"),options:[
@ -172,8 +175,6 @@ var RED = (function() {
{id:"menu-item-export-library",label:RED._("menu.label.library"),disabled:true,onselect:RED.library.export} {id:"menu-item-export-library",label:RED._("menu.label.library"),disabled:true,onselect:RED.library.export}
]}, ]},
null, null,
{id:"menu-item-config-nodes",label:RED._("menu.label.configurationNodes"),onselect:RED.sidebar.config.show},
null,
{id:"menu-item-subflow",label:RED._("menu.label.subflows"), options: [ {id:"menu-item-subflow",label:RED._("menu.label.subflows"), options: [
{id:"menu-item-subflow-create",label:RED._("menu.label.createSubflow"),onselect:RED.subflow.createSubflow}, {id:"menu-item-subflow-create",label:RED._("menu.label.createSubflow"),onselect:RED.subflow.createSubflow},
{id:"menu-item-subflow-convert",label:RED._("menu.label.selectionToSubflow"),disabled:true,onselect:RED.subflow.convertToSubflow}, {id:"menu-item-subflow-convert",label:RED._("menu.label.selectionToSubflow"),disabled:true,onselect:RED.subflow.convertToSubflow},

View File

@ -20,26 +20,67 @@ RED.sidebar = (function() {
id:"sidebar-tabs", id:"sidebar-tabs",
onchange:function(tab) { onchange:function(tab) {
$("#sidebar-content").children().hide(); $("#sidebar-content").children().hide();
$("#"+tab.id).show(); if (tab.onchange) {
tab.onchange.call(tab);
}
$(tab.content).show();
}, },
onremove: function(tab) { onremove: function(tab) {
$("#"+tab.id).remove(); $(tab.content).remove();
if (tab.onremove) {
tab.onremove.call(tab);
}
} }
}); });
function addTab(title,content,closeable) { var knownTabs = {
$("#sidebar-content").append(content);
$(content).hide(); };
var id = content.id || "tab-"+title.replace(/([;&,\.\+\*\~':"\!\^#$%@\[\]\(\)=>\|])/g, "\\$1" );
sidebar_tabs.addTab({id:id,label:title,closeable:closeable}); function addTab(title,content,closeable,visible) {
//content.style.position = "absolute"; var options;
//$('#sidebar').tabs("refresh"); if (typeof title === "string") {
// TODO: legacy support in case anyone uses this...
options = {
id: content.id,
label: title,
name: title,
content: content,
closeable: closeable,
visible: visible
}
} else if (typeof title === "object") {
options = title;
}
$("#sidebar-content").append(options.content);
$(options.content).hide();
var id = options.id;
RED.menu.addItem("menu-item-sidebar-menu",{
id:"menu-item-sidebar-menu-"+options.id,
label:options.name,
onselect:function() {
showSidebar(options.id);
}
});
knownTabs[options.id] = options;
if (options.visible !== false) {
sidebar_tabs.addTab(knownTabs[options.id]);
}
} }
function removeTab(title) { function removeTab(id) {
sidebar_tabs.removeTab("tab-"+title); sidebar_tabs.removeTab(id);
delete knownTabs[id];
RED.menu.removeItem("menu-item-sidebar-menu-"+id);
//TODO: remove menu item
} }
var sidebarSeparator = {}; var sidebarSeparator = {};
$("#sidebar-separator").draggable({ $("#sidebar-separator").draggable({
axis: "x", axis: "x",
@ -70,7 +111,7 @@ RED.sidebar = (function() {
if (sidebarSeparator.opening) { if (sidebarSeparator.opening) {
newSidebarWidth -= 13; newSidebarWidth -= 13;
} }
if (newSidebarWidth > 150) { if (newSidebarWidth > 150) {
if (sidebarSeparator.chartWidth+d < 200) { if (sidebarSeparator.chartWidth+d < 200) {
ui.position.left = 200+sidebarSeparator.start-sidebarSeparator.chartWidth; ui.position.left = 200+sidebarSeparator.start-sidebarSeparator.chartWidth;
@ -78,7 +119,7 @@ RED.sidebar = (function() {
newSidebarWidth = sidebarSeparator.width-d; newSidebarWidth = sidebarSeparator.width-d;
} }
} }
if (newSidebarWidth < 150) { if (newSidebarWidth < 150) {
if (!sidebarSeparator.closing) { if (!sidebarSeparator.closing) {
$("#sidebar").addClass("closing"); $("#sidebar").addClass("closing");
@ -117,7 +158,7 @@ RED.sidebar = (function() {
eventHandler.emit("resize"); eventHandler.emit("resize");
} }
}); });
function toggleSidebar(state) { function toggleSidebar(state) {
if (!state) { if (!state) {
$("#main-container").addClass("sidebar-closed"); $("#main-container").addClass("sidebar-closed");
@ -127,28 +168,35 @@ RED.sidebar = (function() {
} }
eventHandler.emit("resize"); eventHandler.emit("resize");
} }
function showSidebar(id) { function showSidebar(id) {
if (id) { if (id) {
sidebar_tabs.activateTab("tab-"+id); if (!containsTab(id)) {
sidebar_tabs.addTab(knownTabs[id]);
}
sidebar_tabs.activateTab(id);
if (!RED.menu.isSelected("menu-item-sidebar")) {
RED.menu.setSelected("menu-item-sidebar",true);
}
} }
} }
function containsTab(id) { function containsTab(id) {
return sidebar_tabs.contains("tab-"+id); return sidebar_tabs.contains(id);
} }
function init () { function init () {
RED.keyboard.add(/* SPACE */ 32,{ctrl:true},function(){RED.menu.setSelected("menu-item-sidebar",!RED.menu.isSelected("menu-item-sidebar"));d3.event.preventDefault();}); RED.keyboard.add(/* SPACE */ 32,{ctrl:true},function(){RED.menu.setSelected("menu-item-sidebar",!RED.menu.isSelected("menu-item-sidebar"));d3.event.preventDefault();});
showSidebar(); showSidebar();
RED.sidebar.info.show(); RED.sidebar.info.init();
RED.sidebar.config.init();
// hide info bar at start if screen rather narrow... // hide info bar at start if screen rather narrow...
if ($(window).width() < 600) { toggleSidebar(); } if ($(window).width() < 600) { toggleSidebar(); }
} }
var eventHandler = (function() { var eventHandler = (function() {
var handlers = {}; var handlers = {};
return { return {
on: function(evt,func) { on: function(evt,func) {
handlers[evt] = handlers[evt]||[]; handlers[evt] = handlers[evt]||[];
@ -159,12 +207,12 @@ RED.sidebar = (function() {
for (var i=0;i<handlers[evt].length;i++) { for (var i=0;i<handlers[evt].length;i++) {
handlers[evt][i](arg); handlers[evt][i](arg);
} }
} }
} }
} }
})(); })();
return { return {
init: init, init: init,
addTab: addTab, addTab: addTab,
@ -174,5 +222,5 @@ RED.sidebar = (function() {
toggleSidebar: toggleSidebar, toggleSidebar: toggleSidebar,
on: eventHandler.on on: eventHandler.on
} }
})(); })();

View File

@ -16,17 +16,24 @@
RED.sidebar.config = (function() { RED.sidebar.config = (function() {
var content = document.createElement("div"); var content = document.createElement("div");
content.id = "tab-config";
content.style.paddingTop = "4px"; content.style.paddingTop = "4px";
content.style.paddingLeft = "4px"; content.style.paddingLeft = "4px";
content.style.paddingRight = "4px"; content.style.paddingRight = "4px";
var list = $("<ul>",{class:"tab-config-list"}).appendTo(content); var list = $("<ul>",{class:"tab-config-list"}).appendTo(content);
function init() {
RED.sidebar.addTab({
id: "config",
label: RED._("sidebar.config.label"),
name: RED._("sidebar.config.name"),
content: content,
closeable: true,
visible: false,
onchange: function() { refresh(); }
});
}
function show() { function show() {
if (!RED.sidebar.containsTab("config")) {
RED.sidebar.addTab(RED._("sidebar.config.title"),content,true);
}
refresh(); refresh();
RED.sidebar.show("config"); RED.sidebar.show("config");
} }
@ -78,6 +85,7 @@ RED.sidebar.config = (function() {
}); });
} }
return { return {
init:init,
show:show, show:show,
refresh:refresh refresh:refresh
} }

View File

@ -27,17 +27,23 @@ RED.sidebar.info = (function() {
}); });
var content = document.createElement("div"); var content = document.createElement("div");
content.id = "tab-info";
content.style.paddingTop = "4px"; content.style.paddingTop = "4px";
content.style.paddingLeft = "4px"; content.style.paddingLeft = "4px";
content.style.paddingRight = "4px"; content.style.paddingRight = "4px";
var propertiesExpanded = false; var propertiesExpanded = false;
function init() {
RED.sidebar.addTab({
id: "info",
label: RED._("sidebar.info.label"),
name: RED._("sidebar.info.name"),
content: content
});
}
function show() { function show() {
if (!RED.sidebar.containsTab("info")) {
RED.sidebar.addTab(RED._("sidebar.info.title"),content,false);
}
RED.sidebar.show("info"); RED.sidebar.show("info");
} }
@ -184,6 +190,7 @@ RED.sidebar.info = (function() {
}); });
return { return {
init: init,
show: show, show: show,
refresh:refresh, refresh:refresh,
clear: clear clear: clear

View File

@ -13,32 +13,32 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
RED.tabs = (function() { RED.tabs = (function() {
function createTabs(options) { function createTabs(options) {
var tabs = {}; var tabs = {};
var ul = $("#"+options.id) var ul = $("#"+options.id)
ul.addClass("red-ui-tabs"); ul.addClass("red-ui-tabs");
ul.children().first().addClass("active"); ul.children().first().addClass("active");
ul.children().addClass("red-ui-tab"); ul.children().addClass("red-ui-tab");
function onTabClick() { function onTabClick() {
activateTab($(this)); activateTab($(this));
return false; return false;
} }
function onTabDblClick() { function onTabDblClick() {
if (options.ondblclick) { if (options.ondblclick) {
options.ondblclick(tabs[$(this).attr('href').slice(1)]); options.ondblclick(tabs[$(this).attr('href').slice(1)]);
} }
return false; return false;
} }
function activateTab(link) { function activateTab(link) {
if (typeof link === "string") { if (typeof link === "string") {
link = ul.find("a[href='#"+link+"']"); link = ul.find("a[href='#"+link+"']");
@ -51,7 +51,7 @@ RED.tabs = (function() {
} }
} }
} }
function updateTabWidths() { function updateTabWidths() {
var tabs = ul.find("li.red-ui-tab"); var tabs = ul.find("li.red-ui-tab");
var width = ul.width(); var width = ul.width();
@ -60,11 +60,11 @@ RED.tabs = (function() {
var pct = 100*tabWidth/width; var pct = 100*tabWidth/width;
tabs.css({width:pct+"%"}); tabs.css({width:pct+"%"});
} }
ul.find("li.red-ui-tab a").on("click",onTabClick).on("dblclick",onTabDblClick); ul.find("li.red-ui-tab a").on("click",onTabClick).on("dblclick",onTabDblClick);
updateTabWidths(); updateTabWidths();
function removeTab(id) { function removeTab(id) {
var li = ul.find("a[href='#"+id+"']").parent(); var li = ul.find("a[href='#"+id+"']").parent();
if (li.hasClass("active")) { if (li.hasClass("active")) {
@ -81,20 +81,20 @@ RED.tabs = (function() {
delete tabs[id]; delete tabs[id];
updateTabWidths(); updateTabWidths();
} }
return { return {
addTab: function(tab) { addTab: function(tab) {
tabs[tab.id] = tab; tabs[tab.id] = tab;
var li = $("<li/>",{class:"red-ui-tab"}).appendTo(ul); var li = $("<li/>",{class:"red-ui-tab"}).appendTo(ul);
var link = $("<a/>",{href:"#"+tab.id, class:"red-ui-tab-label"}).appendTo(li); var link = $("<a/>",{href:"#"+tab.id, class:"red-ui-tab-label"}).appendTo(li);
link.html(tab.label); link.html(tab.label);
link.on("click",onTabClick); link.on("click",onTabClick);
link.on("dblclick",onTabDblClick); link.on("dblclick",onTabDblClick);
if (tab.closeable) { if (tab.closeable) {
var closeLink = $("<a/>",{href:"#",class:"red-ui-tab-close"}).appendTo(li); var closeLink = $("<a/>",{href:"#",class:"red-ui-tab-close"}).appendTo(li);
closeLink.html('<i class="fa fa-times" />'); closeLink.html('<i class="fa fa-times" />');
closeLink.on("click",function(event) { closeLink.on("click",function(event) {
removeTab(tab.id); removeTab(tab.id);
}); });
@ -127,7 +127,7 @@ RED.tabs = (function() {
} }
} }
return { return {
create: createTabs create: createTabs
} }

View File

@ -28,6 +28,7 @@ RED.workspaces = (function() {
var tabId = RED.nodes.id(); var tabId = RED.nodes.id();
do { do {
workspaceIndex += 1; workspaceIndex += 1;
//TODO: nls of Sheet
} while($("#workspace-tabs a[title='Sheet "+workspaceIndex+"']").size() !== 0); } while($("#workspace-tabs a[title='Sheet "+workspaceIndex+"']").size() !== 0);
ws = {type:"tab",id:tabId,label:"Sheet "+workspaceIndex}; ws = {type:"tab",id:tabId,label:"Sheet "+workspaceIndex};

View File

@ -16,16 +16,18 @@
}, },
"menu": { "menu": {
"label": { "label": {
"sidebar": "Sidebar", "sidebar": {
"displayStatus": "Display node status", "sidebar": "Sidebar",
"show": "Toggle Sidebar"
},
"displayStatus": "Display Node Status",
"import": "Import", "import": "Import",
"export": "Export", "export": "Export",
"clipboard": "Clipboard", "clipboard": "Clipboard",
"library": "Library", "library": "Library",
"configurationNodes": "Configuration nodes",
"subflows": "Subflows", "subflows": "Subflows",
"createSubflow": "Create subflow", "createSubflow": "Create Subflow",
"selectionToSubflow": "Selection to subflow", "selectionToSubflow": "Selection to Subflow",
"workspaces": "Workspaces", "workspaces": "Workspaces",
"add": "Add", "add": "Add",
"rename": "Rename", "rename": "Rename",
@ -175,7 +177,8 @@
}, },
"sidebar": { "sidebar": {
"info": { "info": {
"title": "info", "name": "Node Information",
"label": "info",
"node": "Node", "node": "Node",
"type": "Type", "type": "Type",
"id": "ID", "id": "ID",
@ -186,7 +189,8 @@
"arrayItems": "__count__ items" "arrayItems": "__count__ items"
}, },
"config": { "config": {
"title": "config" "name": "Configuration nodes",
"label": "config"
} }
} }
} }

View File

@ -128,7 +128,6 @@
}, },
onpaletteadd: function() { onpaletteadd: function() {
var content = document.createElement("div"); var content = document.createElement("div");
content.id = "tab-debug";
var toolbar = document.createElement("div"); var toolbar = document.createElement("div");
toolbar.id = "debug-toolbar"; toolbar.id = "debug-toolbar";
@ -140,7 +139,12 @@
messages.id = "debug-content"; messages.id = "debug-content";
content.appendChild(messages); content.appendChild(messages);
RED.sidebar.addTab(this._("debug.sidebarTitle"),content); RED.sidebar.addTab({
id: "debug",
label: this._("debug.sidebar.label"),
name: this._("debug.sidebar.name"),
content: content
});
function getTimestamp() { function getTimestamp() {
var d = new Date(); var d = new Date();

View File

@ -81,7 +81,10 @@
"activated": "Successfully activated: __label__", "activated": "Successfully activated: __label__",
"deactivated": "Successfully deactivated: __label__" "deactivated": "Successfully deactivated: __label__"
}, },
"sidebarTitle": "debug" "sidebar": {
"label": "debug",
"name": "Debug messages"
}
}, },
"exec": { "exec": {
"spawnerr": "Spawn command must be just the command - no spaces or extra parameters", "spawnerr": "Spawn command must be just the command - no spaces or extra parameters",