mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-28 02:27:57 +08:00
Switch between generating report PDF and export all PDF [SCI-2641]
This commit is contained in:
parent
a16d16bc5b
commit
d970576d60
8 changed files with 70 additions and 66 deletions
|
@ -186,7 +186,8 @@ class ReportsController < ApplicationController
|
|||
@project, current_user, current_team
|
||||
)
|
||||
|
||||
page_html_string = render_to_string 'reports/new.html.erb', export_all: true
|
||||
page_html_string = render_to_string 'reports/new.html.erb',
|
||||
locals: { export_all: true }
|
||||
parsed_page_html = Nokogiri::HTML(page_html_string)
|
||||
parsed_pdf_html = parsed_page_html.at_css('#report-content')
|
||||
@report.destroy
|
||||
|
|
|
@ -41,75 +41,78 @@ module ReportsHelper
|
|||
locals = provided_locals.nil? ? {} : provided_locals.clone
|
||||
locals[:children] = children_html
|
||||
|
||||
# Set path and filename local variables for files and tables
|
||||
if element['type_of'] == 'my_module_repository'
|
||||
obj_name = Repository.find(element[:repository_id]).name + '.csv'
|
||||
obj_folder_name = 'Inventories'
|
||||
if provided_locals[:export_all]
|
||||
# Set path and filename local variables for files and tables
|
||||
|
||||
locals[:filename] = obj_name
|
||||
locals[:path] = "#{obj_folder_name}/#{obj_name}"
|
||||
elsif element['type_of'].in? %w(step_asset step_table result_asset
|
||||
result_table)
|
||||
if element['type_of'] == 'my_module_repository'
|
||||
obj_name = Repository.find(element[:repository_id]).name + '.csv'
|
||||
obj_folder_name = 'Inventories'
|
||||
|
||||
parent_el = ReportElement.find(element['parent_id'])
|
||||
parent_type = parent_el[:type_of]
|
||||
parent = parent_type.singularize.classify.constantize
|
||||
.find(parent_el["#{parent_type}_id"])
|
||||
locals[:filename] = obj_name
|
||||
locals[:path] = "#{obj_folder_name}/#{obj_name}"
|
||||
elsif element['type_of'].in? %w(step_asset step_table result_asset
|
||||
result_table)
|
||||
|
||||
if parent.class == Step
|
||||
obj_name = if element['type_of'] == 'step_asset'
|
||||
name = Asset.find(element[:asset_id]).file_file_name
|
||||
suffix = name.split('.').second
|
||||
suffix.prepend('.') if suffix
|
||||
name.split('.').first
|
||||
else
|
||||
name = Table.find(element[:table_id]).name
|
||||
suffix = '.csv'
|
||||
name.empty? ? 'Table' : name
|
||||
end
|
||||
obj_name = obj_name.truncate(
|
||||
parent_el = ReportElement.find(element['parent_id'])
|
||||
parent_type = parent_el[:type_of]
|
||||
parent = parent_type.singularize.classify.constantize
|
||||
.find(parent_el["#{parent_type}_id"])
|
||||
|
||||
if parent.class == Step
|
||||
obj_name = if element['type_of'] == 'step_asset'
|
||||
name = Asset.find(element[:asset_id]).file_file_name
|
||||
suffix = name.split('.').second
|
||||
suffix.prepend('.') if suffix
|
||||
name.split('.').first
|
||||
else
|
||||
name = Table.find(element[:table_id]).name
|
||||
suffix = '.csv'
|
||||
name.empty? ? 'Table' : name
|
||||
end
|
||||
obj_name = obj_name.truncate(
|
||||
Constants::EXPORTED_FILE_NAME_TRUNCATION_LENGTH,
|
||||
omission: ''
|
||||
)
|
||||
obj_name += "_Step#{parent.position + 1}#{suffix}"
|
||||
obj_folder_name = 'Protocol attachments'
|
||||
parent_module = if parent.protocol.present?
|
||||
parent.protocol.my_module
|
||||
else
|
||||
parent.my_module
|
||||
end
|
||||
else
|
||||
obj_name = if element['type_of'] == 'result_asset'
|
||||
name = Asset.find(element[:result_id]).file_file_name
|
||||
suffix = name.split('.').second
|
||||
suffix.prepend('.') if suffix
|
||||
name.split('.').first
|
||||
else
|
||||
name = Result.find(element[:result_id]).name
|
||||
suffix = '.csv'
|
||||
name.empty? ? 'Table' : name
|
||||
end
|
||||
obj_name = obj_name.truncate(
|
||||
Constants::EXPORTED_FILE_NAME_TRUNCATION_LENGTH,
|
||||
omission: ''
|
||||
)
|
||||
obj_name += suffix
|
||||
obj_folder_name = 'Results attachments'
|
||||
parent_module = parent
|
||||
end
|
||||
|
||||
parent_module_name = parent_module.name.truncate(
|
||||
Constants::EXPORTED_FILE_NAME_TRUNCATION_LENGTH,
|
||||
omission: ''
|
||||
)
|
||||
obj_name += "_Step#{parent.position + 1}#{suffix}"
|
||||
obj_folder_name = 'Protocol attachments'
|
||||
parent_module = if parent.protocol.present?
|
||||
parent.protocol.my_module
|
||||
else
|
||||
parent.my_module
|
||||
end
|
||||
else
|
||||
obj_name = if element['type_of'] == 'result_asset'
|
||||
name = Asset.find(element[:result_id]).file_file_name
|
||||
suffix = name.split('.').second
|
||||
suffix.prepend('.') if suffix
|
||||
name.split('.').first
|
||||
else
|
||||
name = Result.find(element[:result_id]).name
|
||||
suffix = '.csv'
|
||||
name.empty? ? 'Table' : name
|
||||
end
|
||||
obj_name = obj_name.truncate(
|
||||
parent_exp_name = parent_module.experiment.name.truncate(
|
||||
Constants::EXPORTED_FILE_NAME_TRUNCATION_LENGTH,
|
||||
omission: ''
|
||||
)
|
||||
obj_name += suffix
|
||||
obj_folder_name = 'Results attachments'
|
||||
parent_module = parent
|
||||
|
||||
locals[:filename] = obj_name
|
||||
locals[:path] = "#{parent_exp_name}/#{parent_module_name}/" \
|
||||
"#{obj_folder_name}/#{obj_name}"
|
||||
end
|
||||
|
||||
parent_module_name = parent_module.name.truncate(
|
||||
Constants::EXPORTED_FILE_NAME_TRUNCATION_LENGTH,
|
||||
omission: ''
|
||||
)
|
||||
parent_exp_name = parent_module.experiment.name.truncate(
|
||||
Constants::EXPORTED_FILE_NAME_TRUNCATION_LENGTH,
|
||||
omission: ''
|
||||
)
|
||||
|
||||
locals[:filename] = obj_name
|
||||
locals[:path] = "#{parent_exp_name}/#{parent_module_name}/" \
|
||||
"#{obj_folder_name}/#{obj_name}"
|
||||
end
|
||||
|
||||
# ReportExtends is located in config/initializers/extends/report_extends.rb
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<div class="pull-left repository-name">
|
||||
<%=t "projects.reports.elements.module_repository.name", repository: repository.name, my_module: my_module.name %>
|
||||
</div>
|
||||
<% if defined? path and path.present? %>
|
||||
<% if defined? export_all and export_all%>
|
||||
<div class="pull-left table-name">
|
||||
<a href="<%= path %>">
|
||||
<em><%=t "projects.reports.elements.module_repository.table_name",
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<%= result.name %>
|
||||
</div>
|
||||
<div class="pull-left file-name">
|
||||
<% if defined? path and path.present? %>
|
||||
<% if defined? export_all and export_all %>
|
||||
<a href="<%= path %>">
|
||||
<em><%=t "projects.reports.elements.result_asset.file_name",
|
||||
file: filename %></em>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<div class="pull-left result-name">
|
||||
<%= result.name %>
|
||||
</div>
|
||||
<% if defined? path and path.present? %>
|
||||
<% if defined? export_all and export_all %>
|
||||
<div class="pull-left table-name">
|
||||
<a href="<%= path %>">
|
||||
<em><%=t "projects.reports.elements.result_table.table_name",
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<span class="<%= icon_class %>"></span>
|
||||
</div>
|
||||
<div class="pull-left file-name">
|
||||
<% if defined? path and path.present? %>
|
||||
<% if defined? export_all and export_all %>
|
||||
<a href="<%= path %>">
|
||||
<em><%=t 'projects.reports.elements.step_asset.file_name',
|
||||
file: filename %></em>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<span class="fas fa-table"></span>
|
||||
</div>
|
||||
<div class="pull-left table-name">
|
||||
<% if defined? path and path.present? %>
|
||||
<% if defined? export_all and export_all %>
|
||||
<a href="<%= path %>">
|
||||
<em><%=t 'projects.reports.elements.step_table.table_name',
|
||||
name: filename %></em>
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
<% if @report.present? %>
|
||||
<% @report.root_elements.each do |el| %>
|
||||
<%= render_report_element(el) %>
|
||||
<%= render_report_element(el, local_assigns) %>
|
||||
<%= render_new_element(false) %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
|
|
Loading…
Reference in a new issue