Skip to content

Commit 075d4b2

Browse files
kdp-cloudstuzart
authored andcommitted
Merge pull request #2470 from seek4science/2469-download-spreadsheet-does-not-work-from-default-view
Fix download spreadsheet from default view (cherry picked from commit 03ee6ef)
1 parent acd1d2f commit 075d4b2

File tree

13 files changed

+90
-56
lines changed

13 files changed

+90
-56
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ const typeaheadSopsUrl = "<%= dynamic_table_typeahead_sops_path(study_id: '__STU
5757
const typeaheadDataFilesUrl = "<%= typeahead_data_files_path %>";
5858
const typeaheadStrainsUrl = "<%= typeahead_strains_path %>";
5959

60-
// Checking if settings are enabled
61-
const registeredSopsEnabled = <%= Seek::Config.sops_enabled %>;
62-
const registeredDataFilesEnabled = <%= Seek::Config.data_files_enabled %>;
63-
const registeredOrganismsEnabled = <%= Seek::Config.organisms_enabled %>;
64-
const idFieldName = window.instanceName + " id";
6560
const handleSelect = (e) => {
6661
$j(e).parents("table").DataTable().row(e.closest("tr")).data()[0] = e.is(":checked")
6762
if (!e.is(":checked")) {
@@ -80,8 +75,11 @@ const handleSelect = (e) => {
8075
};
8176
$j.dynamicTable.prototype = {
8277
init: function (rows, columns, options = {}) {
83-
const studyId = options.studyId;
84-
const assayId = options.assayId;
78+
// Checking if settings in SEEK config are enabled
79+
const registeredSopsEnabled = options.config.registeredSopsEnabled;
80+
const registeredDataFilesEnabled = options.config.registeredDataFilesEnabled;
81+
const registeredOrganismsEnabled = options.config.registeredOrganismsEnabled;
82+
const idFieldName = options.config.idFieldName;
8583

8684
columns.forEach((c) => {
8785
let linkedSamplesUrl;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ async function exportToExcel(tableName, studyId, assayId, sampleTypeId, projectI
253253
}
254254

255255
// Get the ID field (instance name + " id")
256-
const idFieldName = "<%= Seek::Config.instance_name %> id";
256+
const idFieldName = `${instanceName} id`;
257257

258258
// Construct the list of objects
259259
const sampleIds = rows.map((row) => {

app/controllers/isa_assays_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def new
1616
study = Study.find(params[:study_id])
1717
new_position =
1818
if params[:is_assay_stream] || params[:source_assay_id].nil? # If first assay is of class assay stream
19-
study.assay_streams.any? ? study.assay_streams.map(&:position).max + 1 : 0
19+
study.assay_streams.any? ? (study.assay_streams.map(&:position).max || 0) + 1 : 0
2020
elsif params[:source_assay_id] == params[:assay_stream_id] # If first assay in the stream
2121
0
2222
else

app/helpers/templates_helper.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ def template_attribute_details(template_attribute)
1717
def load_templates
1818
privilege = Seek::Permissions::Translator.translate('view')
1919
Template.order(:group, :group_order).select { |t| t.can_perform?(privilege) }.map do |item|
20-
{ title: item.title&.sanitize,
21-
group: item.group&.sanitize,
22-
level: item.level&.sanitize,
23-
organism: item.organism&.sanitize,
20+
{ title: sanitize(item.title),
21+
group: sanitize(item.group),
22+
level: sanitize(item.level),
23+
organism: sanitize(item.organism),
2424
template_id: item.id,
25-
description: item.description&.sanitize,
25+
description: sanitize(item.description),
2626
group_order: item.group_order,
2727
attributes: item.template_attributes.order(:pos).map { |a| map_template_attributes(a) } }
2828
end
@@ -77,19 +77,19 @@ def template_attribute_type_link(template_attribute)
7777
def map_template_attributes(attribute)
7878
{
7979
attribute_type_id: attribute.sample_attribute_type_id,
80-
data_type: SampleAttributeType.find(attribute.sample_attribute_type_id)&.title&.sanitize,
80+
data_type: sanitize(SampleAttributeType.find(attribute.sample_attribute_type_id)&.title),
8181
cv_id: attribute.sample_controlled_vocab_id,
8282
allow_cv_free_text: attribute.allow_cv_free_text,
83-
title: attribute.title&.sanitize,
83+
title: sanitize(attribute.title),
8484
is_title: attribute.is_title,
85-
short_name: attribute.short_name&.sanitize,
86-
description: attribute.description&.sanitize,
87-
pid: attribute.pid&.sanitize,
85+
short_name: sanitize(attribute.short_name),
86+
description: sanitize(attribute.description),
87+
pid: sanitize(attribute.pid),
8888
required: attribute.required,
8989
unit_id: attribute.unit_id,
9090
pos: attribute.pos,
9191
isa_tag_id: attribute.isa_tag_id,
92-
isa_tag_title: attribute.isa_tag&.title&.sanitize,
92+
isa_tag_title: sanitize(attribute.isa_tag&.title),
9393
linked_sample_type_id: attribute.linked_sample_type_id,
9494
template_attribute_id: attribute.id
9595
}

app/views/isa_assays/_assay_design.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</p>
4343
<% end %>
4444
<script>
45-
window.instanceName = "<%= Seek::Config.instance_name %>";
45+
const instanceName = "<%= Seek::Config.instance_name %>"
4646
async function loadDynamicTableFromDefaultView(element) {
4747
await loadItemDetails(`/assays/${id}`, { view: "default" });
4848
}

app/views/isa_assays/_assay_samples.html.erb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,20 @@
2828
window.sampleDynamicTable = new $j.dynamicTable('#assay-samples-table');
2929
const elem = $j("#btn_save_assay_sample")
3030
const options = {
31+
config: {
32+
registeredSopsEnabled: <%= Seek::Config.sops_enabled %>,
33+
registeredDataFilesEnabled: <%= Seek::Config.data_files_enabled %>,
34+
registeredOrganismsEnabled: <%= Seek::Config.organisms_enabled %>,
35+
idFieldName: "<%= Seek::Config.instance_name %> id",
36+
},
3137
assayId: "<%= assay&.id %>",
3238
url: dynamicTableDataPath,
3339
data: function(d) {
3440
if (assaySamplesInitialLoad) {
3541
assaySamplesInitialLoad = false;
3642
return;
3743
}
38-
d.sample_type_id = '<%=sample_type.id%>';
44+
d.sample_type_id = '<%=sample_type&.id%>';
3945
d.rows_pad = "true"
4046
},
4147
callback: () => assayDynamicTable.table.ajax.reload(),

app/views/isa_assays/_assay_table.html.erb

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,29 @@
2020
$j(document).ready(function () {
2121
const dt = <%= sanitize(dt_aggregated(assay&.study, assay).to_json) %>
2222
window.assayDynamicTable = new $j.dynamicTable('#assay-table')
23-
const ajax = {
24-
url: dynamicTableDataPath,
25-
data: function(d) {
26-
if (assayOverviewInitialLoad) {
27-
assayOverviewInitialLoad = false;
28-
return;
29-
}
30-
d.study_id = '<%=assay&.study&.id%>';
31-
d.assay_id = '<%=assay&.id%>';
32-
d.rows_pad = "true";
23+
const options = {
24+
config: {
25+
registeredSopsEnabled: <%= Seek::Config.sops_enabled %>,
26+
registeredDataFilesEnabled: <%= Seek::Config.data_files_enabled %>,
27+
registeredOrganismsEnabled: <%= Seek::Config.organisms_enabled %>,
28+
idFieldName: "<%= Seek::Config.instance_name %> id",
29+
},
30+
ajax: {
31+
url: dynamicTableDataPath,
32+
data: function (d) {
33+
if (assayOverviewInitialLoad) {
34+
assayOverviewInitialLoad = false;
35+
return;
3336
}
34-
}
35-
assayDynamicTable.init(dt.rows, dt.columns, { readonly: true, level: "assay", ajax })
37+
d.study_id = '<%=assay&.study&.id%>';
38+
d.assay_id = '<%=assay&.id%>';
39+
d.rows_pad = "true";
40+
}
41+
},
42+
readonly: true,
43+
level: "assay"
44+
}
45+
assayDynamicTable.init(dt.rows, dt.columns, options)
3646
const types = assayDynamicTable.getSampleTypes()
3747
createSampleTypeOptions(dt.sample_types)
3848
});

app/views/isa_studies/_source_material.html.erb

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,22 @@ uploadExcel: 'sourceUploadExcel()', sample_type_id: sample_type&.id} %>
3131
window.sourceDynamicTable = new $j.dynamicTable('#source-material-table');
3232
const elem = $j("#btn_save_source");
3333
const options = {
34-
ajax:{
35-
url: dynamicTableDataPath,
36-
data: function(d) {
37-
if (sourceMaterialInitialLoad) {
38-
sourceMaterialInitialLoad = false;
39-
return;
40-
}
41-
d.sample_type_id = '<%=sample_type.id%>';
42-
d.rows_pad = "true"
43-
}
34+
config: {
35+
registeredSopsEnabled: <%= Seek::Config.sops_enabled %>,
36+
registeredDataFilesEnabled: <%= Seek::Config.data_files_enabled %>,
37+
registeredOrganismsEnabled: <%= Seek::Config.organisms_enabled %>,
38+
idFieldName: "<%= Seek::Config.instance_name %> id"
39+
},
40+
ajax:{
41+
url: dynamicTableDataPath,
42+
data: function(d) {
43+
if (sourceMaterialInitialLoad) {
44+
sourceMaterialInitialLoad = false;
45+
return;
46+
}
47+
d.sample_type_id = '<%=sample_type.id%>';
48+
d.rows_pad = "true"
49+
}
4450
},
4551
callback: () => studyDynamicTable.table.ajax.reload(),
4652
enableLoading: () => {

app/views/isa_studies/_study_design.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<% end %>
5050

5151
<script>
52-
window.instanceName = "<%= Seek::Config.instance_name %>";
52+
const instanceName = "<%= Seek::Config.instance_name %>"
5353
async function loadDynamicTableFromDefaultView(element) {
5454
await loadItemDetails(`/studies/${id}`, { view: "default" });
5555
}

app/views/isa_studies/_study_samples.html.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
window.sampleDynamicTable = new $j.dynamicTable('#study-samples-table');
2525
const elem = $j("#btn_save_sample");
2626
const options = {
27+
config: {
28+
registeredSopsEnabled: <%= Seek::Config.sops_enabled %>,
29+
registeredDataFilesEnabled: <%= Seek::Config.data_files_enabled %>,
30+
registeredOrganismsEnabled: <%= Seek::Config.organisms_enabled %>,
31+
idFieldName: "<%= Seek::Config.instance_name %> id"
32+
},
2733
studyId: <%= study&.id %>,
2834
ajax:{
2935
url: dynamicTableDataPath,

0 commit comments

Comments
 (0)