mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-11 01:44:34 +08:00
Limit created report relations depth to tasks [SCI-5665]
This commit is contained in:
parent
ce0f57e3f3
commit
bca88188de
12 changed files with 98 additions and 70 deletions
|
@ -173,8 +173,35 @@ module ReportsHelper
|
|||
html_doc.to_s
|
||||
end
|
||||
|
||||
def filter_steps_for_report(steps, settings)
|
||||
include_completed_steps = settings.dig('task', 'protocol', 'completed_steps')
|
||||
include_uncompleted_steps = settings.dig('task', 'protocol', 'uncompleted_steps')
|
||||
if include_completed_steps && include_uncompleted_steps
|
||||
steps
|
||||
elsif include_completed_steps
|
||||
steps.where(completed: true)
|
||||
elsif include_uncompleted_steps
|
||||
steps.where(completed: false)
|
||||
else
|
||||
steps.none
|
||||
end
|
||||
end
|
||||
|
||||
def order_results_for_report(results, order)
|
||||
case order
|
||||
when 'atoz'
|
||||
results.order(name: :asc)
|
||||
when 'ztoa'
|
||||
results.order(name: :desc)
|
||||
when 'new'
|
||||
results.order(updated_at: :desc)
|
||||
else
|
||||
results.order(updated_at: :asc)
|
||||
end
|
||||
end
|
||||
|
||||
def report_experiment_descriptions(report)
|
||||
report.report_elements.experiment.collect do |experiment_element|
|
||||
report.report_elements.experiment.map do |experiment_element|
|
||||
experiment_element.experiment.description
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,6 +29,7 @@ module Reports
|
|||
footer: { html: { template: "reports/templates/#{template_name}/footer",
|
||||
locals: { report: report },
|
||||
layout: 'reports/footer_header.html.erb' } },
|
||||
assigns: { settings: report.settings },
|
||||
locals: { report: report },
|
||||
disable_javascript: false,
|
||||
template: 'reports/report.pdf.erb'
|
||||
|
|
|
@ -29,7 +29,10 @@ class Report < ApplicationRecord
|
|||
|
||||
# Report either has many report elements (if grouped by timestamp),
|
||||
# or many module elements (if grouped by module)
|
||||
has_many :report_elements, inverse_of: :report, dependent: :delete_all
|
||||
has_many :report_elements,
|
||||
-> { where(type_of: ReportExtends::ACTIVE_REPORT_ELEMENTS) },
|
||||
inverse_of: :report,
|
||||
dependent: :delete_all
|
||||
|
||||
DEFAULT_SETTINGS = {
|
||||
all_tasks: true,
|
||||
|
|
|
@ -64,19 +64,6 @@ module ReportActions
|
|||
my_modules.sort_by { |m| selected_my_modules.index m.id }.each do |my_module|
|
||||
my_module_element = save_element({ 'my_module_id' => my_module.id }, :my_module, experiment_element)
|
||||
|
||||
if @settings.dig('task', 'protocol', 'description')
|
||||
save_element({ 'my_module_id' => my_module.id }, :my_module_protocol, my_module_element)
|
||||
end
|
||||
|
||||
generate_steps_content(my_module, my_module_element)
|
||||
|
||||
generate_results_content(my_module, my_module_element)
|
||||
|
||||
if @settings.dig('task', 'activities')
|
||||
save_element({ 'my_module_id' => my_module.id }, :my_module_activity, my_module_element)
|
||||
|
||||
end
|
||||
|
||||
my_module.experiment.project.assigned_repositories_and_snapshots.each do |repository|
|
||||
next unless @content['repositories'].include?(repository.id)
|
||||
|
||||
|
@ -88,60 +75,11 @@ module ReportActions
|
|||
end
|
||||
|
||||
MY_MODULE_ADDONS_ELEMENTS.each do |e|
|
||||
send("generate_#{e}_content", my_module, my_module_element)
|
||||
public_send("generate_#{e}_content", my_module, my_module_element)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def generate_steps_content(my_module, my_module_element)
|
||||
my_module.protocols.first.steps
|
||||
.includes(:checklists, :step_tables, :step_assets, :step_comments)
|
||||
.order(:position).each do |step|
|
||||
step_element = nil
|
||||
if step.completed && @settings.dig('task', 'protocol', 'completed_steps')
|
||||
step_element = save_element({ 'step_id' => step.id }, :step, my_module_element)
|
||||
elsif @settings.dig('task', 'protocol', 'uncompleted_steps')
|
||||
step_element = save_element({ 'step_id' => step.id }, :step, my_module_element)
|
||||
end
|
||||
|
||||
next unless step_element
|
||||
|
||||
if @settings.dig('task', 'protocol', 'step_checklists')
|
||||
step.checklists.each do |checklist|
|
||||
save_element({ 'checklist_id' => checklist.id }, :step_checklist, step_element)
|
||||
end
|
||||
end
|
||||
|
||||
if @settings.dig('task', 'protocol', 'step_tables')
|
||||
step.step_tables.each do |table|
|
||||
save_element({ 'table_id' => table.id }, :step_table, step_element)
|
||||
end
|
||||
end
|
||||
|
||||
if @settings.dig('task', 'protocol', 'step_files')
|
||||
step.step_assets.each do |asset|
|
||||
save_element({ 'asset_id' => asset.id }, :step_asset, step_element)
|
||||
end
|
||||
end
|
||||
|
||||
if @settings.dig('task', 'protocol', 'step_comments')
|
||||
save_element({ 'step_id' => step.id }, :step_comments, step_element)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def generate_results_content(my_module, my_module_element)
|
||||
my_module.results do |result|
|
||||
result_type = (result.result_asset || result.result_table || result.result_text).class.to_s.underscore
|
||||
|
||||
next unless @settings.dig('task', result_type)
|
||||
|
||||
result_element = save_element({ 'result_id' => result.id }, result_type, my_module_element)
|
||||
|
||||
save_element({ 'result_id' => result.id }, :result_comments, result_element)
|
||||
end
|
||||
end
|
||||
|
||||
def save_element(reference, type_of, parent)
|
||||
el = ReportElement.new
|
||||
el.position = @element_position
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<% if my_module.blank? and @my_module.present? then my_module = @my_module end %>
|
||||
<% my_module ||= @my_module %>
|
||||
<% timestamp = Time.current + 1.year - 2.days %>
|
||||
<% activities = ActivitiesService.my_module_activities(my_module).order(created_at: :desc) %>
|
||||
<div class="report-element report-module-activity-element" data-ts="<%= timestamp.to_i %>" data-type="my_module_activity" data-id='{ "my_module_id": <%= my_module.id %> }' data-scroll-id="<%= my_module.id %>" data-order="<%= order == :asc ? "asc" : "desc" %>" data-name="<%=t "projects.reports.elements.module_activity.sidebar_name" %>" data-icon-class="fas fa-list">
|
||||
<div class="report-element report-module-activity-element" data-ts="<%= timestamp.to_i %>" data-type="my_module_activity" data-id='{ "my_module_id": <%= my_module.id %> }' data-scroll-id="<%= my_module.id %>" data-name="<%=t "projects.reports.elements.module_activity.sidebar_name" %>" data-icon-class="fas fa-list">
|
||||
<div class="report-element-header">
|
||||
<div class="row">
|
||||
<div class="pull-left activity-icon">
|
||||
|
|
|
@ -80,6 +80,29 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="report-element-children">
|
||||
<% if @settings.dig('task', 'protocol', 'description') %>
|
||||
<%= render partial: 'reports/elements/my_module_protocol_element.html.erb', locals: { protocol: my_module.protocol } %>
|
||||
<% end %>
|
||||
|
||||
<% filter_steps_for_report(my_module.protocol.steps, @settings).order(:position).each do |step| %>
|
||||
<%= render partial: 'reports/elements/my_module_step_element.html.erb', locals: { step: step } %>
|
||||
<% end %>
|
||||
|
||||
<% order_results_for_report(my_module.results, @settings.dig('task', 'result_order')) do |result| %>
|
||||
<% if result.is_asset && @settings.dig('task', 'file_results') %>
|
||||
<%= render partial: 'reports/elements/my_module_result_asset_element.html.erb', locals: { result: result } %>
|
||||
<% elsif result.is_table && @settings.dig('task', 'table_results') %>
|
||||
<%= render partial: 'reports/elements/my_module_result_table_element.html.erb', locals: { result: result } %>
|
||||
<% elsif result.is_text && @settings.dig('task', 'text_results') %>
|
||||
<%= render partial: 'reports/elements/my_module_result_text_element.html.erb', locals: { result: result } %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if @settings.dig('task', 'activities') %>
|
||||
<%= render partial: 'reports/elements/my_module_activity_element.html.erb', locals: { my_module: my_module } %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="report-element-children">
|
||||
<%= children if (defined? children and children.present?) %>
|
||||
</div>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<% protocol ||= my_module.protocol %>
|
||||
<% my_module = protocol.my_module %>
|
||||
<% for_export_all = defined?(export_all) && export_all %>
|
||||
<div class="report-element report-module-protocol-element" data-ts="<%= protocol.created_at %>" data-type="my_module_protocol" data-id='{ "my_module_id": <%= my_module.id %> }' data-scroll-id="<%= protocol.id %>">
|
||||
<div class="report-element-header">
|
||||
|
|
|
@ -57,6 +57,11 @@
|
|||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="report-element-children">
|
||||
<% if @settings.dig('task', 'result_comments') %>
|
||||
<%= render partial: 'reports/elements/result_comments_element.html.erb', locals: { result: result } %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="report-element-children">
|
||||
<%= children if (defined? children and children.present?) %>
|
||||
</div>
|
||||
|
|
|
@ -38,6 +38,11 @@
|
|||
<div class="hot-table-container"></div>
|
||||
<table class="report-common-table-format"></table>
|
||||
</div>
|
||||
<div class="report-element-children">
|
||||
<% if @settings.dig('task', 'result_comments') %>
|
||||
<%= render partial: 'reports/elements/result_comments_element.html.erb', locals: { result: result } %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="report-element-children">
|
||||
<%= children if (defined? children and children.present?) %>
|
||||
</div>
|
||||
|
|
|
@ -35,6 +35,11 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="report-element-children">
|
||||
<% if @settings.dig('task', 'result_comments') %>
|
||||
<%= render partial: 'reports/elements/result_comments_element.html.erb', locals: { result: result } %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="report-element-children">
|
||||
<%= children if (defined? children and children.present?) %>
|
||||
</div>
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
<% if step.blank? and @step.present? then step = @step end %>
|
||||
<% step ||= @step %>
|
||||
<% step_type_str = step.completed ? 'completed' : 'uncompleted' %>
|
||||
<% user = step.completed? ? step.last_modified_by : step.user %>
|
||||
<% timestamp = step.completed ? step.completed_on : step.created_at %>
|
||||
<% tables = step.tables %>
|
||||
<% assets = step.assets %>
|
||||
<% checklists = step.checklists %>
|
||||
<% comments = step.step_comments %>
|
||||
<% for_export_all = defined?(export_all) && export_all %>
|
||||
<div class="report-element report-step-element"
|
||||
data-ts="<%= timestamp.to_i %>"
|
||||
|
@ -49,6 +48,26 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="report-element-children">
|
||||
<% if @settings.dig('task', 'protocol', 'step_tables') %>
|
||||
<% tables.each do |table| %>
|
||||
<%= render partial: 'reports/elements/step_table_element.html.erb', locals: { table: table } %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if @settings.dig('task', 'protocol', 'step_files') %>
|
||||
<% assets.each do |asset| %>
|
||||
<%= render partial: 'reports/elements/step_asset_element.html.erb', locals: { asset: asset } %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if @settings.dig('task', 'protocol', 'step_checklists') %>
|
||||
<% checklists.each do |checklist| %>
|
||||
<%= render partial: 'reports/elements/step_checklist_element.html.erb', locals: { checklist: checklist } %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if @settings.dig('task', 'protocol', 'step_comments') %>
|
||||
<%= render partial: 'reports/elements/step_comments_element.html.erb', locals: { step: step } %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="report-element-children">
|
||||
<%= children if (defined? children and children.present?) %>
|
||||
</div>
|
||||
|
|
|
@ -57,6 +57,8 @@ module ReportExtends
|
|||
end
|
||||
end
|
||||
|
||||
ACTIVE_REPORT_ELEMENTS = %i(project_header my_module project_activity experiment my_module_repository)
|
||||
|
||||
# Module contents element
|
||||
MODULE_CONTENTS = [
|
||||
ModuleElement.new([:protocol],
|
||||
|
|
Loading…
Reference in a new issue