mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Include module list in global-config node when exporting flows
This commit is contained in:
parent
80e60538e2
commit
6d5948b56e
@ -1428,7 +1428,12 @@ RED.nodes = (function() {
|
||||
/**
|
||||
* Converts the current node selection to an exportable JSON Object
|
||||
**/
|
||||
function createExportableNodeSet(set, exportedIds, exportedSubflows, exportedConfigNodes) {
|
||||
function createExportableNodeSet(set, {
|
||||
exportedIds,
|
||||
exportedSubflows,
|
||||
exportedConfigNodes,
|
||||
includeModuleConfig = false
|
||||
} = {}) {
|
||||
var nns = [];
|
||||
|
||||
exportedIds = exportedIds || {};
|
||||
@ -1462,7 +1467,7 @@ RED.nodes = (function() {
|
||||
subflowSet = subflowSet.concat(RED.nodes.junctions(subflowId))
|
||||
subflowSet = subflowSet.concat(RED.nodes.groups(subflowId))
|
||||
|
||||
var exportableSubflow = createExportableNodeSet(subflowSet, exportedIds, exportedSubflows, exportedConfigNodes);
|
||||
var exportableSubflow = createExportableNodeSet(subflowSet, { exportedIds, exportedSubflows, exportedConfigNodes });
|
||||
nns = exportableSubflow.concat(nns);
|
||||
}
|
||||
}
|
||||
@ -1497,13 +1502,16 @@ RED.nodes = (function() {
|
||||
}
|
||||
nns.push(convertedNode);
|
||||
if (node.type === "group") {
|
||||
nns = nns.concat(createExportableNodeSet(node.nodes, exportedIds, exportedSubflows, exportedConfigNodes));
|
||||
nns = nns.concat(createExportableNodeSet(node.nodes, { exportedIds, exportedSubflows, exportedConfigNodes }));
|
||||
}
|
||||
} else {
|
||||
var convertedSubflow = convertSubflow(node, { credentials: false });
|
||||
nns.push(convertedSubflow);
|
||||
}
|
||||
}
|
||||
if (includeModuleConfig) {
|
||||
updateGlobalConfigModuleList(nns)
|
||||
}
|
||||
return nns;
|
||||
}
|
||||
|
||||
@ -1541,6 +1549,7 @@ RED.nodes = (function() {
|
||||
RED.nodes.eachNode(function(n) {
|
||||
nns.push(convertNode(n, opts));
|
||||
})
|
||||
updateGlobalConfigModuleList(nns)
|
||||
return nns;
|
||||
}
|
||||
|
||||
@ -2886,7 +2895,33 @@ RED.nodes = (function() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getModuleListForNodes(nodes) {
|
||||
const modules = {}
|
||||
nodes.forEach(n => {
|
||||
const nodeSet = RED.nodes.registry.getNodeSetForType(n.type)
|
||||
if (nodeSet) {
|
||||
modules[nodeSet.module] = nodeSet.version
|
||||
}
|
||||
})
|
||||
return modules
|
||||
}
|
||||
function updateGlobalConfigModuleList(nodes) {
|
||||
const modules = getModuleListForNodes(nodes)
|
||||
delete modules['node-red']
|
||||
const hasModules = (Object.keys(modules).length > 0)
|
||||
let globalConfigNode = nodes.find(n => n.type === 'global-config')
|
||||
if (!globalConfigNode && hasModules) {
|
||||
globalConfigNode = {
|
||||
id: RED.nodes.id(),
|
||||
type: 'global-config',
|
||||
env: [],
|
||||
modules
|
||||
}
|
||||
nodes.push(globalConfigNode)
|
||||
} else if (globalConfigNode) {
|
||||
globalConfigNode.modules = modules
|
||||
}
|
||||
}
|
||||
return {
|
||||
init: function() {
|
||||
RED.events.on("registry:node-type-added",function(type) {
|
||||
|
@ -714,7 +714,7 @@ RED.clipboard = (function() {
|
||||
nodes = RED.view.selection().nodes||[];
|
||||
}
|
||||
// Don't include the subflow meta-port nodes in the exported selection
|
||||
nodes = RED.nodes.createExportableNodeSet(nodes.filter(function(n) { return n.type !== 'subflow'}));
|
||||
nodes = RED.nodes.createExportableNodeSet(nodes.filter(function(n) { return n.type !== 'subflow'}), { includeModuleConfig: true });
|
||||
} else if (type === 'flow') {
|
||||
var activeWorkspace = RED.workspaces.active();
|
||||
nodes = RED.nodes.groups(activeWorkspace);
|
||||
@ -729,7 +729,7 @@ RED.clipboard = (function() {
|
||||
});
|
||||
var parentNode = RED.nodes.workspace(activeWorkspace)||RED.nodes.subflow(activeWorkspace);
|
||||
nodes.unshift(parentNode);
|
||||
nodes = RED.nodes.createExportableNodeSet(nodes);
|
||||
nodes = RED.nodes.createExportableNodeSet(nodes, { includeModuleConfig: true });
|
||||
} else if (type === 'full') {
|
||||
nodes = RED.nodes.createCompleteNodeSet({ credentials: false });
|
||||
}
|
||||
@ -832,7 +832,7 @@ RED.clipboard = (function() {
|
||||
children: []
|
||||
};
|
||||
treeSubflows.push(subflows[node.id])
|
||||
} else {
|
||||
} else if (node.type !== 'global-config') {
|
||||
nodes.push(node);
|
||||
}
|
||||
});
|
||||
|
@ -33,8 +33,7 @@ RED.envVar = (function() {
|
||||
id: RED.nodes.id(),
|
||||
type: "global-config",
|
||||
env: [],
|
||||
name: "global-config",
|
||||
label: "",
|
||||
modules: {},
|
||||
hasUsers: false,
|
||||
users: [],
|
||||
credentials: cred,
|
||||
|
@ -5801,8 +5801,8 @@ RED.view = (function() {
|
||||
|
||||
if (globalConfig) {
|
||||
// merge global env to existing global-config
|
||||
var env0 = gconf.env;
|
||||
var env1 = globalConfig.env;
|
||||
var env0 = gconf.env || [];
|
||||
var env1 = globalConfig.env || []
|
||||
var newEnv = Array.from(env0);
|
||||
var changed = false;
|
||||
|
||||
|
@ -11,12 +11,13 @@
|
||||
RED.nodes.registerType('global-config',{
|
||||
category: 'config',
|
||||
defaults: {
|
||||
name: { value: "" },
|
||||
env: { value: [] },
|
||||
modules: { value: {} }
|
||||
},
|
||||
credentials: {
|
||||
map: { type: "map" }
|
||||
},
|
||||
label: 'global-config',
|
||||
oneditprepare: function() {
|
||||
$('#node-input-edit-env-var').on('click', function(evt) {
|
||||
RED.actions.invoke('core:show-user-settings', 'envvar')
|
||||
|
Loading…
x
Reference in New Issue
Block a user