mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add rest endpoint for add/remove and send updates to editor
This commit is contained in:
@@ -176,6 +176,27 @@ var RED = function() {
|
||||
}
|
||||
}
|
||||
});
|
||||
RED.comms.subscribe("node/#",function(topic,msg) {
|
||||
if (topic == "node/added") {
|
||||
for (var i=0;i<msg.length;i++) {
|
||||
var m = msg[i];
|
||||
var id = m.id;
|
||||
$.get('nodes/'+id, function(data) {
|
||||
$("body").append(data);
|
||||
var typeList = "<ul><li>"+m.types.join("</li><li>")+"</li></ul>";
|
||||
RED.notify("Node"+(m.types.length!=1 ? "s":"")+" added to palette:"+typeList,"success");
|
||||
});
|
||||
}
|
||||
} else if (topic == "node/removed") {
|
||||
if (msg.types) {
|
||||
for (var i=0;i<msg.types.length;i++) {
|
||||
RED.palette.remove(msg.types[i]);
|
||||
}
|
||||
var typeList = "<ul><li>"+msg.types.join("</li><li>")+"</li></ul>";
|
||||
RED.notify("Node"+(msg.types.length!=1 ? "s":"")+" removed from palette:"+typeList,"success");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -21,27 +21,31 @@ RED.palette = function() {
|
||||
|
||||
function createCategoryContainer(category){
|
||||
|
||||
$("#palette-container").append('\
|
||||
<div class="palette-category">\
|
||||
<div id="header-'+category+'" class="palette-header"><i class="expanded icon-chevron-down"></i><span>'+category+'</span></div>\
|
||||
<div class="palette-content" id="palette-base-category-'+category+'">\
|
||||
<div id="palette-'+category+'-input"></div>\
|
||||
<div id="palette-'+category+'-output"></div>\
|
||||
<div id="palette-'+category+'-function"></div>\
|
||||
</div>\
|
||||
</div>');
|
||||
$("#palette-container").append('<div class="palette-category">'+
|
||||
'<div id="header-'+category+'" class="palette-header"><i class="expanded icon-chevron-down"></i><span>'+category+'</span></div>'+
|
||||
'<div class="palette-content" id="palette-base-category-'+category+'">'+
|
||||
'<div id="palette-'+category+'-input"></div>'+
|
||||
'<div id="palette-'+category+'-output"></div>'+
|
||||
'<div id="palette-'+category+'-function"></div>'+
|
||||
'</div>'+
|
||||
'</div>');
|
||||
|
||||
}
|
||||
|
||||
core.forEach(createCategoryContainer);
|
||||
|
||||
function addNodeType(nt,def) {
|
||||
|
||||
if ($("#palette_node_"+nt).length) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (exclusion.indexOf(def.category)===-1) {
|
||||
|
||||
var category = def.category.split("-");
|
||||
|
||||
var d = document.createElement("div");
|
||||
d.id = "pn_"+nt;
|
||||
d.id = "palette_node_"+nt;
|
||||
d.type = nt;
|
||||
|
||||
var label = /^(.*?)([ -]in|[ -]out)?$/.exec(nt)[1];
|
||||
@@ -71,15 +75,14 @@ RED.palette = function() {
|
||||
d.appendChild(port);
|
||||
}
|
||||
|
||||
if($("#palette-base-category-"+category[0]).length == 0){
|
||||
createCategoryContainer(category[0]);
|
||||
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>');
|
||||
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(); }
|
||||
|
||||
@@ -111,6 +114,10 @@ RED.palette = function() {
|
||||
}
|
||||
}
|
||||
|
||||
function removeNodeType(type) {
|
||||
$("#palette_node_"+type).remove();
|
||||
}
|
||||
|
||||
function filterChange() {
|
||||
var val = $("#palette-search-input").val();
|
||||
if (val == "") {
|
||||
@@ -155,6 +162,7 @@ RED.palette = function() {
|
||||
});
|
||||
|
||||
return {
|
||||
add:addNodeType
|
||||
add:addNodeType,
|
||||
remove:removeNodeType
|
||||
};
|
||||
}();
|
||||
|
Reference in New Issue
Block a user