Skip to content

Commit 33798f6

Browse files
committed
Update node appearance - add button docs
1 parent 6ac195c commit 33798f6

37 files changed

+170
-64
lines changed

Diff for: _posts/2019-08-16-going-async.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: blog
33
title: Making flows asynchronous by default
44
author: nick
5-
description: Changes are coming in Node-RED 1.0 to how messages are routed in a flow. Find out what its means to go asynchronous.
5+
description: Changes are coming in Node-RED 1.0 to how messages are routed in a flow. Find out what it means to go asynchronous.
66
---
77

88
In Node-RED 1.0, we are changing the way messages pass between nodes from being
@@ -92,7 +92,7 @@ When a flow branches, the branches will be evaluated in 'parallel'.
9292
![](/blog/content/images/2019/08/flow2-async.svg)
9393

9494
Which also means a flow with Debug nodes at each point, will log the message
95-
is the expected order.
95+
in the expected order.
9696

9797
![](/blog/content/images/2019/08/flow4-async.svg)
9898

Diff for: docs/creating-nodes/appearance.md

+133-42
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,26 @@ The value of the property can be either a string or a function.
1616

1717
If the value is a string, that is used as the icon.
1818

19-
If the value is a function, it will get evaluated when the node is first loaded, or after it has been edited. The function is expected to return the value to use as the icon.
20-
The function will be called both for nodes in the workspace, where `this` references a node instance, as well as
21-
for the node's entry in the palette. In this latter case, `this` will not refer to a particular node instance and
22-
the function *must* return a valid value.
19+
If the value is a function, it will get evaluated when the node is first loaded,
20+
or after it has been edited. The function is expected to return the value to use
21+
as the icon.
22+
23+
The function will be called both for nodes in the workspace, where `this` references
24+
a node instance, as well as for the node's entry in the palette. In this latter case,
25+
`this` will not refer to a particular node instance and the function *must* return
26+
a valid value.
27+
28+
{% highlight javascript %}
29+
...
30+
icon: "file.png",
31+
...
32+
{% endhighlight %}
2333

24-
...
25-
icon: "file.png",
26-
...
34+
The icon can be either:
2735

28-
There are some stock icons available for use, or the node can provide its own.
36+
- the name of a stock icon provided by Node-RED,
37+
- the name of a custom icon provided by the module,
38+
- a Font Awesome 4.7 icon
2939

3040
#### Stock icons
3141

@@ -48,24 +58,28 @@ There are some stock icons available for use, or the node can provide its own.
4858
</style>
4959

5060
<ul class="nr-icon-list">
51-
<li><img src="images/alert.png"/> alert.png</li>
52-
<li><img src="images/arrow-in.png"/> arrow-in.png</li>
53-
<li><img src="images/bridge-dash.png"/> bridge-dash.png</li>
54-
<li><img src="images/bridge.png"/> bridge.png</li>
55-
<li><img src="images/db.png"/> db.png</li>
56-
<li><img src="images/debug.png"/> debug.png</li>
57-
<li><img src="images/envelope.png"/> envelope.png</li>
58-
<li><img src="images/feed.png"/> feed.png</li>
59-
<li><img src="images/file.png"/> file.png</li>
60-
<li><img src="images/function.png"/> function.png</li>
61-
<li><img src="images/hash.png"/> hash.png</li>
62-
<li><img src="images/inject.png"/> inject.png</li>
63-
<li><img src="images/light.png"/> light.png</li>
64-
<li><img src="images/serial.png"/> serial.png</li>
65-
<li><img src="images/template.png"/> template.png</li>
66-
<li><img src="images/white-globe.png"/> white-globe.png</li>
61+
<li><img src="images/alert.svg"/> alert.png</li>
62+
<li><img src="images/arrow-in.svg"/> arrow-in.png</li>
63+
<li><img src="images/bridge-dash.svg"/> bridge-dash.png</li>
64+
<li><img src="images/bridge.svg"/> bridge.png</li>
65+
<li><img src="images/db.svg"/> db.png</li>
66+
<li><img src="images/debug.svg"/> debug.png</li>
67+
<li><img src="images/envelope.svg"/> envelope.png</li>
68+
<li><img src="images/feed.svg"/> feed.png</li>
69+
<li><img src="images/file.svg"/> file.png</li>
70+
<li><img src="images/function.svg"/> function.png</li>
71+
<li><img src="images/hash.svg"/> hash.png</li>
72+
<li><img src="images/inject.svg"/> inject.png</li>
73+
<li><img src="images/light.svg"/> light.png</li>
74+
<li><img src="images/serial.svg"/> serial.png</li>
75+
<li><img src="images/template.svg"/> template.png</li>
76+
<li><img src="images/white-globe.svg"/> white-globe.png</li>
6777
</ul>
6878

