Commit aec165d0 authored by Ryan Herbert's avatar Ryan Herbert

file.py, sample_set.py file forms

Removing the datalists in the previous commit opened the way to use
At.js for autocompletion purposes.
Querying the set lists asynchronously helps save a little time, making
the app a bit faster, and should work in a wider variety of browsers.

See #2118
parent 1f5dc3fb
......@@ -83,6 +83,10 @@ VidjilAutoComplete.prototype = {
this.setupAtWho(input, this.atWhoTags);
},
setupSamples: function(input) {
this.setupAtWho(input, this.atWhoSamples);
},
setupAtWho: function(input, callback) {
var $input = $(input);
if ($input.data('needs-atwho')) {
......@@ -114,6 +118,43 @@ VidjilAutoComplete.prototype = {
});
},
atWhoSamples : function($input) {
var self = this;
var at = '';
this.initCache(at);
this.dataUrls[at] = this.datasource.db_address + 'sample_set/auto_complete'
var callbacks = self.getDefaultCallbacks()
callbacks.beforeSave = function(data) {
if (data.length == 1 && data[0] == VidjilAutoComplete.defaultLoadingData[0]) {
return data;
}
var res = $.map(data, function(i) {
return {
name: i,
search: i
};
});
return res;
};
callbacks.matcher = function(flag, subtext) {
var regex = new RegExp(`[\\s\\S]+`);
var match = regex.exec(subtext);
if (match) {
return match[0];
}
return null;
};
$input.atwho({
at: at,
alias: 'samples',
data: VidjilAutoComplete.defaultLoadingData,
callbacks: callbacks,
searchKey: 'search',
});
},
getDefaultCallbacks : function() {
var fetchData = this.fetchData.bind(this);
var isLoaded = this.isLoaded.bind(this);
......
......@@ -21,25 +21,6 @@ def extract_id(target, error):
return id
except:
raise ValueError('invalid input %s' % target)
def get_sample_set_list(type, reference):
query = db(
auth.vidjil_accessible_query(PermissionEnum.read.value, db[type])
).select(
db[type].ALL, # sub optimal, use helpers to reduce ?
orderby = ~db[type].id
)
ss_list = []
ref = ""
factory = ModelFactory()
helper = factory.get_instance(type=type)
for row in query :
tmp = helper.get_id_string(row)
ss_list.append(tmp)
if reference == row.id:
ref = tmp
return ss_list, ref
def add():
sample_set = db.sample_set[request.vars["id"]]
......
......@@ -2,6 +2,7 @@
import gluon.contrib.simplejson, datetime
import vidjil_utils
import time
import json
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
......@@ -577,3 +578,30 @@ def change_permission():
res = {"message": ACCESS_DENIED}
log.error(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
def get_sample_set_list(type):
query = db(
auth.vidjil_accessible_query(PermissionEnum.read.value, db[type])
).select(
db[type].ALL, # sub optimal, use helpers to reduce ?
orderby = ~db[type].id
)
ss_list = []
factory = ModelFactory()
helper = factory.get_instance(type=type)
for row in query :
tmp = helper.get_id_string(row)
ss_list.append(tmp)
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 = {}
for sample_type in sample_types:
result[sample_type] = get_sample_set_list(sample_type)
return json.dumps(result)
......@@ -59,7 +59,7 @@
{{ for key in id_strings: }}
<tr>
<td><label for="{{=key}}_id" id="{{=key}}_id__label">{{=key if key != 'generic' else 'set'}}: </label></td>
<td><input id="{{=key}}_list" name="{{=key}}_id" type="text" size="80" value="{{=id_strings[key]}}"></td>
<td><input onfocus="new VidjilAutoComplete().setupSamples(this);" data-needs-atwho="true" data-keys=["{{=key}}"] id="{{=key}}_list" name="{{=key}}_id" type="text" size="80" value="{{=id_strings[key]}}"></td>
</tr>
{{ pass }}
<tr class='db_table_split' ><td colspan="2"> sample information </td></tr>
......
......@@ -65,7 +65,7 @@ info = db.sequence_file[request.vars["id"]]
{{ for key in id_strings: }}
<tr>
<td><label for="{{=key}}_id" id="{{=key}}_id__label">{{=key if key != 'generic' else 'set'}}: </label></td>
<td><input id="{{=key}}_list" name="{{=key}}_id" type="text" size="80" value="{{=id_strings[key]}}"></td>
<td><input onfocus="new VidjilAutoComplete().setupSamples(this);" data-needs-atwho="true" data-keys=["{{=key}}"] id="{{=key}}_list" name="{{=key}}_id" type="text" size="80" value="{{=id_strings[key]}}"></td>
</tr>
{{ pass }}
......
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