Commit db26a998 authored by Ryan Herbert's avatar Ryan Herbert

Merge branch 'feature-cs/faster_autocomplete' into 'dev'

Feature cs/faster autocomplete

Closes #3100

See merge request !217
parents f69a9343 cacfcda2
Pipeline #30145 passed with stages
in 49 seconds
......@@ -157,6 +157,10 @@ VidjilAutoComplete.prototype = {
// code modified from atwho source
callbacks.highlighter = function(li, query) {
var def = VidjilAutoComplete.defaultLoadingData[0];
if (li.substr(4, def.length) == def) {
return li;
}
var mapper = {'p': 'patient',
'r': 'run',
's': 'generic'}
......@@ -192,12 +196,26 @@ VidjilAutoComplete.prototype = {
});
};
callbacks.filter = function(query, data, searchKey) {
var fetchData = self.fetchData.bind(self);
var isLoaded = self.isLoaded.bind(self);
var val = this.$inputor.val()
var keys = [val];
if ((VidjilAutoComplete.isLoading(data) || !isLoaded(keys)) && (val.length == 0 || val.length >= 3)) {
this.$inputor.atwho('load', this.at, VidjilAutoComplete.defaultLoadingData);
fetchData(this.$inputor, this.at, keys);
return data;
}
return $.fn.atwho.default.callbacks.filter(query, data, searchKey);
};
$input.atwho({
at: at,
alias: 'samples',
data: VidjilAutoComplete.defaultLoadingData,
callbacks: callbacks,
searchKey: 'search',
limit: 10
});
},
......
......@@ -773,31 +773,43 @@ def change_permission():
log.error(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
def get_sample_set_list(type):
def get_sample_set_list(stype, q):
factory = ModelFactory()
helper = factory.get_instance(type=stype)
limitby = None
if q is not None and len(q) == 0:
q = None
if not q :
limitby = (0, 10)
filter_query = helper.get_name_filter_query(q)
query = db(
(auth.vidjil_accessible_query(PermissionEnum.admin.value, db.sample_set))&
(db[type].sample_set_id == db.sample_set.id)
(db[stype].sample_set_id == db.sample_set.id) &
(filter_query)
).select(
db[type].ALL, # sub optimal, use helpers to reduce ?
orderby = ~db[type].sample_set_id,
limitby=(0,500)
db[stype].ALL, # sub optimal, use helpers to reduce ?
orderby = ~db[stype].sample_set_id,
limitby = limitby
)
ss_list = []
factory = ModelFactory()
helper = factory.get_instance(type=type)
for row in query :
tmp = helper.get_id_string(row)
ss_list.append({'name':tmp, 'id': row.sample_set_id, 'type': type})
ss_list.append({'name':tmp, 'id': row.sample_set_id, 'type': stype})
return ss_list
def auto_complete():
if "keys" not in request.vars:
return error_message("missing group ids")
sample_types = json.loads(request.vars['keys'])
result = {}
query = json.loads(request.vars['keys'])[0]
sample_types = [defs.SET_TYPE_PATIENT, defs.SET_TYPE_RUN, defs.SET_TYPE_GENERIC]
result = []
for sample_type in sample_types:
result[sample_type] = get_sample_set_list(sample_type)
result += get_sample_set_list(sample_type, query)
return json.dumps(result)
res = {}
res[query] = result
return json.dumps(res)
......@@ -108,6 +108,11 @@ class SampleSet(object):
if key in row:
row['string'].append(str(row[key]))
def get_name_filter_query(self, query):
if query is None or query == '':
return (db[self.type].name != None)
return (db[self.type].name.like('%' + query + "%"))
@abstractmethod
def filter(self, filter_str, data):
pass
......
......@@ -62,3 +62,9 @@ class Patient(SampleSet):
if (data["first_name"] + data['last_name']).find('|') >= 0:
error.append("illegal character '|' in name")
return error
def get_name_filter_query(self, query):
if query is None or query == '':
return (db[self.type].id > 0)
return ((db[self.type].first_name.like('%' + query + "%")) |
(db[self.type].last_name.like('%' + query + '%')))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment