Skip to content

Commit 7c3b1d7

Browse files
committed
Copy over "sample" node files freo main project as this is where most people will be adding extra nodes.
1 parent 553c978 commit 7c3b1d7

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed

99-sample.html.demo

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<!--
2+
Copyright 2013 IBM Corp.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<!-- Sample html file that corresponds to the 99-sample.js file -->
18+
<!-- This creates and configures the onscreen elements of the node -->
19+
20+
<!-- If you use this as a template, replace IBM Corp. with your own name. -->
21+
22+
<!-- First, the content of the edit dialog is defined. -->
23+
24+
<script type="text/x-red" data-template-name="sample">
25+
<!-- data-template-name identifies the node type this is for -->
26+
27+
<!-- Each of the following divs creates a field in the edit dialog. -->
28+
<!-- Generally, there should be an input for each property of the node. -->
29+
<!-- The for and id attributes identify the corresponding property -->
30+
<!-- (with the 'node-input-' prefix). -->
31+
<!-- The available icon classes are defined in Twitter Bootstrap -->
32+
<div class="form-row">
33+
<label for="node-input-topic"><i class="icon-tasks"></i> Topic</label>
34+
<input type="text" id="node-input-topic" placeholder="Topic">
35+
</div>
36+
37+
<!-- By convention, most nodes have a 'name' property. The following div -->
38+
<!-- provides the necessary field. -->
39+
<div class="form-row">
40+
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
41+
<input type="text" id="node-input-name" placeholder="Name">
42+
</div>
43+
</script>
44+
45+
46+
<!-- Next, some simple help text is provided for the node. -->
47+
<script type="text/x-red" data-help-name="sample">
48+
<!-- data-help-name identifies the node type this help is for -->
49+
<!-- This content appears in the Info sidebar when a node is selected -->
50+
<!-- The first <p> is used as the pop-up tool tip when hovering over a -->
51+
<!-- node in the palette. -->
52+
<p>Simple sample input node. Just sends a single message when it starts up.
53+
This is not very useful.</p>
54+
<p>Outputs an object called <b>msg</b> containing <b>msg.topic</b> and
55+
<b>msg.payload</b>. msg.payload is a String.</p>
56+
</script>
57+
58+
<!-- Finally, the node type is registered along with all of its properties -->
59+
<!-- The example below shows a small subset of the properties that can be set-->
60+
<script type="text/javascript">
61+
RED.nodes.registerType('sample',{
62+
category: 'input', // the palette category
63+
defaults: { // defines the editable properties of the node
64+
name: {value:""}, // along with default values.
65+
topic: {value:"", required:true}
66+
},
67+
inputs:0, // set the number of inputs - only 0 or 1
68+
outputs:1, // set the number of outputs - 0 to n
69+
icon: "arrow-in.png", // set the icon (held in public/icons)
70+
label: function() { // sets the default label contents
71+
return this.name||this.topic||"sample";
72+
},
73+
labelStyle: function() { // sets the class to apply to the label
74+
return this.name?"node_label_italic":"";
75+
}
76+
});
77+
</script>

99-sample.js.demo

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Copyright 2013 IBM Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
**/
16+
17+
// If you use this as a template, replace IBM Corp. with your own name.
18+
19+
// Sample Node-RED node file
20+
21+
// Require main module
22+
var RED = require(process.env.NODE_RED_HOME+"/red/red");
23+
24+
// The main node definition - most things happen in here
25+
function SampleNode(n) {
26+
// Create a RED node
27+
RED.nodes.createNode(this,n);
28+
29+
// Store local copies of the node configuration (as defined in the .html)
30+
this.topic = n.topic;
31+
32+
// Do whatever you need to do in here - declare callbacks etc
33+
// Note: this sample doesn't do anything much - it will only send
34+
// this message once at startup...
35+
// Look at other real nodes for some better ideas of what to do....
36+
var msg = {};
37+
msg.topic = this.topic;
38+
msg.payload = "Hello world !"
39+
40+
// send out the message to the rest of the workspace.
41+
this.send(msg);
42+
43+
this.on("close", function() {
44+
// Called when the node is shutdown - eg on redeploy.
45+
// Allows ports to be closed, connections dropped etc.
46+
// eg: this.client.disconnect();
47+
});
48+
}
49+
50+
// Register the node by name. This must be called before overriding any of the
51+
// Node functions.
52+
RED.nodes.registerType("sample",SampleNode);

0 commit comments

Comments
 (0)