2015-10-17 20:05:23 +02:00
|
|
|
/**
|
2016-01-13 00:03:33 +01:00
|
|
|
* Copyright 2013, 2016 IBM Corp.
|
2015-10-17 20:05:23 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
**/
|
|
|
|
RED.sidebar.config = (function() {
|
|
|
|
|
|
|
|
|
|
|
|
var content = document.createElement("div");
|
2016-05-03 16:45:29 +02:00
|
|
|
content.className = "sidebar-node-config";
|
2015-10-17 20:05:23 +02:00
|
|
|
|
2016-01-13 00:55:18 +01:00
|
|
|
$('<div class="button-group sidebar-header">'+
|
2016-02-18 11:28:22 +01:00
|
|
|
'<a class="sidebar-header-button-toggle selected" id="workspace-config-node-filter-all" href="#"><span data-i18n="sidebar.config.filterAll"></span></a>'+
|
|
|
|
'<a class="sidebar-header-button-toggle" id="workspace-config-node-filter-unused" href="#"><span data-i18n="sidebar.config.filterUnused"></span></a> '+
|
2016-01-13 00:03:33 +01:00
|
|
|
'</div>'
|
|
|
|
).appendTo(content);
|
|
|
|
|
2016-01-12 18:54:53 +01:00
|
|
|
|
2016-01-13 00:03:33 +01:00
|
|
|
var toolbar = $('<div>'+
|
|
|
|
'<a class="sidebar-footer-button" id="workspace-config-node-collapse-all" href="#"><i class="fa fa-angle-double-up"></i></a> '+
|
|
|
|
'<a class="sidebar-footer-button" id="workspace-config-node-expand-all" href="#"><i class="fa fa-angle-double-down"></i></a>'+
|
|
|
|
'</div>');
|
2016-01-12 18:54:53 +01:00
|
|
|
|
2016-01-13 00:03:33 +01:00
|
|
|
var globalCategories = $("<div>").appendTo(content);
|
2016-01-12 18:54:53 +01:00
|
|
|
var flowCategories = $("<div>").appendTo(content);
|
|
|
|
var subflowCategories = $("<div>").appendTo(content);
|
|
|
|
|
|
|
|
var showUnusedOnly = false;
|
|
|
|
|
|
|
|
var categories = {};
|
|
|
|
|
|
|
|
function getOrCreateCategory(name,parent,label) {
|
|
|
|
name = name.replace(/\./i,"-");
|
|
|
|
if (!categories[name]) {
|
|
|
|
var container = $('<div class="palette-category workspace-config-node-category" id="workspace-config-node-category-'+name+'"></div>').appendTo(parent);
|
|
|
|
var header = $('<div class="workspace-config-node-tray-header palette-header"><i class="fa fa-angle-down expanded"></i></div>').appendTo(container);
|
|
|
|
if (label) {
|
2016-01-13 11:30:24 +01:00
|
|
|
$('<span class="config-node-label"/>').text(label).appendTo(header);
|
2016-01-12 18:54:53 +01:00
|
|
|
} else {
|
2016-01-13 11:30:24 +01:00
|
|
|
$('<span class="config-node-label" data-i18n="sidebar.config.'+name+'">').appendTo(header);
|
2016-01-12 18:54:53 +01:00
|
|
|
}
|
2016-01-13 11:30:24 +01:00
|
|
|
$('<span class="config-node-filter-info"></span>').appendTo(header);
|
2016-01-12 18:54:53 +01:00
|
|
|
category = $('<ul class="palette-content config-node-list"></ul>').appendTo(container);
|
|
|
|
container.i18n();
|
|
|
|
var icon = header.find("i");
|
|
|
|
var result = {
|
2016-01-13 11:30:24 +01:00
|
|
|
label: label,
|
2016-01-12 18:54:53 +01:00
|
|
|
list: category,
|
|
|
|
size: function() {
|
|
|
|
return result.list.find("li:not(.config_node_none)").length
|
|
|
|
},
|
|
|
|
open: function(snap) {
|
|
|
|
if (!icon.hasClass("expanded")) {
|
|
|
|
icon.addClass("expanded");
|
|
|
|
if (snap) {
|
|
|
|
result.list.show();
|
|
|
|
} else {
|
|
|
|
result.list.slideDown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
close: function(snap) {
|
|
|
|
if (icon.hasClass("expanded")) {
|
|
|
|
icon.removeClass("expanded");
|
|
|
|
if (snap) {
|
|
|
|
result.list.hide();
|
|
|
|
} else {
|
|
|
|
result.list.slideUp();
|
|
|
|
}
|
|
|
|
}
|
2016-01-13 00:03:33 +01:00
|
|
|
},
|
|
|
|
isOpen: function() {
|
|
|
|
return icon.hasClass("expanded");
|
2016-01-12 18:54:53 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
header.on('click', function(e) {
|
2016-01-13 00:03:33 +01:00
|
|
|
if (result.isOpen()) {
|
2016-01-12 18:54:53 +01:00
|
|
|
result.close();
|
|
|
|
} else {
|
|
|
|
result.open();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
categories[name] = result;
|
2016-01-13 11:30:24 +01:00
|
|
|
} else {
|
|
|
|
if (categories[name].label !== label) {
|
|
|
|
categories[name].list.parent().find('.config-node-label').text(label);
|
|
|
|
categories[name].label = label;
|
|
|
|
}
|
2016-01-12 18:54:53 +01:00
|
|
|
}
|
|
|
|
return categories[name];
|
|
|
|
}
|
|
|
|
|
|
|
|
function createConfigNodeList(id,nodes) {
|
|
|
|
var category = getOrCreateCategory(id.replace(/\./i,"-"))
|
|
|
|
var list = category.list;
|
|
|
|
|
2015-10-17 20:05:23 +02:00
|
|
|
nodes.sort(function(A,B) {
|
|
|
|
if (A.type < B.type) { return -1;}
|
|
|
|
if (A.type > B.type) { return 1;}
|
|
|
|
return 0;
|
|
|
|
});
|
2016-01-12 18:54:53 +01:00
|
|
|
if (showUnusedOnly) {
|
2016-01-13 11:30:24 +01:00
|
|
|
var hiddenCount = nodes.length;
|
2016-01-12 18:54:53 +01:00
|
|
|
nodes = nodes.filter(function(n) {
|
|
|
|
return n.users.length === 0;
|
|
|
|
})
|
2016-01-13 11:30:24 +01:00
|
|
|
hiddenCount = hiddenCount - nodes.length;
|
|
|
|
if (hiddenCount > 0) {
|
|
|
|
list.parent().find('.config-node-filter-info').text(RED._('sidebar.config.filtered',{count:hiddenCount})).show();
|
|
|
|
} else {
|
|
|
|
list.parent().find('.config-node-filter-info').hide();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
list.parent().find('.config-node-filter-info').hide();
|
2016-01-12 18:54:53 +01:00
|
|
|
}
|
2015-10-17 20:05:23 +02:00
|
|
|
list.empty();
|
|
|
|
if (nodes.length === 0) {
|
|
|
|
$('<li class="config_node_none" data-i18n="sidebar.config.none">NONE</li>').i18n().appendTo(list);
|
2016-01-12 18:54:53 +01:00
|
|
|
category.close(true);
|
2015-10-17 20:05:23 +02:00
|
|
|
} else {
|
|
|
|
var currentType = "";
|
|
|
|
nodes.forEach(function(node) {
|
|
|
|
var label = "";
|
|
|
|
if (typeof node._def.label == "function") {
|
2016-08-11 15:49:22 +02:00
|
|
|
try {
|
|
|
|
label = node._def.label.call(node);
|
|
|
|
} catch(err) {
|
2016-10-21 14:47:54 +02:00
|
|
|
console.log("Definition error: "+node._def.type+".label",err);
|
|
|
|
label = node._def.type;
|
2016-08-11 15:49:22 +02:00
|
|
|
}
|
|
|
|
|
2015-10-17 20:05:23 +02:00
|
|
|
} else {
|
|
|
|
label = node._def.label;
|
|
|
|
}
|
|
|
|
label = label || node.id;
|
|
|
|
if (node.type != currentType) {
|
|
|
|
$('<li class="config_node_type">'+node.type+'</li>').appendTo(list);
|
|
|
|
currentType = node.type;
|
|
|
|
}
|
|
|
|
|
2016-09-30 00:46:29 +02:00
|
|
|
var entry = $('<li class="palette_node config_node palette_node_id_'+node.id.replace(/\./g,"-")+'"></li>').appendTo(list);
|
2015-10-17 20:05:23 +02:00
|
|
|
$('<div class="palette_label"></div>').text(label).appendTo(entry);
|
|
|
|
|
|
|
|
var iconContainer = $('<div/>',{class:"palette_icon_container palette_icon_container_right"}).text(node.users.length).appendTo(entry);
|
|
|
|
if (node.users.length === 0) {
|
|
|
|
entry.addClass("config_node_unused");
|
|
|
|
}
|
|
|
|
entry.on('click',function(e) {
|
|
|
|
RED.sidebar.info.refresh(node);
|
|
|
|
});
|
|
|
|
entry.on('dblclick',function(e) {
|
|
|
|
RED.editor.editConfig("", node.type, node.id);
|
|
|
|
});
|
|
|
|
var userArray = node.users.map(function(n) { return n.id });
|
|
|
|
entry.on('mouseover',function(e) {
|
|
|
|
RED.nodes.eachNode(function(node) {
|
|
|
|
if( userArray.indexOf(node.id) != -1) {
|
|
|
|
node.highlighted = true;
|
|
|
|
node.dirty = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
RED.view.redraw();
|
|
|
|
});
|
|
|
|
|
|
|
|
entry.on('mouseout',function(e) {
|
|
|
|
RED.nodes.eachNode(function(node) {
|
|
|
|
if(node.highlighted) {
|
|
|
|
node.highlighted = false;
|
|
|
|
node.dirty = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
RED.view.redraw();
|
|
|
|
});
|
|
|
|
});
|
2016-01-12 18:54:53 +01:00
|
|
|
category.open(true);
|
2015-10-17 20:05:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function refreshConfigNodeList() {
|
2016-01-12 18:54:53 +01:00
|
|
|
var validList = {"global":true};
|
2015-10-17 20:05:23 +02:00
|
|
|
|
2016-01-12 18:54:53 +01:00
|
|
|
getOrCreateCategory("global",globalCategories);
|
2015-10-17 20:05:23 +02:00
|
|
|
|
2016-01-12 18:54:53 +01:00
|
|
|
RED.nodes.eachWorkspace(function(ws) {
|
2016-01-14 16:22:00 +01:00
|
|
|
validList[ws.id.replace(/\./g,"-")] = true;
|
2016-01-12 18:54:53 +01:00
|
|
|
getOrCreateCategory(ws.id,flowCategories,ws.label);
|
|
|
|
})
|
|
|
|
RED.nodes.eachSubflow(function(sf) {
|
2016-01-14 16:22:00 +01:00
|
|
|
validList[sf.id.replace(/\./g,"-")] = true;
|
2016-01-12 18:54:53 +01:00
|
|
|
getOrCreateCategory(sf.id,subflowCategories,sf.name);
|
|
|
|
})
|
2016-01-14 16:22:00 +01:00
|
|
|
$(".workspace-config-node-category").each(function() {
|
|
|
|
var id = $(this).attr('id').substring("workspace-config-node-category-".length);
|
|
|
|
if (!validList[id]) {
|
|
|
|
$(this).remove();
|
|
|
|
delete categories[id];
|
|
|
|
}
|
|
|
|
})
|
2016-01-12 18:54:53 +01:00
|
|
|
var globalConfigNodes = [];
|
|
|
|
var configList = {};
|
2015-10-17 20:05:23 +02:00
|
|
|
RED.nodes.eachConfig(function(cn) {
|
2016-01-12 18:54:53 +01:00
|
|
|
if (cn.z) {//} == RED.workspaces.active()) {
|
2016-01-14 16:22:00 +01:00
|
|
|
configList[cn.z.replace(/\./g,"-")] = configList[cn.z.replace(/\./g,"-")]||[];
|
|
|
|
configList[cn.z.replace(/\./g,"-")].push(cn);
|
2015-10-17 20:05:23 +02:00
|
|
|
} else if (!cn.z) {
|
|
|
|
globalConfigNodes.push(cn);
|
|
|
|
}
|
|
|
|
});
|
2016-01-12 18:54:53 +01:00
|
|
|
for (var id in validList) {
|
|
|
|
if (validList.hasOwnProperty(id)) {
|
|
|
|
createConfigNodeList(id,configList[id]||[]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
createConfigNodeList('global',globalConfigNodes);
|
2015-10-17 20:05:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function init() {
|
|
|
|
RED.sidebar.addTab({
|
|
|
|
id: "config",
|
|
|
|
label: RED._("sidebar.config.label"),
|
|
|
|
name: RED._("sidebar.config.name"),
|
|
|
|
content: content,
|
2016-01-12 18:54:53 +01:00
|
|
|
toolbar: toolbar,
|
2015-10-17 20:05:23 +02:00
|
|
|
closeable: true,
|
|
|
|
visible: false,
|
|
|
|
onchange: function() { refreshConfigNodeList(); }
|
|
|
|
});
|
2016-12-04 23:59:43 +01:00
|
|
|
RED.actions.add("core:show-config-tab",function() {RED.sidebar.show('config')});
|
2016-01-12 18:54:53 +01:00
|
|
|
|
|
|
|
$("#workspace-config-node-collapse-all").on("click", function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
for (var cat in categories) {
|
|
|
|
if (categories.hasOwnProperty(cat)) {
|
|
|
|
categories[cat].close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$("#workspace-config-node-expand-all").on("click", function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
for (var cat in categories) {
|
|
|
|
if (categories.hasOwnProperty(cat)) {
|
|
|
|
if (categories[cat].size() > 0) {
|
|
|
|
categories[cat].open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-01-13 00:03:33 +01:00
|
|
|
$('#workspace-config-node-filter-all').on("click",function(e) {
|
2016-01-12 18:54:53 +01:00
|
|
|
e.preventDefault();
|
|
|
|
if (showUnusedOnly) {
|
2016-01-13 00:03:33 +01:00
|
|
|
$(this).addClass('selected');
|
|
|
|
$('#workspace-config-node-filter-unused').removeClass('selected');
|
|
|
|
showUnusedOnly = !showUnusedOnly;
|
|
|
|
refreshConfigNodeList();
|
2015-10-17 20:05:23 +02:00
|
|
|
}
|
2016-01-13 00:03:33 +01:00
|
|
|
});
|
|
|
|
$('#workspace-config-node-filter-unused').on("click",function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
if (!showUnusedOnly) {
|
|
|
|
$(this).addClass('selected');
|
|
|
|
$('#workspace-config-node-filter-all').removeClass('selected');
|
|
|
|
showUnusedOnly = !showUnusedOnly;
|
|
|
|
refreshConfigNodeList();
|
|
|
|
}
|
|
|
|
});
|
2015-10-17 20:05:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
2016-09-30 00:46:29 +02:00
|
|
|
function show(id) {
|
|
|
|
if (typeof id === 'boolean') {
|
2016-10-11 16:06:34 +02:00
|
|
|
if (id) {
|
2016-01-13 00:03:33 +01:00
|
|
|
$('#workspace-config-node-filter-unused').click();
|
|
|
|
} else {
|
|
|
|
$('#workspace-config-node-filter-all').click();
|
|
|
|
}
|
|
|
|
}
|
2015-10-17 20:05:23 +02:00
|
|
|
refreshConfigNodeList();
|
2016-09-30 00:46:29 +02:00
|
|
|
if (typeof id === "string") {
|
|
|
|
$('#workspace-config-node-filter-all').click();
|
|
|
|
id = id.replace(/\./g,"-");
|
|
|
|
setTimeout(function() {
|
|
|
|
var node = $(".palette_node_id_"+id);
|
|
|
|
var y = node.position().top;
|
|
|
|
var h = node.height();
|
|
|
|
var scrollWindow = $(".sidebar-node-config");
|
|
|
|
var scrollHeight = scrollWindow.height();
|
|
|
|
|
|
|
|
if (y+h > scrollHeight) {
|
|
|
|
scrollWindow.animate({scrollTop: '-='+(scrollHeight-(y+h)-30)},150);
|
|
|
|
} else if (y<0) {
|
|
|
|
scrollWindow.animate({scrollTop: '+='+(y-10)},150);
|
|
|
|
}
|
|
|
|
var flash = 21;
|
|
|
|
var flashFunc = function() {
|
|
|
|
if ((flash%2)===0) {
|
|
|
|
node.removeClass('node_highlighted');
|
|
|
|
} else {
|
|
|
|
node.addClass('node_highlighted');
|
|
|
|
}
|
|
|
|
flash--;
|
|
|
|
if (flash >= 0) {
|
|
|
|
setTimeout(flashFunc,100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
flashFunc();
|
|
|
|
},100);
|
|
|
|
}
|
2015-10-17 20:05:23 +02:00
|
|
|
RED.sidebar.show("config");
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
init:init,
|
|
|
|
show:show,
|
2016-05-29 23:31:29 +02:00
|
|
|
refresh:refreshConfigNodeList
|
2015-10-17 20:05:23 +02:00
|
|
|
}
|
|
|
|
})();
|