mirror of
https://github.com/node-red/node-red
synced 2024-11-21 23:48:30 +00:00
Add support for settings object in plugin definition
This commit is contained in:
parent
3f9a29730f
commit
c744af161d
@ -304,7 +304,8 @@ module.exports = {
|
||||
getPluginsByType: plugins.getPluginsByType,
|
||||
getPluginList: plugins.getPluginList,
|
||||
getPluginConfigs: plugins.getPluginConfigs,
|
||||
|
||||
exportPluginSettings: plugins.exportPluginSettings,
|
||||
|
||||
deprecated: require("./deprecated")
|
||||
|
||||
};
|
||||
|
@ -1,11 +1,13 @@
|
||||
const registry = require("./registry");
|
||||
const {events} = require("@node-red/util")
|
||||
const {events} = require("@node-red/util");
|
||||
const clone = require("clone");
|
||||
|
||||
var pluginConfigCache = {};
|
||||
var pluginToId = {};
|
||||
var plugins = {};
|
||||
var pluginsByType = {};
|
||||
var settings;
|
||||
let pluginConfigCache = {};
|
||||
let pluginToId = {};
|
||||
let plugins = {};
|
||||
let pluginsByType = {};
|
||||
let pluginSettings = {};
|
||||
let settings;
|
||||
|
||||
function init(_settings) {
|
||||
settings = _settings;
|
||||
@ -13,6 +15,7 @@ function init(_settings) {
|
||||
pluginConfigCache = {};
|
||||
pluginToId = {};
|
||||
pluginsByType = {};
|
||||
pluginSettings = {};
|
||||
}
|
||||
|
||||
function registerPlugin(nodeSetId,id,definition) {
|
||||
@ -32,6 +35,11 @@ function registerPlugin(nodeSetId,id,definition) {
|
||||
pluginsByType[definition.type] = pluginsByType[definition.type] || [];
|
||||
pluginsByType[definition.type].push(definition);
|
||||
}
|
||||
if (definition.settings) {
|
||||
pluginSettings[id] = definition.settings;
|
||||
}
|
||||
|
||||
|
||||
if (definition.onadd && typeof definition.onadd === 'function') {
|
||||
definition.onadd();
|
||||
}
|
||||
@ -93,11 +101,53 @@ function getPluginList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
function exportPluginSettings(safeSettings) {
|
||||
for (let id in pluginSettings) {
|
||||
if (pluginSettings.hasOwnProperty(id)) {
|
||||
if (settings.hasOwnProperty(id) && !safeSettings.hasOwnProperty(id)) {
|
||||
let pluginTypeSettings = pluginSettings[id];
|
||||
let exportedSet = {};
|
||||
let defaultExportable = false;
|
||||
if (pluginTypeSettings['*'] && pluginTypeSettings['*'].hasOwnProperty("exportable")) {
|
||||
defaultExportable = pluginTypeSettings['*'].exportable;
|
||||
}
|
||||
if (defaultExportable) {
|
||||
exportedSet = clone(settings[id]);
|
||||
}
|
||||
for (let property in pluginTypeSettings) {
|
||||
if (pluginTypeSettings.hasOwnProperty(property)) {
|
||||
let setting = pluginTypeSettings[property];
|
||||
if (defaultExportable) {
|
||||
if (setting.exportable === false) {
|
||||
delete exportedSet[property]
|
||||
} else if (!exportedSet.hasOwnProperty(property) && setting.hasOwnProperty('value')) {
|
||||
exportedSet[property] = setting.value;
|
||||
}
|
||||
} else if (setting.exportable) {
|
||||
if (settings[id].hasOwnProperty(property)) {
|
||||
exportedSet[property] = settings[id][property];
|
||||
} else if (setting.hasOwnProperty('value')) {
|
||||
exportedSet[property] = setting.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Object.keys(exportedSet).length > 0) {
|
||||
safeSettings[id] = exportedSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return safeSettings;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init,
|
||||
registerPlugin,
|
||||
getPlugin,
|
||||
getPluginsByType,
|
||||
getPluginConfigs,
|
||||
getPluginList
|
||||
getPluginList,
|
||||
exportPluginSettings
|
||||
}
|
@ -130,6 +130,7 @@ var api = module.exports = {
|
||||
|
||||
safeSettings.flowEncryptionType = runtime.nodes.getCredentialKeyType();
|
||||
runtime.settings.exportNodeSettings(safeSettings);
|
||||
runtime.plugins.exportPluginSettings(safeSettings);
|
||||
}
|
||||
|
||||
return safeSettings;
|
||||
|
@ -7,4 +7,5 @@ module.exports = {
|
||||
getPluginsByType: registry.getPluginsByType,
|
||||
getPluginList: registry.getPluginList,
|
||||
getPluginConfigs: registry.getPluginConfigs,
|
||||
exportPluginSettings: registry.exportPluginSettings
|
||||
}
|
Loading…
Reference in New Issue
Block a user