diff options
| author | Alon Levy <alon@pobox.com> | 2014-12-29 14:57:00 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2015-01-05 13:23:57 +0200 |
| commit | a4adf9cdf1b3f3aa2d85c188c1eb44ab13e0a660 (patch) | |
| tree | 36b91a35981bceaca99675420214118a4e74797a /src/client | |
| parent | 304ff56ede5803daf7820a9aafba77932e79412a (diff) | |
wip names bus drop, more bacon, fix completer remove names, fix json loading
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/model/graph.js | 27 | ||||
| -rw-r--r-- | src/client/rz_bus.js | 4 | ||||
| -rw-r--r-- | src/client/rz_core.js | 3 | ||||
| -rw-r--r-- | src/client/textanalysis.js | 47 |
4 files changed, 42 insertions, 39 deletions
diff --git a/src/client/model/graph.js b/src/client/model/graph.js index 4d6e1911..12190cd7 100644 --- a/src/client/model/graph.js +++ b/src/client/model/graph.js @@ -1,7 +1,7 @@ "use strict" -define(['Bacon', 'consts', 'util', 'model/core', 'model/util', 'model/diff', 'rz_api_backend', 'rz_api_mesh', 'history', 'rz_bus', 'rz_config'], -function (Bacon, consts, util, model_core, model_util, model_diff, rz_api_backend, rz_api_mesh, history, rz_bus, rz_config) { +define(['Bacon', 'consts', 'util', 'model/core', 'model/util', 'model/diff', 'rz_api_backend', 'rz_api_mesh', 'history', 'rz_config'], +function (Bacon, consts, util, model_core, model_util, model_diff, rz_api_backend, rz_api_mesh, history, rz_config) { var debug = false; @@ -12,8 +12,16 @@ function Graph() { links = [], diffBus = new Bacon.Bus(); + // All operations done on the graph. When the server is used (i.e. always) this + // bus contains the server events, not the user events (most of the time the same just with delay). this.diffBus = diffBus; + // debug + diffBus.onValue(function (v) { + console.log("================="); + console.dir(v); + }); + /** * add node if no previous node is present whose id equals that of the node being added * @@ -148,10 +156,6 @@ function Graph() { rz_api_backend.commit_diff__topo(topo_diff, on_success, on_error); } - if (notify) { - diffBus.push({nodes: {add: [node]}}); - } - return node; } this.__addNode = __addNode; @@ -205,10 +209,6 @@ function Graph() { }; rz_api_backend.commit_diff__topo(topo_diff, on_success, on_error); } - - if (ns.length > 0) { - diffBus.push({nodes: {removed: ns.map(function(n) { return n.id; })}}); - } } this.removeNode = function(id) { @@ -433,8 +433,6 @@ function Graph() { }; rz_api_backend.commit_diff__topo(topo_diff, on_success, on_error); } - - diffBus.push({links: {add: [link]}}); } else { existing_link.name = link.name; existing_link.state = link.state; @@ -538,7 +536,6 @@ function Graph() { var on_ajax_error = function(){ console.log('error with commit to server: danger robinson!'); }; - rz_api_backend.commit_diff__attr(attr_diff, on_ajax_success, on_ajax_error); } @@ -812,6 +809,7 @@ function Graph() { data['node_set'].map(on_backend__node_add); data['link_set'].map(on_backend__link_add); + diffBus.push(data); } /** @@ -833,7 +831,7 @@ function Graph() { this.load_from_json = function(json) { var data = JSON.parse(json), - added_names, + added_nodes, that = this; clear(); @@ -856,7 +854,6 @@ function Graph() { that.addLink(link.__src, link.__dst, link.name, "perm"); }); this.clear_history(); - rz_bus.names.push(added_names); } this.save_to_json = function() { diff --git a/src/client/rz_bus.js b/src/client/rz_bus.js index 38033bc4..444573a4 100644 --- a/src/client/rz_bus.js +++ b/src/client/rz_bus.js @@ -4,12 +4,10 @@ define(['consts', 'Bacon'], function(consts, Bacon) { var ui_key_bus = new Bacon.Bus(), - ui_input_bus = new Bacon.Bus(), - names_bus = new Bacon.Bus(); + ui_input_bus = new Bacon.Bus(); return { ui_key: ui_key_bus, ui_input: ui_input_bus, - names: names_bus, }; }); diff --git a/src/client/rz_core.js b/src/client/rz_core.js index ee42c5c0..2dd62f0e 100644 --- a/src/client/rz_core.js +++ b/src/client/rz_core.js @@ -81,7 +81,6 @@ var svgInput = (function() { }); } else { graph.update_node(d, {name: newname}, function() { - rz_bus.names.push([newname]); update_view__graph(true); }); // TODO - 'updating' graphic @@ -300,7 +299,7 @@ function init_force_layout(){ */ function init_ws_connection(){ if (true == rz_config.backend__maintain_ws_connection){ - rz_mesh.init(); + rz_mesh.init({graph: graph}); } } diff --git a/src/client/textanalysis.js b/src/client/textanalysis.js index d5a050eb..5e78f416 100644 --- a/src/client/textanalysis.js +++ b/src/client/textanalysis.js @@ -59,8 +59,8 @@ function new_tokenize(text, node_token, quote) return tokens; } -define(['rz_core', 'model/core', 'model/util', 'model/diff', 'rz_bus', 'consts'], -function(rz_core, model_core, model_util, model_diff, rz_bus, consts) { +define(['rz_core', 'model/core', 'model/util', 'model/diff', 'consts'], +function(rz_core, model_core, model_util, model_diff, consts) { var typeindex = 0; var nodetypes = consts.nodetypes; @@ -87,6 +87,12 @@ function autoSuggestAddName(name) suggestions_options.push(sugg); } +function autoSuggestRemoveName(name) +{ + delete sugg[name]; + suggestions_options.push(sugg); +} + /* up_to_two_renames: * * allow one letter or 'new node' to anything changes */ @@ -525,23 +531,26 @@ var textAnalyser = function (newtext, finalize) { function init(graph) { - function onNodeAdded(diff) { - if (!diff || !diff.nodes || !diff.nodes.added) { - return; - } - for (var k in diff.nodes.added) { - var node = diff.nodes[k]; - autoSuggestAddName(node.name.toLowerCase()); - } - } - function toLowerCase(n) { - return n.toLowerCase(); - } - function onSuggestedNameAdd(names) { - names.map(toLowerCase).forEach(autoSuggestAddName); - } - graph.diffBus.onValue(onNodeAdded); - rz_bus.names.onValue(onSuggestedNameAdd); + // deal with new nodes + graph.diffBus.filter(function (diff) { + return diff.nodes && diff.nodes.added; + }).map(function (diff) { + return diff.nodes.added.toLowerCase(); + }).onValue(autoSuggestAddName); + + // deal with renamed links + graph.diffBus.filter(function (diff) { + return diff && diff.changed && diff.changed.links; + }).map(function (diff) { + return diff.changed.links; + }).flatMap(Bacon.fromArray) + .onValue(function (diff) { + console.log('renamed link ' + diff.removed + ' -> ' + diff.added); + autoSuggestRemoveName(diff.removed.toLowerCase()); + autoSuggestAddName(diff.added.toLowerCase()); + }); + + // TODO renamed nodes, plus reuse part of the pipeline. } return { |
