Skip to content

Commit 9dbaffc

Browse files
authored
Merge pull request #2314 from seek4science/2312-change-text-in-sample-type-buttons
2312 change text in sample type buttons
2 parents e6ce3c0 + d7c538d commit 9dbaffc

File tree

4 files changed

+68
-30
lines changed

4 files changed

+68
-30
lines changed

app/assets/javascripts/single_page/dynamic_table.js.erb

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ const handleSelect = (e) => {
9494
let isRegisteredDataFile = false;
9595
let isRegisteredStrain = false;
9696
if (c.attribute_type) {
97-
isRegisteredSample = c.attribute_type.base_type.includes("SeekSample");
98-
isCVList = c.attribute_type.base_type === "CVList";
99-
isRegisteredSop = c.attribute_type.base_type === "SeekSop";
100-
isRegisteredDataFile = c.attribute_type.base_type === "SeekDataFile";
101-
isRegisteredStrain = c.attribute_type.base_type === "SeekStrain";
97+
isRegisteredSample = c.attribute_type.includes("SeekSample");
98+
isCVList = c.attribute_type === "CVList";
99+
isRegisteredSop = c.attribute_type === "SeekSop";
100+
isRegisteredDataFile = c.attribute_type === "SeekDataFile";
101+
isRegisteredStrain = c.attribute_type === "SeekStrain";
102102
}
103103

104104
if (isRegisteredSample) {
@@ -173,17 +173,43 @@ const handleSelect = (e) => {
173173
});
174174
// Retrieve the column index of the multi-input cells (select2 items)
175175
// if column has a multi-input cell, it adds the index to the t array (=accumulator)
176-
let multi_link_idx = columns.reduce((t, c, i) => (c.multi_link ? [...t, i + 1] : t), []);
177-
// If it's Assay level table keep the first, otherwise hide all of them
178-
if (options.level == "assay") multi_link_idx = multi_link_idx.slice(1);
179-
this.hiddenColumns = multi_link_idx;
176+
let input_col_ids = columns.reduce((t, c, i) => (c.is_input ? [...t, i + 1] : t), []);
177+
178+
if (options.readonly) {
179+
this.hiddenColumns = columns
180+
.map((col, index) => {
181+
if (
182+
// If it's Assay level table keep the first input in the experiment overview,
183+
// otherwise hide all inputs.
184+
(col.is_input && !col.is_first_input) ||
185+
// Hide ID related fields (id, uuid, ...)
186+
col.is_id_field ||
187+
// Hide the status column
188+
col.title === 'status'
189+
){
190+
return index + 1;
191+
} else {
192+
return -1;
193+
}
194+
})
195+
.filter(index => index !== -1);
196+
} else {
197+
this.hiddenColumns = columns
198+
.map((col, index) => {
199+
// Hide the status column
200+
if (col.title === 'status') {
201+
return index + 1;
202+
} else {
203+
return -1;
204+
}
205+
})
206+
.filter(index => index !== -1);
207+
}
180208
columns.unshift(...defaultCols);
181209

182-
const columnDefs = [{
183-
targets: options.readonly ? [0] : [0, 1]
184-
},
210+
const columnDefs = [
185211
{
186-
targets: options.readonly ? [0, ...multi_link_idx] : [1],
212+
targets: options.readonly ? [0, ...this.hiddenColumns] : [1, 3, ...this.hiddenColumns],
187213
visible: false,
188214
searchable: false
189215
},
@@ -590,7 +616,7 @@ function getNonTextAttributes(st_attributes) {
590616
return st_attributes
591617
.filter(
592618
(attr) => {
593-
const baseType = attr?.attribute_type?.base_type ?? stringType;
619+
const baseType = attr?.attribute_type ?? stringType;
594620
return baseType !== stringType;
595621
})
596622
.map(function (attr) {

app/helpers/dynamic_table_helper.rb

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def dt_aggregated(study, assay = nil)
2525
end
2626
columns = dt_cumulative_cols(sample_types)
2727
rows = dt_cumulative_rows(sample_types, columns.length)
28-
{ columns:, rows:, sample_types: sample_types.map { |s| { title: s.title, id: s.id } } }
28+
{ columns:, rows:, sample_types: sample_types.map { |s| { title: s.title, id: s.id, assay_title: s.assays.first&.title } } }
2929
end
3030

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

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

109109
if a.sample_attribute_type&.seek_sample_multi? || a.sample_attribute_type&.seek_sample?
110-
attribute.merge!({ multi_link: a.sample_attribute_type&.seek_sample_multi?, linked_sample_type: a.linked_sample_type_id })
110+
attribute.merge!(linked_sample_type: a.linked_sample_type_id)
111+
end
112+
113+
if a.input_attribute?
114+
attribute.merge!(is_input: true)
111115
end
112116

113117
attribute
@@ -156,18 +160,21 @@ def get_full_rows(x, depth, row = [], i = 0, rows = [])
156160
end
157161

158162
def dt_cumulative_cols(sample_types)
159-
sample_types.flat_map do |s|
163+
sample_types.flat_map.with_index do |s, i|
160164
s.sample_attributes.map do |a|
161165
attribute = { title: a.title, name: s.id.to_s, required: a.required, description: a.description,
162-
is_title: a.is_title, attribute_type: a.sample_attribute_type }
166+
is_title: a.is_title, attribute_type: a.sample_attribute_type&.base_type }
163167
is_seek_sample_multi = a.sample_attribute_type.seek_sample_multi?
164168
is_seek_sample = a.sample_attribute_type.seek_sample?
165169
is_cv_list = a.sample_attribute_type.seek_cv_list?
166-
attribute.merge!({ multi_link: true, linked_sample_type: a.linked_sample_type.id }) if is_seek_sample_multi
167-
attribute.merge!({ multi_link: false, linked_sample_type: a.linked_sample_type.id }) if is_seek_sample
168-
attribute.merge!({ is_cv_list: true }) if is_cv_list
170+
is_input = a.input_attribute?
171+
attribute.merge!(linked_sample_type: a.linked_sample_type.id) if is_seek_sample_multi || is_seek_sample
172+
# The first input has to show up in the experiment view,
173+
# that's why when i=0, the `is_first_input` flag is set to true.
174+
attribute.merge!({ is_input: true, is_first_input: i == 0 }) if is_input
175+
attribute.merge!(is_cv_list: true) if is_cv_list
169176
attribute
170-
end.unshift({ title: 'id' }, { title: 'uuid' })
177+
end.unshift({ title: 'id', is_id_field: true }, { title: 'uuid', is_id_field: true })
171178
end
172179
end
173180
end

app/views/isa_assays/_assay_table.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
function createSampleTypeOptions(types){
4141
$j("#options_container").append('<div id="checkbox_group" class="btn-group" data-toggle="buttons"></div>')
4242
types.forEach( (t, i) => {
43-
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>`
43+
let assayTitle = t.assay_title;
44+
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>`
4445
$j("#checkbox_group").append(elem)
4546
})
4647
}

app/views/isa_studies/_study_table.html.erb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<%# The study experiment overview table %>
22

33
<% study ||= nil %>
4-
<% valid_study = study&.sample_types&.second %>
4+
<% valid_study = study&.sample_types&.count == 2 %>
55

66
<div style="padding: 0 20px 20px 20px;">
77
<div class="row" id="options_container" style="margin-bottom:15px">
@@ -28,7 +28,7 @@
2828
studyTableInitialLoad = false;
2929
return;
3030
}
31-
d.study_id = '<%=study.id%>';
31+
d.study_id = '<%=study&.id%>';
3232
d.rows_pad = "true";
3333
}
3434
}
@@ -41,10 +41,14 @@
4141

4242
function createSampleTypeOptions(types){
4343
$j("#options_container").append('<div id="checkbox_group" class="btn-group" data-toggle="buttons"></div>')
44-
types.forEach( (t, i) => {
45-
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>`
46-
$j("#checkbox_group").append(elem)
47-
})
44+
let studyTitle = '<%= study&.title || 'Study' %>';
45+
let sourceSampleType = types[0];
46+
let sampleSampleType = types[1];
47+
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>`;
48+
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>`;
49+
[source_elem, sample_elem].forEach((elem) => {
50+
$j("#checkbox_group").append(elem);
51+
});
4852
}
4953

5054
function toggleSampleType(sample_type, e){

0 commit comments

Comments
 (0)