Commit 1f5dc3fb authored by Ryan Herbert's avatar Ryan Herbert

file.py, file forms, database.js start file autocompletion from scratch

This is to start addressing a two issues that we are having with file
uploads.
The first being maintainability. Having three fields that perform the
same task with three times the same code isn't acceptable. This way, the
three fields are generated by the same code.
The second, is an issue with datalists. They don't seem to work
consistently accross all browsers, especially in older versions. And
they don't accept css, or provide a scrolling feature.

The datalists have now been removed, helping to make the controller a
little faster.
parent e1f7e43c
......@@ -373,9 +373,6 @@ Database.prototype = {
//bind javascript
this.init_ajaxform()
//
this.build_suggest_box()
//
this.fixed_header()
......@@ -1023,79 +1020,6 @@ Database.prototype = {
this.call('group/rights', arg)
},
updateList: function(that) {
var lastValue = that.lastValue,
value = that.value,
array = [],
pos = value.indexOf('|'),
start = that.selectionStart,
end = that.selectionEnd,
options;
if (that.options) {
options = that.options;
} else {
options = Object.keys(that.list.options).map(function (option) {
return that.list.options[option].value;
});
that.options = options;
}
if (lastValue !== value && value.length>1) {
that.list.innerHTML = options.filter(function (a) {
if (a === undefined)
return 0
return a.toLowerCase().indexOf(value.toLowerCase()) != -1;
}).slice(0,10).map(function (a) {
return '<option value="' + value + '|' + a + '">' + a + '</option>';
}).join();
this.updateInput(that);
that.lastValue = value;
}
},
updateInput: function(that) {
var value = that.value,
pos = value.indexOf('|'),
start = that.selectionStart,
end = that.selectionEnd;
if (pos != -1) {
value = value.slice(pos + 1);
}
that.value = value;
if (that.lastValue !== value){
if (that.options.indexOf(value)!= -1) {
that.style.color = "green";
} else {
that.style.color = "red";
}
}
that.setSelectionRange(start, end);
},
build_suggest_box: function() {
var self = this
if (document.getElementById("patient_list")){
document.getElementById('patient_list').addEventListener('keyup', function (e) {
self.updateList(this);
});
document.getElementById('patient_list').addEventListener('input', function (e) {
self.updateInput(this);
});
document.getElementById('run_list').addEventListener('keyup', function (e) {
self.updateList(this);
});
document.getElementById('run_list').addEventListener('input', function (e) {
self.updateInput(this);
});
}
},
argsToStr : function (args) {
var str = ""
......
......@@ -54,19 +54,18 @@ def add():
message="The space in directory %s has passed below %d%%." % (defs.DIR_SEQUENCES, defs.FS_LOCK_THRESHHOLD))
return error_message("Uploads are temporarily disabled. System admins have been made aware of the situation.")
patient_id = None
run_id = None
generic_id = None
group_ids = []
if sample_set.sample_type == defs.SET_TYPE_GENERIC:
generic_id = db( db.generic.sample_set_id == request.vars["id"]).select()[0].id
group_ids.append(get_set_group(sample_set.sample_type, generic_id))
if sample_set.sample_type == defs.SET_TYPE_PATIENT:
patient_id = db( db.patient.sample_set_id == request.vars["id"]).select()[0].id
group_ids.append(get_set_group(sample_set.sample_type, patient_id))
if sample_set.sample_type == defs.SET_TYPE_RUN:
run_id = db( db.run.sample_set_id == request.vars["id"]).select()[0].id
group_ids.append(get_set_group(sample_set.sample_type, run_id))
sample_types = [defs.SET_TYPE_GENERIC, defs.SET_TYPE_PATIENT, defs.SET_TYPE_RUN]
id_strings = {}
factory = ModelFactory()
for sample_type in sample_types:
if sample_set.sample_type == sample_type:
row = db(db[sample_type].sample_set_id == request.vars["id"]).select().first()
group_ids.append(get_set_group(sample_type, row.id))
helper = factory.get_instance(type=sample_type)
id_strings[sample_type] = helper.get_id_string(row)
else:
id_strings[sample_type] = ""
group_ids = [int(gid) for gid in group_ids]
......@@ -89,20 +88,11 @@ def add():
info = row.info
))
generic_list, generic = get_sample_set_list(defs.SET_TYPE_GENERIC, generic_id)
patient_list, patient = get_sample_set_list(defs.SET_TYPE_PATIENT, patient_id)
run_list, run = get_sample_set_list(defs.SET_TYPE_RUN, run_id)
source_module_active = hasattr(defs, 'FILE_SOURCE') and hasattr(defs, 'FILE_TYPES')
return dict(message = T('add file'),
generic_list = generic_list,
patient_list = patient_list,
run_list = run_list,
pre_process_list = pre_process_list,
generic = generic,
patient = patient,
id_strings = id_strings,
sample_type = sample_set.sample_type,
run = run,
source_module_active = source_module_active,
group_ids = group_ids)
......@@ -279,26 +269,24 @@ def edit():
info = row.info
))
generic_list, generic = get_sample_set_list(defs.SET_TYPE_GENERIC, relevant_ids['generic'])
patient_list, patient = get_sample_set_list(defs.SET_TYPE_PATIENT, relevant_ids['patient'])
run_list, run = get_sample_set_list(defs.SET_TYPE_RUN, relevant_ids['run'])
group_ids = []
id_strings = {}
factory = ModelFactory()
for key in relevant_ids:
if (relevant_ids[key] is not None):
if relevant_ids[key] is not None:
group_ids.append(get_set_group(key, relevant_ids[key]))
helper = factory.get_instance(type=key)
row = db(db[key].id == relevant_ids[key]).select().first()
id_strings[key] = helper.get_id_string(row)
else:
id_strings[key] = ""
group_ids = [int(gid) for gid in group_ids]
source_module_active = hasattr(defs, 'FILE_SOURCE') and hasattr(defs, 'FILE_TYPES')
return dict(message = T('edit file'),
generic_list = generic_list,
patient_list = patient_list,
run_list = run_list,
patient = patient,
id_strings = id_strings,
pre_process_list = pre_process_list,
run = run,
generic = generic,
file = db.sequence_file[request.vars["id"]],
sample_type = request.vars['sample_type'],
source_module_active = source_module_active,
......
......@@ -53,35 +53,15 @@
</tr>
<tr class='db_table_split' ><td colspan="2"> patient and run </td></tr>
<tr>
<td><label for="generic_id" id="sample_set_id__label">set: </label></td>
<td><input list="generics" id="generic_list" name="generic_id" type="text" size="80" value="{{=generic}}"></td>
<datalist id="generics">
{{for row in generic_list :}}
<option value="{{=row}}">
{{pass}}
</datalist>
<td rowspan="2">* You must associate this sample with at least one patient, run or set.
<br/>You can also associate it with any combination of the three.</td>
<td colspan="2">You must associate this sample with at least one patient, run or set.
<br/>You can also associate it with any combination of the three.</td>
</tr>
{{ for key in id_strings: }}
<tr>
<td><label for="patient_id" id="patient_id__label">patient: </label></td>
<td><input list="patients" id="patient_list" name="patient_id" type="text" size="80" value="{{=patient}}"></td>
<datalist id="patients">
{{for row in patient_list :}}
<option value="{{=row}}">
{{pass}}
</datalist>
</tr>
<tr>
<td><label for="run_id" id="run_id__label">run: </label></td>
<td><input list="runs" id="run_list" name="run_id" type="text" size="80" value="{{=run}}"></td>
<datalist id="runs">
{{for row in run_list :}}
<option value="{{=row}}">
{{pass}}
</datalist>
<td></td>
<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>
</tr>
{{ pass }}
<tr class='db_table_split' ><td colspan="2"> sample information </td></tr>
<tr>
<td><label for="sampling_date" id="sampling_date__label">sampling date: </label></td>
......
......@@ -59,36 +59,15 @@ info = db.sequence_file[request.vars["id"]]
<tr class='db_table_split' ><td colspan="2"> patient and run </td></tr>
<tr>
<td><label for="generic_id" id="generic_id__label">set: </label></td>
<td><input list="generics" id="generic_list" name="generic_id" type="text" size="80" value="{{=generic}}"></td>
<datalist id="generics">
{{for row in generic_list :}}
<option value="{{=row}}">
{{pass}}
</datalist>
<td rowspan="2">* You must associate this sample with at least one patient, run or set.
<br/>You can also associate it with any combination of the three.</td>
<td colspan="2">You must associate this sample with at least one patient, run or set.
<br/>You can also associate it with any combination of the three.</td>
</tr>
{{ for key in id_strings: }}
<tr>
<td><label for="patient_id" id="patient_id__label">patient: </label></td>
<td><input list="patients" id="patient_list" name="patient_id" type="text" size="80" value="{{=patient}}"></td>
<datalist id="patients">
{{for row in patient_list :}}
<option value="{{=row}}">
{{pass}}
</datalist>
<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>
</tr>
<tr>
<td><label for="run_id" id="run_id__label">run: </label></td>
<td><input list="runs" id="run_list" name="run_id" type="text" size="80" value="{{=run}}"></td>
<datalist id="runs">
{{for row in run_list :}}
<option value="{{=row}}">
{{pass}}
</datalist>
<td></td>
</tr>
{{ pass }}
<tr class='db_table_split' ><td colspan="2"> sample information </td></tr>
<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