mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 21:24:23 +08:00
Merge pull request #645 from ZmagoD/zd_SCI_1278
generates samples csv file in background job [fixes SCI-1278]
This commit is contained in:
commit
fcec42ae31
6 changed files with 66 additions and 24 deletions
|
@ -667,7 +667,14 @@ function updateButtons() {
|
|||
$("#deleteSamplesButton").removeClass("disabled");
|
||||
$("#exportSamplesButton").removeClass("disabled");
|
||||
$("#exportSamplesButton").prop("disabled",false);
|
||||
$("#exportSamplesButton").on("click", function() { $('#form-export').submit(); });
|
||||
$("#exportSamplesButton").on("click", function() {
|
||||
$('#modal-export-samples-success')
|
||||
.modal('show')
|
||||
.on('hidden.bs.modal', function() {
|
||||
animateSpinner(null, true);
|
||||
$('#form-export').submit();
|
||||
});
|
||||
});
|
||||
$("#assignSamples").removeClass("disabled");
|
||||
$("#assignSamples").prop("disabled", false);
|
||||
$("#unassignSamples").removeClass("disabled");
|
||||
|
@ -693,7 +700,14 @@ function updateButtons() {
|
|||
$("#deleteSamplesButton").removeClass("disabled");
|
||||
$("#exportSamplesButton").removeClass("disabled");
|
||||
$("#exportSamplesButton").prop("disabled",false);
|
||||
$("#exportSamplesButton").on("click", function() { $('#form-export').submit(); });
|
||||
$("#exportSamplesButton").on("click", function() {
|
||||
$('#modal-export-samples-success')
|
||||
.modal('show')
|
||||
.on('hidden.bs.modal', function() {
|
||||
animateSpinner(null, true);
|
||||
$('#form-export').submit();
|
||||
});
|
||||
});
|
||||
$("#assignSamples").removeClass("disabled");
|
||||
$("#assignSamples").prop("disabled", false);
|
||||
$("#unassignSamples").removeClass("disabled");
|
||||
|
|
|
@ -262,26 +262,20 @@ class TeamsController < ApplicationController
|
|||
end
|
||||
|
||||
def export_samples
|
||||
require "csv"
|
||||
|
||||
respond_to do |format|
|
||||
if params[:sample_ids].present? and params[:header_ids].present?
|
||||
samples = []
|
||||
|
||||
params[:sample_ids].each do |id|
|
||||
sample = Sample.find_by_id(id)
|
||||
|
||||
if sample
|
||||
samples << sample
|
||||
end
|
||||
end
|
||||
format.csv { send_data @team.to_csv(samples, params[:header_ids]) }
|
||||
else
|
||||
format.csv { render nothing: true }
|
||||
end
|
||||
if params[:sample_ids] && params[:header_ids]
|
||||
generate_samples_zip
|
||||
else
|
||||
flash[:alert] = t('zip_export.export_error')
|
||||
end
|
||||
redirect_to :back
|
||||
end
|
||||
|
||||
def routing_error(error = 'Routing error', status = :not_found, exception=nil)
|
||||
redirect_to root_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_vars
|
||||
@team = Team.find_by_id(params[:id])
|
||||
|
||||
|
@ -302,8 +296,12 @@ class TeamsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def routing_error(error = 'Routing error', status = :not_found, exception=nil)
|
||||
redirect_to root_path
|
||||
def generate_samples_zip
|
||||
zip = ZipExport.create(user: current_user)
|
||||
zip.generate_exportable_zip(
|
||||
current_user,
|
||||
@team.to_csv(Sample.where(id: params[:sample_ids]), params[:header_ids]),
|
||||
:samples
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -101,4 +101,10 @@ class ZipExport < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
# generates zip export file for samples
|
||||
def generate_samples_zip(tmp_dir, data, options = {})
|
||||
file = FileUtils.touch("#{tmp_dir}/export.csv").first
|
||||
File.open(file, 'wb') { |f| f.write(data) }
|
||||
end
|
||||
end
|
||||
|
|
20
app/views/samples/_export_samples_modal.html.erb
Normal file
20
app/views/samples/_export_samples_modal.html.erb
Normal file
|
@ -0,0 +1,20 @@
|
|||
<div class="modal fade"
|
||||
id="modal-export-samples-success"
|
||||
tabindex="-1"
|
||||
role="dialog"
|
||||
aria-labelledby="modal-export-samples-successs-label">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title"><%=t 'zip_export.modal_label' %></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<%=t('zip_export.modal_html', email: current_user.email) %>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal"><%= t('general.cancel')%></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -1,6 +1,7 @@
|
|||
<%= render partial: "samples/import_samples_modal" %>
|
||||
<%= render partial: "samples/delete_samples_modal" %>
|
||||
<%= render partial: "samples/delete_custom_field_modal" %>
|
||||
<%= render partial: 'samples/export_samples_modal' %>
|
||||
|
||||
<!-- Modal for parsing sample sheets should be empty at first -->
|
||||
<div class="modal fade" id="modal-parse-samples" tabindex="-1" role="dialog" aria-labelledby=="modal-parse-samples-label"></div>
|
||||
|
@ -8,8 +9,8 @@
|
|||
<div id="alert-container"></div>
|
||||
|
||||
<% if can_view_samples(@team) %>
|
||||
<%= bootstrap_form_tag(url: export_samples_team_path(@team, format: :csv),
|
||||
html: { id: 'form-export', class: 'hidden' }) do |f| %>
|
||||
<%= bootstrap_form_tag(url: export_samples_team_path(@team),
|
||||
html: { id: 'form-export', class: 'hidden' }) do |f| %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -1587,6 +1587,9 @@ en:
|
|||
notification_title: 'Your package is ready to be exported!'
|
||||
expired_title: 'The required file was expired!'
|
||||
expired_description: 'The downloadable file expires in 7 days after its creation.'
|
||||
export_error: 'An error occured.'
|
||||
modal_label: 'Export request received'
|
||||
modal_html: "<p>Your export request is being processed.</p><p>When completed we will <strong>send an email to %{email}</strong> inbox with a link to your exported samples. Note that the link will expire in 7 days.</p>"
|
||||
# This section contains general words that can be used in any parts of
|
||||
# application.
|
||||
tiny_mce:
|
||||
|
|
Loading…
Add table
Reference in a new issue