Skip to content

Commit

Permalink
Download files as attachments
Browse files Browse the repository at this point in the history
The previous download method (inline) was confusing browsers into
trying to read files such as PDFs as HTML
  • Loading branch information
lmrodriguezr committed Mar 26, 2018
1 parent 15b9499 commit 2f1e5f5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
8 changes: 4 additions & 4 deletions app/controllers/query_datasets_controller.rb
Expand Up @@ -76,7 +76,9 @@ def result
qd = @query_dataset
m = qd.miga
res = m.result(params[:result])
unless res.nil?
if res.nil?
render :nothing => true, :status => 200, :content_type => "text/html"
else
abs_path = res.file_path(params[:file])
if Dir.exists?(abs_path) and params[:f] and not params[:f]=~/\//
abs_path = File.expand_path(params[:f], abs_path)
Expand All @@ -93,11 +95,9 @@ def result
else ; "raw/text"
end
send_file(abs_path, filename: File.basename(abs_path),
disposition: "inline", type: type, x_sendfile: true)
disposition: "attachment", type: type, x_sendfile: true)
end
return
end
render :nothing => true, :status => 200, :content_type => "text/html"
end

# Execute the MyTaxa Scan step upon request.
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Expand Up @@ -50,8 +50,8 @@ def breadcrumb(location="")
def plotly(data, layout={})
id = SecureRandom.uuid
content_tag(:div, id:id) do
javascript_tag "Plotly.plot('#{id}', [#{data.to_json}], " +
"#{layout.to_json});"
javascript_tag "$( Plotly.plot('#{id}', [#{data.to_json}], " +
"#{layout.to_json}) );"
end
end

Expand Down
5 changes: 3 additions & 2 deletions app/views/shared/_result.html.erb
Expand Up @@ -66,7 +66,7 @@
<p>
MyTaxa Scan detected regions with unusual taxonomic distribution
(<%= f_path.nil? ? "No report available" :
link_to("download PDF", f_path) %>).
link_to("download PDF", f_path, target: "_blank") %>).
</p>
<% when :mytaxa %>
<%
Expand Down Expand Up @@ -142,7 +142,8 @@
project_result_path(obj.id, key, k) :
obj.is_a?(MiGA::Dataset) ?
reference_dataset_result_path(proj.id, obj.name, key, k) :
query_dataset_result_path(obj.id, key, k), {rel: "tooltip",
query_dataset_result_path(obj.id, key, k),
{rel: "tooltip", target: "_blank",
title: Dir.exist?(f) ? "Folder" : number_to_human_size(File.size f)})
end.compact.
to_sentence(two_words_connector:" or ", last_word_connector:", or ").
Expand Down
6 changes: 4 additions & 2 deletions app/views/shared/results/_distances.html.erb
Expand Up @@ -127,9 +127,11 @@
<p>
This dataset was placed in the context of some representative genomes from
the reference collection. See <%= link_to("BioNJ tree in PDF",
query_dataset_result_path(dataset.id, :distances, :ref_tree_pdf)) %> (or
query_dataset_result_path(dataset.id, :distances, :ref_tree_pdf),
target: "_blank") %> (or
<%= link_to("download it in Newick format",
query_dataset_result_path(dataset.id, :distances, :ref_tree)) %>).
query_dataset_result_path(dataset.id, :distances, :ref_tree),
target: "_blank") %>).
</p>
<% end %>
<div class="panel-group" id=distances role=tablist
Expand Down
5 changes: 3 additions & 2 deletions app/views/shared/results/_ogs.html.erb
Expand Up @@ -19,7 +19,8 @@
<% unless res.data[:files][:core_pan_plot].nil? %>
<p>
See the
<%= link_to "rarefied pangenome and core genome sizes",
project_result_path(project.id, :ogs, :core_pan_plot) %>.
<%= link_to("rarefied pangenome and core genome sizes",
project_result_path(project.id, :ogs, :core_pan_plot),
target: "_blank") %>.
</p>
<% end %>

0 comments on commit 2f1e5f5

Please sign in to comment.