mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge branch 'master' into tabs
This commit is contained in:
commit
a16c0835fd
@ -19,7 +19,7 @@
|
||||
// Sample Node-RED node file
|
||||
|
||||
// Require main module
|
||||
var RED = require("../../red/red");
|
||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
||||
|
||||
// The main node definition - most things happen in here
|
||||
function SampleNode(n) {
|
||||
|
@ -59,13 +59,10 @@
|
||||
icon: "debug.png",
|
||||
align: "right",
|
||||
button: {
|
||||
color: function() {
|
||||
return (typeof this.active === 'undefined') ? ("#87a980" ) : (this.active ? "#87a980" : "#b9b9b9");
|
||||
},
|
||||
toggle: "active",
|
||||
onclick: function() {
|
||||
var label = this.name||"debug";
|
||||
var node = this;
|
||||
d3.xhr("debug/"+this.id).post(function(err,resp) {
|
||||
d3.xhr("debug/"+this.id+"/"+(this.active?"enable":"disable")).post(function(err,resp) {
|
||||
if (err) {
|
||||
if (err.status == 404) {
|
||||
RED.notify("<strong>Error</strong>: debug node not deployed","error");
|
||||
@ -76,14 +73,8 @@
|
||||
}
|
||||
} else if (resp.status == 200) {
|
||||
RED.notify("Successfully activated: "+label,"success");
|
||||
node.active = true;
|
||||
node.dirty = true;
|
||||
RED.view.redraw();
|
||||
} else if (resp.status == 201) {
|
||||
RED.notify("Successfully deactivated: "+label,"success");
|
||||
node.active = false;
|
||||
node.dirty = true;
|
||||
RED.view.redraw();
|
||||
} else {
|
||||
RED.notify("<strong>Error</strong>: unexpected response: ("+resp.status+") "+resp.response,"error");
|
||||
}
|
||||
|
@ -100,15 +100,18 @@ DebugNode.logHandler.on("log",function(msg) {
|
||||
});
|
||||
RED.nodes.addLogHandler(DebugNode.logHandler);
|
||||
|
||||
RED.app.post("/debug/:id", function(req,res) {
|
||||
RED.app.post("/debug/:id/:state", function(req,res) {
|
||||
var node = RED.nodes.getNode(req.params.id);
|
||||
var state = req.params.state;
|
||||
if (node != null) {
|
||||
if (node.active) {
|
||||
node.active = false;
|
||||
res.send(201);
|
||||
} else {
|
||||
if (state === "enable") {
|
||||
node.active = true;
|
||||
res.send(201);
|
||||
} else if (state === "disable") {
|
||||
node.active = false;
|
||||
res.send(200);
|
||||
} else {
|
||||
res.send(404);
|
||||
}
|
||||
} else {
|
||||
res.send(404);
|
||||
|
@ -71,15 +71,13 @@ function TcpOut(n) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
this._close = function() {
|
||||
node.on("close", function() {
|
||||
this.closing = true;
|
||||
client.end();
|
||||
clearTimeout(reconnectTimeout);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
else {
|
||||
} else {
|
||||
var connectedSockets = [];
|
||||
var server = net.createServer(function (socket) {
|
||||
var remoteDetails = socket.remoteAddress+":"+socket.remotePort;
|
||||
@ -89,6 +87,11 @@ function TcpOut(n) {
|
||||
node.log("connection closed from "+remoteDetails);
|
||||
connectedSockets.splice(connectedSockets.indexOf(socket),1);
|
||||
});
|
||||
socket.on('error',function() {
|
||||
node.log("socket error from "+remoteDetails);
|
||||
connectedSockets.splice(connectedSockets.indexOf(socket),1);
|
||||
});
|
||||
|
||||
});
|
||||
node.on("input", function(msg) {
|
||||
if (msg.payload != null) {
|
||||
@ -109,16 +112,12 @@ function TcpOut(n) {
|
||||
server.listen(node.port);
|
||||
node.log('listening on port '+node.port);
|
||||
|
||||
this._close = function() {
|
||||
node.on('close', function() {
|
||||
server.close();
|
||||
node.log('stopped listening on port '+node.port);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
RED.nodes.registerType("tcp out",TcpOut);
|
||||
|
||||
TcpOut.prototype.close = function() {
|
||||
this._close();
|
||||
}
|
||||
|
||||
|
@ -60,8 +60,9 @@
|
||||
<div class="form-row">
|
||||
<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;">
|
||||
<option value=store>Store</option>
|
||||
<option value=delete>Delete</option>
|
||||
<option value=store>save</option>
|
||||
<option value=insert>insert</option>
|
||||
<option value=delete>remove</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row node-input-payonly">
|
||||
|
@ -50,6 +50,11 @@ function MongoOutNode(n) {
|
||||
if (node.payonly) coll.save(msg.payload,function(err,item){ if (err){node.error(err);} });
|
||||
else coll.save(msg,function(err,item){if (err){node.error(err);}});
|
||||
}
|
||||
else if (node.operation == "insert") {
|
||||
delete msg._topic;
|
||||
if (node.payonly) coll.insert(msg.payload,function(err,item){ if (err){node.error(err);} });
|
||||
else coll.insert(msg,function(err,item){if (err){node.error(err);}});
|
||||
}
|
||||
if (node.operation == "delete") {
|
||||
coll.remove(msg.payload, {w:1}, function(err, items){ if (err) node.error(err); });
|
||||
}
|
||||
|
@ -625,6 +625,21 @@ RED.view = function() {
|
||||
d3.event.stopPropagation();
|
||||
}
|
||||
|
||||
function nodeButtonClicked(d) {
|
||||
if (d._def.button.toggle) {
|
||||
d[d._def.button.toggle] = !d[d._def.button.toggle];
|
||||
d.dirty = true;
|
||||
}
|
||||
if (d._def.button.onclick) {
|
||||
d._def.button.onclick.call(d);
|
||||
}
|
||||
|
||||
if (d.dirty) {
|
||||
redraw();
|
||||
}
|
||||
d3.event.preventDefault();
|
||||
}
|
||||
|
||||
function redraw() {
|
||||
vis.attr("transform","scale("+scaleFactor+")");
|
||||
outer.attr("width", space_width*scaleFactor).attr("height", space_height*scaleFactor);
|
||||
@ -658,19 +673,18 @@ RED.view = function() {
|
||||
}
|
||||
|
||||
if (d._def.button) {
|
||||
node.append('rect')
|
||||
.attr("class",function(d) { return (d._def.align == "right") ? "node_right_button_group" : "node_left_button_group"; })
|
||||
.attr("x",function(d) { return (d._def.align == "right") ? 94 : -25; })
|
||||
.attr("y",2)
|
||||
var nodeButtonGroup = node.append('svg:g')
|
||||
.attr("transform",function(d) { return "translate("+((d._def.align == "right") ? 94 : -25)+",2)"; })
|
||||
.attr("class",function(d) { return "node_button "+((d._def.align == "right") ? "node_right_button" : "node_left_button"); });
|
||||
nodeButtonGroup.append('rect')
|
||||
.attr("rx",8)
|
||||
.attr("ry",8)
|
||||
.attr("width",32)
|
||||
.attr("height",node_height-4)
|
||||
.attr("fill","#eee");//function(d) { return d._def.color;})
|
||||
node.append('rect')
|
||||
.attr("class",function(d) { return (d._def.align == "right") ? "node_right_button" : "node_left_button"; })
|
||||
.attr("x",function(d) { return (d._def.align == "right") ? 104 : -20; })
|
||||
.attr("y",6)
|
||||
nodeButtonGroup.append('rect')
|
||||
.attr("x",function(d) { return d._def.align == "right"? 10:5})
|
||||
.attr("y",4)
|
||||
.attr("rx",5)
|
||||
.attr("ry",5)
|
||||
.attr("width",16)
|
||||
@ -680,9 +694,15 @@ RED.view = function() {
|
||||
.on("mousedown",function(d) {if (!lasso) { d3.select(this).attr("fill-opacity",0.2);d3.event.preventDefault(); d3.event.stopPropagation();}})
|
||||
.on("mouseup",function(d) {if (!lasso) { d3.select(this).attr("fill-opacity",0.4);d3.event.preventDefault();d3.event.stopPropagation();}})
|
||||
.on("mouseover",function(d) {if (!lasso) { d3.select(this).attr("fill-opacity",0.4);}})
|
||||
.on("mouseout",function(d) {if (!lasso) { d3.select(this).attr("fill-opacity",1);}})
|
||||
.on("click",function(d) { d._def.button.onclick.call(d); d3.event.preventDefault(); })
|
||||
.on("touchstart",function(d) { d._def.button.onclick.call(d); d3.event.preventDefault(); })
|
||||
.on("mouseout",function(d) {if (!lasso) {
|
||||
var op = 1;
|
||||
if (d._def.button.toggle) {
|
||||
op = d[d._def.button.toggle]?1:0.2;
|
||||
}
|
||||
d3.select(this).attr("fill-opacity",op);
|
||||
}})
|
||||
.on("click",nodeButtonClicked)
|
||||
.on("touchstart",nodeButtonClicked)
|
||||
}
|
||||
|
||||
var mainRect = node.append("rect")
|
||||
@ -818,10 +838,24 @@ RED.view = function() {
|
||||
});
|
||||
thisNode.selectAll(".node_icon").attr("height",function(d){return Math.min(50,d.h);}).attr("y",function(d){return (d.h-Math.min(50,d.h))/2;});
|
||||
|
||||
thisNode.selectAll('.node_right_button_group').attr("transform",function(d){return "translate("+(d.w-100)+","+0+")";});
|
||||
thisNode.selectAll('.node_right_button').attr("transform",function(d){return "translate("+(d.w-100)+","+0+")";}).attr("fill",function(d) {
|
||||
return typeof d._def.button.color === "function" ? d._def.button.color.call(d):(d._def.button.color != null ? d._def.button.color : d._def.color)
|
||||
thisNode.selectAll('.node_right_button').attr("transform",function(d){
|
||||
var x = d.w-6;
|
||||
if (d._def.button.toggle && !d[d._def.button.toggle]) {
|
||||
x = x - 8;
|
||||
}
|
||||
return "translate("+x+",2)";
|
||||
});
|
||||
thisNode.selectAll('.node_right_button rect').attr("fill-opacity",function(d){
|
||||
if (d._def.button.toggle) {
|
||||
return d[d._def.button.toggle]?1:0.2;
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
|
||||
|
||||
//thisNode.selectAll('.node_right_button').attr("transform",function(d){return "translate("+(d.w - d._def.button.width.call(d))+","+0+")";}).attr("fill",function(d) {
|
||||
// return typeof d._def.button.color === "function" ? d._def.button.color.call(d):(d._def.button.color != null ? d._def.button.color : d._def.color)
|
||||
//});
|
||||
|
||||
thisNode.selectAll('.node_badge_group').attr("transform",function(d){return "translate("+(d.w-40)+","+(d.h+3)+")";});
|
||||
thisNode.selectAll('text.node_badge_label').text(function(d,i) {
|
||||
|
@ -329,10 +329,11 @@ a.brand img {
|
||||
stroke: #ff7f0e;
|
||||
}
|
||||
.node_highlighted {
|
||||
stroke: #ff0000;
|
||||
stroke: #dd1616;
|
||||
stroke-width: 2;
|
||||
stroke-dasharray: 10, 4;
|
||||
}
|
||||
.node_hovered {
|
||||
dstroke: #ff7f0e;
|
||||
}
|
||||
|
||||
.port_hovered {
|
||||
@ -563,7 +564,6 @@ div.node-info {
|
||||
#node-select-library li.list-hover {
|
||||
background: #ffffd0;
|
||||
}
|
||||
|
||||
.node-text-editor {
|
||||
border:1px solid #ccc;
|
||||
border-radius:5px;
|
||||
|
Loading…
Reference in New Issue
Block a user