mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add toggle button support to core, tidying up debug node
This commit is contained in:
@@ -59,16 +59,10 @@
|
||||
icon: "debug.png",
|
||||
align: "right",
|
||||
button: {
|
||||
color: function() {
|
||||
return (typeof this.active === 'undefined') ? ("#87a980" ) : (this.active ? "#87a980" : "#b9b9b9");
|
||||
},
|
||||
wide: function() {
|
||||
return (typeof this.active === 'undefined') ? 100 : (this.active ? 100 : 110);
|
||||
},
|
||||
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");
|
||||
@@ -79,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,16 +100,19 @@ 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;
|
||||
if (state === "enable") {
|
||||
node.active = true;
|
||||
res.send(201);
|
||||
} else {
|
||||
node.active = true;
|
||||
} else if (state === "disable") {
|
||||
node.active = false;
|
||||
res.send(200);
|
||||
}
|
||||
} else {
|
||||
res.send(404);
|
||||
}
|
||||
} else {
|
||||
res.send(404);
|
||||
}
|
||||
|
Reference in New Issue
Block a user