1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add a use case. Fix the URL of settings API.

Kazuki-Nakanishi 2017-03-22 23:52:33 +09:00
parent 106e8e745e
commit 46b6a9c75d

@ -1,6 +1,6 @@
/settings API returns only the following built-in fields by default.
http://nodered.jp/docs/api/admin/methods/get/settings/
http://nodered.org/docs/api/admin/methods/get/settings/
A node can add their own settings to be output with the above settings API.
@ -47,3 +47,43 @@ The node settings in settings.js are not shown in the following cases.
* The setting is not defined in any node.
* A node setting sets false to exportable.
* A node is disabled.
## Use Cases
### Change node color
Currently, node color is fixed in each node. Using node settings, user can change a node color as they like.
1. Add settings object to registerType definition in nodes/core/io/21-httprequest.js as follows.
```
RED.nodes.registerType("http request",HTTPRequest,{
credentials: {
user: {type:"text"},
password: {type: "password"}
},
settings: {
httpRequestColor: {
value: "rgb(231, 231, 174)",
exportable: true
}
}
});
```
2. Change registerType definition in nodes/core/io/21-httprequest.html as follows.
```
<script type="text/javascript">
var nodeColor = RED.settings.nodeSettings.httpRequestColor;
RED.nodes.registerType('http request',{
category: 'function',
color: nodeColor,
defaults: {
...
```
3. Add httpRequestColor definition in settings.js
```
module.exports = {
httpRequestColor: "rgb(255, 0, 0)",
...
```
You can see an http request node with red color by following the above three steps.