79+
**Note**: In Node-RED 1.0, all of these icons have been replaced with SVG alternatives
80+
for a better appearance. For ensure backwards compatibility, the editor will automatically
81+
swap any request for the png version for the SVG version if it is available.
82+
6983
#### Custom icon
7084

7185
A node can provide its own icon in a directory called `icons` alongside its `.js`
@@ -74,17 +88,25 @@ looks for a given icon filename. Because of this, the icon filename must be uniq
7488

7589
The icon should be white on a transparent background, 40 x 60 in size.
7690

77-
#### User defined icon
91+
#### Font Awesome icon
7892

79-
From Node-RED version 0.18 the node's icon can be overwritten by the user using the `node settings` section of the configuration editor.
93+
Node-RED includes the full set of [Font Awesome 4.7 icons](https://fontawesome.com/v4.7.0/icons/).
8094

81-
<div style="text-align:center">
82-
<img title="port label editor" src="images/user-defined-icon.png"/>
83-
</div>
95+
To specify a FA icon, the property should take the form:
96+
97+
{% highlight javascript %}
98+
...
99+
icon: "font-awesome/fa-automobile",
100+
...
101+
{% endhighlight %}
102+
103+
#### User defined icon
84104

85-
The name of installed modules that contain one or more icon files or `node-red` for core nodes are shown on the left. The name of icon files in the module are shown on the right.
105+
Individual node icons can be customised by the user within the editor on the 'appearance'
106+
tab of the node's edit dialog.
86107

87-
**Note**: If a node has `icon` property by default, the node's icon cannot be overwritten (e.g. ui_button node of node-red-dashboard).
108+
**Note**: If a node has an `icon` property in its `defaults` object, its icon
109+
cannot be customised. For example, the `ui_button` node of `node-red-dashboard`.
88110

89111
### Background Colour
90112

@@ -227,27 +249,31 @@ align: 'right',
227249

228250
#### Port labels
229251

230-
From Node-RED version **0.17** onwards nodes can optionally provide labels on their input
231-
and output ports, that can be seen by hovering the mouse over the port.
252+
Nodes can provide labels on their input and output ports that can be seen by
253+
hovering the mouse over the port.
232254

233255
<div style="text-align:center">
234256
<img title="port labels" src="images/node-labels.png"/>
235257
</div>
236258

237259
These can either be set statically by the node's html file
238260

239-
...,
240-
inputLabels: "parameter for input",
241-
outputLabels: ["stdout","stderr","rc"],
242-
...
261+
{% highlight javascript %}
262+
...
263+
inputLabels: "parameter for input",
264+
outputLabels: ["stdout","stderr","rc"],
265+
...
266+
{% endhighlight %}
243267

244268
or generated by a function, that is passed an index to indicate the output pin (starting from 0).
245269

246-
...,
247-
outputLabels: function(index) {
248-
return "my port number "+index;
249-
}
250-
...
270+
{% highlight javascript %}
271+
...
272+
outputLabels: function(index) {
273+
return "my port number "+index;
274+
}
275+
...
276+
{% endhighlight %}
251277

252278

253279
In both cases they can be overwritten by the user using the `node settings` section of the configuration editor.
@@ -261,3 +287,68 @@ In both cases they can be overwritten by the user using the `node settings` sect
261287
</div>
262288

263289
**Note**: Labels are not generated dynamically, and cannot be set by `msg` properties.
290+
291+
### Buttons
292+
293+
A node can have a button on its left or right hand edge, as seen with the core
294+
Inject and Debug nodes.
295+
296+
A key principle is the editor is not a dashboard for controlling your flows. So
297+
in general, nodes should not have buttons on them. The Inject and Debug nodes are
298+
special cases as the buttons play a role in the development of flows.
299+
300+
The `button` property in its definition is used to describe the behaviour of the
301+
button. It must provide, as a minimum, an `onclick` function that will be called
302+
when the button is clicked.
303+
304+
{% highlight javascript %}
305+
...
306+
button: {
307+
onclick: function() {
308+
// Called when the button is clicked
309+
}
310+
},
311+
...
312+
{% endhighlight %}
313+
314+
The property can also define an `enabled` function to dynamically enable and
315+
disable the button based on the node's current configuration. Similarly, it can
316+
define a `visible` function to determine whether the button should be shown at all.
317+
318+
{% highlight javascript %}
319+
...
320+
button: {
321+
enabled: function() {
322+
// return whether or not the button is enabled, based on the current
323+
// configuration of the node
324+
return !this.changed
325+
},
326+
visible: function() {
327+
// return whether or not the button is visible, based on the current
328+
// configuration of the node
329+
return this.hasButton
330+
},
331+
onclick: function() { }
332+
},
333+
...
334+
{% endhighlight %}
335+
336+
The `button` can also be configured as a toggle button - as seen with the Debug
337+
node. This is done by added a property called `toggle` that identifies a property
338+
in the node's `defaults` object that should be used to store a boolean value whose
339+
value is toggled whenever the button is pressed.
340+
341+
342+
{% highlight javascript %}
343+
...
344+
defaults: {
345+
...
346+
buttonState: {value: true}
347+
...
348+
},
349+
button: {
350+
toggle: "buttonState",
351+
onclick: function() { }
352+
}
353+
...
354+
{% endhighlight %}

Diff for: docs/creating-nodes/first-node.md

+18-20
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ slug: first node
88
Nodes get created when a flow is deployed, they may send and receive some messages
99
whilst the flow is running and they get deleted when the next flow is deployed.
1010

11-
They typically consist of a pair of files; a JavaScript file that defines what the
12-
node does, and an html file that defines the node's properties, edit dialog and
13-
help text.
11+
They consist of a pair of files:
12+
- a JavaScript file that defines what the node does,
13+
- an html file that defines the node's properties, edit dialog and help text.
1414

1515
A `package.json` file is used to package it all together as an npm module.
1616

@@ -25,7 +25,8 @@ A `package.json` file is used to package it all together as an npm module.
2525
This example will show how to create a node that converts message payloads to
2626
all lower-case characters.
2727

28-
Ensure you have the recommended LTS version of Node.js installed on your system. As of this writing this is version **LTS 8.x** which includes npm version 5.x.
28+
Ensure you have the current LTS version of Node.js installed on your system. At
29+
the time of writing this is 10.x.
2930

3031
Create a directory where you will develop your code. Within that directory, create the following files:
3132

@@ -152,44 +153,41 @@ For more information about the editor part of the node, see [here](node-html).
152153

153154
Once you have created a basic node module as described above, you can install it into your Node-RED runtime.
154155

155-
To test a node module locally using npm 5.x, the [`npm install <folder>`](https://docs.npmjs.com/cli/install) command can be used. This allows you
156-
to develop the node in a local directory and have it linked into a local node-red install during development.
156+
To test a node module locally the [`npm install <folder>`](https://docs.npmjs.com/cli/install)
157+
command can be used. This allows you to develop the node in a local directory and
158+
have it linked into a local node-red install during development.
157159

158160
In your node-red user directory, typically `~/.node-red`, run:
159161

160162
npm install <location of node module>
161163

162-
For example, on Mac OS or linux, if your node is located at `~/dev/node-red-contrib-example-lower-case` you would type the following:
164+
For example, on Mac OS or Linux, if your node is located at `~/dev/node-red-contrib-example-lower-case` you would do the following:
163165

164166
cd ~/.node-red
165167
npm install ~/dev/node-red-contrib-example-lower-case
166168

167-
This creates a symbolic link to your node module project directory in `~/.node-red/node_modules` so that Node-RED will discover the node when it starts. Any changes to the node's file can be picked up by simply restarting Node-RED. On Windows, again, using npm 5.x or greater:
169+
On Windows you would do:
168170

169171
cd C:\Users\my_name\.node_red
170172
npm install C:\Users\my_name\Documents\GitHub\node-red-contrib-example-lower-case
171173

172-
If you are using an older version of npm, you can create a symbolic link manually to your project. For example, on Mac or linux systems:
173-
174-
cd ~/.node-red/node_modules
175-
ln -s ~/dev/node-red-contrib-example-lower-case .
176-
177-
On Windows with older versions of npm, use `mklink` instead:
178-
179-
cd C:\Users\my_name\.node_red
180-
mklink /D node_modules\node-red-contrib-example-lower-case C:\Users\my_name\Documents\GitHub\node-red-contrib-example-lower-case
174+
This creates a symbolic link to your node module project directory in `~/.node-red/node_modules` so that Node-RED will discover the node when it starts. Any changes to the node's file can be picked up by simply restarting Node-RED. On Windows, again, using npm 5.x or greater:
181175

182176
<div class="doc-callout">
183-
<em>Note</em> : npm 5 will add your module as a dependency in the <code>package.json</code> file located in your user directory. If you want to prevent this, use the npm <code>--no-save</code> option.
177+
<em>Note</em> : <code>npm</code> will automatically add an entry for your module in the
178+
<code>package.json</code> file located in your user directory. If you don't want
179+
it to do this, use the <code>--no-save</code> option to the <code>npm install</code>
180+
command.
184181
</div>
185182

186183
### Unit Testing
187184

188-
To support unit testing, an npm module called [`node-red-node-test-helper`](https://www.npmjs.com/package/node-red-node-test-helper) can be used. The test-helper is a framework built on the Node-RED runtime to make it easier to test nodes.
185+
To support unit testing, an npm module called [`node-red-node-test-helper`](https://www.npmjs.com/package/node-red-node-test-helper) can be used. The test-helper is a framework
186+
built on the Node-RED runtime to make it easier to test nodes.
189187

190188
Using this framework, you can create test flows, and then assert that your node properties and output is working as expected. For example, to add a unit test to the lower-case node you can add a `test` folder to your node module package containing a file called `_spec.js`
191189

192-
<h4><i class="fa fa-file-o"></i> test/_spec.js</h4>
190+
<h4 id="lower-casespecjs"><i class="fa fa-file-o"></i> test/lower-case_spec.js</h4>
193191

194192
```javascript
195193
var should = require("should");

Diff for: docs/creating-nodes/images/alert.png

-308 Bytes
Binary file not shown.

Diff for: docs/creating-nodes/images/alert.svg

+1
Loading

Diff for: docs/creating-nodes/images/arrow-in.png

-393 Bytes
Binary file not shown.

Diff for: docs/creating-nodes/images/arrow-in.svg

+1
Loading

Diff for: docs/creating-nodes/images/bridge-dash.png

-508 Bytes
Binary file not shown.

Diff for: docs/creating-nodes/images/bridge-dash.svg

+1
Loading

Diff for: docs/creating-nodes/images/bridge.png

-575 Bytes
Binary file not shown.

Diff for: docs/creating-nodes/images/bridge.svg

+1
Loading

Diff for: docs/creating-nodes/images/db.png

-459 Bytes
Binary file not shown.

Diff for: docs/creating-nodes/images/db.svg

+1
Loading

Diff for: docs/creating-nodes/images/debug.png

-218 Bytes
Binary file not shown.

Diff for: docs/creating-nodes/images/debug.svg

+1
Loading

Diff for: docs/creating-nodes/images/envelope.png

-324 Bytes
Binary file not shown.

Diff for: docs/creating-nodes/images/envelope.svg

+1
Loading

Diff for: docs/creating-nodes/images/feed.png

-378 Bytes
Binary file not shown.

Diff for: docs/creating-nodes/images/feed.svg

+1
Loading

Diff for: docs/creating-nodes/images/file.png

-255 Bytes
Binary file not shown.

Diff for: docs/creating-nodes/images/file.svg

+1
Loading

Diff for: docs/creating-nodes/images/function.png

-457 Bytes
Binary file not shown.

Diff for: docs/creating-nodes/images/function.svg

+1
Loading

Diff for: docs/creating-nodes/images/hash.png

-502 Bytes
Binary file not shown.

Diff for: docs/creating-nodes/images/hash.svg

+1
Loading

Diff for: docs/creating-nodes/images/inject.png

-449 Bytes
Binary file not shown.

Diff for: docs/creating-nodes/images/inject.svg

+1
Loading

Diff for: docs/creating-nodes/images/light.png

-639 Bytes
Binary file not shown.

Diff for: docs/creating-nodes/images/light.svg

+1
Loading

Diff for: docs/creating-nodes/images/serial.png

-273 Bytes
Binary file not shown.

Diff for: docs/creating-nodes/images/serial.svg

+1
Loading

Diff for: docs/creating-nodes/images/template.png

-488 Bytes
Binary file not shown.

Diff for: docs/creating-nodes/images/template.svg

+1
Loading

Diff for: docs/creating-nodes/images/user-defined-icon.png

-6.86 KB
Binary file not shown.

Diff for: docs/creating-nodes/images/white-globe.png

-707 Bytes
Binary file not shown.

Diff for: docs/creating-nodes/images/white-globe.svg

+1
Loading

0 commit comments

Comments
 (0)