Commit 951ebbc7 authored by Ryan Herbert's avatar Ryan Herbert
Browse files

add 'tokens' for adding samples to sets

rather than having a long string of id strings when adding a sample to
multiple sets, we now have spans that represent the set id strings and
the input is emptied after adding each set.
parent 50ed4eec
......@@ -69,6 +69,7 @@ function loadAfterConf() {
"../url",
"../autocomplete",
"../tips",
"../tokeniser",
// Speed test
"../speed_test",
"../../test/QUnit/testFiles/data_test",
......
......@@ -130,22 +130,12 @@ VidjilAutoComplete.prototype = {
}
var res = $.map(data, function(i) {
return {
name: i.name.substr(3),
search: i.name
name: i.name
};
});
return res;
};
callbacks.matcher = function(flag, subtext) {
var regex = /:?([\s0-9a-z_\[\]\(\)]+),?\s*/ig
var match = subtext.match(regex);
if (match) {
return match[match.length - 1];
}
return null;
};
// code taken directly from atwho source in order to allow use of brackets in inputs
callbacks.highlighter = function(li, query) {
var regexp;
......@@ -159,8 +149,9 @@ VidjilAutoComplete.prototype = {
};
callbacks.beforeInsert = function(value) {
return value + ", "
callbacks.beforeInsert = function(value, li) {
$input.data('set-id', value);
return value.substr(3);
};
$input.atwho({
......
/* This file is part of Vidjil <http://www.vidjil.org>,
* High-throughput Analysis of V(D)J Immune Repertoire.
* Copyright (C) 2013-2017 by Bonsai bioinformatics
* at CRIStAL (UMR CNRS 9189, Université Lille) and Inria Lille
* Contributors:
* Marc Duez <marc.duez@vidjil.org>
* The Vidjil Team <contact@vidjil.org>
*
* "Vidjil" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "Vidjil" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "Vidjil". If not, see <http://www.gnu.org/licenses/>
*/
function Tokeniser() {
if (typeof Tokeniser.instance === 'object') {
return Tokeniser.instance;
}
Tokeniser.instance = this;
return this;
}
Tokeniser.prototype = {
setup: function(input, target) {
var self = this;
if ($(input).data('needs-tokeniser')) {
$(input).on("keydown", function(e) {
if (e.which === 13) {
e.preventDefault();
self.tokenise(this, target);
}
});
$(input).data('needs-tokeniser', false);
}
},
tokenise: function(input, target) {
var class_mapping = {
":p": "patient_token",
":r": "run_token",
":s": "generic_token"
};
var token = document.createElement('span');
var text = $(input).val().trim();
var set_id = $(input).data('set-id');
var className = "set_token " + class_mapping[set_id.substr(0, 2)];
token.className = className;
token.innerText = text;
$(token).data('set-id', set_id);
$(input).val("");
$(input).data('set-id');
target.appendChild(token);
},
readTokens: function(target) {
var nodes = $(target).children('.set_token');
return nodes.map(function callback() {
return $(this).data('set-id');
})
.get()
.join();
}
}
......@@ -79,7 +79,7 @@ def filter_set_ids(req_vars):
def form():
group_ids = []
set_ids = []
sets = []
relevant_ids = []
factory = ModelFactory()
sample_types = [defs.SET_TYPE_GENERIC, defs.SET_TYPE_PATIENT, defs.SET_TYPE_RUN]
......@@ -126,9 +126,7 @@ def form():
for t in relevant_ids:
group_ids.append(get_set_group(t[0], t[1]))
row = db(db[t[0]].id == t[1]).select().first()
set_ids.append(helpers[t[0]].get_id_string(row))
sets_string = ', '.join(set_ids)
sets.append({'type': t[0], 'id': helpers[t[0]].get_id_string(row)})
group_ids = [int(gid) for gid in group_ids]
......@@ -154,7 +152,7 @@ def form():
source_module_active = hasattr(defs, 'FILE_SOURCE') and hasattr(defs, 'FILE_TYPES')
return dict(message = T('edit file'),
pre_process_list = pre_process_list,
sets_string = sets_string,
sets = sets,
file = db.sequence_file[request.vars["file_id"]],
sample_type = sample_type,
source_module_active = source_module_active,
......
......@@ -3,7 +3,7 @@
<h3>Edit sequence file</h3>
<form id="upload_form" action="DB_ADDRESS/file/submit" enctype="multipart/form-data" method="post">
<form id="upload_form" action="DB_ADDRESS/file/submit" enctype="multipart/form-data" method="post" onsubmit="document.getElementById('set_list').value = new Tokeniser().readTokens(document.getElementById('set_div'));">
<input type="hidden" id="filename" name="filename" type="text" value="">
<input type="hidden" id="file_id" name="file_id" value="{{if "file_id" in request.vars:}}{{=request.vars["file_id"]}}{{pass}}" >
<input type="hidden" id="sample_set_id" name="sample_set_id" value="{{if "sample_set_id" in request.vars:}}{{=request.vars["id"]}}{{pass}}" >
......@@ -61,7 +61,29 @@
</tr>
<tr>
<td><label for="set_ids" id="set_ids__label">sets: </label></td>
<td><input onfocus="new VidjilAutoComplete().setupSamples(this);" data-needs-atwho="true" data-group-ids="{{=group_ids}}" data-keys='["generic", "patient", "run"]' id="set_list" name="set_ids" type="text" size="80" value="{{=sets_string}}" autocomplete="off"></td>
<td>
<div id="set_div" style="width:100%;">
<input
id="token_input"
onfocus="new VidjilAutoComplete().setupSamples(this); new Tokeniser().setup(this, this.parentNode);"
data-needs-atwho="true"
data-needs-tokeniser="true"
data-group-ids="{{=group_ids}}"
data-keys='["generic", "patient", "run"]'
type="text"
size="80">
<input
hidden
id="set_list"
name="set_ids"
type="text"
size="80">
<br>
{{ for set in sets: }}
<span class="set_token {{=set['type']}}_token" data-set-id="{{=set['id']}}">{{=set['id'][3:]}}</span>
{{pass}}
</div>
</td>
</tr>
<tr class='db_table_split' ><td colspan="2"> sample information </td></tr>
......
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