From a2f7f38e3126ce80515179448ba2440b8bafaaca Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 30 May 2022 11:33:56 +0200 Subject: [PATCH] Update step structure in report [SCI-6855] --- .../reports/docx/draw_my_module_protocol.rb | 22 +++++++++++-------- app/services/reports/docx/draw_step.rb | 17 +++++++------- app/services/reports/docx/draw_step_text.rb | 13 +++++++++++ 3 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 app/services/reports/docx/draw_step_text.rb diff --git a/app/services/reports/docx/draw_my_module_protocol.rb b/app/services/reports/docx/draw_my_module_protocol.rb index 33ee757c5..3c7e2721b 100644 --- a/app/services/reports/docx/draw_my_module_protocol.rb +++ b/app/services/reports/docx/draw_my_module_protocol.rb @@ -3,15 +3,19 @@ module Reports::Docx::DrawMyModuleProtocol def draw_my_module_protocol(my_module) protocol = my_module.protocol - return false if protocol.description.blank? - @docx.p I18n.t 'projects.reports.elements.module.protocol.user_time', - timestamp: I18n.l(protocol.created_at, format: :full) - @docx.hr - html = custom_auto_link(protocol.description, team: @report_team) - Reports::HtmlToWordConverter.new(@docx, { scinote_url: @scinote_url, - link_style: @link_style }).html_to_word_converter(html) - @docx.p - @docx.p + @docx.h4 protocol.name, italic: false + + if protocol.description.present? + + @docx.p I18n.t 'projects.reports.elements.module.protocol.user_time', + timestamp: I18n.l(protocol.created_at, format: :full) + @docx.hr + html = custom_auto_link(protocol.description, team: @report_team) + Reports::HtmlToWordConverter.new(@docx, { scinote_url: @scinote_url, + link_style: @link_style }).html_to_word_converter(html) + @docx.p + @docx.p + end end end diff --git a/app/services/reports/docx/draw_step.rb b/app/services/reports/docx/draw_step.rb index df98c1c68..304d078f8 100644 --- a/app/services/reports/docx/draw_step.rb +++ b/app/services/reports/docx/draw_step.rb @@ -30,21 +30,22 @@ module Reports::Docx::DrawStep @docx.p I18n.t 'projects.reports.elements.step.no_description' end - if @settings.dig('task', 'protocol', 'step_tables') - step.tables.each do |table| - draw_step_table(table) + step.step_orderable_elements.order(:position).each do |e| + if e.orderable_type == 'StepTable' && @settings.dig('task', 'protocol', 'step_tables') + draw_step_table(e.orderable.table) end + if e.orderable_type == 'Checklist' && @settings.dig('task', 'protocol', 'step_checklists') + draw_step_checklist(e.orderable) + end + + draw_step_text(e.orderable) if e.orderable_type == 'StepText' end if @settings.dig('task', 'protocol', 'step_files') step.assets.each do |asset| draw_step_asset(asset) end end - if @settings.dig('task', 'protocol', 'step_checklists') - step.checklists.each do |checklist| - draw_step_checklist(checklist) - end - end + draw_step_comments(step) if @settings.dig('task', 'protocol', 'step_comments') @docx.p diff --git a/app/services/reports/docx/draw_step_text.rb b/app/services/reports/docx/draw_step_text.rb new file mode 100644 index 000000000..9729ca3b3 --- /dev/null +++ b/app/services/reports/docx/draw_step_text.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Reports::Docx::DrawStepText + def draw_step_text(step_text) + if step_text.text.present? + html = custom_auto_link(step_text.text, team: @report_team) + Reports::HtmlToWordConverter.new(@docx, { scinote_url: @scinote_url, + link_style: @link_style }).html_to_word_converter(html) + else + @docx.p I18n.t 'projects.reports.elements.step.no_description' + end + end +end