Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 40 additions & 14 deletions app/assets/javascripts/single_page/dynamic_table.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ const handleSelect = (e) => {
let isRegisteredDataFile = false;
let isRegisteredStrain = false;
if (c.attribute_type) {
isRegisteredSample = c.attribute_type.base_type.includes("SeekSample");
isCVList = c.attribute_type.base_type === "CVList";
isRegisteredSop = c.attribute_type.base_type === "SeekSop";
isRegisteredDataFile = c.attribute_type.base_type === "SeekDataFile";
isRegisteredStrain = c.attribute_type.base_type === "SeekStrain";
isRegisteredSample = c.attribute_type.includes("SeekSample");
isCVList = c.attribute_type === "CVList";
isRegisteredSop = c.attribute_type === "SeekSop";
isRegisteredDataFile = c.attribute_type === "SeekDataFile";
isRegisteredStrain = c.attribute_type === "SeekStrain";
}

if (isRegisteredSample) {
Expand Down Expand Up @@ -173,17 +173,43 @@ const handleSelect = (e) => {
});
// Retrieve the column index of the multi-input cells (select2 items)
// if column has a multi-input cell, it adds the index to the t array (=accumulator)
let multi_link_idx = columns.reduce((t, c, i) => (c.multi_link ? [...t, i + 1] : t), []);
// If it's Assay level table keep the first, otherwise hide all of them
if (options.level == "assay") multi_link_idx = multi_link_idx.slice(1);
this.hiddenColumns = multi_link_idx;
let input_col_ids = columns.reduce((t, c, i) => (c.is_input ? [...t, i + 1] : t), []);

if (options.readonly) {
this.hiddenColumns = columns
.map((col, index) => {
if (
// If it's Assay level table keep the first input in the experiment overview,
// otherwise hide all inputs.
(col.is_input && !col.is_first_input) ||
// Hide ID related fields (id, uuid, ...)
col.is_id_field ||
// Hide the status column
col.title === 'status'
){
return index + 1;
} else {
return -1;
}
})
.filter(index => index !== -1);
} else {
this.hiddenColumns = columns
.map((col, index) => {
// Hide the status column
if (col.title === 'status') {
return index + 1;
} else {
return -1;
}
})
.filter(index => index !== -1);
}
columns.unshift(...defaultCols);

const columnDefs = [{
targets: options.readonly ? [0] : [0, 1]
},
const columnDefs = [
{
targets: options.readonly ? [0, ...multi_link_idx] : [1],
targets: options.readonly ? [0, ...this.hiddenColumns] : [1, 3, ...this.hiddenColumns],
visible: false,
searchable: false
},
Expand Down Expand Up @@ -590,7 +616,7 @@ function getNonTextAttributes(st_attributes) {
return st_attributes
.filter(
(attr) => {
const baseType = attr?.attribute_type?.base_type ?? stringType;
const baseType = attr?.attribute_type ?? stringType;
return baseType !== stringType;
})
.map(function (attr) {
Expand Down
25 changes: 16 additions & 9 deletions app/helpers/dynamic_table_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def dt_aggregated(study, assay = nil)
end
columns = dt_cumulative_cols(sample_types)
rows = dt_cumulative_rows(sample_types, columns.length)
{ columns:, rows:, sample_types: sample_types.map { |s| { title: s.title, id: s.id } } }
{ columns:, rows:, sample_types: sample_types.map { |s| { title: s.title, id: s.id, assay_title: s.assays.first&.title } } }
end

private
Expand Down Expand Up @@ -99,15 +99,19 @@ def transform_registered_sample_single(json_metadata, input_key)
def dt_cols(sample_type)
attribs = sample_type.sample_attributes.map do |a|
attribute = { title: a.title, name: sample_type.id.to_s, required: a.required, description: a.description,
is_title: a.is_title, attribute_type: a.sample_attribute_type }
is_title: a.is_title, attribute_type: a.sample_attribute_type&.base_type }

if a.sample_attribute_type&.controlled_vocab?
cv_allows_free_text = a.allow_cv_free_text
attribute.merge!({ cv_allows_free_text: cv_allows_free_text, cv_id: a.sample_controlled_vocab_id })
end

if a.sample_attribute_type&.seek_sample_multi? || a.sample_attribute_type&.seek_sample?
attribute.merge!({ multi_link: a.sample_attribute_type&.seek_sample_multi?, linked_sample_type: a.linked_sample_type_id })
attribute.merge!(linked_sample_type: a.linked_sample_type_id)
end

if a.input_attribute?
attribute.merge!(is_input: true)
end

attribute
Expand Down Expand Up @@ -156,18 +160,21 @@ def get_full_rows(x, depth, row = [], i = 0, rows = [])
end

def dt_cumulative_cols(sample_types)
sample_types.flat_map do |s|
sample_types.flat_map.with_index do |s, i|
s.sample_attributes.map do |a|
attribute = { title: a.title, name: s.id.to_s, required: a.required, description: a.description,
is_title: a.is_title, attribute_type: a.sample_attribute_type }
is_title: a.is_title, attribute_type: a.sample_attribute_type&.base_type }
is_seek_sample_multi = a.sample_attribute_type.seek_sample_multi?
is_seek_sample = a.sample_attribute_type.seek_sample?
is_cv_list = a.sample_attribute_type.seek_cv_list?
attribute.merge!({ multi_link: true, linked_sample_type: a.linked_sample_type.id }) if is_seek_sample_multi
attribute.merge!({ multi_link: false, linked_sample_type: a.linked_sample_type.id }) if is_seek_sample
attribute.merge!({ is_cv_list: true }) if is_cv_list
is_input = a.input_attribute?
attribute.merge!(linked_sample_type: a.linked_sample_type.id) if is_seek_sample_multi || is_seek_sample
# The first input has to show up in the experiment view,
# that's why when i=0, the `is_first_input` flag is set to true.
attribute.merge!({ is_input: true, is_first_input: i == 0 }) if is_input
attribute.merge!(is_cv_list: true) if is_cv_list
attribute
end.unshift({ title: 'id' }, { title: 'uuid' })
end.unshift({ title: 'id', is_id_field: true }, { title: 'uuid', is_id_field: true })
end
end
end
3 changes: 2 additions & 1 deletion app/views/isa_assays/_assay_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
function createSampleTypeOptions(types){
$j("#options_container").append('<div id="checkbox_group" class="btn-group" data-toggle="buttons"></div>')
types.forEach( (t, i) => {
let elem = `<label class="btn btn-default active sp-btn-variant-${i%2}"><input id="checkbox-${t.id}" type="checkbox" checked onchange="toggleSampleType(${t.id}, $j(this))" />${t.title}</label>`
let assayTitle = t.assay_title;
let elem = `<label class="btn btn-default active sp-btn-variant-${i%2}"><input id="checkbox-${t.id}" type="checkbox" checked onchange="toggleSampleType(${t.id}, $j(this))" />${assayTitle}</label>`
$j("#checkbox_group").append(elem)
})
}
Expand Down
16 changes: 10 additions & 6 deletions app/views/isa_studies/_study_table.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%# The study experiment overview table %>

<% study ||= nil %>
<% valid_study = study&.sample_types&.second %>
<% valid_study = study&.sample_types&.count == 2 %>

<div style="padding: 0 20px 20px 20px;">
<div class="row" id="options_container" style="margin-bottom:15px">
Expand All @@ -28,7 +28,7 @@
studyTableInitialLoad = false;
return;
}
d.study_id = '<%=study.id%>';
d.study_id = '<%=study&.id%>';
d.rows_pad = "true";
}
}
Expand All @@ -41,10 +41,14 @@

function createSampleTypeOptions(types){
$j("#options_container").append('<div id="checkbox_group" class="btn-group" data-toggle="buttons"></div>')
types.forEach( (t, i) => {
let elem = `<label class="btn btn-default active sp-btn-variant-${i%2}"><input id="checkbox-${t.id}" type="checkbox" checked onchange="toggleSampleType(${t.id}, $j(this))" />${t.title}</label>`
$j("#checkbox_group").append(elem)
})
let studyTitle = '<%= study&.title || 'Study' %>';
let sourceSampleType = types[0];
let sampleSampleType = types[1];
let source_elem = `<label class="btn btn-default active sp-btn-variant-0"><input id="checkbox-${sourceSampleType.id}" type="checkbox" checked onchange="toggleSampleType(${sourceSampleType.id}, $j(this))" />${studyTitle} - sources</label>`;
let sample_elem = `<label class="btn btn-default active sp-btn-variant-1"><input id="checkbox-${sampleSampleType.id}" type="checkbox" checked onchange="toggleSampleType(${sampleSampleType.id}, $j(this))" />${studyTitle} - samples</label>`;
[source_elem, sample_elem].forEach((elem) => {
$j("#checkbox_group").append(elem);
});
}

function toggleSampleType(sample_type, e){
Expand Down