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

Add "use strict" to most core nodes.

(skipping ones that may have other work in progress)
This commit is contained in:
Dave C-J 2014-05-29 22:13:21 +01:00
parent 7ad28de52a
commit 2cdaed1325
22 changed files with 128 additions and 99 deletions

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
var sentiment = require('sentiment'); var sentiment = require('sentiment');
function SentimentNode(n) { function SentimentNode(n) {

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
var mustache = require("mustache"); var mustache = require("mustache");
var util = require("util"); var util = require("util");
var fs = require('fs'); var fs = require('fs');

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
function CommentNode(n) { function CommentNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
} }

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
function UnknownNode(n) { function UnknownNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
} }

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
var util = require("util"); var util = require("util");
var exec = require('child_process').exec; var exec = require('child_process').exec;
var fs = require('fs'); var fs = require('fs');

View File

@ -102,7 +102,7 @@
<script type="text/x-red" data-template-name="mqtt-broker"> <script type="text/x-red" data-template-name="mqtt-broker">
<div class="form-row node-input-broker"> <div class="form-row node-input-broker">
<label for="node-config-input-broker"><i class="icon-bookmark"></i> Broker</label> <label for="node-config-input-broker"><i class="icon-bookmark"></i> Broker</label>
<input class="input-append-left" type="text" id="node-config-input-broker" placeholder="Broker" style="width: 40%;" > <input class="input-append-left" type="text" id="node-config-input-broker" placeholder="localhost" style="width: 40%;" >
<label for="node-config-input-port" style="margin-left: 10px; width: 35px; "> Port</label> <label for="node-config-input-port" style="margin-left: 10px; width: 35px; "> Port</label>
<input type="text" id="node-config-input-port" placeholder="Port" style="width:45px"> <input type="text" id="node-config-input-port" placeholder="Port" style="width:45px">
</div> </div>
@ -124,7 +124,7 @@
RED.nodes.registerType('mqtt-broker',{ RED.nodes.registerType('mqtt-broker',{
category: 'config', category: 'config',
defaults: { defaults: {
broker: {value:"localhost",required:true}, broker: {value:"",required:true},
port: {value:1883,required:true,validate:RED.validators.number()}, port: {value:1883,required:true,validate:RED.validators.number()},
clientid: { value:"" } clientid: { value:"" }
//user -> credentials //user -> credentials
@ -132,6 +132,7 @@
}, },
label: function() { label: function() {
if (this.broker == "") { this.broker = "localhost"; }
return (this.clientid?this.clientid+"@":"")+this.broker+":"+this.port; return (this.clientid?this.clientid+"@":"")+this.broker+":"+this.port;
}, },
oneditprepare: function() { oneditprepare: function() {
@ -144,10 +145,10 @@
} else { } else {
$('#node-config-input-pass').val(''); $('#node-config-input-pass').val('');
} }
}); });
}, },
oneditsave: function() { oneditsave: function() {
if (this.broker == "") { this.broker = "localhost"; }
var newUser = $('#node-config-input-user').val(); var newUser = $('#node-config-input-user').val();
var newPass = $('#node-config-input-pass').val(); var newPass = $('#node-config-input-pass').val();
var credentials = {}; var credentials = {};

View File

@ -15,7 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
var ws = require("ws"), var ws = require("ws"),
inspect = require("sys").inspect; inspect = require("sys").inspect;

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
var notify = require("fs.notify"); var notify = require("fs.notify");
var fs = require("fs"); var fs = require("fs");
var sep = require("path").sep; var sep = require("path").sep;

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
var dgram = require('dgram'); var dgram = require('dgram');
// The Input Node // The Input Node

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
var operators = { var operators = {
'eq': function(a, b) { return a == b; }, 'eq': function(a, b) { return a == b; },
'neq': function(a, b) { return a != b; }, 'neq': function(a, b) { return a != b; },

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
function ChangeNode(n) { function ChangeNode(n) {
RED.nodes.createNode(this, n); RED.nodes.createNode(this, n);
this.action = n.action; this.action = n.action;

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
function RangeNode(n) { function RangeNode(n) {
RED.nodes.createNode(this, n); RED.nodes.createNode(this, n);
this.action = n.action; this.action = n.action;

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
function CSVNode(n) { function CSVNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.template = n.temp.split(","); this.template = n.temp.split(",");

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
var util = require("util"); var util = require("util");
function JSONNode(n) { function JSONNode(n) {

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
var xml2js = require('xml2js'); var xml2js = require('xml2js');
var parseString = xml2js.parseString; var parseString = xml2js.parseString;
var builder = new xml2js.Builder({renderOpts:{pretty:false}}); var builder = new xml2js.Builder({renderOpts:{pretty:false}});

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
var FeedParser = require("feedparser"); var FeedParser = require("feedparser");
var request = require("request"); var request = require("request");
@ -68,4 +69,3 @@ module.exports = function(RED) {
} }
} }
} }

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
var util = require('util'); var util = require('util');
var nodemailer = require("nodemailer"); var nodemailer = require("nodemailer");
var Imap = null; var Imap = null;

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
var irc = require("irc"); var irc = require("irc");
var util = require("util"); var util = require("util");

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
var fs = require("fs"); var fs = require("fs");
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
var fs = require("fs"); var fs = require("fs");
function FileNode(n) { function FileNode(n) {

View File

@ -105,9 +105,10 @@
<div class="form-row"> <div class="form-row">
<label for="node-input-operation"><i class="icon-wrench"></i> Operation</label> <label for="node-input-operation"><i class="icon-wrench"></i> Operation</label>
<select type="text" id="node-input-operation" style="display: inline-block; vertical-align: top;"> <select type="text" id="node-input-operation" style="display: inline-block; vertical-align: top;">
<option value=store>save</option> <option value="store">save</option>
<option value=insert>insert</option> <option value="insert">insert</option>
<option value=delete>remove</option> <option value="update">update</option>
<option value="delete">remove</option>
</select> </select>
</div> </div>
<div class="form-row node-input-payonly"> <div class="form-row node-input-payonly">

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
var mongo = require('mongodb'); var mongo = require('mongodb');
var MongoClient = mongo.MongoClient; var MongoClient = mongo.MongoClient;
@ -116,6 +117,15 @@ module.exports = function(RED) {
coll.insert(msg,function(err,item){if (err){node.error(err);}}); coll.insert(msg,function(err,item){if (err){node.error(err);}});
} }
} }
else if (node.operation == "update") {
delete msg._topic;
if (node.payonly) {
if (typeof msg.payload !== "object") { msg.payload = {"payload":msg.payload}; }
coll.update(msg.payload,function(err,item){ if (err){node.error(err);} });
} else {
coll.update(msg,function(err,item){if (err){node.error(err);}});
}
}
if (node.operation == "delete") { if (node.operation == "delete") {
coll.remove(msg.payload, {w:1}, function(err, items){ if (err) node.error(err); }); coll.remove(msg.payload, {w:1}, function(err, items){ if (err) node.error(err); });
} }