diff options
| author | Alon Levy <alon@pobox.com> | 2015-02-25 00:22:53 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2015-02-25 00:22:53 +0200 |
| commit | 64324f317b6fbd9a1b636b0b21e123155f8153d4 (patch) | |
| tree | e9796eb67a99133b49d2151a0034b180c364f0ad /src/client | |
| parent | 717200a13ce38ad113620a092f786e9b1ea6ee85 (diff) | |
client: selection tools: add link nodes in fan
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/model/graph.js | 17 | ||||
| -rw-r--r-- | src/client/textanalysis.js | 3 | ||||
| -rw-r--r-- | src/client/view/selection.js | 41 |
3 files changed, 55 insertions, 6 deletions
diff --git a/src/client/model/graph.js b/src/client/model/graph.js index c7e255ec..4feb8a52 100644 --- a/src/client/model/graph.js +++ b/src/client/model/graph.js @@ -542,6 +542,21 @@ function Graph(spec) { this.commit_and_tx_diff__topo(topo_diff); } + /** + * links the first node in the list to the rest of the list. + */ + var nodes__link_fan = function(node_ids) { + util.assert(node_ids.length > 1); // strictly speaking we can also treat 1 as correct usage + var src_id = node_ids[0], + src_node = find_node__by_id(src_id), + added_links = node_ids.slice(1).map(function (tgt_id) { + return model_core.create_link__set_random_id(src_node, find_node__by_id(tgt_id), + {name: 'link'}); + }); + commit_and_tx_diff__topo(model_diff.new_topo_diff({link_set_add: added_links})); + }; + this.nodes__link_fan = nodes__link_fan; + var nodes__merge = function(node_ids) { util.assert(node_ids.length > 1); // strictly speaking we can also treat 1 as correct usage var merged = _.rest(node_ids); @@ -570,7 +585,7 @@ function Graph(spec) { link_set_add: added_links, node_id_set_rm: merged}); commit_and_tx_diff__topo(topo_diff); - } + }; this.nodes__merge = nodes__merge; var _remove_link_set = function(link_id_set) { diff --git a/src/client/textanalysis.js b/src/client/textanalysis.js index 5371c472..02f24211 100644 --- a/src/client/textanalysis.js +++ b/src/client/textanalysis.js @@ -503,6 +503,9 @@ var textAnalyser = function (spec) { ret.drop_conjugator_links = true; // leaving since we might change behavior again + // textanalysis.ui uses this. should make this more explicit + ret.thirds = thirds; + ret.applyToGraph = function(spec) { var edit_graph = spec.edit_graph, backend_commit = spec.backend_commit, diff --git a/src/client/view/selection.js b/src/client/view/selection.js index d91bafbd..8f05f12d 100644 --- a/src/client/view/selection.js +++ b/src/client/view/selection.js @@ -1,6 +1,28 @@ define(['rz_core', 'Bacon', 'jquery', 'underscore'], function(rz_core, Bacon, $, _) { +function list_from_list_like(list_like) +{ + var list = [], + i; + + for (i = 0 ; i < list_like.length ; ++i) { + list.push(list_like[i]); + } + return list; +} + +function list_call(list, field) +{ + list.forEach(function (item) { + item[field].apply(item, list_from_list_like(arguments).slice(2)); + }); +} + +function root_nodes_ids() { + return _.pluck(root_nodes, 'id'); +} + function Selection() { } @@ -173,16 +195,25 @@ var update = function(nodes, append) var setup_merge_button = function(main_graph) { var merge_root_selection = function() { - main_graph.nodes__merge(_.pluck(root_nodes, 'id')); - } - var merge_btn = $('#btn_merge'); + main_graph.nodes__merge(root_nodes_ids()); + }, + link_fan_root_selection = function() { + main_graph.nodes__link_fan(root_nodes_ids()); + }, + merge_btn = $('#btn_merge'), + link_fan_btn = $('#btn_link_fan'), + buttons = [merge_btn, link_fan_btn]; + merge_btn.asEventStream('click').onValue(merge_root_selection); + link_fan_btn.asEventStream('click').onValue(link_fan_root_selection); + selectionChangedBus.map(function (selection) { return selection.root_nodes.length > 1; }) .onValue(function (visible) { if (visible) { - merge_btn.show(); + list_call(buttons, 'show'); } else { - merge_btn.hide(); + list_call(buttons, 'hide'); + buttons.forEach(function (btn) { btn.hide(); }); } }); } |
