Skip to content

Commit

Permalink
Copy over "sample" node files freo main project as this is where most…
Browse files Browse the repository at this point in the history
… people will be adding extra nodes.
  • Loading branch information
dceejay committed Oct 31, 2013
1 parent 553c978 commit 7c3b1d7
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
77 changes: 77 additions & 0 deletions 99-sample.html.demo
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!--
Copyright 2013 IBM Corp.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<!-- Sample html file that corresponds to the 99-sample.js file -->
<!-- This creates and configures the onscreen elements of the node -->

<!-- If you use this as a template, replace IBM Corp. with your own name. -->

<!-- First, the content of the edit dialog is defined. -->

<script type="text/x-red" data-template-name="sample">
<!-- data-template-name identifies the node type this is for -->

<!-- Each of the following divs creates a field in the edit dialog. -->
<!-- Generally, there should be an input for each property of the node. -->
<!-- The for and id attributes identify the corresponding property -->
<!-- (with the 'node-input-' prefix). -->
<!-- The available icon classes are defined in Twitter Bootstrap -->
<div class="form-row">
<label for="node-input-topic"><i class="icon-tasks"></i> Topic</label>
<input type="text" id="node-input-topic" placeholder="Topic">
</div>

<!-- By convention, most nodes have a 'name' property. The following div -->
<!-- provides the necessary field. -->
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>


<!-- Next, some simple help text is provided for the node. -->
<script type="text/x-red" data-help-name="sample">
<!-- data-help-name identifies the node type this help is for -->
<!-- This content appears in the Info sidebar when a node is selected -->
<!-- The first <p> is used as the pop-up tool tip when hovering over a -->
<!-- node in the palette. -->
<p>Simple sample input node. Just sends a single message when it starts up.
This is not very useful.</p>
<p>Outputs an object called <b>msg</b> containing <b>msg.topic</b> and
<b>msg.payload</b>. msg.payload is a String.</p>
</script>

<!-- Finally, the node type is registered along with all of its properties -->
<!-- The example below shows a small subset of the properties that can be set-->
<script type="text/javascript">
RED.nodes.registerType('sample',{
category: 'input', // the palette category
defaults: { // defines the editable properties of the node
name: {value:""}, // along with default values.
topic: {value:"", required:true}
},
inputs:0, // set the number of inputs - only 0 or 1
outputs:1, // set the number of outputs - 0 to n
icon: "arrow-in.png", // set the icon (held in public/icons)
label: function() { // sets the default label contents
return this.name||this.topic||"sample";
},
labelStyle: function() { // sets the class to apply to the label
return this.name?"node_label_italic":"";
}
});
</script>
52 changes: 52 additions & 0 deletions 99-sample.js.demo
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright 2013 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

// If you use this as a template, replace IBM Corp. with your own name.

// Sample Node-RED node file

// Require main module
var RED = require(process.env.NODE_RED_HOME+"/red/red");

// The main node definition - most things happen in here
function SampleNode(n) {
// Create a RED node
RED.nodes.createNode(this,n);

// Store local copies of the node configuration (as defined in the .html)
this.topic = n.topic;

// Do whatever you need to do in here - declare callbacks etc
// Note: this sample doesn't do anything much - it will only send
// this message once at startup...
// Look at other real nodes for some better ideas of what to do....
var msg = {};
msg.topic = this.topic;
msg.payload = "Hello world !"

// send out the message to the rest of the workspace.
this.send(msg);

this.on("close", function() {
// Called when the node is shutdown - eg on redeploy.
// Allows ports to be closed, connections dropped etc.
// eg: this.client.disconnect();
});
}

// Register the node by name. This must be called before overriding any of the
// Node functions.
RED.nodes.registerType("sample",SampleNode);

0 comments on commit 7c3b1d7

Please sign in to comment.