From f2ce89be26456be0fba9b298a19e98b83482170d Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Mon, 24 Nov 2014 20:30:09 +0200 Subject: add search The added input lets you select by *oring* multiple space less expressions. i.e. 'a b' will find all nodes with name containing either 'a' or 'b'. Not the specification, will be remedied later (i.e. maybe tomorrow, who knows). excuse the bulk commit, this does 3 things: splits off selection logic into src/view/selection - handles setting state explicityl on Node's, still bad. - bad at least the 'selected' state (i.e. boolean) is in one place. - common point for clicking on nodes/edges and selecting view selection input makes graph.getConnectedNodesAndLinks accept an array and not just a single node implements the search functionality outlined in the first paragraph. --- src/main.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/main.js') diff --git a/src/main.js b/src/main.js index b4f71001..feefcf57 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,5 @@ -define(['textanalysis.ui', 'textanalysis', 'buttons', 'history', 'drag_n_drop', 'robot', 'model/core', 'rz_config', 'rz_core'], -function(textanalysis_ui, textanalysis, buttons, history, drag_n_drop, robot, model_core, rz_config, rz_core) { +define(['textanalysis.ui', 'textanalysis', 'buttons', 'history', 'drag_n_drop', 'robot', 'model/core', 'rz_config', 'rz_core', 'view/selection'], +function(textanalysis_ui, textanalysis, buttons, history, drag_n_drop, robot, model_core, rz_config, rz_core, selection) { function getParameterByName(name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); @@ -43,6 +43,18 @@ function(textanalysis_ui, textanalysis, buttons, history, drag_n_drop, $('#search').focus(); } }; + // TODO: move me somewhere + $('#search').on('input', function(e) { + var text = this.value, + r = new RegExp(text.replace(' ', '|')); // TODO fails for quotes + console.log('search: ' + text); + if (text.length > 0) { + selection.byVisitors(function (n) { return n.name.match(r); }); + } else { + selection.clear(); + } + rz_core.update_view__graph(false); + }); // TODO: interaction between the hack above and this model_core.init(rz_config); textanalysis.init(); -- cgit v1.3.1