mirror of https://github.com/node-red/node-red.git
Merge pull request #5591 from node-red/allow-override-of-node-defaults
Allow a nodes defaults to be overridden by settings.js filepull/5598/head
commit
994fef45ce
|
|
@ -277,7 +277,7 @@ RED.nodes = (function() {
|
|||
nodeDefinitions[nt] = def;
|
||||
|
||||
if (def.defaults) {
|
||||
for (var d in def.defaults) {
|
||||
for (let d in def.defaults) {
|
||||
if (def.defaults.hasOwnProperty(d)) {
|
||||
if (def.defaults[d].type) {
|
||||
try {
|
||||
|
|
@ -286,16 +286,20 @@ RED.nodes = (function() {
|
|||
console.warn(err);
|
||||
}
|
||||
}
|
||||
|
||||
if (internalProperties.includes(d)) {
|
||||
console.warn(`registerType: ${nt}: the property "${d}" is internal and cannot be used.`);
|
||||
delete def.defaults[d];
|
||||
}
|
||||
const settingOverride = RED.settings?.nodeDefaults?.[def.type]?.[d]
|
||||
if (settingOverride !== undefined) {
|
||||
console.log(`Applying node default override for ${def.type}.${d}:`, settingOverride);
|
||||
def.defaults[d]._override = true;
|
||||
def.defaults[d]._originalValue = def.defaults[d].value;
|
||||
def.defaults[d].value = settingOverride;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RED.events.emit("registry:node-type-added",nt);
|
||||
},
|
||||
removeNodeType: function(nt) {
|
||||
|
|
@ -406,9 +410,9 @@ RED.nodes = (function() {
|
|||
},
|
||||
/**
|
||||
* Add an object to our dirty/clean tracking state
|
||||
* @param {String} z
|
||||
* @param {String} id
|
||||
* @param {Boolean} isDirty
|
||||
* @param {String} z
|
||||
* @param {String} id
|
||||
* @param {Boolean} isDirty
|
||||
*/
|
||||
addObjectToWorkspace: function (z, id, isDirty) {
|
||||
if (isDirty) {
|
||||
|
|
@ -421,8 +425,8 @@ RED.nodes = (function() {
|
|||
},
|
||||
/**
|
||||
* Remove an object from our dirty/clean tracking state
|
||||
* @param {String} z
|
||||
* @param {String} id
|
||||
* @param {String} z
|
||||
* @param {String} id
|
||||
*/
|
||||
removeObjectFromWorkspace: function (z, id) {
|
||||
if (!addedDirtyObjects.has(id)) {
|
||||
|
|
@ -444,7 +448,7 @@ RED.nodes = (function() {
|
|||
api.addNode(n)
|
||||
},
|
||||
/**
|
||||
* @param {array} nodes
|
||||
* @param {array} nodes
|
||||
* @param {boolean} direction true:forwards false:back
|
||||
* @param {boolean} singleStep true:single-step false:all-the-way
|
||||
*/
|
||||
|
|
@ -2117,7 +2121,7 @@ RED.nodes = (function() {
|
|||
$("<li>").text(t).appendTo(typeList);
|
||||
})
|
||||
typeList = typeList[0].outerHTML;
|
||||
|
||||
|
||||
unknownNotification = RED.notify(
|
||||
"<p>"+RED._("clipboard.importUnrecognised",{count:unknownTypes.length})+"</p>"+typeList,
|
||||
notificationOptions
|
||||
|
|
@ -2358,7 +2362,7 @@ RED.nodes = (function() {
|
|||
// We need to sort new_nodes (which only contains config nodes at this point)
|
||||
// to ensure they get added in the right order. If NodeA depends on NodeB, then
|
||||
// NodeB must be added first.
|
||||
|
||||
|
||||
// Limit us to 5 full iterations of the list - this should be more than
|
||||
// enough to process the list as config->config node relationships are
|
||||
// not very common
|
||||
|
|
|
|||
|
|
@ -172,6 +172,10 @@ var api = module.exports = {
|
|||
safeSettings.runtimeState.ui = false; // cannot have UI without endpoint
|
||||
}
|
||||
|
||||
if (runtime.settings.nodeDefaults) {
|
||||
safeSettings.nodeDefaults = runtime.settings.nodeDefaults;
|
||||
}
|
||||
|
||||
runtime.settings.exportNodeSettings(safeSettings);
|
||||
runtime.plugins.exportPluginSettings(safeSettings);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -313,10 +313,10 @@ module.exports = {
|
|||
ui: false,
|
||||
},
|
||||
telemetry: {
|
||||
/**
|
||||
/**
|
||||
* By default, telemetry is disabled until the user provides consent the first
|
||||
* time they open the editor.
|
||||
*
|
||||
*
|
||||
* The following property can be uncommented and set to true/false to enable/disable
|
||||
* telemetry without seeking further consent in the editor.
|
||||
* The user can override this setting via the user settings dialog within the editor
|
||||
|
|
@ -620,4 +620,23 @@ module.exports = {
|
|||
// * - reason: if result is false, the HTTP reason string to return
|
||||
// */
|
||||
//},
|
||||
|
||||
/*******************************************************************************
|
||||
* Node Default Overrides
|
||||
*
|
||||
* This allows the user to override default values of a node. These are the values
|
||||
* that are applied when a node is added to the workspace. They do not affect
|
||||
* nodes that have already been deployed.
|
||||
*
|
||||
* The available properties of a node type can be found in the Information sidebar when
|
||||
* selecting a node of that type.
|
||||
*
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
// nodeDefaults: {
|
||||
// "debug": {
|
||||
// "complete": true // set the debug node to show complete msg by default
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue