Ensure plugins api provides a filtered view

pr_4387
Nick O'Leary 2024-03-21 16:37:05 +00:00
parent 3df3096bb4
commit fef93818c9
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
3 changed files with 102 additions and 67 deletions

View File

@ -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,18 +295,18 @@ 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 (setElements) {
if (inUseCount > 0) {
setElements.enableButton.text(RED._('palette.editor.inuse'));
setElements.enableButton.addClass('disabled');
@ -321,6 +321,7 @@ RED.palette.editor = (function() {
setElements.setRow.toggleClass("red-ui-palette-module-set-disabled",!set.enabled);
}
}
}
if (errorCount === 0) {
nodeEntry.errorRow.hide()
@ -861,12 +862,17 @@ 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();
}
})
function populateSetList() {
var setList = Object.keys(entry.sets)
setList.sort(function(A,B) {
return A.toLowerCase().localeCompare(B.toLowerCase());
@ -881,6 +887,13 @@ RED.palette.editor = (function() {
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'))})
}
}
$('<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);
@ -899,7 +912,23 @@ RED.palette.editor = (function() {
});
}
})
} else if (set.plugins) {
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);
@ -914,6 +943,7 @@ RED.palette.editor = (function() {
swatches: typeSwatches
};
});
}
enableButton.on("click", function(evt) {
evt.preventDefault();
if (object.totalUseCount === 0) {

View File

@ -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];

View File

@ -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;