mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Allow a node to declare settings that should be exported
This commit is contained in:
parent
4794fe495c
commit
fca77a868f
@ -216,6 +216,14 @@ module.exports = function(RED) {
|
|||||||
credentials: {
|
credentials: {
|
||||||
user: {type:"text"},
|
user: {type:"text"},
|
||||||
password: {type: "password"}
|
password: {type: "password"}
|
||||||
|
},
|
||||||
|
settings: {
|
||||||
|
httpRequestColour: {
|
||||||
|
value: "red",
|
||||||
|
// validate: function(v) { return IT MUST BE A NUMBER },
|
||||||
|
// required: false,
|
||||||
|
exportable: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,8 @@ module.exports = {
|
|||||||
safeSettings.editorTheme.palette.editable = false;
|
safeSettings.editorTheme.palette.editable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
settings.exportNodeSettings(safeSettings);
|
||||||
|
|
||||||
res.json(safeSettings);
|
res.json(safeSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,9 +50,14 @@ function registerType(nodeSet,type,constructor,opts) {
|
|||||||
type = nodeSet;
|
type = nodeSet;
|
||||||
nodeSet = "";
|
nodeSet = "";
|
||||||
}
|
}
|
||||||
if (opts && opts.credentials) {
|
if (opts) {
|
||||||
|
if (opts.credentials) {
|
||||||
credentials.register(type,opts.credentials);
|
credentials.register(type,opts.credentials);
|
||||||
}
|
}
|
||||||
|
if (opts.settings) {
|
||||||
|
settings.registerNodeSettings(type,opts.settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
registry.registerType(nodeSet,type,constructor);
|
registry.registerType(nodeSet,type,constructor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ var log = require("./log");
|
|||||||
|
|
||||||
var userSettings = null;
|
var userSettings = null;
|
||||||
var globalSettings = null;
|
var globalSettings = null;
|
||||||
|
var nodeSettings = null;
|
||||||
var storage = null;
|
var storage = null;
|
||||||
|
|
||||||
var persistentSettings = {
|
var persistentSettings = {
|
||||||
@ -38,6 +39,7 @@ var persistentSettings = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
globalSettings = null;
|
globalSettings = null;
|
||||||
|
nodeSettings = {};
|
||||||
},
|
},
|
||||||
load: function(_storage) {
|
load: function(_storage) {
|
||||||
storage = _storage;
|
storage = _storage;
|
||||||
@ -99,6 +101,26 @@ var persistentSettings = {
|
|||||||
userSettings = null;
|
userSettings = null;
|
||||||
globalSettings = null;
|
globalSettings = null;
|
||||||
storage = null;
|
storage = null;
|
||||||
|
},
|
||||||
|
registerNodeSettings: function(type, opts) {
|
||||||
|
//console.log(type,opts);
|
||||||
|
// 1. TODO: validate the option names are allowed for the node type
|
||||||
|
|
||||||
|
// 2. store this information against the node type
|
||||||
|
nodeSettings[type] = opts;
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: remove the node settings if the node is disabled/removed from runtime
|
||||||
|
},
|
||||||
|
exportNodeSettings: function(safeSettings) {
|
||||||
|
// 1. forEach type in nodeSettings...
|
||||||
|
// 2. forEach setting for that type...
|
||||||
|
// 3. if globalSettings has a property with the required name...
|
||||||
|
// 4. set safeSettings.property to that value
|
||||||
|
// 5. else if the setting has a default 'value' provided
|
||||||
|
// 6. set safeSettings.property to that value
|
||||||
|
|
||||||
|
return safeSettings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ describe("api index", function() {
|
|||||||
describe("disables editor", function() {
|
describe("disables editor", function() {
|
||||||
before(function() {
|
before(function() {
|
||||||
api.init({},{
|
api.init({},{
|
||||||
settings:{httpNodeRoot:true, httpAdminRoot: true,disableEditor:true},
|
settings:{httpNodeRoot:true, httpAdminRoot: true,disableEditor:true, exportNodeSettings: function() {}},
|
||||||
events: {on:function(){},removeListener: function(){}},
|
events: {on:function(){},removeListener: function(){}},
|
||||||
log: {info:function(){},_:function(){}},
|
log: {info:function(){},_:function(){}},
|
||||||
nodes: {paletteEditorEnabled: function(){return true}}
|
nodes: {paletteEditorEnabled: function(){return true}}
|
||||||
|
@ -42,7 +42,10 @@ describe("info api", function() {
|
|||||||
foo: 123,
|
foo: 123,
|
||||||
httpNodeRoot: "testHttpNodeRoot",
|
httpNodeRoot: "testHttpNodeRoot",
|
||||||
version: "testVersion",
|
version: "testVersion",
|
||||||
paletteCategories :["red","blue","green"]
|
paletteCategories :["red","blue","green"],
|
||||||
|
exportNodeSettings: function(obj) {
|
||||||
|
obj.testNodeSetting = "helloWorld";
|
||||||
|
}
|
||||||
},
|
},
|
||||||
nodes: {
|
nodes: {
|
||||||
paletteEditorEnabled: function() { return true; }
|
paletteEditorEnabled: function() { return true; }
|
||||||
@ -59,7 +62,9 @@ describe("info api", function() {
|
|||||||
res.body.should.have.property("version","testVersion");
|
res.body.should.have.property("version","testVersion");
|
||||||
res.body.should.have.property("paletteCategories",["red","blue","green"]);
|
res.body.should.have.property("paletteCategories",["red","blue","green"]);
|
||||||
res.body.should.have.property("editorTheme",{test:456});
|
res.body.should.have.property("editorTheme",{test:456});
|
||||||
|
res.body.should.have.property("testNodeSetting","helloWorld");
|
||||||
res.body.should.not.have.property("foo",123);
|
res.body.should.not.have.property("foo",123);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -68,8 +73,8 @@ describe("info api", function() {
|
|||||||
settings: {
|
settings: {
|
||||||
httpNodeRoot: "testHttpNodeRoot",
|
httpNodeRoot: "testHttpNodeRoot",
|
||||||
version: "testVersion",
|
version: "testVersion",
|
||||||
paletteCategories :["red","blue","green"]
|
paletteCategories :["red","blue","green"],
|
||||||
|
exportNodeSettings: function() {}
|
||||||
},
|
},
|
||||||
nodes: {
|
nodes: {
|
||||||
paletteEditorEnabled: function() { return false; }
|
paletteEditorEnabled: function() { return false; }
|
||||||
|
Loading…
Reference in New Issue
Block a user