Skip to content

Commit

Permalink
fix debug undo/redo by introducing a sideEffectCallback in history ob…
Browse files Browse the repository at this point in the history
…ject
  • Loading branch information
cinhcet committed May 19, 2020
1 parent a69db4d commit a6a781f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 31 deletions.
Expand Up @@ -452,6 +452,11 @@ RED.history = (function() {
}
}

if(ev.sideEffectCallback && typeof ev.sideEffectCallback === 'function') {
inverseEv.sideEffectCallback = ev.sideEffectCallback;
ev.sideEffectCallback(ev);
}

Object.keys(modifiedTabs).forEach(function(id) {
var subflow = RED.nodes.subflow(id);
if (subflow) {
Expand Down
75 changes: 44 additions & 31 deletions packages/node_modules/@node-red/nodes/core/common/21-debug.html
Expand Up @@ -36,6 +36,25 @@
<script type="text/javascript">
(function() {
var subWindow = null;

function activateAjaxCall(node, active, successCallback) {
$.ajax({
url: "debug/"+node.id+"/"+(active?"enable":"disable"),
type: "POST",
success: successCallback,
error: function(jqXHR,textStatus,errorThrown) {
if (jqXHR.status == 404) {
RED.notify(node._("common.notification.error", {message: node._("common.notification.errors.not-deployed")}),"error");
} else if (jqXHR.status === 0) {
RED.notify(node._("common.notification.error", {message: node._("common.notification.errors.no-response")}),"error");
} else {
// TODO where is the err.status comming from?
RED.notify(node._("common.notification.error",{message:node._("common.notification.errors.unexpected",{status:err.status,message:err.response})}),"error");
}
}
});
}

RED.nodes.registerType('debug',{
category: 'common',
defaults: {
Expand Down Expand Up @@ -73,38 +92,28 @@
onclick: function() {
var label = this.name||"debug";
var node = this;
$.ajax({
url: "debug/"+this.id+"/"+(this.active?"enable":"disable"),
type: "POST",
success: function(resp, textStatus, xhr) {
var historyEvent = {
t:'edit',
node:node,
changes:{
active:!node.active
},
dirty:node.dirty,
changed:node.changed
};
node.changed = true;
node.dirty = true;
RED.nodes.dirty(true);
RED.history.push(historyEvent);
RED.view.redraw();
if (xhr.status == 200) {
RED.notify(node._("debug.notification.activated",{label:label}),"success");
} else if (xhr.status == 201) {
RED.notify(node._("debug.notification.deactivated",{label:label}),"success");
}
},
error: function(jqXHR,textStatus,errorThrown) {
if (jqXHR.status == 404) {
RED.notify(node._("common.notification.error", {message: node._("common.notification.errors.not-deployed")}),"error");
} else if (jqXHR.status === 0) {
RED.notify(node._("common.notification.error", {message: node._("common.notification.errors.no-response")}),"error");
} else {
RED.notify(node._("common.notification.error",{message:node._("common.notification.errors.unexpected",{status:err.status,message:err.response})}),"error");
activateAjaxCall(node, node.active, function(resp, textStatus, xhr) {
var historyEvent = {
t:'edit',
node:node,
changes:{
active:!node.active
},
dirty:node.dirty,
changed:node.changed,
sideEffectCallback: function(ev) {
activateAjaxCall(ev.node, ev.node.active);
}
};
node.changed = true;
node.dirty = true;
RED.nodes.dirty(true);
RED.history.push(historyEvent);
RED.view.redraw();
if (xhr.status == 200) {
RED.notify(node._("debug.notification.activated",{label:label}),"success");
} else if (xhr.status == 201) {
RED.notify(node._("debug.notification.deactivated",{label:label}),"success");
}
});
}
Expand Down Expand Up @@ -281,11 +290,15 @@
changed: n.changed,
changes: {
active: n.active
},
sideEffectCallback: function() {
activateAjaxCall(n, n.active);
}
});
n.active = false;
n.changed = true;
n.dirty = true;
activateAjaxCall(n, n.active);
}
}
});
Expand Down

0 comments on commit a6a781f

Please sign in to comment.