Add link nodes

This commit is contained in:
Nick O'Leary 2016-02-12 23:18:08 +00:00
parent f07c8108fc
commit e1d09349ff
6 changed files with 135 additions and 1 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 609 B

After

Width:  |  Height:  |  Size: 508 B

BIN
editor/icons/link-out.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 B

View File

@ -0,0 +1,74 @@
<!--
Copyright 2016 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.
-->
<script type="text/x-red" data-template-name="link in">
<div class="form-row">
<label for="node-input-event"><i class="fa fa-rss"></i> <span data-i18n="link.label.event"></span></label>
<input type="text" id="node-input-event" data-i18n="[placeholder]link.label.event">
</div>
</script>
<script type="text/x-red" data-help-name="link in">
<p>Receive messages from any link nodes that send the specified event.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('link in',{
category: 'input',
color:"#87D8CF",
defaults: {
event: {value:"",required: true}
},
inputs:0,
outputs:1,
icon: "link-out.png",
label: function() {
return this.event||this._("link.linkIn");
},
labelStyle: function() {
return this.event?"node_label_italic":"";
}
});
</script>
<script type="text/x-red" data-help-name="link out">
<p>Send a message to any link input nodes listening for a given event.</p>
</script>
<script type="text/x-red" data-template-name="link out">
<div class="form-row">
<label for="node-input-event"><i class="fa fa-rss"></i> <span data-i18n="link.label.event"></span></label>
<input type="text" id="node-input-event" data-i18n="[placeholder]link.label.event">
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('link out',{
category: 'output',
color:"#87D8CF",
defaults: {
event: {value:"",required: true}
},
align:"right",
inputs:1,
outputs:0,
icon: "link-out.png",
label: function() {
return this.event||this._("link.linkOut");
},
labelStyle: function() {
return this.event?"node_label_italic":"";
}
});
</script>

View File

@ -0,0 +1,52 @@
/**
* Copyright 2016 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.
**/
module.exports = function(RED) {
"use strict";
function LinkInNode(n) {
RED.nodes.createNode(this,n);
var node = this;
if (n.event) {
var handler = function(msg) {
msg._event = n.event;
node.receive(msg);
}
RED.events.on("node:"+n.event,handler);
this.on("input", function(msg) {
this.send(msg);
});
this.on("close",function() {
RED.events.removeListener("node:"+n.event,handler);
})
}
}
RED.nodes.registerType("link in",LinkInNode);
function LinkOutNode(n) {
RED.nodes.createNode(this,n);
var node = this;
if (n.event) {
this.on("input", function(msg) {
msg._event = n.event;
RED.events.emit("node:"+n.event,msg)
});
}
}
RED.nodes.registerType("link out",LinkOutNode);
}

View File

@ -114,6 +114,13 @@
"name": "Debug messages"
}
},
"link": {
"linkIn": "link in",
"linkOut": "link out",
"label": {
"event": "Event name"
}
},
"exec": {
"spawnerr": "Spawn command must be just the command - no spaces or extra parameters",
"badstdout": "Bad STDOUT",

View File

@ -1,5 +1,5 @@
/**
* Copyright 2015 IBM Corp.
* Copyright 2015, 2016 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -67,6 +67,7 @@ function createNodeApi(node) {
nodes: {},
log: {},
settings: {},
events: runtime.events,
util: runtime.util,
version: runtime.version,
}