mirror of https://github.com/node-red/node-red.git
Ensure plugins api provides a filtered view
parent
3df3096bb4
commit
fef93818c9
|
@ -253,7 +253,6 @@ RED.palette.editor = (function() {
|
|||
nodeEntry.removeButton.show();
|
||||
|
||||
let pluginCount = 0;
|
||||
|
||||
for (let setName in moduleInfo.sets) {
|
||||
if (moduleInfo.sets.hasOwnProperty(setName)) {
|
||||
let set = moduleInfo.sets[setName];
|
||||
|
@ -276,8 +275,9 @@ RED.palette.editor = (function() {
|
|||
for (var setName in moduleInfo.sets) {
|
||||
if (moduleInfo.sets.hasOwnProperty(setName)) {
|
||||
var inUseCount = 0;
|
||||
var set = moduleInfo.sets[setName];
|
||||
var setElements = nodeEntry.sets[setName];
|
||||
const set = moduleInfo.sets[setName];
|
||||
const setElements = nodeEntry.sets[setName]
|
||||
|
||||
if (set.err) {
|
||||
errorCount++;
|
||||
var errMessage = set.err;
|
||||
|
@ -295,30 +295,31 @@ RED.palette.editor = (function() {
|
|||
for (var i=0;i<moduleInfo.sets[setName].types.length;i++) {
|
||||
var t = moduleInfo.sets[setName].types[i];
|
||||
inUseCount += (typesInUse[t]||0);
|
||||
var swatch = setElements.swatches[t];
|
||||
if (set.enabled) {
|
||||
if (setElements && set.enabled) {
|
||||
var def = RED.nodes.getType(t);
|
||||
if (def && def.color) {
|
||||
swatch.css({background:RED.utils.getNodeColor(t,def)});
|
||||
swatch.css({border: "1px solid "+getContrastingBorder(swatch.css('backgroundColor'))})
|
||||
setElements.swatches[t].css({background:RED.utils.getNodeColor(t,def)});
|
||||
setElements.swatches[t].css({border: "1px solid "+getContrastingBorder(setElements.swatches[t].css('backgroundColor'))})
|
||||
}
|
||||
}
|
||||
}
|
||||
nodeEntries[module].setUseCount[setName] = inUseCount;
|
||||
nodeEntries[module].totalUseCount += inUseCount;
|
||||
|
||||
if (inUseCount > 0) {
|
||||
setElements.enableButton.text(RED._('palette.editor.inuse'));
|
||||
setElements.enableButton.addClass('disabled');
|
||||
} else {
|
||||
setElements.enableButton.removeClass('disabled');
|
||||
if (set.enabled) {
|
||||
setElements.enableButton.text(RED._('palette.editor.disable'));
|
||||
if (setElements) {
|
||||
if (inUseCount > 0) {
|
||||
setElements.enableButton.text(RED._('palette.editor.inuse'));
|
||||
setElements.enableButton.addClass('disabled');
|
||||
} else {
|
||||
setElements.enableButton.text(RED._('palette.editor.enable'));
|
||||
setElements.enableButton.removeClass('disabled');
|
||||
if (set.enabled) {
|
||||
setElements.enableButton.text(RED._('palette.editor.disable'));
|
||||
} else {
|
||||
setElements.enableButton.text(RED._('palette.editor.enable'));
|
||||
}
|
||||
}
|
||||
setElements.setRow.toggleClass("red-ui-palette-module-set-disabled",!set.enabled);
|
||||
}
|
||||
setElements.setRow.toggleClass("red-ui-palette-module-set-disabled",!set.enabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -861,59 +862,88 @@ RED.palette.editor = (function() {
|
|||
if (container.hasClass('expanded')) {
|
||||
container.removeClass('expanded');
|
||||
contentRow.slideUp();
|
||||
setTimeout(() => {
|
||||
contentRow.empty()
|
||||
}, 200)
|
||||
object.elements.sets = {}
|
||||
} else {
|
||||
container.addClass('expanded');
|
||||
populateSetList()
|
||||
contentRow.slideDown();
|
||||
}
|
||||
})
|
||||
|
||||
var setList = Object.keys(entry.sets)
|
||||
setList.sort(function(A,B) {
|
||||
return A.toLowerCase().localeCompare(B.toLowerCase());
|
||||
});
|
||||
setList.forEach(function(setName) {
|
||||
var set = entry.sets[setName];
|
||||
var setRow = $('<div>',{class:"red-ui-palette-module-set"}).appendTo(contentRow);
|
||||
var buttonGroup = $('<div>',{class:"red-ui-palette-module-set-button-group"}).appendTo(setRow);
|
||||
var typeSwatches = {};
|
||||
let enableButton;
|
||||
if (set.types) {
|
||||
set.types.forEach(function(t) {
|
||||
var typeDiv = $('<div>',{class:"red-ui-palette-module-type"}).appendTo(setRow);
|
||||
typeSwatches[t] = $('<span>',{class:"red-ui-palette-module-type-swatch"}).appendTo(typeDiv);
|
||||
$('<span>',{class:"red-ui-palette-module-type-node"}).text(t).appendTo(typeDiv);
|
||||
})
|
||||
enableButton = $('<a href="#" class="red-ui-button red-ui-button-small"></a>').appendTo(buttonGroup);
|
||||
enableButton.on("click", function(evt) {
|
||||
evt.preventDefault();
|
||||
if (object.setUseCount[setName] === 0) {
|
||||
var currentSet = RED.nodes.registry.getNodeSet(set.id);
|
||||
shade.show();
|
||||
var newState = !currentSet.enabled
|
||||
changeNodeState(set.id,newState,shade,function(xhr){
|
||||
if (xhr) {
|
||||
if (xhr.responseJSON) {
|
||||
RED.notify(RED._('palette.editor.errors.'+(newState?'enable':'disable')+'Failed',{module: id,message:xhr.responseJSON.message}));
|
||||
}
|
||||
function populateSetList() {
|
||||
var setList = Object.keys(entry.sets)
|
||||
setList.sort(function(A,B) {
|
||||
return A.toLowerCase().localeCompare(B.toLowerCase());
|
||||
});
|
||||
setList.forEach(function(setName) {
|
||||
var set = entry.sets[setName];
|
||||
var setRow = $('<div>',{class:"red-ui-palette-module-set"}).appendTo(contentRow);
|
||||
var buttonGroup = $('<div>',{class:"red-ui-palette-module-set-button-group"}).appendTo(setRow);
|
||||
var typeSwatches = {};
|
||||
let enableButton;
|
||||
if (set.types) {
|
||||
set.types.forEach(function(t) {
|
||||
var typeDiv = $('<div>',{class:"red-ui-palette-module-type"}).appendTo(setRow);
|
||||
typeSwatches[t] = $('<span>',{class:"red-ui-palette-module-type-swatch"}).appendTo(typeDiv);
|
||||
if (set.enabled) {
|
||||
var def = RED.nodes.getType(t);
|
||||
if (def && def.color) {
|
||||
typeSwatches[t].css({background:RED.utils.getNodeColor(t,def)});
|
||||
typeSwatches[t].css({border: "1px solid "+getContrastingBorder(typeSwatches[t].css('backgroundColor'))})
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
} else if (set.plugins) {
|
||||
set.plugins.forEach(function(p) {
|
||||
var typeDiv = $('<div>',{class:"red-ui-palette-module-type"}).appendTo(setRow);
|
||||
// typeSwatches[p.id] = $('<span>',{class:"red-ui-palette-module-type-swatch"}).appendTo(typeDiv);
|
||||
$('<span><i class="fa fa-puzzle-piece" aria-hidden="true"></i> </span>',{class:"red-ui-palette-module-type-swatch"}).appendTo(typeDiv);
|
||||
$('<span>',{class:"red-ui-palette-module-type-node"}).text(p.id).appendTo(typeDiv);
|
||||
})
|
||||
}
|
||||
}
|
||||
$('<span>',{class:"red-ui-palette-module-type-node"}).text(t).appendTo(typeDiv);
|
||||
})
|
||||
enableButton = $('<a href="#" class="red-ui-button red-ui-button-small"></a>').appendTo(buttonGroup);
|
||||
enableButton.on("click", function(evt) {
|
||||
evt.preventDefault();
|
||||
if (object.setUseCount[setName] === 0) {
|
||||
var currentSet = RED.nodes.registry.getNodeSet(set.id);
|
||||
shade.show();
|
||||
var newState = !currentSet.enabled
|
||||
changeNodeState(set.id,newState,shade,function(xhr){
|
||||
if (xhr) {
|
||||
if (xhr.responseJSON) {
|
||||
RED.notify(RED._('palette.editor.errors.'+(newState?'enable':'disable')+'Failed',{module: id,message:xhr.responseJSON.message}));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
object.elements.sets[set.name] = {
|
||||
setRow: setRow,
|
||||
enableButton: enableButton,
|
||||
swatches: typeSwatches
|
||||
};
|
||||
});
|
||||
if (object.setUseCount[setName] > 0) {
|
||||
enableButton.text(RED._('palette.editor.inuse'));
|
||||
enableButton.addClass('disabled');
|
||||
} else {
|
||||
enableButton.removeClass('disabled');
|
||||
if (set.enabled) {
|
||||
enableButton.text(RED._('palette.editor.disable'));
|
||||
} else {
|
||||
enableButton.text(RED._('palette.editor.enable'));
|
||||
}
|
||||
}
|
||||
setRow.toggleClass("red-ui-palette-module-set-disabled",!set.enabled);
|
||||
|
||||
|
||||
}
|
||||
if (set.plugins) {
|
||||
set.plugins.forEach(function(p) {
|
||||
var typeDiv = $('<div>',{class:"red-ui-palette-module-type"}).appendTo(setRow);
|
||||
// typeSwatches[p.id] = $('<span>',{class:"red-ui-palette-module-type-swatch"}).appendTo(typeDiv);
|
||||
$('<span><i class="fa fa-puzzle-piece" aria-hidden="true"></i> </span>',{class:"red-ui-palette-module-type-swatch"}).appendTo(typeDiv);
|
||||
$('<span>',{class:"red-ui-palette-module-type-node"}).text(p.id).appendTo(typeDiv);
|
||||
})
|
||||
}
|
||||
|
||||
object.elements.sets[set.name] = {
|
||||
setRow: setRow,
|
||||
enableButton: enableButton,
|
||||
swatches: typeSwatches
|
||||
};
|
||||
});
|
||||
}
|
||||
enableButton.on("click", function(evt) {
|
||||
evt.preventDefault();
|
||||
if (object.totalUseCount === 0) {
|
||||
|
|
|
@ -66,7 +66,7 @@ function getPluginConfigs(lang) {
|
|||
for (var module in moduleConfigs) {
|
||||
/* istanbul ignore else */
|
||||
if (moduleConfigs.hasOwnProperty(module)) {
|
||||
result += get_config_of_plugins(moduleConfigs[module].plugins);
|
||||
result += generateModulePluginConfig(moduleConfigs[module]);
|
||||
}
|
||||
}
|
||||
pluginConfigCache[lang] = result;
|
||||
|
@ -78,14 +78,14 @@ function getPluginConfig(id, lang) {
|
|||
let result = '';
|
||||
let moduleConfigs = registry.getModuleList();
|
||||
if (moduleConfigs.hasOwnProperty(id)) {
|
||||
result = get_config_of_plugins(moduleConfigs[id].plugins);
|
||||
result = generateModulePluginConfig(moduleConfigs[id]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// helper function to avoid code duplication
|
||||
function get_config_of_plugins(plugins) {
|
||||
function generateModulePluginConfig(module) {
|
||||
let result = '';
|
||||
const plugins = module.plugins
|
||||
for (let plugin in plugins) {
|
||||
if (plugins.hasOwnProperty(plugin)) {
|
||||
let config = plugins[plugin];
|
||||
|
|
|
@ -65,7 +65,12 @@ function filterNodeInfo(n) {
|
|||
r.err = n.err;
|
||||
}
|
||||
if (n.hasOwnProperty("plugins")) {
|
||||
r.plugins = n.plugins;
|
||||
r.plugins = n.plugins.map(p => {
|
||||
return {
|
||||
id: p.id,
|
||||
type: p.type
|
||||
}
|
||||
});
|
||||
}
|
||||
if (n.type === "plugin") {
|
||||
r.editor = !!n.template;
|
||||
|
|
Loading…
Reference in New Issue