From e2c49c7e619378cb384c9b8306df823cf57ffac4 Mon Sep 17 00:00:00 2001 From: Andrej Date: Mon, 7 Oct 2024 14:45:04 +0200 Subject: [PATCH] Remove some empty in docx reports [SCI-11056] --- app/services/reports/docx/draw_experiment.rb | 17 +++++----- app/services/reports/docx/draw_my_module.rb | 26 ++++++++------ .../reports/docx/draw_my_module_protocol.rb | 1 - .../reports/docx/draw_result_comments.rb | 5 +-- .../reports/docx/draw_result_table.rb | 2 +- app/services/reports/docx/draw_result_text.rb | 15 ++++---- app/services/reports/docx/draw_step.rb | 34 +++++++++---------- app/services/reports/docx/draw_step_asset.rb | 2 +- .../reports/docx/draw_step_checklist.rb | 2 +- .../reports/docx/draw_step_comments.rb | 5 +-- app/services/reports/docx/draw_step_table.rb | 2 +- app/services/reports/docx/draw_step_text.rb | 16 +++++---- 12 files changed, 70 insertions(+), 57 deletions(-) diff --git a/app/services/reports/docx/draw_experiment.rb b/app/services/reports/docx/draw_experiment.rb index 50b55e347..ebe3ae7ca 100644 --- a/app/services/reports/docx/draw_experiment.rb +++ b/app/services/reports/docx/draw_experiment.rb @@ -15,14 +15,15 @@ module Reports::Docx::DrawExperiment link_style end - @docx.p do - unless settings['exclude_timestamps'] - text I18n.t('projects.reports.elements.experiment.user_time', - code: experiment.code, timestamp: I18n.l(experiment.created_at, format: :full)), color: color[:gray] - end - if experiment.archived? - text ' | ' - text I18n.t('search.index.archived'), color: color[:gray] + if !settings['exclude_timestamps'] || experiment.archived? + @docx.p do + unless settings['exclude_timestamps'] + text I18n.t('projects.reports.elements.experiment.user_time', + code: experiment.code, + timestamp: I18n.l(experiment.created_at, format: :full)), color: color[:gray] + text ' | ' if experiment.archived? + end + text I18n.t('search.index.archived'), color: color[:gray] if experiment.archived? end end html = custom_auto_link(experiment.description, team: @report_team) diff --git a/app/services/reports/docx/draw_my_module.rb b/app/services/reports/docx/draw_my_module.rb index 3f48772bc..bd859baab 100644 --- a/app/services/reports/docx/draw_my_module.rb +++ b/app/services/reports/docx/draw_my_module.rb @@ -16,14 +16,15 @@ module Reports::Docx::DrawMyModule link_style end - @docx.p do - unless settings['exclude_timestamps'] - text I18n.t('projects.reports.elements.module.user_time', code: my_module.code, - timestamp: I18n.l(my_module.created_at, format: :full)), color: color[:gray] - end - if my_module.archived? - text ' | ' - text I18n.t('search.index.archived'), color: color[:gray] + if my_module.archived? || !settings['exclude_timestamps'] + @docx.p do + unless settings['exclude_timestamps'] + text I18n.t('projects.reports.elements.module.user_time', code: my_module.code, + timestamp: I18n.l(my_module.created_at, format: :full)), color: color[:gray] + text ' | ' if my_module.archived? + end + + text I18n.t('search.index.archived'), color: color[:gray] if my_module.archived? end end @@ -74,10 +75,13 @@ module Reports::Docx::DrawMyModule filter_steps_for_report(my_module.protocol.steps, @settings).order(:position).each do |step| draw_step(step) end - - draw_results(my_module) unless without_results - @docx.p + + unless without_results + draw_results(my_module) + @docx.p + end + subject.children.active.each do |child| next if without_repositories && child.type_of == 'my_module_repository' diff --git a/app/services/reports/docx/draw_my_module_protocol.rb b/app/services/reports/docx/draw_my_module_protocol.rb index 9092b088d..0f3b56dbe 100644 --- a/app/services/reports/docx/draw_my_module_protocol.rb +++ b/app/services/reports/docx/draw_my_module_protocol.rb @@ -20,7 +20,6 @@ module Reports::Docx::DrawMyModuleProtocol 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_result_comments.rb b/app/services/reports/docx/draw_result_comments.rb index 3fc68ef1f..ebec9ad13 100644 --- a/app/services/reports/docx/draw_result_comments.rb +++ b/app/services/reports/docx/draw_result_comments.rb @@ -8,8 +8,10 @@ module Reports::Docx::DrawResultComments @docx.p @docx.p I18n.t('projects.reports.elements.result_comments.name', result: result.name), bold: true, size: Constants::REPORT_DOCX_STEP_ELEMENTS_TITLE_SIZE - comments.each do |comment| + comments.find_each.with_index do |comment, index| comment_ts = comment.created_at + + @docx.p unless index.zero? @docx.p I18n.t('projects.reports.elements.result_comments.comment_prefix', user: comment.user.full_name, date: I18n.l(comment_ts, format: :full_date), @@ -17,7 +19,6 @@ module Reports::Docx::DrawResultComments html = custom_auto_link(comment.message, team: @report_team) Reports::HtmlToWordConverter.new(@docx, { scinote_url: @scinote_url, link_style: @link_style }).html_to_word_converter(html) - @docx.p end end end diff --git a/app/services/reports/docx/draw_result_table.rb b/app/services/reports/docx/draw_result_table.rb index bd73c48e9..f919cc8a4 100644 --- a/app/services/reports/docx/draw_result_table.rb +++ b/app/services/reports/docx/draw_result_table.rb @@ -40,8 +40,8 @@ module Reports::Docx::DrawResultTable end @docx.p do text I18n.t 'projects.reports.elements.result_table.table_name', name: table.name - text ' ' unless settings['exclude_timestamps'] + text ' ' text I18n.t('projects.reports.elements.result_table.user_time', timestamp: I18n.l(timestamp, format: :full), user: result.user.full_name), color: color[:gray] end diff --git a/app/services/reports/docx/draw_result_text.rb b/app/services/reports/docx/draw_result_text.rb index 252bf68d8..baf9bc9f3 100644 --- a/app/services/reports/docx/draw_result_text.rb +++ b/app/services/reports/docx/draw_result_text.rb @@ -6,12 +6,15 @@ module Reports::Docx::DrawResultText timestamp = element.created_at settings = @settings color = @color - @docx.p do - text result_text.name.presence || '', italic: true - text ' ' - unless settings['exclude_timestamps'] - text I18n.t('projects.reports.elements.result_text.user_time', - timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] + if result_text.name.present? || !settings['exclude_timestamps'] + @docx.p do + text result_text.name.to_s, italic: true + text ' ' if result_text.name.present? + + unless settings['exclude_timestamps'] + text I18n.t('projects.reports.elements.result_text.user_time', + timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] + end end end html = custom_auto_link(result_text.text, team: @report_team) diff --git a/app/services/reports/docx/draw_step.rb b/app/services/reports/docx/draw_step.rb index 376911fc4..579a24c4e 100644 --- a/app/services/reports/docx/draw_step.rb +++ b/app/services/reports/docx/draw_step.rb @@ -11,21 +11,24 @@ module Reports::Docx::DrawStep @docx.h4( "#{I18n.t('projects.reports.elements.step.step_pos', pos: step.position_plus_one)} #{step.name}" ) - @docx.p do - unless settings['exclude_task_metadata'] - if step.completed - text I18n.t('protocols.steps.completed'), color: color[:green], bold: true - else - text I18n.t('protocols.steps.uncompleted'), color: color[:gray], bold: true + + unless settings['exclude_task_metadata'] || settings['exclude_timestamps'] + @docx.p do + unless settings['exclude_task_metadata'] + if step.completed + text I18n.t('protocols.steps.completed'), color: color[:green], bold: true + else + text I18n.t('protocols.steps.uncompleted'), color: color[:gray], bold: true + end + end + unless settings['exclude_timestamps'] + text ' | ' unless settings['exclude_task_metadata'] + text I18n.t( + "projects.reports.elements.step.#{step_type_str}.user_time", + user: user.full_name, + timestamp: I18n.l(timestamp, format: :full) + ), color: color[:gray] end - end - unless settings['exclude_timestamps'] - text ' | ' unless settings['exclude_task_metadata'] - text I18n.t( - "projects.reports.elements.step.#{step_type_str}.user_time", - user: user.full_name, - timestamp: I18n.l(timestamp, format: :full) - ), color: color[:gray] end end @@ -46,9 +49,6 @@ module Reports::Docx::DrawStep end draw_step_comments(step) if @settings.dig('task', 'protocol', 'step_comments') - - @docx.p - @docx.p end def handle_step_table(table) diff --git a/app/services/reports/docx/draw_step_asset.rb b/app/services/reports/docx/draw_step_asset.rb index 14987e698..5b6569919 100644 --- a/app/services/reports/docx/draw_step_asset.rb +++ b/app/services/reports/docx/draw_step_asset.rb @@ -23,8 +23,8 @@ module Reports::Docx::DrawStepAsset link I18n.t('projects.reports.elements.download'), asset_url do italic true end - text ' ' unless settings['exclude_timestamps'] + text ' ' text I18n.t('projects.reports.elements.step_asset.user_time', timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] end diff --git a/app/services/reports/docx/draw_step_checklist.rb b/app/services/reports/docx/draw_step_checklist.rb index ffd2f8192..5c510c9f9 100644 --- a/app/services/reports/docx/draw_step_checklist.rb +++ b/app/services/reports/docx/draw_step_checklist.rb @@ -16,8 +16,8 @@ module Reports::Docx::DrawStepChecklist team, I18n.t('projects.reports.elements.step_checklist.checklist_name', name: checklist.name) ).text, italic: true - text ' ' unless settings['exclude_timestamps'] + text ' ' text I18n.t('projects.reports.elements.step_checklist.user_time', timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] end diff --git a/app/services/reports/docx/draw_step_comments.rb b/app/services/reports/docx/draw_step_comments.rb index 87d0abc5f..f9733eaeb 100644 --- a/app/services/reports/docx/draw_step_comments.rb +++ b/app/services/reports/docx/draw_step_comments.rb @@ -8,8 +8,10 @@ module Reports::Docx::DrawStepComments @docx.p @docx.p I18n.t('projects.reports.elements.step_comments.name', step: step.name), bold: true, size: Constants::REPORT_DOCX_STEP_ELEMENTS_TITLE_SIZE - comments.each do |comment| + comments.find_each.with_index do |comment, index| comment_ts = comment.created_at + + @docx.p unless index.zero? @docx.p I18n.t('projects.reports.elements.step_comments.comment_prefix', user: comment.user.full_name, date: I18n.l(comment_ts, format: :full_date), @@ -17,7 +19,6 @@ module Reports::Docx::DrawStepComments html = custom_auto_link(comment.message, team: @report_team) Reports::HtmlToWordConverter.new(@docx, { scinote_url: @scinote_url, link_style: @link_style }).html_to_word_converter(html) - @docx.p end end end diff --git a/app/services/reports/docx/draw_step_table.rb b/app/services/reports/docx/draw_step_table.rb index f7c115691..3565c200e 100644 --- a/app/services/reports/docx/draw_step_table.rb +++ b/app/services/reports/docx/draw_step_table.rb @@ -39,8 +39,8 @@ module Reports::Docx::DrawStepTable end @docx.p do text I18n.t("projects.reports.elements.#{table_type}.table_name", name: table.name), italic: true - text ' ' unless settings['exclude_timestamps'] + text ' ' text I18n.t("projects.reports.elements.#{table_type}.user_time", timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] end diff --git a/app/services/reports/docx/draw_step_text.rb b/app/services/reports/docx/draw_step_text.rb index 66f0ed84c..5fc364639 100644 --- a/app/services/reports/docx/draw_step_text.rb +++ b/app/services/reports/docx/draw_step_text.rb @@ -6,12 +6,16 @@ module Reports::Docx::DrawStepText timestamp = element.created_at color = @color settings = @settings - @docx.p do - text step_text.name.presence || '', italic: true - text ' ' - unless settings['exclude_timestamps'] - text I18n.t('projects.reports.elements.result_text.user_time', - timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] + + if step_text.name.present? || !settings['exclude_timestamps'] + @docx.p do + text step_text.name.to_s, italic: true + text ' ' if step_text.name.present? + + unless settings['exclude_timestamps'] + text I18n.t('projects.reports.elements.result_text.user_time', + timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] + end end end if step_text.text.present?