Commit bd79a951 authored by Ryan Herbert's avatar Ryan Herbert Committed by Mikaël Salson

add in-search filtering

parent adcf7e89
......@@ -210,8 +210,7 @@ def all():
step = None
page = None
is_not_filtered = "sort" not in request.vars and "filter" not in request.vars
if request.vars['page'] is not None and is_not_filtered:
if request.vars['page'] is not None:
page = int(request.vars['page'])
step = 50
......@@ -226,7 +225,7 @@ def all():
helper = factory.get_instance(type=type)
f = time.time()
slist = SampleSetList(helper, page, step, tags)
slist = SampleSetList(helper, page, step, tags, search)
# failsafe if filtered display all results
step = len(slist) if step is None else step
......@@ -245,7 +244,6 @@ def all():
else:
result = sorted(result, key = lambda row : row.id, reverse=not reverse)
result = helper.filter(search, result)
log.info("%s list %s" % (request.vars["type"], search), extra={'user_id': auth.user.id,
'record_id': None,
'table_name': "sample_set"})
......
......@@ -166,6 +166,10 @@ class SampleSet(object):
def get_dedicated_group(self):
pass
@abstractmethod
def get_filtered_fields(self, search):
pass
def get_sample_name(sample_set_id):
'''
Return the name associated with a sample set (eg. a run or a
......
......@@ -42,3 +42,7 @@ class Generic(SampleSet):
def get_dedicated_group(self):
table = db[self.type]
return [table.name]
def get_filtered_fields(self, search):
table = db[self.type]
return table.name.contains(search)
......@@ -75,6 +75,11 @@ class Patient(SampleSet):
table = db[self.type]
return [table.first_name, table.last_name, table.birth]
def get_filtered_fields(self, search):
table = db[self.type]
return (table.first_name.contains(search) |
table.last_name.contains(search))
def get_name_filter_query(self, query):
if query is None or query == '':
return (db[self.type].id > 0)
......
......@@ -72,3 +72,7 @@ class Run(SampleSet):
def get_dedicated_group(self):
table = db[self.type]
return [table.name]
def get_filtered_fields(self, search):
table = db[self.type]
return table.name.contains(search)
......@@ -4,7 +4,7 @@ class SampleSetList():
This class is used to load all the required information for such a list.
'''
def __init__(self, helper, page=None, step=None, tags=None):
def __init__(self, helper, page=None, step=None, tags=None, search=None):
self.type = helper.get_type()
s_table = db[self.type]
......@@ -45,6 +45,14 @@ class SampleSetList():
(s_table.sample_set_id == db.sample_set.id) &
(s_table.creator == db.auth_user.id))
if search is not None and search != "":
query = (query &
(helper.get_filtered_fields(search) |
s_table.info.contains(search) |
db.config.name.contains(search) |
db.auth_group.role.contains(search) |
db.auth_user.last_name.contains(search)))
select = [
s_table.id.with_alias('id'),
s_table.sample_set_id.with_alias('sample_set_id'),
......
......@@ -8,7 +8,7 @@
<div class="db_block">
<div class="db_block_left">
search
<input id="db_filter_input" type="text" value="{{=request.vars["filter"]}}" onchange="db.call('sample_set/all', {'type': '{{=helper.get_type()}}', 'filter' : this.value} )"
<input id="db_filter_input" type="text" value="{{=request.vars["filter"]}}" onchange="db.call('sample_set/all', {'type': '{{=helper.get_type()}}', 'filter' : this.value, 'page': 0} )"
onfocus="new VidjilAutoComplete().setupTags(this);"
data-needs-atwho="true" data-keys="{{=group_ids}}">
</div>
......@@ -84,11 +84,11 @@
{{ if page > 0 or len(query) > step: }}
page:
{{ if page > 0: }}
<i class="icon-left-open-1" onclick="db.call('sample_set/all', {'type': '{{=helper.get_type()}}', 'page': {{=page-1}}})"></i>
<i class="icon-left-open-1" onclick="db.call('sample_set/all', {'type': '{{=helper.get_type()}}', 'filter': '{{=request.vars['filter']}}', 'page': {{=page-1}}})"></i>
{{ pass }}
{{= page + 1 }}
{{if len(query) > step : }}
<i class="icon-right-open-1" onclick="db.call('sample_set/all', {'type': '{{=helper.get_type()}}', 'page': {{=page+1}}})"></i>
<i class="icon-right-open-1" onclick="db.call('sample_set/all', {'type': '{{=helper.get_type()}}', 'filter': '{{=request.vars['filter']}}', 'page': {{=page+1}}})"></i>
{{ pass }}
{{ pass }}
</div>
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