Merge lp:~ben-hutchings/ensoft-sextant/autocomplete-fix into lp:ensoft-sextant

Proposed by Ben Hutchings
Status: Superseded
Proposed branch: lp:~ben-hutchings/ensoft-sextant/autocomplete-fix
Merge into: lp:ensoft-sextant
Diff against target: 217 lines (+76/-30)
4 files modified
resources/sextant/web/interface.html (+6/-5)
resources/sextant/web/queryjavascript.js (+46/-15)
src/sextant/db_api.py (+10/-3)
src/sextant/web/server.py (+14/-7)
To merge this branch: bzr merge lp:~ben-hutchings/ensoft-sextant/autocomplete-fix
Reviewer Review Type Date Requested Status
Robert Pending
Review via email: mp+241401@code.launchpad.net

This proposal supersedes a proposal from 2014-11-05.

This proposal has been superseded by a proposal from 2014-11-11.

Description of the change

Web gui now has a hard limit on how many functions it is willing to get for the autocomplete menu. If there are more than this number of functions in the program, the empty list will be returned. Maximum number of functions is set to 75 at present - more than this leads to drop down lists not displaying properly sometimes.

Substring search in function names. Debouncing (one second timer at present).

To post a comment you must log in.
Revision history for this message
Ben Hutchings (ben-hutchings) wrote : Posted in a previous version of this proposal

Also the limit is hardcoded in web/server.py, not db_api.py.

34. By Ben Hutchings

removed debug output

35. By Ben Hutchings

fixed missing var in javascript, fixed unused global variables in python.

36. By Ben Hutchings

fixed bug by which timeout was never being tripped

37. By Ben Hutchings

whitespace changes, added missing var

38. By Ben Hutchings

indentation fix

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'resources/sextant/web/interface.html'
2--- resources/sextant/web/interface.html 2014-09-04 09:46:18 +0000
3+++ resources/sextant/web/interface.html 2014-11-11 16:13:40 +0000
4@@ -17,8 +17,8 @@
5 <div class="toolbar">
6 <div>
7 Program:
8- <input list="program_names" id="program_name" class="textbox"
9- onblur="get_names_for_autocomplete('funcs')" style="width: 150px" />
10+ <input list="program_names" id="program_name" class="textbox" style="width: 150px" />
11+ <!-- onblur="get_names_for_autocomplete('funcs')" -->
12 <datalist id="program_names"></datalist>
13
14 <select id="query_list" class="dropdown" onchange="display_when();">
15@@ -44,13 +44,14 @@
16 </div>
17 <div id="toolbar-row2" style="margin-left: 234px;">
18 <!--list to populate arguments. Updates when program name is specified-->
19- <datalist id="function_names"></datalist>
20+ <datalist id="function_names_1"></datalist>
21+ <datalist id="function_names_2"></datalist>
22
23 <span id="argument_1" style="size:20;"></span>
24- <input list="function_names" id="function_1" class="textbox" style="size:20;"></input>
25+ <input list="function_names_1" autocomplete="off" id="function_1" class="textbox" style="size:20;" onkeyup="get_names_for_autocomplete('funcs_with_timeout_1')"></input>
26
27 <span id="argument_2" style="size:20;"></span>
28- <input list="function_names" id="function_2" class="textbox" style="size:20;"></input>
29+ <input list="function_names_2" autocomplete="off" id="function_2" class="textbox" style="size:20;" onkeyup="get_names_for_autocomplete('funcs_with_timeout_2')"></input>
30 </div>
31 </div>
32
33
34=== modified file 'resources/sextant/web/queryjavascript.js'
35--- resources/sextant/web/queryjavascript.js 2014-09-29 21:08:33 +0000
36+++ resources/sextant/web/queryjavascript.js 2014-11-11 16:13:40 +0000
37@@ -6,42 +6,73 @@
38 //server or function names from a specific program.
39
40
41-function get_names_for_autocomplete(info_needed){
42+var timeout = null;
43+
44+
45+function get_names_for_autocomplete(info_needed, search){
46 //Function queries to database to create a list
47 //which is used to populate the auto-complete text boxes.
48+ if (typeof search == 'undefined') {
49+ search = "";
50+ }
51+
52 var xmlhttp = new XMLHttpRequest();
53 xmlhttp.onreadystatechange = function(){
54 if (xmlhttp.status = 200){
55 var values_list = xmlhttp.responseText;
56+ do_timeout = false;
57 if (values_list != "") {
58 values_list = JSON.parse(values_list);
59 if (info_needed =='programs'){
60 //We need to populate the program names list
61 add_options("program_names", values_list);
62 }
63- if (info_needed =='funcs'){
64- //We need to populate the functions list for the arguments
65- add_options("function_names", values_list);
66- }
67+ if (info_needed == 'funcs_with_timeout_1') {
68+ add_options("function_names_1", values_list);
69+ do_timeout = true;
70+ }
71+ if (info_needed == 'funcs_with_timeout_2') {
72+ add_options("function_names_2", values_list);
73+ do_timeout = true;
74+ }
75 }
76 }
77 }
78 if (info_needed == 'programs'){
79 var string = "/database_properties?query=" + info_needed + "&program_name=";
80+ xmlhttp.open("GET", string, true);
81+ xmlhttp.send();
82 }
83 else{
84- var string = "/database_properties?query=" + "functions" +
85- "&program_name=" + document.getElementById("program_name").value;
86- if (info_needed == 'programs'){
87- var string = "/database_properties?query=" +
88- info_needed + "&program_name=" + prog_name;
89- }
90+ var target = null;
91+
92+ if (info_needed == 'funcs_with_timeout_1') {
93+ target = 'function_1';
94+ }
95+ else {
96+ target = 'function_2';
97+ }
98+
99+ timeoutfn = function() {
100+ var string = "/database_properties?query=" + "functions" +
101+ "&program_name=" + document.getElementById("program_name").value +
102+ "&search=" + document.getElementById(target).value;
103+ xmlhttp.open("GET", string, true);
104+ xmlhttp.send();
105+ timeout = null;
106+ };
107+
108+ if (do_timeout == true && timeout === null) {
109+ timeout = window.setTimeout(timeoutfn, 1000);
110+ } else if (do_timeout == true) {
111+ window.clearTimeout(timeout);
112+ timeout = window.setTimeout(timeoutfn, 1000);
113+ } else {
114+ timeoutfn();
115+ }
116+
117 //"GET" information from the specified url (string)
118- xmlhttp.open("GET", string, true);
119- xmlhttp.send();
120 }
121- xmlhttp.open("GET", string, true);
122- xmlhttp.send();
123 }
124
125
126
127=== modified file 'src/sextant/db_api.py'
128--- src/sextant/db_api.py 2014-10-23 11:15:48 +0000
129+++ src/sextant/db_api.py 2014-11-11 16:13:40 +0000
130@@ -34,6 +34,8 @@
131 # prior to copy over to the remote server.
132 TMP_DIR = '/tmp/sextant'
133
134+SEARCH_NAMES_LIMIT = 50
135+
136 # A function is deemed 'common' if it has more than this
137 # many connections.
138 COMMON_CUTOFF = 10
139@@ -832,7 +834,7 @@
140 result = self._db.query(q, returns=neo4jrestclient.Node)
141 return bool(result)
142
143- def get_function_names(self, program_name):
144+ def get_function_names(self, program_name, search, max_funcs):
145 """
146 Execute query to retrieve a list of all functions in the program.
147 Any of the output names can be used verbatim in any SextantConnection
148@@ -845,8 +847,13 @@
149 if not validate_query(program_name):
150 return set()
151
152- q = (' MATCH (:program {{name: "{}"}})-[:subject]->(f:func)'
153- ' RETURN f.name').format(program_name)
154+ if not search:
155+ q = (' MATCH (:program {{name: "{}"}})-[:subject]->(f:func)'
156+ ' RETURN f.name LIMIT {}').format(program_name, max_funcs)
157+ else:
158+ q = (' MATCH (:program {{name: "{}"}})-[:subject]->(f:func)'
159+ ' WHERE f.name =~ ".*{}.*" RETURN f.name LIMIT {}'
160+ .format(program_name, search, max_funcs))
161 return {func[0] for func in self._db.query(q)}
162
163 def get_all_functions_called(self, program_name, function_calling):
164
165=== modified file 'src/sextant/web/server.py'
166--- src/sextant/web/server.py 2014-10-13 15:09:08 +0000
167+++ src/sextant/web/server.py 2014-11-11 16:13:40 +0000
168@@ -28,6 +28,7 @@
169
170 # global SextantConnection object which deals with the port forwarding
171 CONNECTION = None
172+CONNECTION_MAX_FUNCTION_NAMES = 500
173
174 RESPONSE_CODE_OK = 200
175 RESPONSE_CODE_BAD_REQUEST = 400
176@@ -218,8 +219,12 @@
177 return CONNECTION.get_program_names()
178
179 @staticmethod
180- def _get_function_names(program_name):
181- return CONNECTION.get_function_names(program_name)
182+ def _get_function_names(program_name, search=""):
183+ max_funcs = 76;
184+ programs = CONNECTION.programs_with_metadata()
185+ result = CONNECTION.get_function_names(program_name, search, max_funcs)
186+ return result if len(result) < max_funcs else set()
187+
188
189 @defer.inlineCallbacks
190 def _render_GET(self, request):
191@@ -247,19 +252,21 @@
192 request.finish()
193 defer.returnValue(None)
194 program_name = request.args['program_name'][0]
195+ search = request.args.get('search', [''])[0]
196
197- funcnames = yield deferToThread(self._get_function_names, program_name)
198+ funcnames = yield deferToThread(self._get_function_names, program_name, search)
199 if funcnames is None:
200 request.setResponseCode(404)
201 request.setHeader("content-type", "text/plain")
202 request.write("No program with name %s was found in the Sextant." % escape(program_name))
203 request.finish()
204 defer.returnValue(None)
205+ else:
206+ request.setHeader("content-type", "application/json")
207+ request.write(json.dumps(list(funcnames)))
208
209- request.setHeader("content-type", "application/json")
210- request.write(json.dumps(list(funcnames)))
211- request.finish()
212- defer.returnValue(None)
213+ request.finish()
214+ defer.returnValue(None)
215
216 else:
217 request.setResponseCode(400)

Subscribers

People subscribed via source and target branches