From f7ff8bc38410c2666665c4c70cc71c17f6eb7835 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Tue, 23 Dec 2014 21:53:46 +0200 Subject: use topo_diff for user input changes pretty large commit, but it mainly boils to - reusing the same format clone returns to the client for topo_diff bad bad code introduced mainly in client side, but server wasn't spared: - graph/commit_topo__diff massages the links too much - this should not be there at all, it should be in the correct format to begin with. server code duplication between clone & topo_diff post processing, should be factored out on the good side: single transaction whenever user presses enter, and the correct place to send back any accumulated diffs (other user changes). --- src/client/textanalysis.js | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'src/client/textanalysis.js') diff --git a/src/client/textanalysis.js b/src/client/textanalysis.js index 7881a767..63287913 100644 --- a/src/client/textanalysis.js +++ b/src/client/textanalysis.js @@ -467,17 +467,19 @@ var textAnalyser = function (newtext, finalize) { graph.removeNodes(function(n){ return "temp" == n.state; }); graph.removeLinks("temp"); - ret.for_each_node_add(function (node) { - if (true == finalize && node.state == 'temp') { - console.log('bug: temp node creation on finalize'); - } else { - if (!finalize) { - lastnode = graph.addNode(node); + if (!finalize) { // finalize done via topo diff below + ret.for_each_node_add(function (node) { + if (true == finalize && node.state == 'temp') { + console.log('bug: temp node creation on finalize'); } else { - graph.addNode(node); + if (!finalize) { + lastnode = graph.addNode(node); + } else { + graph.addNode(node); + } } - } - }); + }); + } } ret.for_each_link_add(function (link) { if (false == finalize || link.name !== 'and') { @@ -499,13 +501,19 @@ var textAnalyser = function (newtext, finalize) { // broadcast diff: // - finalize? // - broadcast_diff requested by caller - var topo_diff = model_util.adapt_format_write_topo_diff(ret.nodes, ret.links); - var diff_set = model_diff.new_diff_set(); - diff_set.add_diff_obj(topo_diff); - graph.commit_diff_set(diff_set); + var on_success = function (ret) { + console.dir(ret); + rz_core.update_view__graph(); + } + var on_error = function () { + console.log('askeeeeeeeeeeeeew'); + } + // drop bubble node + ret.node_set_add = ret.node_set_add.filter(function(n) { return n.type != 'bubble'; }); + graph.commit_diff__topo(ret, on_success, on_error); } - // UPDATE GRAPH ONCE + // update graph if not going through backend rz_core.update_view__graph(!finalize && comp.graph_same); }; -- cgit v1.3.1