Commit c8f26ed9 authored by Mathieu Giraud's avatar Mathieu Giraud

Merge branch...

Merge branch 'feature-sc/2728-pouvoir-sauter-depuis-un-sample-a-ses-groupes-patient-run-set' into 'dev'

Resolve "Pouvoir sauter depuis un sample à ses groupes patient/run/set"

Closes #4220 and #2728

See merge request !635
parents f5aab3ca 612cfa59
Pipeline #159761 failed with stages
in 8 minutes
......@@ -301,8 +301,8 @@ code_quality:
test_server_unit:
stage: test_unit
script:
- virtualenv $CI_BUILD_REF_SLUG
- source $CI_BUILD_REF_SLUG/bin/activate
- virtualenv $CI_COMMIT_SHORT_SHA
- source $CI_COMMIT_SHORT_SHA/bin/activate
- pip install -r requirements.txt
- make -C server install_web2py_standalone
- make -C server launch_fuse_server
......
......@@ -125,6 +125,22 @@ def index():
)
)
all_sequence_files = [r.sample_set_membership.sequence_file_id for r in query]
(shared_sets, sample_sets) = get_associated_sample_sets(all_sequence_files, [sample_set_id])
samplesets = SampleSets(sample_sets.keys())
sets_names = samplesets.get_names()
## assign set to each rows
for row in query:
row.list_share_set = []
if row.sequence_file.id in shared_sets:
for elt in shared_sets[row.sequence_file.id]:
values = {"title": sets_names[elt],
"sample_type": sample_sets[elt].sample_type, "id":elt}
row.list_share_set.append(values)
tag_decorator = TagDecorator(get_tag_prefix())
query_pre_process = db( db.pre_process.id >0 ).select()
pre_process_list = {}
......@@ -142,6 +158,7 @@ def index():
'table_name': "sample_set"})
#if (auth.can_view_patient(request.vars["id"]) ):
return dict(query=query,
has_shared_sets = len(shared_sets) > 0,
pre_process_list=pre_process_list,
config_id=config_id,
info=info_file,
......
......@@ -127,6 +127,35 @@ def get_sequence_file_sample_sets(sequence_file_id):
sample_set_ids.append(row.sample_set_id)
return sample_set_ids
def get_associated_sample_sets(sequence_file_ids, forbidden_ids = []):
'''
From a list of sequence_file IDs return a tuple.
The first component of the tuple is a dictionary whose keys are
the sequence_file IDs and the values are lists of sample sets those sequence_files
belong to.
The second component of the tuple is a dictionary whose keys are sample set IDs
and the values are the corresponding sample sets. The sample sets in this dictionary
are the sample sets which share a sequence file whose ID is in sequence_file_ids.
forbidden_ids: list of the sample sets IDs that must not be retrieved.
'''
shared_sequences = db(
(db.sample_set_membership.sequence_file_id.belongs(sequence_file_ids))
& ~(db.sample_set_membership.sample_set_id.belongs(forbidden_ids))
).select(
db.sample_set.ALL,
db.sample_set_membership.sequence_file_id,
left = db.sample_set.on(db.sample_set.id == db.sample_set_membership.sample_set_id)
)
shared_sets = defaultdict(list)
for shared in shared_sequences:
shared_sets[shared.sample_set_membership.sequence_file_id].append(shared.sample_set.id)
sample_sets = {s.sample_set.id : s.sample_set for s in shared_sequences}
return (shared_sets, sample_sets)
def get_sequence_file_config_ids(sequence_file_id):
'''
return the list of configs run ona sequence_file
......
......@@ -218,6 +218,9 @@ class TestSample < ServerTest
end
def test_set_association_create
## 1. get the patient, run, set IDs of the sample sets which have #set_assoc_0 in the description
$b.a(:class => ["button", "button_token", "patient_token"], :text => "patients").click
Watir::Wait.until(timeout: 30) {$b.execute_script("return jQuery.active") == 0}
table = $b.table(:id => "table")
......@@ -239,6 +242,8 @@ class TestSample < ServerTest
set_id = table.a(:text => "#set_assoc_0").parent.parent.td(:class => 'uid').text
## 2. Add a sample in the patient and make the association with the other sets
samples_table = go_to_set_by_tag "#set_assoc_0"
$b.span(:class => "button2", :text => "+ add samples").click
Watir::Wait.until(timeout: 30) {$b.execute_script("return jQuery.active") == 0}
......@@ -264,6 +269,7 @@ class TestSample < ServerTest
form.text_field(:id => "file_sampling_date_0").set("2010-10-10")
form.text_field(:id => "file_info_0").set("#my_file_add")
# Include the three sets (patient, run and set we identified previously)
val = ":p 0 (2010-10-10) (#{patient_id})|:r run 0 (#{run_id})|:s generic 0 (#{set_id})"
$b.execute_script("return $('#file_set_list').val('#{val}');")
......@@ -271,6 +277,22 @@ class TestSample < ServerTest
samples_table = $b.table(:id => "table")
samples_table.wait_until(&:present?)
# Check that the "associated sets" header appears
assert(samples_table.td(:text => "associated sets").present?)
# We are on the patient we should have a link to the run and the set
$b.screenshot.save('/tmp/ci.png')
# Get the row with the created file
tag = samples_table.a(:text=>"#my_file_add")
assert(tag.present?)
tr = tag.parent.parent
assert (tr.present?)
assert (tr.tag_name == "tr")
assert(tr.span(:class => ["set_token", "run_token"], :text => "run 0").present?)
generic_span = tr.span(:class => ["generic_token", "set_token"], :title => "generic 0")
assert(generic_span.present?)
assert (generic_span.onclick.include? "db.call('sample_set/index'"), "onclick contains: "+generic_span.onclick
# Checking in the edit form that the three sets appear
samples_table.a(:text => "#set_assoc_0").parent.parent.i(:class => "icon-pencil-2").click
form = $b.form(:id => "upload_form")
......
......@@ -50,6 +50,9 @@
<td class="column_100"> sampling date </td>
<td> info </td>
<td> size </td>
{{if has_shared_sets: }}
<td> associated sets </td>
{{pass}}
<td> pre-process </td>
{{if auth.is_admin():}} <td> uploader </td> {{pass}}
<td class="column5"> </td>
......@@ -88,6 +91,17 @@
<td {{if row.sequence_file.data_file == None :}} {{=XML("class='inactive' title='file is missing' ")}} {{pass}} >
{{=vidjil_utils.format_size(row.sequence_file.size_file)}} </td>
{{ has_pre_process = row.sequence_file.pre_process_id != None}}
{{if has_shared_sets:}}
<td>
<!-- Select set with this sample -->
{{ for sample_set in row.list_share_set:}}
<!-- Show values -->
<span class="{{ =sample_set['sample_type'] }}_token set_token" title="{{ =sample_set['title'] }}" onclick="db.call('sample_set/index', {'id': '{{ =int(sample_set['id']) }}', 'config_id': -1 })" >
{{ =sample_set['title'] }}
</span>
{{ pass }}
</td>
{{pass}}
<td {{if has_pre_process:}} class="pointer"
title="View more information on the pre-process {{=pre_process_list[row.sequence_file.pre_process_id]}}"{{pass}}
{{if has_pre_process:}} onclick="db.call('pre_process/info', {'sequence_file_id' :'{{=row.sequence_file.id }}', 'sample_set_id' : '{{=request.vars["id"]}}'} )" {{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