From 7f309f2207ce03a3079700176ebcd30161fe10ac Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Tue, 23 Dec 2014 14:39:25 +0200 Subject: client: removal of links through server; Fixes #228 Code is ugly on too many counts, but mainly: 1. repeats local change twice, once for temp and once for non-temp that goes through server. 2. handles topo_diff reply expecting a single id instead of having a general topo_diff reply handler that will take care of it, possibly hanging a callback on it for graph update. --- src/client/model/graph.js | 36 ++++++++++++++++++++++++++++++++++-- src/client/rz_core.js | 7 +++++-- 2 files changed, 39 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/client/model/graph.js b/src/client/model/graph.js index 063bc3c5..b671671e 100644 --- a/src/client/model/graph.js +++ b/src/client/model/graph.js @@ -542,13 +542,45 @@ function Graph() { } } - this.removeLink = function(link) { + var linkGetIndexFromId = function(link_id) { + for (var i = 0 ; i < links.length ; ++i) { + if (links[i].id == link_id) { + return i; + } + } + } + + this.removeLink = function(link, on_success, on_error) { var i; + if (link.id === undefined) { + console.log('bug: link without an id'); + } + + function graph_on_success(ret) { + var link_id = ret[0][0]; + links.splice(linkGetIndexFromId(link_id), 1); + if (on_success) { + on_success(); + } + } + for (i = 0 ; i < links.length; ++i) { if (link.id !== undefined) { if (link.id === links[i].id) { - links.splice(i, 1); + if (link.state == 'temp') { + links.splice(i, 1); + if (on_success) { + on_success(); + } + } else { + if (rz_config.backend_enabled) { + var topo_diff = model_diff.new_topo_diff({ + link_set_rm: [link.id] + }); + rz_api_backend.commit_diff__topo(topo_diff, graph_on_success, on_error); + } + } return; } } else { diff --git a/src/client/rz_core.js b/src/client/rz_core.js index 7006af36..0ab227d8 100644 --- a/src/client/rz_core.js +++ b/src/client/rz_core.js @@ -380,9 +380,12 @@ function update_view__graph(no_relayout) { dst = this.link.__dst; view.edge_info.on_delete(function () { - graph.removeLink(that.link); - update_view__graph(true); view.edge_info.hide(); + graph.removeLink(that.link, function() { + update_view__graph(true); + }, function() { + console.log("error: could not remove link"); + }); }); view.edge_info.show(d); selection.update([src, dst]); -- cgit v1.3.1