Commit 2046cc47 authored by Ryan Herbert's avatar Ryan Herbert
Browse files

file form refactor set selection

One group of sets for all files in the form.
parent 3dd6e9c7
......@@ -74,32 +74,37 @@ def validate(myfile):
error.append("date (wrong format)")
return error
def validate_sets(myfile, errors):
myfile['id_dict'] = {}
myfile['sets'] = []
def validate_sets(set_ids):
id_dict = {}
sets = []
errors = []
if len(myfile['set_ids']) == 0:
log.debug('set_ids: ' + str(set_ids))
log.debug('len: ' + str(len(set_ids)))
if len(set_ids) == 0:
errors.append("missing set association")
return myfile
mf = ModelFactory()
helpers = {}
set_ids = [x.strip() for x in myfile['set_ids'].split(',')]
for sid in set_ids:
set_ids_arr = []
if len(set_ids) > 0:
set_ids_arr = [x.strip() for x in set_ids.split(',')]
log.debug('set_ids array: ' + str(set_ids))
for sid in set_ids_arr:
try:
set_type = extract_set_type(sid)
if set_type not in myfile['id_dict']:
if set_type not in id_dict:
helpers[set_type] = mf.get_instance(set_type)
myfile['id_dict'][set_type] = []
myfile['sets'].append({'type': set_type, 'id': sid})
id_dict[set_type] = []
sets.append({'type': set_type, 'id': sid})
set_id = helpers[set_type].parse_id_string(sid)
myfile['id_dict'][set_type].append(set_id)
id_dict[set_type].append(set_id)
if not auth.can_modify_sample_set(set_id) :
errors.append("missing permission for %s %d" % (set_type, set_id))
except ValueError:
errors.append("Invalid %s %s" % (key, set_ids[set_type]))
return myfile
errors.append("Invalid %s %s" % (key, sid))
return sets, id_dict, errors
def get_pre_process_list():
query_pre_process = db(
......@@ -188,20 +193,15 @@ def form():
myfile = db.sequence_file[request.vars["file_id"]]
if myfile is None:
myfile = {}
myfile['sets'] = get_set_list(relevant_ids, helpers)
sets = get_set_list(relevant_ids, helpers)
upload_group_ids = [int(gid) for gid in get_upload_group_ids(auth)]
group_ids = [int(g['id']) for g in get_default_creation_group(auth)[0]]
pre_process_list = get_pre_process_list()
data = {}
data['file'] = [myfile]
data['sets'] = sets
data['sample_type'] = sample_type
data['errors'] = []
source_module_active = hasattr(defs, 'FILE_SOURCE') and hasattr(defs, 'FILE_TYPES')
return dict(message = T('edit file'),
pre_process_list = pre_process_list,
files = [myfile],
sample_type = sample_type,
source_module_active = source_module_active,
group_ids = group_ids,
upload_group_ids = upload_group_ids)
return form_response(data)
#TODO check data
def submit():
......@@ -215,9 +215,16 @@ def submit():
pre_process = int(f['pre_process'])
pre_process_flag = "WAIT"
sets, id_dict, errors = validate_sets(data['set_ids'])
data['sets'] = sets
data['errors'] = errors
if len(errors) > 0:
return form_response(data)
for f in data['file']:
errors = validate(f)
f = validate_sets(f, errors)
if len(errors) > 0:
f['error'] = errors
......@@ -247,8 +254,8 @@ def submit():
action = "add"
mes = "file (%d) %s %sed" % (f["id"], f["filename"], action)
for key in f['id_dict']:
for sid in f['id_dict'][key]:
for key in id_dict:
for sid in id_dict[key]:
group_id = get_set_group(sid)
register_tags(db, 'sequence_file', fid, f["info"], group_id, reset=True)
......@@ -266,7 +273,7 @@ def submit():
file_data['network'] = True
db.sequence_file[fid] = file_data
link_to_sample_sets(fid, f['id_dict'])
link_to_sample_sets(fid, id_dict)
log.info(mes, extra={'user_id': auth.user.id,\
'record_id': f['id'],\
......@@ -278,19 +285,24 @@ def submit():
"message": "successfully added/edited file(s)"}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else:
source_module_active = hasattr(defs, 'FILE_SOURCE') and hasattr(defs, 'FILE_TYPES')
response.view = 'file/form.html'
upload_group_ids = [int(gid) for gid in get_upload_group_ids(auth)]
group_ids = [int(g['id']) for g in get_default_creation_group(auth)[0]]
pre_process_list = get_pre_process_list()
return dict(message=T("an error occured"),
pre_process_list = pre_process_list,
files = data['file'],
sample_type = data['sample_type'],
source_module_active = source_module_active,
group_ids = group_ids,
upload_group_ids = upload_group_ids)
return form_response(data)
def form_response(data):
source_module_active = hasattr(defs, 'FILE_SOURCE') and hasattr(defs, 'FILE_TYPES')
response.view = 'file/form.html'
upload_group_ids = [int(gid) for gid in get_upload_group_ids(auth)]
group_ids = [int(g['id']) for g in get_default_creation_group(auth)[0]]
pre_process_list = get_pre_process_list()
return dict(message=T("an error occured"),
pre_process_list = pre_process_list,
files = data['file'],
sets = data['sets'],
sample_type = data['sample_type'],
errors = data['errors'],
source_module_active = source_module_active,
group_ids = group_ids,
upload_group_ids = upload_group_ids)
def upload():
session.forget(response)
mes = ""
......
......@@ -27,6 +27,46 @@
{{pass}}
</select>
</fieldset>
<fieldset>
<legend>set selection</legend>
<div>
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.
</div>
<div class="field_div">
{{ if len(errors) > 0: }}
<div class="error">{{=", ".join(errors)}}</div>
{{ pass }}
<label for="set_ids_{{=0}}" id="set_ids__label_{{=0}}">sets: </label>
<div class="token_div form-control" onclick="$('#token_input_{{=0}}').focus()">
<input
hidden
id="file_set_list_{{=0}}"
name="set_ids"
type="text"
value="{{=",".join([set['id'] for set in sets])}}">
<div id="set_div_{{=0}}" class="token_container">
{{ for set in sets: }}
<span class="set_token {{=set['type']}}_token" data-set-id="{{=set['id']}}">
<i class="icon-cancel" onclick="this.parentNode.parentNode.removeChild(this.parentNode);"></i>
{{=set['id'][3:]}}
</span>
{{pass}}
</div>
<input
id="token_input_{{=0}}"
class="token_input"
autocomplete="off"
onfocus="new VidjilAutoComplete().setupSamples(this);
new Tokeniser(document.getElementById('set_div_{{=0}}'), document.getElementById('file_set_list_{{=0}}'));"
data-needs-atwho="true"
data-needs-tokeniser="true"
data-group-ids="{{=upload_group_ids}}"
data-keys='["generic", "patient", "run"]'
type="text">
</div>
</div>
</fieldset>
<div id="fieldset_container">
{{ for i, file in enumerate(files): }}
{{ include 'partial/file/form.html' }}
......
......@@ -43,43 +43,6 @@
</div>
</div>
</fieldset>
<fieldset>
<legend>set selection</legend>
<div>
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.
</div>
<div class="field_div">
<label for="set_ids_{{=i}}" id="set_ids__label_{{=i}}">sets: </label>
<div class="token_div form-control" onclick="$('#token_input_{{=i}}').focus()">
<input
hidden
id="file_set_list_{{=i}}"
name="file[{{=i}}][set_ids]"
type="text"
value="{{=",".join([set['id'] for set in file['sets']])}}">
<div id="set_div_{{=i}}" class="token_container">
{{ for set in file['sets']: }}
<span class="set_token {{=set['type']}}_token" data-set-id="{{=set['id']}}">
<i class="icon-cancel" onclick="this.parentNode.parentNode.removeChild(this.parentNode);"></i>
{{=set['id'][3:]}}
</span>
{{pass}}
</div>
<input
id="token_input_{{=i}}"
class="token_input"
autocomplete="off"
onfocus="new VidjilAutoComplete().setupSamples(this);
new Tokeniser(document.getElementById('set_div_{{=i}}'), document.getElementById('file_set_list_{{=i}}'));"
data-needs-atwho="true"
data-needs-tokeniser="true"
data-group-ids="{{=upload_group_ids}}"
data-keys='["generic", "patient", "run"]'
type="text">
</div>
</div>
</fieldset>
<fieldset>
<legend>sample information</legend>
<div class="field_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