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

Added dynamic category capability

This commit is contained in:
tjkoury 2014-06-30 11:31:02 -04:00
parent e15de8cf37
commit 5959da2d37
2 changed files with 93 additions and 109 deletions

View File

@ -80,51 +80,7 @@
<div id="main-container" class="sidebar-closed"> <div id="main-container" class="sidebar-closed">
<div id="palette"> <div id="palette">
<img src="spin.svg" class="palette-spinner"/> <img src="spin.svg" class="palette-spinner"/>
<div class="palette-scroll"> <div id="palette-container" class="palette-scroll">
<div class="palette-category">
<div class="palette-header"><i class="expanded icon-chevron-down"></i><span>inputs</span></div>
<div class="palette-content" id="palette-input"></div>
</div>
<div class="palette-category">
<div class="palette-header"><i class="expanded icon-chevron-down"></i><span>outputs</span></div>
<div class="palette-content" id="palette-output"></div>
</div>
<div class="palette-category">
<div class="palette-header"><i class="expanded icon-chevron-down"></i><span>functions</span></div>
<div class="palette-content" id="palette-function"></div>
</div>
<div class="palette-category">
<div class="palette-header"><i class="expanded icon-chevron-down"></i><span>social</span></div>
<div class="palette-content">
<div id="palette-social-input"></div>
<div id="palette-social-output"></div>
<div id="palette-social-function"></div>
</div>
</div>
<div class="palette-category">
<div class="palette-header"><i class="expanded icon-chevron-down"></i><span>storage</span></div>
<div class="palette-content">
<div id="palette-storage-input"></div>
<div id="palette-storage-output"></div>
<div id="palette-storage-function"></div>
</div>
</div>
<div class="palette-category">
<div class="palette-header"><i class="expanded icon-chevron-down"></i><span>analysis</span></div>
<div class="palette-content">
<div id="palette-analysis-input"></div>
<div id="palette-analysis-output"></div>
<div id="palette-analysis-function"></div>
</div>
</div>
<div class="palette-category">
<div class="palette-header"><i class="expanded icon-chevron-down"></i><span>advanced</span></div>
<div class="palette-content">
<div id="palette-advanced-input"></div>
<div id="palette-advanced-output"></div>
<div id="palette-advanced-function"></div>
</div>
</div>
</div> </div>
<div id="palette-search"> <div id="palette-search">
<i class="icon-search"></i><input id="palette-search-input" type="text" placeholder="filter"><a href="#" id="palette-search-clear"><i class="icon-remove"></i></a></input> <i class="icon-search"></i><input id="palette-search-input" type="text" placeholder="filter"><a href="#" id="palette-search-clear"><i class="icon-remove"></i></a></input>

View File

@ -13,71 +13,99 @@
* 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.palette = function() { RED.palette = function() {
function addNodeType(nt,def) { var exclusion = ['config','unknown'];
if (def.category != 'config') { var core = ['input', 'output', 'function', 'social', 'storage', 'analysis', 'advanced'];
var d = document.createElement("div");
d.id = "pn_"+nt;
d.type = nt;
var label = /^(.*?)([ -]in|[ -]out)?$/.exec(nt)[1]; function createCategoryContainer(category){
d.innerHTML = '<div class="palette_label">'+label+"</div>"; console.log(category);
d.className="palette_node"; $("#palette-container").append('\
if (def.icon) { <div class="palette-category">\
d.style.backgroundImage = "url(icons/"+def.icon+")"; <div id="header-'+category+'" class="palette-header"><i class="expanded icon-chevron-down"></i><span>'+category+'</span></div>\
if (def.align == "right") { <div class="palette-content" id="palette-base-category-'+category+'"></div>\
d.style.backgroundPosition = "95% 50%"; </div>');
} else if (def.inputs > 0) {
d.style.backgroundPosition = "10% 50%";
}
}
d.style.backgroundColor = def.color;
if (def.outputs > 0) {
var port = document.createElement("div");
port.className = "palette_port palette_port_output";
d.appendChild(port);
}
if (def.inputs > 0) {
var port = document.createElement("div");
port.className = "palette_port";
d.appendChild(port);
}
// TODO: add categories dynamically?
$("#palette-"+def.category).append(d);
d.onmousedown = function(e) { e.preventDefault(); }
$(d).popover({
title:d.type,
placement:"right",
trigger: "hover",
delay: { show: 750, hide: 50 },
html: true,
container:'body',
content: $(($("script[data-help-name|='"+nt+"']").html()||"<p>no information available</p>").trim())[0]
});
$(d).click(function() {
var help = '<div class="node-help">'+($("script[data-help-name|='"+d.type+"']").html()||"")+"</div>";
$("#tab-info").html(help);
});
$(d).draggable({
helper: 'clone',
appendTo: 'body',
revert: true,
revertDuration: 50
});
}
} }
$(".palette-header").click(function(e) { core.forEach(createCategoryContainer);
$(this).next().slideToggle();
$(this).children("i").toggleClass("expanded"); function addNodeType(nt,def) {
}); if (exclusion.indexOf(def.category)===-1) {
var category = def.category.split("-");
var d = document.createElement("div");
d.id = "pn_"+nt;
d.type = nt;
var label = /^(.*?)([ -]in|[ -]out)?$/.exec(nt)[1];
d.innerHTML = '<div class="palette_label">'+label+"</div>";
d.className="palette_node";
if (def.icon) {
d.style.backgroundImage = "url(icons/"+def.icon+")";
if (def.align == "right") {
d.style.backgroundPosition = "95% 50%";
} else if (def.inputs > 0) {
d.style.backgroundPosition = "10% 50%";
}
}
d.style.backgroundColor = def.color;
if (def.outputs > 0) {
var port = document.createElement("div");
port.className = "palette_port palette_port_output";
d.appendChild(port);
}
if (def.inputs > 0) {
var port = document.createElement("div");
port.className = "palette_port";
d.appendChild(port);
}
if($("#palette-base-category-"+category[0]).length == 0){
createCategoryContainer(category[0]);
}
if($("#palette-"+def.category).length == 0){
$("#palette-base-category-"+category[0]).append('\
<div id="palette-'+def.category+'"></div>');
}
$("#palette-"+def.category).append(d);
d.onmousedown = function(e) { e.preventDefault(); }
$(d).popover({
title:d.type,
placement:"right",
trigger: "hover",
delay: { show: 750, hide: 50 },
html: true,
container:'body',
content: $(($("script[data-help-name|='"+nt+"']").html()||"<p>no information available</p>").trim())[0]
});
$(d).click(function() {
var help = '<div class="node-help">'+($("script[data-help-name|='"+d.type+"']").html()||"")+"</div>";
$("#tab-info").html(help);
});
$(d).draggable({
helper: 'clone',
appendTo: 'body',
revert: true,
revertDuration: 50
});
$("#header-"+category[0]).off('click').on('click', function(e) {
$(this).next().slideToggle();
$(this).children("i").toggleClass("expanded");
});
}
}
function filterChange() { function filterChange() {
var val = $("#palette-search-input").val(); var val = $("#palette-search-input").val();