From b4bcd69683cc4e9f9b50c2ca1ce7f980e95d1e45 Mon Sep 17 00:00:00 2001 From: Anton Date: Tue, 13 Aug 2024 14:14:00 +0200 Subject: [PATCH 01/28] Add exclude metadata from reports [SCI-10978] --- app/assets/javascripts/reports/new.js | 2 ++ .../elements/_experiment_element.html.erb | 8 +++-- .../elements/_my_module_element.html.erb | 32 +++++++++++-------- .../_my_module_protocol_element.html.erb | 8 +++-- .../_my_module_result_asset_element.html.erb | 4 ++- .../_my_module_result_table_element.html.erb | 8 +++-- .../_my_module_result_text_element.html.erb | 8 +++-- .../elements/_my_module_step_element.html.erb | 8 +++-- .../elements/_project_header_element.html.erb | 8 +++-- .../elements/_step_asset_element.html.erb | 8 +++-- .../elements/_step_checklist_element.html.erb | 8 +++-- .../elements/_step_table_element.html.erb | 8 +++-- .../elements/_step_text_element.html.erb | 8 +++-- app/views/reports/wizard/_third_step.html.erb | 10 ++++++ config/locales/en.yml | 1 + 15 files changed, 84 insertions(+), 45 deletions(-) diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js index ad280af9f7..28e4078262 100644 --- a/app/assets/javascripts/reports/new.js +++ b/app/assets/javascripts/reports/new.js @@ -1052,6 +1052,8 @@ function reportHandsonTableConverter() { reportData.report.settings.task.result_order = dropdownSelector.getValues('#taskResultsOrder'); + reportData.report.settings.exclude_metada = $('.exclude-metadata-setting')[0].checked; + return reportData; } diff --git a/app/views/reports/elements/_experiment_element.html.erb b/app/views/reports/elements/_experiment_element.html.erb index 86804dc9a6..8ef08378e3 100644 --- a/app/views/reports/elements/_experiment_element.html.erb +++ b/app/views/reports/elements/_experiment_element.html.erb @@ -9,9 +9,11 @@ <%= t('search.index.archived') %> <% end %> -
- <%= t('projects.reports.elements.experiment.user_time', code: experiment.code, timestamp: l(timestamp, format: :full)) %> -
+ <% unless @settings.dig('exclude_metadata') %> +
+ <%= t('projects.reports.elements.experiment.user_time', code: experiment.code, timestamp: l(timestamp, format: :full)) %> +
+ <% end %> <% if experiment.description.present? %> <%= custom_auto_link(experiment.description, team: current_team, base64_encoded_imgs: export_all) %> <% end %> diff --git a/app/views/reports/elements/_my_module_element.html.erb b/app/views/reports/elements/_my_module_element.html.erb index 43d9fd6653..5624954184 100644 --- a/app/views/reports/elements/_my_module_element.html.erb +++ b/app/views/reports/elements/_my_module_element.html.erb @@ -9,9 +9,11 @@ <%= t('search.index.archived') %> <% end %> -
- <%= t('projects.reports.elements.module.user_time', code: my_module.code, timestamp: l(timestamp, format: :full)) %> -
+ <% unless @settings.dig('exclude_metadata') %> +
+ <%= t('projects.reports.elements.module.user_time', code: my_module.code, timestamp: l(timestamp, format: :full)) %> +
+ <% end %>

<% if my_module.started_on.present? %> <%= t('projects.reports.elements.module.started_on', started_on: l(my_module.started_on, format: :full)) %> @@ -36,18 +38,20 @@ <% end %>

-
-
- <%= t('projects.reports.elements.module.tags_header') %> -
- <% if (tags = my_module.tags.order(:id)).present? %> - <% tags.each do |tag| %> -
- <%= tag.name %> -
+ <% unless @settings.dig('exclude_metadata') %> +
+
+ <%= t('projects.reports.elements.module.tags_header') %> +
+ <% if (tags = my_module.tags.order(:id)).present? %> + <% tags.each do |tag| %> +
+ <%= tag.name %> +
+ <% end %> <% end %> - <% end %> -
+
+ <% end %>
<% if my_module.description.present? %> diff --git a/app/views/reports/elements/_my_module_protocol_element.html.erb b/app/views/reports/elements/_my_module_protocol_element.html.erb index 9fd76c321c..88755ca91e 100644 --- a/app/views/reports/elements/_my_module_protocol_element.html.erb +++ b/app/views/reports/elements/_my_module_protocol_element.html.erb @@ -9,9 +9,11 @@ <%= t('projects.reports.elements.module.protocol.name') %> <% end %> -
- <%= t('projects.reports.elements.module.protocol.user_time', code: protocol.original_code, timestamp: l(protocol.created_at, format: :full)) %> -
+ <% unless @settings.dig('exclude_metadata') %> +
+ <%= t('projects.reports.elements.module.protocol.user_time', code: protocol.original_code, timestamp: l(protocol.created_at, format: :full)) %> +
+ <% end %>
<% if @settings.dig('task', 'protocol', 'description') && protocol.description.present? %> <%= custom_auto_link(protocol.prepare_for_report(:description, export_all: export_all), diff --git a/app/views/reports/elements/_my_module_result_asset_element.html.erb b/app/views/reports/elements/_my_module_result_asset_element.html.erb index 65c9a3e431..71857134b0 100644 --- a/app/views/reports/elements/_my_module_result_asset_element.html.erb +++ b/app/views/reports/elements/_my_module_result_asset_element.html.erb @@ -26,7 +26,9 @@ <% end %>
- <%= t("projects.reports.elements.result_asset.user_time", user: result.user.full_name, timestamp: l(timestamp, format: :full)) %> + <% unless @settings.dig('exclude_metadata') %> + <%= t("projects.reports.elements.result_asset.user_time", user: result.user.full_name, timestamp: l(timestamp, format: :full)) %> + <% end %> <% if report.settings.dig(:task, :file_results_previews) && ActiveStorageFileUtil.previewable_document?(asset&.file&.blob) %> <%= t('projects.reports.elements.result_asset.full_preview_attached') %> <% end %> diff --git a/app/views/reports/elements/_my_module_result_table_element.html.erb b/app/views/reports/elements/_my_module_result_table_element.html.erb index 2464735b8a..749b20985b 100644 --- a/app/views/reports/elements/_my_module_result_table_element.html.erb +++ b/app/views/reports/elements/_my_module_result_table_element.html.erb @@ -21,9 +21,11 @@ <% end %> <% end %>
-
- <%= t('projects.reports.elements.result_table.user_time', timestamp: l(timestamp, format: :full)) %> -
+ <% unless @settings.dig('exclude_metadata') %> +
+ <%= t('projects.reports.elements.result_table.user_time', timestamp: l(timestamp, format: :full)) %> +
+ <% end %>
diff --git a/app/views/reports/elements/_my_module_result_text_element.html.erb b/app/views/reports/elements/_my_module_result_text_element.html.erb index b3b96926f8..d65b63a96b 100644 --- a/app/views/reports/elements/_my_module_result_text_element.html.erb +++ b/app/views/reports/elements/_my_module_result_text_element.html.erb @@ -11,9 +11,11 @@ <% end %>
-
- <%= t("projects.reports.elements.result_text.user_time", timestamp: l(timestamp, format: :full)) %> -
+ <% unless @settings.dig('exclude_metadata') %> +
+ <%= t("projects.reports.elements.result_text.user_time", timestamp: l(timestamp, format: :full)) %> +
+ <% end %>
diff --git a/app/views/reports/elements/_my_module_step_element.html.erb b/app/views/reports/elements/_my_module_step_element.html.erb index f0b636cd2d..15f6d32ea4 100644 --- a/app/views/reports/elements/_my_module_step_element.html.erb +++ b/app/views/reports/elements/_my_module_step_element.html.erb @@ -10,9 +10,11 @@ <%= t('projects.reports.elements.step.step_pos', pos: (step.position_plus_one)) %> <%= step.name %> <%= step_status_label(step) %> -
- <%= t("projects.reports.elements.step.#{step_type_str}.user_time", user: user.full_name , timestamp: l(timestamp, format: :full)) %> -
+ <% unless @settings.dig('exclude_metadata') %> +
+ <%= t("projects.reports.elements.step.#{step_type_str}.user_time", user: user.full_name , timestamp: l(timestamp, format: :full)) %> +
+ <% end %>
<% step.step_orderable_elements.order(:position).each do |e| %> diff --git a/app/views/reports/elements/_project_header_element.html.erb b/app/views/reports/elements/_project_header_element.html.erb index 54ad6a6293..735afe95ec 100644 --- a/app/views/reports/elements/_project_header_element.html.erb +++ b/app/views/reports/elements/_project_header_element.html.erb @@ -7,9 +7,11 @@ <%= t('search.index.archived') %> <% end %> -
- <%= t('projects.reports.elements.project_header.user_time', code: project.code, timestamp: l(project.created_at, format: :full)) %> -
+ <% unless @settings.dig('exclude_metadata') %> +
+ <%= t('projects.reports.elements.project_header.user_time', code: project.code, timestamp: l(project.created_at, format: :full)) %> +
+ <% end %>
<% if defined?(children) %>
diff --git a/app/views/reports/elements/_step_asset_element.html.erb b/app/views/reports/elements/_step_asset_element.html.erb index 2842a7adf7..75ea457626 100644 --- a/app/views/reports/elements/_step_asset_element.html.erb +++ b/app/views/reports/elements/_step_asset_element.html.erb @@ -18,9 +18,11 @@ <% end %> -
-  <%= t('projects.reports.elements.step_asset.user_time', timestamp: l(timestamp, format: :full)) %> -
+ <% unless @settings.dig('exclude_metadata') %> +
+  <%= t('projects.reports.elements.step_asset.user_time', timestamp: l(timestamp, format: :full)) %> +
+ <% end %>
<% if asset.previewable? && !asset.list? %> diff --git a/app/views/reports/elements/_step_checklist_element.html.erb b/app/views/reports/elements/_step_checklist_element.html.erb index f4d625d1a1..9a7917aa3e 100644 --- a/app/views/reports/elements/_step_checklist_element.html.erb +++ b/app/views/reports/elements/_step_checklist_element.html.erb @@ -9,9 +9,11 @@ team: current_team, base64_encoded_imgs: export_all) %>
-
- <%= t('projects.reports.elements.step_checklist.user_time', timestamp: l(timestamp, format: :full)) %> -
+ <% unless @settings.dig('exclude_metadata') %> +
+ <%= t('projects.reports.elements.step_checklist.user_time', timestamp: l(timestamp, format: :full)) %> +
+ <% end %>
<% items.each do |item| %> diff --git a/app/views/reports/elements/_step_table_element.html.erb b/app/views/reports/elements/_step_table_element.html.erb index e3334f08c9..1cc9c8b3c4 100644 --- a/app/views/reports/elements/_step_table_element.html.erb +++ b/app/views/reports/elements/_step_table_element.html.erb @@ -18,9 +18,11 @@ <% end %> <% end %>
-
- <%= t("projects.reports.elements.#{table_type}.user_time", timestamp: l(timestamp, format: :full)) %> -
+ <% unless @settings.dig('exclude_metadata') %> +
+ <%= t("projects.reports.elements.#{table_type}.user_time", timestamp: l(timestamp, format: :full)) %> +
+ <% end %>
diff --git a/app/views/reports/elements/_step_text_element.html.erb b/app/views/reports/elements/_step_text_element.html.erb index 01c274f891..9a62410c3e 100644 --- a/app/views/reports/elements/_step_text_element.html.erb +++ b/app/views/reports/elements/_step_text_element.html.erb @@ -8,9 +8,11 @@ <% end %>
-
- <%= t("projects.reports.elements.step_text.user_time", timestamp: l(timestamp, format: :full)) %> -
+ <% unless @settings.dig('exclude_metadata') %> +
+ <%= t("projects.reports.elements.step_text.user_time", timestamp: l(timestamp, format: :full)) %> +
+ <% end %>
<% if step_text.text.present? %> diff --git a/app/views/reports/wizard/_third_step.html.erb b/app/views/reports/wizard/_third_step.html.erb index 642eb9db57..d56af9b24b 100644 --- a/app/views/reports/wizard/_third_step.html.erb +++ b/app/views/reports/wizard/_third_step.html.erb @@ -194,6 +194,16 @@
+
  • +
    + + /> + + + <%= t("projects.reports.wizard.third_step.exclude_metadata") %> +
    +
    +
  • diff --git a/config/locales/en.yml b/config/locales/en.yml index 4e5d25a02d..55582e52c2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -851,6 +851,7 @@ en: results_comments: "Result comments" additional_content: "Additional content" task_activity: "Include task activity" + exclude_metadata: "Exclude metadata" archived: "[archived]" deleted: "[deleted]" From 5105079f8123636f4fc06f609a1033249d569c9a Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 14 Aug 2024 10:52:16 +0200 Subject: [PATCH 02/28] Add exclude metadata settings [SCI-10978] --- app/assets/javascripts/reports/new.js | 2 +- app/services/reports/docx/draw_experiment.rb | 7 +++- app/services/reports/docx/draw_my_module.rb | 37 +++++++++++-------- .../reports/docx/draw_my_module_protocol.rb | 6 ++- .../reports/docx/draw_project_header.rb | 10 +++-- .../reports/docx/draw_result_asset.rb | 6 ++- .../reports/docx/draw_result_table.rb | 7 +++- app/services/reports/docx/draw_result_text.rb | 7 +++- app/services/reports/docx/draw_results.rb | 9 +++-- app/services/reports/docx/draw_step.rb | 13 ++++--- app/services/reports/docx/draw_step_asset.rb | 7 +++- .../reports/docx/draw_step_checklist.rb | 7 +++- app/services/reports/docx/draw_step_table.rb | 7 +++- app/services/reports/docx/draw_step_text.rb | 7 +++- .../elements/_experiment_element.html.erb | 2 +- .../elements/_my_module_element.html.erb | 32 ++++++++-------- .../_my_module_protocol_element.html.erb | 2 +- .../_my_module_result_asset_element.html.erb | 2 +- .../_my_module_result_table_element.html.erb | 2 +- .../_my_module_result_text_element.html.erb | 2 +- .../elements/_my_module_step_element.html.erb | 2 +- .../elements/_project_header_element.html.erb | 2 +- .../elements/_step_asset_element.html.erb | 2 +- .../elements/_step_checklist_element.html.erb | 2 +- .../elements/_step_table_element.html.erb | 2 +- .../elements/_step_text_element.html.erb | 2 +- config/database.yml | 1 - 27 files changed, 113 insertions(+), 74 deletions(-) diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js index 28e4078262..519bae0989 100644 --- a/app/assets/javascripts/reports/new.js +++ b/app/assets/javascripts/reports/new.js @@ -1052,7 +1052,7 @@ function reportHandsonTableConverter() { reportData.report.settings.task.result_order = dropdownSelector.getValues('#taskResultsOrder'); - reportData.report.settings.exclude_metada = $('.exclude-metadata-setting')[0].checked; + reportData.report.settings.exclude_metadata = $('.exclude-metadata-setting')[0].checked; return reportData; } diff --git a/app/services/reports/docx/draw_experiment.rb b/app/services/reports/docx/draw_experiment.rb index e02d018a7a..d7355ab360 100644 --- a/app/services/reports/docx/draw_experiment.rb +++ b/app/services/reports/docx/draw_experiment.rb @@ -4,6 +4,7 @@ module Reports::Docx::DrawExperiment def draw_experiment(subject) color = @color link_style = @link_style + settings = @settings scinote_url = @scinote_url experiment = subject.experiment return unless can_read_experiment?(@user, experiment) @@ -15,8 +16,10 @@ def draw_experiment(subject) end @docx.p do - text I18n.t('projects.reports.elements.experiment.user_time', - code: experiment.code, timestamp: I18n.l(experiment.created_at, format: :full)), color: color[:gray] + unless settings['exclude_metadata'] + 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] diff --git a/app/services/reports/docx/draw_my_module.rb b/app/services/reports/docx/draw_my_module.rb index e85ccf7014..a174a61717 100644 --- a/app/services/reports/docx/draw_my_module.rb +++ b/app/services/reports/docx/draw_my_module.rb @@ -4,6 +4,7 @@ module Reports::Docx::DrawMyModule def draw_my_module(subject, without_results: false, without_repositories: false) color = @color link_style = @link_style + settings = @settings scinote_url = @scinote_url my_module = subject.my_module tags = my_module.tags.order(:id) @@ -16,8 +17,10 @@ def draw_my_module(subject, without_results: false, without_repositories: false) end @docx.p do - 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] + unless settings['exclude_metadata'] + 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] @@ -38,22 +41,24 @@ def draw_my_module(subject, without_results: false, without_repositories: false) end end - status = my_module.my_module_status - @docx.p do - text I18n.t('projects.reports.elements.module.status') - text ' ' - text "[#{status.name}]", color: (status.light_color? ? '000000' : status.color.delete('#')) - if my_module.completed? - text " #{I18n.t('my_modules.states.completed')} #{I18n.l(my_module.completed_on, format: :full)}" + unless settings['exclude_metadata'] + status = my_module.my_module_status + @docx.p do + text I18n.t('projects.reports.elements.module.status') + text ' ' + text "[#{status.name}]", color: (status.light_color? ? '000000' : status.color.delete('#')) + if my_module.completed? + text " #{I18n.t('my_modules.states.completed')} #{I18n.l(my_module.completed_on, format: :full)}" + end end - end - if tags.present? - @docx.p do - text I18n.t('projects.reports.elements.module.tags_header') - tags.each do |tag| - text ' ' - text "[#{tag.name}]", color: tag.color.delete('#') + if tags.present? + @docx.p do + text I18n.t('projects.reports.elements.module.tags_header') + tags.each do |tag| + text ' ' + text "[#{tag.name}]", color: tag.color.delete('#') + end end end end diff --git a/app/services/reports/docx/draw_my_module_protocol.rb b/app/services/reports/docx/draw_my_module_protocol.rb index 2096569ffe..04d03800c0 100644 --- a/app/services/reports/docx/draw_my_module_protocol.rb +++ b/app/services/reports/docx/draw_my_module_protocol.rb @@ -12,8 +12,10 @@ def draw_my_module_protocol(my_module) end if @settings.dig('task', 'protocol', 'description') && protocol.description.present? - @docx.p I18n.t('projects.reports.elements.module.protocol.user_time', code: protocol.original_code, - timestamp: I18n.l(protocol.created_at, format: :full)), color: @color[:gray] + unless @settings['exclude_metadata'] + @docx.p I18n.t('projects.reports.elements.module.protocol.user_time', code: protocol.original_code, + timestamp: I18n.l(protocol.created_at, format: :full)), color: @color[:gray] + end 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) diff --git a/app/services/reports/docx/draw_project_header.rb b/app/services/reports/docx/draw_project_header.rb index defa8e36ea..56e2b65694 100644 --- a/app/services/reports/docx/draw_project_header.rb +++ b/app/services/reports/docx/draw_project_header.rb @@ -15,10 +15,12 @@ def draw_project_header(subject) link_style end - @docx.p do - text I18n.t('projects.reports.elements.project_header.user_time', code: project.code, - timestamp: I18n.l(project.created_at, format: :full)), color: color[:gray] - br + unless @settings['exclude_metadata'] + @docx.p do + text I18n.t('projects.reports.elements.project_header.user_time', code: project.code, + timestamp: I18n.l(project.created_at, format: :full)), color: color[:gray] + br + end end end end diff --git a/app/services/reports/docx/draw_result_asset.rb b/app/services/reports/docx/draw_result_asset.rb index 030de2591a..80520c4c77 100644 --- a/app/services/reports/docx/draw_result_asset.rb +++ b/app/services/reports/docx/draw_result_asset.rb @@ -25,8 +25,10 @@ def draw_result_asset(result, settings) end text " #{I18n.t('search.index.archived')} ", bold: true if result.archived? text ' ' + I18n.t('projects.reports.elements.result_asset.file_name', file: asset.file_name) - text ' ' + I18n.t('projects.reports.elements.result_asset.user_time', - user: result.user.full_name, timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] + unless settings['exclude_metadata'] + text ' ' + I18n.t('projects.reports.elements.result_asset.user_time', + user: result.user.full_name, timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] + end if settings.dig(:task, :file_results_previews) && ActiveStorageFileUtil.previewable_document?(asset&.file&.blob) text " #{I18n.t('projects.reports.elements.result_asset.full_preview_attached')}", color: color[:gray] diff --git a/app/services/reports/docx/draw_result_table.rb b/app/services/reports/docx/draw_result_table.rb index 661d41a466..0d3923623d 100644 --- a/app/services/reports/docx/draw_result_table.rb +++ b/app/services/reports/docx/draw_result_table.rb @@ -5,6 +5,7 @@ def draw_result_table(element) result = element.result table = element.orderable.table timestamp = table.created_at + settings = @settings color = @color obj = self table_data = JSON.parse(table.contents_utf_8)['data'] @@ -40,8 +41,10 @@ def draw_result_table(element) @docx.p do text I18n.t 'projects.reports.elements.result_table.table_name', name: table.name 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] + unless settings['exclude_metadata'] + 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 end end end diff --git a/app/services/reports/docx/draw_result_text.rb b/app/services/reports/docx/draw_result_text.rb index 2ab606a7e6..1dbfe17d5a 100644 --- a/app/services/reports/docx/draw_result_text.rb +++ b/app/services/reports/docx/draw_result_text.rb @@ -4,12 +4,15 @@ module Reports::Docx::DrawResultText def draw_result_text(element) result_text = element.orderable timestamp = element.created_at + settings = @settings color = @color @docx.p do text result_text.name.presence || '', italic: true text ' ' - text I18n.t('projects.reports.elements.result_text.user_time', - timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] + unless settings['exclude_metadata'] + text I18n.t('projects.reports.elements.result_text.user_time', + timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] + end end html = custom_auto_link(result_text.text, team: @report_team) Reports::HtmlToWordConverter.new(@docx, { scinote_url: @scinote_url, diff --git a/app/services/reports/docx/draw_results.rb b/app/services/reports/docx/draw_results.rb index 0baedb9cf8..c35942da83 100644 --- a/app/services/reports/docx/draw_results.rb +++ b/app/services/reports/docx/draw_results.rb @@ -3,6 +3,7 @@ module Reports::Docx::DrawResults def draw_results(my_module) color = @color + settings = @settings return unless can_read_my_module?(@user, my_module) if my_module.results.any? && (%w(file_results table_results text_results).any? { |k| @settings.dig('task', k) }) @@ -11,9 +12,11 @@ def draw_results(my_module) @docx.p do text result.name.presence || I18n.t('projects.reports.unnamed'), italic: true text " #{I18n.t('search.index.archived')} ", bold: true if result.archived? - text I18n.t('projects.reports.elements.result.user_time', - timestamp: I18n.l(result.created_at, format: :full), - user: result.user.full_name), color: color[:gray] + unless settings['exclude_metadata'] + text I18n.t('projects.reports.elements.result.user_time', + timestamp: I18n.l(result.created_at, format: :full), + user: result.user.full_name), color: color[:gray] + end end draw_result_asset(result, @settings) if @settings.dig('task', 'file_results') result.result_orderable_elements.each do |element| diff --git a/app/services/reports/docx/draw_step.rb b/app/services/reports/docx/draw_step.rb index 6d4e27da6d..b2892ba6ad 100644 --- a/app/services/reports/docx/draw_step.rb +++ b/app/services/reports/docx/draw_step.rb @@ -6,6 +6,7 @@ def draw_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 + settings = @settings @docx.p @docx.h4( "#{I18n.t('projects.reports.elements.step.step_pos', pos: step.position_plus_one)} #{step.name}" @@ -17,11 +18,13 @@ def draw_step(step) text I18n.t('protocols.steps.uncompleted'), color: color[:gray], bold: true end text ' | ' - 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] + unless settings['exclude_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 step.step_orderable_elements.order(:position).each do |element| diff --git a/app/services/reports/docx/draw_step_asset.rb b/app/services/reports/docx/draw_step_asset.rb index 8d83ca221b..fab9c36f6a 100644 --- a/app/services/reports/docx/draw_step_asset.rb +++ b/app/services/reports/docx/draw_step_asset.rb @@ -5,6 +5,7 @@ def draw_step_asset(asset) timestamp = asset.created_at asset_url = Rails.application.routes.url_helpers.asset_download_url(asset) color = @color + settings = @settings @docx.p begin @@ -23,8 +24,10 @@ def draw_step_asset(asset) italic true end text ' ' - text I18n.t('projects.reports.elements.step_asset.user_time', - timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] + unless settings['exclude_metadata'] + text I18n.t('projects.reports.elements.step_asset.user_time', + timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] + end end end end diff --git a/app/services/reports/docx/draw_step_checklist.rb b/app/services/reports/docx/draw_step_checklist.rb index e2662e60ec..c6e946e5b8 100644 --- a/app/services/reports/docx/draw_step_checklist.rb +++ b/app/services/reports/docx/draw_step_checklist.rb @@ -4,6 +4,7 @@ module Reports::Docx::DrawStepChecklist def draw_step_checklist(checklist) team = @report_team user = @user + settings = @settings items = checklist.checklist_items timestamp = checklist.created_at @@ -16,8 +17,10 @@ def draw_step_checklist(checklist) I18n.t('projects.reports.elements.step_checklist.checklist_name', name: checklist.name) ).text, italic: true text ' ' - text I18n.t('projects.reports.elements.step_checklist.user_time', - timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] + unless settings['exclude_metadata'] + text I18n.t('projects.reports.elements.step_checklist.user_time', + timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] + end end if items.any? @docx.ul do diff --git a/app/services/reports/docx/draw_step_table.rb b/app/services/reports/docx/draw_step_table.rb index a0826741af..8b3b4909b8 100644 --- a/app/services/reports/docx/draw_step_table.rb +++ b/app/services/reports/docx/draw_step_table.rb @@ -4,6 +4,7 @@ module Reports::Docx::DrawStepTable def draw_step_table(table, table_type) color = @color timestamp = table.created_at + settings = @settings obj = self table_data = JSON.parse(table.contents_utf_8)['data'] table_data = obj.add_headers_to_table(table_data, table_type == 'step_well_plates_table') @@ -39,8 +40,10 @@ def draw_step_table(table, table_type) @docx.p do text I18n.t("projects.reports.elements.#{table_type}.table_name", name: table.name), italic: true text ' ' - text I18n.t("projects.reports.elements.#{table_type}.user_time", - timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] + unless settings['exclude_metadata'] + text I18n.t("projects.reports.elements.#{table_type}.user_time", + timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] + end end end end diff --git a/app/services/reports/docx/draw_step_text.rb b/app/services/reports/docx/draw_step_text.rb index 978386a947..6218595a02 100644 --- a/app/services/reports/docx/draw_step_text.rb +++ b/app/services/reports/docx/draw_step_text.rb @@ -5,11 +5,14 @@ def draw_step_text(element) step_text = element.orderable timestamp = element.created_at color = @color + settings = @settings @docx.p do text step_text.name.presence || '', italic: true text ' ' - text I18n.t('projects.reports.elements.result_text.user_time', - timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] + unless settings['exclude_metadata'] + text I18n.t('projects.reports.elements.result_text.user_time', + timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] + end end if step_text.text.present? html = custom_auto_link(step_text.text, team: @report_team) diff --git a/app/views/reports/elements/_experiment_element.html.erb b/app/views/reports/elements/_experiment_element.html.erb index 8ef08378e3..475c96b7bf 100644 --- a/app/views/reports/elements/_experiment_element.html.erb +++ b/app/views/reports/elements/_experiment_element.html.erb @@ -9,7 +9,7 @@ <%= t('search.index.archived') %> <% end %> - <% unless @settings.dig('exclude_metadata') %> + <% unless @settings['exclude_metadata'] %>
    <%= t('projects.reports.elements.experiment.user_time', code: experiment.code, timestamp: l(timestamp, format: :full)) %>
    diff --git a/app/views/reports/elements/_my_module_element.html.erb b/app/views/reports/elements/_my_module_element.html.erb index 5624954184..5ad3cee731 100644 --- a/app/views/reports/elements/_my_module_element.html.erb +++ b/app/views/reports/elements/_my_module_element.html.erb @@ -9,7 +9,7 @@ <%= t('search.index.archived') %> <% end %> - <% unless @settings.dig('exclude_metadata') %> + <% unless @settings['exclude_metadata'] %>
    <%= t('projects.reports.elements.module.user_time', code: my_module.code, timestamp: l(timestamp, format: :full)) %>
    @@ -24,21 +24,23 @@ <%= t('projects.reports.elements.module.due_date', due_date: l(my_module.due_date, format: :full)) %> <% end %>

    -

    - <% status = my_module.my_module_status %> - <%= t('projects.reports.elements.module.status') %> - - <%= status.name %> - - <% if my_module.completed? %> - - <%= t('my_modules.states.completed') %> - <%= l(my_module.completed_on, format: :full) %> + <% unless @settings['exclude_metadata'] %> +

    + <% status = my_module.my_module_status %> + <%= t('projects.reports.elements.module.status') %> + + <%= status.name %> - <% end %> -

    - <% unless @settings.dig('exclude_metadata') %> + <% if my_module.completed? %> + + <%= t('my_modules.states.completed') %> + <%= l(my_module.completed_on, format: :full) %> + + <% end %> +

    + <% end %> + <% unless @settings['exclude_metadata'] %>
    <%= t('projects.reports.elements.module.tags_header') %> diff --git a/app/views/reports/elements/_my_module_protocol_element.html.erb b/app/views/reports/elements/_my_module_protocol_element.html.erb index 88755ca91e..1aa86ecb11 100644 --- a/app/views/reports/elements/_my_module_protocol_element.html.erb +++ b/app/views/reports/elements/_my_module_protocol_element.html.erb @@ -9,7 +9,7 @@ <%= t('projects.reports.elements.module.protocol.name') %> <% end %> - <% unless @settings.dig('exclude_metadata') %> + <% unless @settings['exclude_metadata'] %>
    <%= t('projects.reports.elements.module.protocol.user_time', code: protocol.original_code, timestamp: l(protocol.created_at, format: :full)) %>
    diff --git a/app/views/reports/elements/_my_module_result_asset_element.html.erb b/app/views/reports/elements/_my_module_result_asset_element.html.erb index 71857134b0..5485a789de 100644 --- a/app/views/reports/elements/_my_module_result_asset_element.html.erb +++ b/app/views/reports/elements/_my_module_result_asset_element.html.erb @@ -26,7 +26,7 @@ <% end %>
    - <% unless @settings.dig('exclude_metadata') %> + <% unless @settings['exclude_metadata'] %> <%= t("projects.reports.elements.result_asset.user_time", user: result.user.full_name, timestamp: l(timestamp, format: :full)) %> <% end %> <% if report.settings.dig(:task, :file_results_previews) && ActiveStorageFileUtil.previewable_document?(asset&.file&.blob) %> diff --git a/app/views/reports/elements/_my_module_result_table_element.html.erb b/app/views/reports/elements/_my_module_result_table_element.html.erb index 749b20985b..e5fd49f52c 100644 --- a/app/views/reports/elements/_my_module_result_table_element.html.erb +++ b/app/views/reports/elements/_my_module_result_table_element.html.erb @@ -21,7 +21,7 @@ <% end %> <% end %>
    - <% unless @settings.dig('exclude_metadata') %> + <% unless @settings['exclude_metadata'] %>
    <%= t('projects.reports.elements.result_table.user_time', timestamp: l(timestamp, format: :full)) %>
    diff --git a/app/views/reports/elements/_my_module_result_text_element.html.erb b/app/views/reports/elements/_my_module_result_text_element.html.erb index d65b63a96b..94e02fa52e 100644 --- a/app/views/reports/elements/_my_module_result_text_element.html.erb +++ b/app/views/reports/elements/_my_module_result_text_element.html.erb @@ -11,7 +11,7 @@ <% end %>
    - <% unless @settings.dig('exclude_metadata') %> + <% unless @settings['exclude_metadata'] %>
    <%= t("projects.reports.elements.result_text.user_time", timestamp: l(timestamp, format: :full)) %>
    diff --git a/app/views/reports/elements/_my_module_step_element.html.erb b/app/views/reports/elements/_my_module_step_element.html.erb index 15f6d32ea4..2be53b1a96 100644 --- a/app/views/reports/elements/_my_module_step_element.html.erb +++ b/app/views/reports/elements/_my_module_step_element.html.erb @@ -10,7 +10,7 @@ <%= t('projects.reports.elements.step.step_pos', pos: (step.position_plus_one)) %> <%= step.name %> <%= step_status_label(step) %> - <% unless @settings.dig('exclude_metadata') %> + <% unless @settings['exclude_metadata'] %>
    <%= t("projects.reports.elements.step.#{step_type_str}.user_time", user: user.full_name , timestamp: l(timestamp, format: :full)) %>
    diff --git a/app/views/reports/elements/_project_header_element.html.erb b/app/views/reports/elements/_project_header_element.html.erb index 735afe95ec..9e355d6d9c 100644 --- a/app/views/reports/elements/_project_header_element.html.erb +++ b/app/views/reports/elements/_project_header_element.html.erb @@ -7,7 +7,7 @@ <%= t('search.index.archived') %> <% end %> - <% unless @settings.dig('exclude_metadata') %> + <% unless @settings['exclude_metadata'] %>
    <%= t('projects.reports.elements.project_header.user_time', code: project.code, timestamp: l(project.created_at, format: :full)) %>
    diff --git a/app/views/reports/elements/_step_asset_element.html.erb b/app/views/reports/elements/_step_asset_element.html.erb index 75ea457626..880ab97ee1 100644 --- a/app/views/reports/elements/_step_asset_element.html.erb +++ b/app/views/reports/elements/_step_asset_element.html.erb @@ -18,7 +18,7 @@ <% end %> - <% unless @settings.dig('exclude_metadata') %> + <% unless @settings['exclude_metadata'] %>
     <%= t('projects.reports.elements.step_asset.user_time', timestamp: l(timestamp, format: :full)) %>
    diff --git a/app/views/reports/elements/_step_checklist_element.html.erb b/app/views/reports/elements/_step_checklist_element.html.erb index 9a7917aa3e..1951fde551 100644 --- a/app/views/reports/elements/_step_checklist_element.html.erb +++ b/app/views/reports/elements/_step_checklist_element.html.erb @@ -9,7 +9,7 @@ team: current_team, base64_encoded_imgs: export_all) %> - <% unless @settings.dig('exclude_metadata') %> + <% unless @settings['exclude_metadata'] %>
    <%= t('projects.reports.elements.step_checklist.user_time', timestamp: l(timestamp, format: :full)) %>
    diff --git a/app/views/reports/elements/_step_table_element.html.erb b/app/views/reports/elements/_step_table_element.html.erb index 1cc9c8b3c4..dfda2ac144 100644 --- a/app/views/reports/elements/_step_table_element.html.erb +++ b/app/views/reports/elements/_step_table_element.html.erb @@ -18,7 +18,7 @@ <% end %> <% end %> - <% unless @settings.dig('exclude_metadata') %> + <% unless @settings['exclude_metadata'] %>
    <%= t("projects.reports.elements.#{table_type}.user_time", timestamp: l(timestamp, format: :full)) %>
    diff --git a/app/views/reports/elements/_step_text_element.html.erb b/app/views/reports/elements/_step_text_element.html.erb index 9a62410c3e..8c8ff72ebd 100644 --- a/app/views/reports/elements/_step_text_element.html.erb +++ b/app/views/reports/elements/_step_text_element.html.erb @@ -8,7 +8,7 @@ <% end %> - <% unless @settings.dig('exclude_metadata') %> + <% unless @settings['exclude_metadata'] %>
    <%= t("projects.reports.elements.step_text.user_time", timestamp: l(timestamp, format: :full)) %>
    diff --git a/config/database.yml b/config/database.yml index a44a2ec67b..c7f72cd5c9 100644 --- a/config/database.yml +++ b/config/database.yml @@ -35,7 +35,6 @@ development: # The password associated with the postgres role (username). # password: mysecretpassword - # Connect on a TCP socket. Omitted by default since the client uses a # domain socket that doesn't need configuration. Windows does not have # domain sockets, so uncomment these lines. From dddf2be610e7a28790f0b79239a7b95605596b13 Mon Sep 17 00:00:00 2001 From: Andrej Date: Tue, 20 Aug 2024 15:01:42 +0200 Subject: [PATCH 03/28] Update caracal version [SCI-10985] --- Gemfile | 3 +-- Gemfile.lock | 16 +++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 453dea286a..62c5bdb796 100644 --- a/Gemfile +++ b/Gemfile @@ -47,8 +47,7 @@ gem 'aspector' # Aspect-oriented programming for Rails gem 'auto_strip_attributes', '~> 2.1' # Removes unnecessary whitespaces AR gem 'bcrypt', '~> 3.1.10' # gem 'caracal' -# gem 'caracal', git: 'https://github.com/scinote-eln/caracal.git', branch: 'rubyzip2' # Build docx report -gem 'caracal_the_curve', '~> 1.4', '>= 1.4.6' +gem 'caracal', git: 'https://github.com/scinote-eln/caracal.git', branch: 'custom-docx-reports' # Build docx report gem 'caxlsx' # Build XLSX files gem 'deface', '~> 1.9' gem 'down', '~> 5.0' diff --git a/Gemfile.lock b/Gemfile.lock index 5a29368f28..0baa4846f0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,6 +22,16 @@ GIT docile (>= 1.1.0) rails (>= 4) +GIT + remote: https://github.com/scinote-eln/caracal.git + revision: f8e4c279adfee7801eb1024e1d6a18bb06c9c76a + branch: custom-docx-reports + specs: + caracal (1.4.1) + nokogiri (~> 1.6) + rubyzip (>= 2.3) + tilt (>= 1.4) + GIT remote: https://github.com/scinote-eln/img2zpl revision: 23d61cfc3e90ac4caa62dd08546fa0d7590a5140 @@ -217,10 +227,6 @@ GEM capybara-email (3.0.2) capybara (>= 2.4, < 4.0) mail - caracal_the_curve (1.4.6) - nokogiri (~> 1.6) - rubyzip (>= 1.1.0, < 3.0) - tilt (>= 1.4) case_transform (0.2) activesupport caxlsx (4.0.0) @@ -799,7 +805,7 @@ DEPENDENCIES canaid! capybara capybara-email - caracal_the_curve (~> 1.4, >= 1.4.6) + caracal! caxlsx cssbundling-rails cucumber-rails From f912f6bc41502760b7659c47e7da33ce456f0017 Mon Sep 17 00:00:00 2001 From: Andrej Date: Tue, 27 Aug 2024 13:40:10 +0200 Subject: [PATCH 04/28] Fix docx templates [SCI-10988] --- .../reports/repositories_input_component.rb | 5 +- app/services/reports/docx/draw_step.rb | 2 +- .../docx_templates/custom_template/docx.rb | 188 ------------------ .../custom_template/edit.html.erb | 57 ------ .../docx_templates/custom_template/name.txt | 1 - 5 files changed, 3 insertions(+), 250 deletions(-) delete mode 100644 app/views/reports/docx_templates/custom_template/docx.rb delete mode 100644 app/views/reports/docx_templates/custom_template/edit.html.erb delete mode 100644 app/views/reports/docx_templates/custom_template/name.txt diff --git a/app/components/reports/repositories_input_component.rb b/app/components/reports/repositories_input_component.rb index c7909d8c7d..f168cc3966 100644 --- a/app/components/reports/repositories_input_component.rb +++ b/app/components/reports/repositories_input_component.rb @@ -2,10 +2,9 @@ module Reports class RepositoriesInputComponent < TemplateValueComponent - def initialize(report:, name:, label:, placeholder: nil, editing: true, displayed_field: :name) + def initialize(report:, name:, label:, placeholder: nil, editing: true, displayed_field: :name, user: nil) super(report: report, name: name, label: label, placeholder: placeholder, editing: editing) - - live_repositories = Repository.accessible_by_teams(report.team).sort_by { |r| r.name.downcase } + live_repositories = Repository.viewable_by_user(user, report.team).sort_by { |r| r.name.downcase } snapshots_of_deleted = RepositorySnapshot.left_outer_joins(:original_repository) .where(team: report.team) .where.not(original_repository: live_repositories) diff --git a/app/services/reports/docx/draw_step.rb b/app/services/reports/docx/draw_step.rb index b2892ba6ad..ef762fcb90 100644 --- a/app/services/reports/docx/draw_step.rb +++ b/app/services/reports/docx/draw_step.rb @@ -17,8 +17,8 @@ def draw_step(step) else text I18n.t('protocols.steps.uncompleted'), color: color[:gray], bold: true end - text ' | ' unless settings['exclude_metadata'] + text ' | ' text I18n.t( "projects.reports.elements.step.#{step_type_str}.user_time", user: user.full_name, diff --git a/app/views/reports/docx_templates/custom_template/docx.rb b/app/views/reports/docx_templates/custom_template/docx.rb deleted file mode 100644 index b2e16276af..0000000000 --- a/app/views/reports/docx_templates/custom_template/docx.rb +++ /dev/null @@ -1,188 +0,0 @@ -# frozen_string_literal: true - -module CustomTemplateDocx - def prepare_docx - report_name = get_template_value('custom_docx_report_name') - report_number = get_template_value('custom_docx_report_number') - - @project_members = @report.project&.users - - report_authors = @project_members.where(id: get_template_value('custom_docx_author[]')).pluck(:full_name).join(', ') - report_reviewers = @project_members.where(id: get_template_value('custom_docx_reviewer[]')).pluck(:full_name).join(', ') - report_author_role = get_template_value('custom_docx_author_role') - report_reviewer_role = get_template_value('custom_docx_reviewer_role') - - @docx.header do |header| - header.table [[report_name, 'custom report']] do - border_size 1 - cell_style cols[0], width: 8000 - cell_style cols[1], width: 2800 - end - end - - @docx.footer do |footer| - pages = Caracal::Core::Models::TableCellModel.new do - p do - field :page - text ' of ' - field :numpages - end - end - footer.table [['Confidential', pages]] do - border_top do - size 1 - end - cell_style cols[0], width: 9500 - cell_style cols[1], width: 1000 - end - end - - @docx.p - - logo_data = File.read(Rails.root.join('app/assets/images/scinote_logo.png')) - - c1 = Caracal::Core::Models::TableCellModel.new do - p report_name, bold: true - p '' - end - - c2 = Caracal::Core::Models::TableCellModel.new do - img 'logo.png' do - data logo_data - height 20 - width 100 - align :left - end - end - - c3 = Caracal::Core::Models::TableCellModel.new do - p "Author: #{report_authors}" - p "Role: #{report_author_role}" - end - - c4 = Caracal::Core::Models::TableCellModel.new do - p "Reviewer: #{report_reviewers}" - p "Role: #{report_reviewer_role}" - end - - c5 = Caracal::Core::Models::TableCellModel.new do - p "Report number:" - p report_number - end - - @docx.table [[c1, c2], [c3, c4, c5]] do - border_size 2 - cell_style rows[0], width: 3500 - cell_style rows[1], width: 3500 - cell_style rows[0][0], colspan: 2 - end - - @docx.p - - @docx.table_of_contents do |toc| - toc.title 'Table of Contents' - toc.opts 'TOC \o "1-4" \h \z \u \t "Heading 5,1"' - end - - @docx.page - - my_modules_elements = [] - @report.root_elements.each do |subject| - my_modules_elements += subject.children.active if subject.type_of == 'experiment' - end - - @my_modules = MyModule.where(id: my_modules_elements.map { |element| element.my_module.id }) - - @docx.h1 'Chapter 1' - @docx.h2 'Sub chapter 1' if get_template_value('custom_docx_sub_chapter_1') - @docx.h2 'Sub chapter 2' if get_template_value('custom_docx_sub_chapter_2') - @docx.h1 'Chapter 2' - if get_template_value('custom_docx_sub_chapter_3') - @docx.h2 'Sub chapter 3 with inventory' - draw_repositories(get_template_value('custom_docx_sub_chapter_3_inventories[]')) - end - if get_template_value('custom_docx_sub_chapter_4') - @docx.h2 'Sub chapter 4 with inventory' - draw_repositories(get_template_value('custom_docx_sub_chapter_4_inventories[]')) - end - @docx.h2 'Sub chapter 5' if get_template_value('custom_docx_sub_chapter_5') - @docx.h2 'Sub chapter 6' if get_template_value('custom_docx_sub_chapter_6') - @docx.h2 'Sub chapter 7' if get_template_value('custom_docx_sub_chapter_7') - @docx.h1 'Chapter 3' - if get_template_value('custom_docx_sub_chapter_8') - @docx.h2 'Sub chapter 8 with task' - my_modules_elements.each do |element| - draw_my_module(element, without_results: true, without_repositories: true) - end - end - @docx.h2 'Sub chapter 9' if get_template_value('custom_docx_sub_chapter_9') - @docx.h2 'Sub chapter 10' if get_template_value('custom_docx_sub_chapter_10') - @docx.h2 'Sub chapter 11' if get_template_value('custom_docx_sub_chapter_11') - if get_template_value('custom_docx_sub_chapter_12') - @docx.h2 'Sub chapter 12' - @docx.h3 'Sub sub chapter 1' if get_template_value('custom_docx_sub_sub_chapter_1') - @docx.h3 'Sub sub chapter 2' if get_template_value('custom_docx_sub_sub_chapter_2') - end - @docx.h1 'Chapter 4' - if get_template_value('custom_docx_sub_chapter_13') - @docx.h2 'Sub chapter 13 with results' - my_modules_elements.each do |element| - draw_results(element.my_module) - end - end - @docx.h2 'Sub chapter 14' if get_template_value('custom_docx_sub_chapter_14') - @docx.h2 'Sub chapter 15' if get_template_value('custom_docx_sub_chapter_15') - @docx.h2 'Sub chapter 16' if get_template_value('custom_docx_sub_chapter_16') - @docx.h2 'Sub chapter 17' if get_template_value('custom_docx_sub_chapter_17') - @docx.h1 'Chapter 5' - end - - def repository_docx_json(repository, rows) - headers = [ - I18n.t('repositories.table.id'), - I18n.t('repositories.table.row_name'), - I18n.t('repositories.table.added_on'), - I18n.t('repositories.table.added_by') - ] - custom_columns = [] - return false unless repository - - repository.repository_columns.order(:id).each do |column| - headers.push(column.name) - custom_columns.push(column.id) - end - - records = repository.repository_rows.where(id: rows) - .select(:id, :name, :created_at, :created_by_id, :repository_id, :parent_id, :archived) - { headers: headers, rows: records, custom_columns: custom_columns } - end - - def load_repositories(repositories_id) - live_repositories = Repository.accessible_by_teams(@report.team).where(id: repositories_id).sort_by { |r| r.name.downcase } - snapshots_of_deleted = RepositorySnapshot.left_outer_joins(:original_repository) - .where(team: @report.team) - .where(parent_id: repositories_id) - .where.not(original_repository: live_repositories) - .select('DISTINCT ON ("repositories"."parent_id") "repositories".*') - .sort_by { |r| r.name.downcase } - live_repositories + snapshots_of_deleted - end - - def draw_repositories(repositories_id) - load_repositories(repositories_id).each do |repository| - rows = repository.repository_rows.where(id: @my_modules.joins(:my_module_repository_rows).select(:repository_row_id)).select(:id) - repository_data = repository_docx_json(repository, rows) - - next unless repository_data[:rows].any? && can_read_repository?(@user, repository) - - table = prepare_row_columns(repository_data, nil, repository) - - @docx.p - @docx.p repository.name, bold: true, size: Constants::REPORT_DOCX_STEP_ELEMENTS_TITLE_SIZE - @docx.table table, border_size: Constants::REPORT_DOCX_TABLE_BORDER_SIZE - - @docx.p - @docx.p - end - end -end diff --git a/app/views/reports/docx_templates/custom_template/edit.html.erb b/app/views/reports/docx_templates/custom_template/edit.html.erb deleted file mode 100644 index 6bef2a79ed..0000000000 --- a/app/views/reports/docx_templates/custom_template/edit.html.erb +++ /dev/null @@ -1,57 +0,0 @@ -<% content_for :toc do %> -

    Chapter 1

    -
    - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_chapter_1, label: 'Sub chapter 1') %> - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_chapter_2, label: 'Sub chapter 2') %> -
    -

    Chapter 2

    -
    -
    - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_chapter_3, label: 'Sub chapter 3 with inventory') %> -
    - <%= render Reports::RepositoriesInputComponent.new(report: report, name: 'custom_docx_sub_chapter_3_inventories[]', label: 'Inventories') %> -
    -
    -
    - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_chapter_4, label: 'Sub chapter 4 with inventory') %> -
    - <%= render Reports::RepositoriesInputComponent.new(report: report, name: 'custom_docx_sub_chapter_4_inventories[]', label: 'Inventories') %> -
    -
    - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_chapter_5, label: 'Sub chapter 5') %> - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_chapter_6, label: 'Sub chapter 6') %> - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_chapter_7, label: 'Sub chapter 7') %> -
    -

    Chapter 3

    -
    - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_chapter_8, label: 'Sub chapter 8 with task') %> - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_chapter_9, label: 'Sub chapter 9') %> - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_chapter_10, label: 'Sub chapter 10') %> - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_chapter_11, label: 'Sub chapter 11') %> - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_chapter_12, label: 'Sub chapter 12') %> -
    - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_sub_chapter_1, label: 'Sub sub chapter 1') %> - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_sub_chapter_2, label: 'Sub sub chapter 2') %> -
    -
    -

    Chapter 4

    -
    - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_chapter_13, label: 'Sub chapter 13 with results') %> - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_chapter_14, label: 'Sub chapter 14') %> - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_chapter_15, label: 'Sub chapter 15') %> - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_chapter_16, label: 'Sub chapter 16') %> - <%= render Reports::CheckboxInputComponent.new(report: report, name: :custom_docx_sub_chapter_17, label: 'Sub chapter 17') %> -
    -

    Chapter 5

    -<% end %> - -<% content_for :cover do %> - <%= render Reports::TextInputComponent.new(report: report, name: :custom_docx_report_name, label: 'Report name') %> - <%= render Reports::TextInputComponent.new(report: report, name: :custom_docx_report_number, label: 'Report number') %> - - <%= render Reports::ProjectMembersInputComponent.new(report: report, name: 'custom_docx_author[]', label: 'Author') %> - <%= render Reports::TextInputComponent.new(report: report, name: :custom_docx_author_role, label: 'Author Role') %> - - <%= render Reports::ProjectMembersInputComponent.new(report: report, name: 'custom_docx_reviewer[]', label: 'Reviewer') %> - <%= render Reports::TextInputComponent.new(report: report, name: :custom_docx_reviewer_role, label: 'Reviewer Role') %> -<% end %> diff --git a/app/views/reports/docx_templates/custom_template/name.txt b/app/views/reports/docx_templates/custom_template/name.txt deleted file mode 100644 index 0ad39c9160..0000000000 --- a/app/views/reports/docx_templates/custom_template/name.txt +++ /dev/null @@ -1 +0,0 @@ -Custom Template From dddffc11cd737df18669bf9da79a7140097b14ac Mon Sep 17 00:00:00 2001 From: Andrej Date: Wed, 28 Aug 2024 11:57:41 +0200 Subject: [PATCH 05/28] Improve report wizards [SCI-10989] --- app/assets/javascripts/reports/new.js | 13 ++++++-- app/controllers/reports_controller.rb | 32 ++++++++++++++++++- app/helpers/reports_helper.rb | 4 +++ app/services/reports/docx.rb | 2 +- .../reports/template_values_editor.html.erb | 6 +++- .../wizard/_no_template_values.html.erb | 6 +++- .../_project_template_selector.html.erb | 4 ++- config/locales/en.yml | 6 ++-- 8 files changed, 63 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js index 519bae0989..168aab5de3 100644 --- a/app/assets/javascripts/reports/new.js +++ b/app/assets/javascripts/reports/new.js @@ -1258,7 +1258,8 @@ function reportHandsonTableConverter() { function reCheckContinueButton() { if (dropdownSelector.getValues('#projectSelector').length > 0 && dropdownSelector.getValues('#templateSelector').length > 0 - && dropdownSelector.getValues('#docxTemplateSelector').length > 0) { + && (dropdownSelector.getValues('#docxTemplateSelector').length > 0 + || $('#docxTemplateSelector').closest('.hidden').length > 0)) { $('.continue-button').attr('disabled', false); } else { $('.continue-button').attr('disabled', true); @@ -1281,6 +1282,12 @@ function reportHandsonTableConverter() { if (dropdownSelector.getValues('#projectSelector').length > 0) { dropdownSelector.enableSelector('#templateSelector'); dropdownSelector.enableSelector('#docxTemplateSelector'); + if ($('#templateSelector').data('defaultTemplate')) { + dropdownSelector.selectValues('#templateSelector', $('#templateSelector').data('defaultTemplate')); + } + if ($('#docxTemplateSelector').data('defaultTemplate')) { + dropdownSelector.selectValues('#docxTemplateSelector', $('#docxTemplateSelector').data('defaultTemplate')); + } } else { dropdownSelector.selectValues('#templateSelector', ''); dropdownSelector.disableSelector('#templateSelector'); @@ -1354,7 +1361,7 @@ function reportHandsonTableConverter() { } function loadTemplate() { - let template = $('#templateSelector').val(); + const template = dropdownSelector.getValues('#templateSelector'); let params = { project_id: dropdownSelector.getValues('#projectSelector'), template: template @@ -1384,7 +1391,7 @@ function reportHandsonTableConverter() { } function loadDocxTemplate() { - let template = $('#docxTemplateSelector').val(); + const template = dropdownSelector.getValues('#docxTemplateSelector'); let params = { project_id: dropdownSelector.getValues('#projectSelector'), template: template diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index bb13046b44..7bb30bfe86 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -18,7 +18,8 @@ class ReportsController < ApplicationController before_action :check_create_permissions, only: %i(new create) before_action :check_manage_permissions, only: %i(edit update generate_pdf generate_docx) before_action :switch_team_with_param, only: :index - after_action :generate_pdf_report, only: %i(create update generate_pdf) + after_action :generate_pdf_report, only: %i(generate_pdf) + after_action :generate_report, only: %i(create update) # Index showing all reports of a single project def index @@ -44,6 +45,8 @@ def new def new_template_values if Extends::REPORT_TEMPLATES.key?(params[:template]&.to_sym) template = params[:template] + @type = :pdf + @template_name = Extends::REPORT_TEMPLATES[params[:template].to_sym] else return render_404 end @@ -69,6 +72,7 @@ def new_template_values else render json: { html: render_to_string(partial: 'reports/wizard/no_template_values', + locals: { type: @type, template: @template_name }, formats: :html) } end @@ -77,6 +81,8 @@ def new_template_values def new_docx_template_values if Extends::DOCX_REPORT_TEMPLATES.key?(params[:template]&.to_sym) template = params[:template] + @type = :docx + @template_name = Extends::DOCX_REPORT_TEMPLATES[params[:template].to_sym] else return render_404 end @@ -102,6 +108,7 @@ def new_docx_template_values else render json: { html: render_to_string(partial: 'reports/wizard/no_template_values', + locals: { type: @type, template: @template_name }, formats: :html) } end @@ -363,6 +370,9 @@ def load_wizard_vars .merge(MyModule.active) .group(:id) .select(:id, :name) + @default_template = Extends::REPORT_TEMPLATES.keys.first.to_s if Extends::REPORT_TEMPLATES.one? + + @default_docx_template = Extends::DOCX_REPORT_TEMPLATES.keys.first.to_s if Extends::DOCX_REPORT_TEMPLATES.one? && custom_templates(Extends::DOCX_REPORT_TEMPLATES) end def check_project_read_permissions @@ -430,6 +440,26 @@ def generate_pdf_report Rails.logger.error e.message end + def generate_docx_report + return unless @report.persisted? + + @report.docx_processing! + log_activity(:generate_docx_report) + + ensure_report_template! + Reports::DocxJob.perform_later(@report.id, user_id: current_user.id, root_url: root_url) + rescue ActiveRecord::ActiveRecordError => e + Rails.logger.error e.message + end + + def generate_report + return unless @report.persisted? + + generate_pdf_report + + generate_docx_report if @report.settings['docx_template'].present? && custom_templates(Extends::DOCX_REPORT_TEMPLATES) + end + def ensure_report_template! return if @report.settings['template'].present? diff --git a/app/helpers/reports_helper.rb b/app/helpers/reports_helper.rb index 7dcc859296..5a05d13e2b 100644 --- a/app/helpers/reports_helper.rb +++ b/app/helpers/reports_helper.rb @@ -106,4 +106,8 @@ def report_experiment_descriptions(report) experiment_element.experiment.description end end + + def custom_templates(templates) + templates.any? { |template, _| template != :scinote_template } + end end diff --git a/app/services/reports/docx.rb b/app/services/reports/docx.rb index 46445f338c..72e6ce3398 100644 --- a/app/services/reports/docx.rb +++ b/app/services/reports/docx.rb @@ -30,7 +30,7 @@ def initialize(report, docx, options) @link_style = {} @color = {} @scinote_url = options[:scinote_url][0..-2] - @template = @settings[:docx_template] || 'scinote_template' + @template = @settings[:docx_template].presence || 'scinote_template' extend "#{@template.camelize}Docx".constantize end diff --git a/app/views/layouts/reports/template_values_editor.html.erb b/app/views/layouts/reports/template_values_editor.html.erb index 225c32a4a1..841b024efb 100644 --- a/app/views/layouts/reports/template_values_editor.html.erb +++ b/app/views/layouts/reports/template_values_editor.html.erb @@ -1,6 +1,10 @@

    - <%= t('projects.reports.wizard.first_step.values_editor.title') %> + <% if @type == :pdf %> + <%= t('projects.reports.wizard.first_step.values_editor.title_pdf', template: @template_name) %> + <% else %> + <%= t('projects.reports.wizard.first_step.values_editor.title_docx', template: @template_name) %> + <% end %>

    -
    +
    <%= label_tag :docxTemplateSelector, t('projects.reports.wizard.first_step.select_docx_template') %> <%= select_tag :docxTemplateSelector, options_for_select(@docx_templates.invert, @active_docx_template), @@ -32,6 +33,7 @@ disable_on_load: report.settings[:docx_template].blank? && report.new_record?, placeholder: t('projects.reports.wizard.first_step.select_docx_template'), selected_template: report.settings[:docx_template], + default_template: @default_docx_template, values_editor_path: reports_new_docx_template_values_path(report_id: report.id) } %>
    diff --git a/config/locales/en.yml b/config/locales/en.yml index 55582e52c2..3e481c9a8f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -803,13 +803,15 @@ en: report_description: "Report description (optional)" report_description_placeholder: "In this report you can see..." values_editor: - title: "Enter template data" + title_pdf: "PDF %{template}" + title_docx: "DOCX %{template}" description: "This template requires you to fill out additional information about this project. This is the only place you will be able to do so." header: "Header" cover: "Title page" footer: "Footer" toc: "Table of contents" - no_values_title: "No additional data required" + no_values_title_pdf: "PDF %{template}: No additional data required" + no_values_title_docx: "DOCX %{template}: No additional data required" no_values_description: "SciNote template doesn’t need any additional input for it to be successfully generated." second_step: select_project_content: "Select and reorder experiments and tasks" From 0e662d572125d1fde85cb954da4bfdd64b0df68a Mon Sep 17 00:00:00 2001 From: Andrej Date: Fri, 30 Aug 2024 11:59:21 +0200 Subject: [PATCH 06/28] Fix caracal library version [SCI-10985] --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 037850e82b..09abcdc32f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -24,10 +24,10 @@ GIT GIT remote: https://github.com/scinote-eln/caracal.git - revision: f8e4c279adfee7801eb1024e1d6a18bb06c9c76a + revision: f30bd2d26229c8118cc392c3a18409cb9a12ae02 branch: custom-docx-reports specs: - caracal (1.4.1) + caracal (1.4.2) nokogiri (~> 1.6) rubyzip (>= 2.3) tilt (>= 1.4) From b2539d13667d467599c79218b8ce48c7a84905d0 Mon Sep 17 00:00:00 2001 From: Andrej Date: Tue, 3 Sep 2024 15:53:29 +0200 Subject: [PATCH 07/28] Fix repositories component for docx [SCI-10988] --- app/assets/javascripts/reports/new.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js index 168aab5de3..73abc4cfa1 100644 --- a/app/assets/javascripts/reports/new.js +++ b/app/assets/javascripts/reports/new.js @@ -982,7 +982,7 @@ function reportHandsonTableConverter() { // Template values reportData.template_values = {}; - $.each($('.report-template-values-container').find('.sci-input-field'), function(i, field) { + $.each($('.report-template-values-container').find('.sci-input-field').not('.report-template-value-dropdown'), (_, field) => { if (field.value.length === 0) return; reportData.template_values[field.name] = { From cb4675c522ea28dca6c412761505e7fab98d1eb3 Mon Sep 17 00:00:00 2001 From: Andrej Date: Wed, 4 Sep 2024 11:56:07 +0200 Subject: [PATCH 08/28] Fix moving of dropdowns on report wizard [SCI-11016] --- app/assets/stylesheets/reports/new.scss | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/assets/stylesheets/reports/new.scss b/app/assets/stylesheets/reports/new.scss index 0355c40640..b5258df6ee 100644 --- a/app/assets/stylesheets/reports/new.scss +++ b/app/assets/stylesheets/reports/new.scss @@ -250,6 +250,16 @@ } } + // scss-lint:disable ImportantRule + .dropdown-selector-container { + .dropdown-container { + left: auto !important; + margin: auto !important; + position: absolute !important; + } + } + // scss-lint:enable ImportantRule + .project-selector-container { background: $color-white; box-shadow: $modal-shadow; From 08bb1c9dc6b063083ce52fa8af7a10cb07198d2e Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Thu, 5 Sep 2024 12:54:21 +0200 Subject: [PATCH 09/28] Implement report template loader [SCI-10999] --- config/initializers/report_template_loader.rb | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 config/initializers/report_template_loader.rb diff --git a/config/initializers/report_template_loader.rb b/config/initializers/report_template_loader.rb new file mode 100644 index 0000000000..1af443d047 --- /dev/null +++ b/config/initializers/report_template_loader.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'httparty' +require 'active_storage/service/s3_service' + +template_zip_url_string = ENV.fetch('REPORT_TEMPLATES_ZIP_URL', nil) + +return unless template_zip_url_string + +template_zip_url = URI.parse(template_zip_url_string) +contents = case template_zip_url.scheme + when 'https' + HTTParty.get(template_zip_url).body + when 's3' + ActiveStorage::Service::S3Service.new( + bucket: template_zip_url.host + ).download(template_zip_url.path[1..]) + end + +root_folder = nil +Zip::File.open_buffer(StringIO.new(contents)) do |zip| + zip.each do |entry| + # set root zip folder + root_folder = entry.name and next if entry.name.count('/') == 1 + + # create path while omitting root zip folder + path = Rails.root.join('app', 'views', 'reports', entry.name.sub(root_folder, '')) + path.dirname.mkpath + + # don't try and write file if entry is a folder + next if entry.name.ends_with?('/') + + path.open('wb') do |f| + f.write(entry.get_input_stream.read) + end + end +end From cce140d3872bba7523920e9fa648d4dd6bb2075e Mon Sep 17 00:00:00 2001 From: Andrej Date: Thu, 5 Sep 2024 13:41:35 +0200 Subject: [PATCH 10/28] Update exclude metadata setting [SCI-11017] --- app/assets/javascripts/reports/new.js | 3 ++- app/models/report.rb | 2 ++ app/services/reports/docx/draw_experiment.rb | 2 +- app/services/reports/docx/draw_my_module.rb | 24 ++++++++--------- .../reports/docx/draw_my_module_protocol.rb | 2 +- .../reports/docx/draw_project_header.rb | 2 +- .../reports/docx/draw_result_asset.rb | 2 +- .../reports/docx/draw_result_table.rb | 2 +- app/services/reports/docx/draw_result_text.rb | 2 +- app/services/reports/docx/draw_results.rb | 2 +- app/services/reports/docx/draw_step.rb | 14 +++++----- app/services/reports/docx/draw_step_asset.rb | 2 +- .../reports/docx/draw_step_checklist.rb | 2 +- app/services/reports/docx/draw_step_table.rb | 2 +- app/services/reports/docx/draw_step_text.rb | 2 +- .../elements/_experiment_element.html.erb | 2 +- .../elements/_my_module_element.html.erb | 26 +++++++++---------- .../_my_module_protocol_element.html.erb | 2 +- .../_my_module_result_asset_element.html.erb | 2 +- .../_my_module_result_table_element.html.erb | 2 +- .../_my_module_result_text_element.html.erb | 2 +- .../elements/_my_module_step_element.html.erb | 6 +++-- .../elements/_project_header_element.html.erb | 2 +- .../elements/_step_asset_element.html.erb | 2 +- .../elements/_step_checklist_element.html.erb | 2 +- .../elements/_step_table_element.html.erb | 2 +- .../elements/_step_text_element.html.erb | 2 +- app/views/reports/wizard/_third_step.html.erb | 16 +++++++++--- config/locales/en.yml | 3 ++- 29 files changed, 76 insertions(+), 60 deletions(-) diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js index 73abc4cfa1..98023b3f05 100644 --- a/app/assets/javascripts/reports/new.js +++ b/app/assets/javascripts/reports/new.js @@ -1052,7 +1052,8 @@ function reportHandsonTableConverter() { reportData.report.settings.task.result_order = dropdownSelector.getValues('#taskResultsOrder'); - reportData.report.settings.exclude_metadata = $('.exclude-metadata-setting')[0].checked; + reportData.report.settings.exclude_task_metadata = $('.exclude-task-metadata-setting')[0].checked; + reportData.report.settings.exclude_timestamps = $('.exclude-timestamps-setting')[0].checked; return reportData; } diff --git a/app/models/report.rb b/app/models/report.rb index 0d1fbc97da..2d9a859084 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -43,6 +43,8 @@ class Report < ApplicationRecord DEFAULT_SETTINGS = { all_tasks: true, + exclude_task_metadata: false, + exclude_timestamps: false, task: { protocol: { description: true, diff --git a/app/services/reports/docx/draw_experiment.rb b/app/services/reports/docx/draw_experiment.rb index d7355ab360..50b55e3479 100644 --- a/app/services/reports/docx/draw_experiment.rb +++ b/app/services/reports/docx/draw_experiment.rb @@ -16,7 +16,7 @@ def draw_experiment(subject) end @docx.p do - unless settings['exclude_metadata'] + 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 diff --git a/app/services/reports/docx/draw_my_module.rb b/app/services/reports/docx/draw_my_module.rb index a174a61717..3f48772bcb 100644 --- a/app/services/reports/docx/draw_my_module.rb +++ b/app/services/reports/docx/draw_my_module.rb @@ -17,7 +17,7 @@ def draw_my_module(subject, without_results: false, without_repositories: false) end @docx.p do - unless settings['exclude_metadata'] + 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 @@ -27,21 +27,21 @@ def draw_my_module(subject, without_results: false, without_repositories: false) end end - if my_module.started_on.present? - @docx.p do - text I18n.t('projects.reports.elements.module.started_on', - started_on: I18n.l(my_module.started_on, format: :full)) + unless settings['exclude_task_metadata'] + if my_module.started_on.present? + @docx.p do + text I18n.t('projects.reports.elements.module.started_on', + started_on: I18n.l(my_module.started_on, format: :full)) + end end - end - if my_module.due_date.present? - @docx.p do - text I18n.t('projects.reports.elements.module.due_date', - due_date: I18n.l(my_module.due_date, format: :full)) + if my_module.due_date.present? + @docx.p do + text I18n.t('projects.reports.elements.module.due_date', + due_date: I18n.l(my_module.due_date, format: :full)) + end end - end - unless settings['exclude_metadata'] status = my_module.my_module_status @docx.p do text I18n.t('projects.reports.elements.module.status') diff --git a/app/services/reports/docx/draw_my_module_protocol.rb b/app/services/reports/docx/draw_my_module_protocol.rb index 04d03800c0..9092b088d3 100644 --- a/app/services/reports/docx/draw_my_module_protocol.rb +++ b/app/services/reports/docx/draw_my_module_protocol.rb @@ -12,7 +12,7 @@ def draw_my_module_protocol(my_module) end if @settings.dig('task', 'protocol', 'description') && protocol.description.present? - unless @settings['exclude_metadata'] + unless @settings['exclude_timestamps'] @docx.p I18n.t('projects.reports.elements.module.protocol.user_time', code: protocol.original_code, timestamp: I18n.l(protocol.created_at, format: :full)), color: @color[:gray] end diff --git a/app/services/reports/docx/draw_project_header.rb b/app/services/reports/docx/draw_project_header.rb index 56e2b65694..c0bbffeef4 100644 --- a/app/services/reports/docx/draw_project_header.rb +++ b/app/services/reports/docx/draw_project_header.rb @@ -15,7 +15,7 @@ def draw_project_header(subject) link_style end - unless @settings['exclude_metadata'] + unless @settings['exclude_timestamps'] @docx.p do text I18n.t('projects.reports.elements.project_header.user_time', code: project.code, timestamp: I18n.l(project.created_at, format: :full)), color: color[:gray] diff --git a/app/services/reports/docx/draw_result_asset.rb b/app/services/reports/docx/draw_result_asset.rb index 80520c4c77..7eac0dff94 100644 --- a/app/services/reports/docx/draw_result_asset.rb +++ b/app/services/reports/docx/draw_result_asset.rb @@ -25,7 +25,7 @@ def draw_result_asset(result, settings) end text " #{I18n.t('search.index.archived')} ", bold: true if result.archived? text ' ' + I18n.t('projects.reports.elements.result_asset.file_name', file: asset.file_name) - unless settings['exclude_metadata'] + unless settings['exclude_timestamps'] text ' ' + I18n.t('projects.reports.elements.result_asset.user_time', user: result.user.full_name, timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] end diff --git a/app/services/reports/docx/draw_result_table.rb b/app/services/reports/docx/draw_result_table.rb index 0d3923623d..bd73c48e98 100644 --- a/app/services/reports/docx/draw_result_table.rb +++ b/app/services/reports/docx/draw_result_table.rb @@ -41,7 +41,7 @@ def draw_result_table(element) @docx.p do text I18n.t 'projects.reports.elements.result_table.table_name', name: table.name text ' ' - unless settings['exclude_metadata'] + unless settings['exclude_timestamps'] 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 1dbfe17d5a..252bf68d81 100644 --- a/app/services/reports/docx/draw_result_text.rb +++ b/app/services/reports/docx/draw_result_text.rb @@ -9,7 +9,7 @@ def draw_result_text(element) @docx.p do text result_text.name.presence || '', italic: true text ' ' - unless settings['exclude_metadata'] + unless settings['exclude_timestamps'] text I18n.t('projects.reports.elements.result_text.user_time', timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] end diff --git a/app/services/reports/docx/draw_results.rb b/app/services/reports/docx/draw_results.rb index c35942da83..ffa3980814 100644 --- a/app/services/reports/docx/draw_results.rb +++ b/app/services/reports/docx/draw_results.rb @@ -12,7 +12,7 @@ def draw_results(my_module) @docx.p do text result.name.presence || I18n.t('projects.reports.unnamed'), italic: true text " #{I18n.t('search.index.archived')} ", bold: true if result.archived? - unless settings['exclude_metadata'] + unless settings['exclude_timestamps'] text I18n.t('projects.reports.elements.result.user_time', timestamp: I18n.l(result.created_at, format: :full), user: result.user.full_name), color: color[:gray] diff --git a/app/services/reports/docx/draw_step.rb b/app/services/reports/docx/draw_step.rb index ef762fcb90..376911fc46 100644 --- a/app/services/reports/docx/draw_step.rb +++ b/app/services/reports/docx/draw_step.rb @@ -12,13 +12,15 @@ def draw_step(step) "#{I18n.t('projects.reports.elements.step.step_pos', pos: step.position_plus_one)} #{step.name}" ) @docx.p do - 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'] + 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_metadata'] - text ' | ' + 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, diff --git a/app/services/reports/docx/draw_step_asset.rb b/app/services/reports/docx/draw_step_asset.rb index fab9c36f6a..14987e6987 100644 --- a/app/services/reports/docx/draw_step_asset.rb +++ b/app/services/reports/docx/draw_step_asset.rb @@ -24,7 +24,7 @@ def draw_step_asset(asset) italic true end text ' ' - unless settings['exclude_metadata'] + unless settings['exclude_timestamps'] 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 c6e946e5b8..ffd2f81923 100644 --- a/app/services/reports/docx/draw_step_checklist.rb +++ b/app/services/reports/docx/draw_step_checklist.rb @@ -17,7 +17,7 @@ def draw_step_checklist(checklist) I18n.t('projects.reports.elements.step_checklist.checklist_name', name: checklist.name) ).text, italic: true text ' ' - unless settings['exclude_metadata'] + unless settings['exclude_timestamps'] 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_table.rb b/app/services/reports/docx/draw_step_table.rb index 8b3b4909b8..f7c115691c 100644 --- a/app/services/reports/docx/draw_step_table.rb +++ b/app/services/reports/docx/draw_step_table.rb @@ -40,7 +40,7 @@ def draw_step_table(table, table_type) @docx.p do text I18n.t("projects.reports.elements.#{table_type}.table_name", name: table.name), italic: true text ' ' - unless settings['exclude_metadata'] + unless settings['exclude_timestamps'] 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 6218595a02..66f0ed84c2 100644 --- a/app/services/reports/docx/draw_step_text.rb +++ b/app/services/reports/docx/draw_step_text.rb @@ -9,7 +9,7 @@ def draw_step_text(element) @docx.p do text step_text.name.presence || '', italic: true text ' ' - unless settings['exclude_metadata'] + unless settings['exclude_timestamps'] text I18n.t('projects.reports.elements.result_text.user_time', timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] end diff --git a/app/views/reports/elements/_experiment_element.html.erb b/app/views/reports/elements/_experiment_element.html.erb index 475c96b7bf..0020d7ec79 100644 --- a/app/views/reports/elements/_experiment_element.html.erb +++ b/app/views/reports/elements/_experiment_element.html.erb @@ -9,7 +9,7 @@ <%= t('search.index.archived') %> <% end %> - <% unless @settings['exclude_metadata'] %> + <% unless @settings['exclude_timestamps'] %>
    <%= t('projects.reports.elements.experiment.user_time', code: experiment.code, timestamp: l(timestamp, format: :full)) %>
    diff --git a/app/views/reports/elements/_my_module_element.html.erb b/app/views/reports/elements/_my_module_element.html.erb index 5ad3cee731..17bcaf304f 100644 --- a/app/views/reports/elements/_my_module_element.html.erb +++ b/app/views/reports/elements/_my_module_element.html.erb @@ -9,22 +9,22 @@ <%= t('search.index.archived') %> <% end %> - <% unless @settings['exclude_metadata'] %> + <% unless @settings['exclude_timestamps'] %>
    <%= t('projects.reports.elements.module.user_time', code: my_module.code, timestamp: l(timestamp, format: :full)) %>
    <% end %> -

    - <% if my_module.started_on.present? %> - <%= t('projects.reports.elements.module.started_on', started_on: l(my_module.started_on, format: :full)) %> - <% end %> -

    -

    - <% if my_module.due_date.present? %> - <%= t('projects.reports.elements.module.due_date', due_date: l(my_module.due_date, format: :full)) %> - <% end %> -

    - <% unless @settings['exclude_metadata'] %> + <% unless @settings['exclude_task_metadata'] %> +

    + <% if my_module.started_on.present? %> + <%= t('projects.reports.elements.module.started_on', started_on: l(my_module.started_on, format: :full)) %> + <% end %> +

    +

    + <% if my_module.due_date.present? %> + <%= t('projects.reports.elements.module.due_date', due_date: l(my_module.due_date, format: :full)) %> + <% end %> +

    <% status = my_module.my_module_status %> <%= t('projects.reports.elements.module.status') %> @@ -39,8 +39,6 @@ <% end %>

    - <% end %> - <% unless @settings['exclude_metadata'] %>
    <%= t('projects.reports.elements.module.tags_header') %> diff --git a/app/views/reports/elements/_my_module_protocol_element.html.erb b/app/views/reports/elements/_my_module_protocol_element.html.erb index 1aa86ecb11..67f2c3adcc 100644 --- a/app/views/reports/elements/_my_module_protocol_element.html.erb +++ b/app/views/reports/elements/_my_module_protocol_element.html.erb @@ -9,7 +9,7 @@ <%= t('projects.reports.elements.module.protocol.name') %> <% end %> - <% unless @settings['exclude_metadata'] %> + <% unless @settings['exclude_timestamps'] %>
    <%= t('projects.reports.elements.module.protocol.user_time', code: protocol.original_code, timestamp: l(protocol.created_at, format: :full)) %>
    diff --git a/app/views/reports/elements/_my_module_result_asset_element.html.erb b/app/views/reports/elements/_my_module_result_asset_element.html.erb index 5485a789de..de71933c62 100644 --- a/app/views/reports/elements/_my_module_result_asset_element.html.erb +++ b/app/views/reports/elements/_my_module_result_asset_element.html.erb @@ -26,7 +26,7 @@ <% end %>
    - <% unless @settings['exclude_metadata'] %> + <% unless @settings['exclude_timestamps'] %> <%= t("projects.reports.elements.result_asset.user_time", user: result.user.full_name, timestamp: l(timestamp, format: :full)) %> <% end %> <% if report.settings.dig(:task, :file_results_previews) && ActiveStorageFileUtil.previewable_document?(asset&.file&.blob) %> diff --git a/app/views/reports/elements/_my_module_result_table_element.html.erb b/app/views/reports/elements/_my_module_result_table_element.html.erb index e5fd49f52c..dbcced513e 100644 --- a/app/views/reports/elements/_my_module_result_table_element.html.erb +++ b/app/views/reports/elements/_my_module_result_table_element.html.erb @@ -21,7 +21,7 @@ <% end %> <% end %>
    - <% unless @settings['exclude_metadata'] %> + <% unless @settings['exclude_timestamps'] %>
    <%= t('projects.reports.elements.result_table.user_time', timestamp: l(timestamp, format: :full)) %>
    diff --git a/app/views/reports/elements/_my_module_result_text_element.html.erb b/app/views/reports/elements/_my_module_result_text_element.html.erb index 94e02fa52e..0dff3eb67c 100644 --- a/app/views/reports/elements/_my_module_result_text_element.html.erb +++ b/app/views/reports/elements/_my_module_result_text_element.html.erb @@ -11,7 +11,7 @@ <% end %>
    - <% unless @settings['exclude_metadata'] %> + <% unless @settings['exclude_timestamps'] %>
    <%= t("projects.reports.elements.result_text.user_time", timestamp: l(timestamp, format: :full)) %>
    diff --git a/app/views/reports/elements/_my_module_step_element.html.erb b/app/views/reports/elements/_my_module_step_element.html.erb index 2be53b1a96..fa330886d6 100644 --- a/app/views/reports/elements/_my_module_step_element.html.erb +++ b/app/views/reports/elements/_my_module_step_element.html.erb @@ -8,9 +8,11 @@
    <%= t('projects.reports.elements.step.step_pos', pos: (step.position_plus_one)) %> <%= step.name %> - <%= step_status_label(step) %> + <% unless @settings['exclude_task_metadata'] %> + <%= step_status_label(step) %> + <% end %>
    - <% unless @settings['exclude_metadata'] %> + <% unless @settings['exclude_timestamps'] %>
    <%= t("projects.reports.elements.step.#{step_type_str}.user_time", user: user.full_name , timestamp: l(timestamp, format: :full)) %>
    diff --git a/app/views/reports/elements/_project_header_element.html.erb b/app/views/reports/elements/_project_header_element.html.erb index 9e355d6d9c..c6d3b9636e 100644 --- a/app/views/reports/elements/_project_header_element.html.erb +++ b/app/views/reports/elements/_project_header_element.html.erb @@ -7,7 +7,7 @@ <%= t('search.index.archived') %> <% end %> - <% unless @settings['exclude_metadata'] %> + <% unless @settings['exclude_timestamps'] %>
    <%= t('projects.reports.elements.project_header.user_time', code: project.code, timestamp: l(project.created_at, format: :full)) %>
    diff --git a/app/views/reports/elements/_step_asset_element.html.erb b/app/views/reports/elements/_step_asset_element.html.erb index 880ab97ee1..04d8313e4e 100644 --- a/app/views/reports/elements/_step_asset_element.html.erb +++ b/app/views/reports/elements/_step_asset_element.html.erb @@ -18,7 +18,7 @@ <% end %> - <% unless @settings['exclude_metadata'] %> + <% unless @settings['exclude_timestamps'] %>
     <%= t('projects.reports.elements.step_asset.user_time', timestamp: l(timestamp, format: :full)) %>
    diff --git a/app/views/reports/elements/_step_checklist_element.html.erb b/app/views/reports/elements/_step_checklist_element.html.erb index 1951fde551..02549a31bb 100644 --- a/app/views/reports/elements/_step_checklist_element.html.erb +++ b/app/views/reports/elements/_step_checklist_element.html.erb @@ -9,7 +9,7 @@ team: current_team, base64_encoded_imgs: export_all) %>
    - <% unless @settings['exclude_metadata'] %> + <% unless @settings['exclude_timestamps'] %>
    <%= t('projects.reports.elements.step_checklist.user_time', timestamp: l(timestamp, format: :full)) %>
    diff --git a/app/views/reports/elements/_step_table_element.html.erb b/app/views/reports/elements/_step_table_element.html.erb index dfda2ac144..813c917669 100644 --- a/app/views/reports/elements/_step_table_element.html.erb +++ b/app/views/reports/elements/_step_table_element.html.erb @@ -18,7 +18,7 @@ <% end %> <% end %>
    - <% unless @settings['exclude_metadata'] %> + <% unless @settings['exclude_timestamps'] %>
    <%= t("projects.reports.elements.#{table_type}.user_time", timestamp: l(timestamp, format: :full)) %>
    diff --git a/app/views/reports/elements/_step_text_element.html.erb b/app/views/reports/elements/_step_text_element.html.erb index 8c8ff72ebd..6e42a74876 100644 --- a/app/views/reports/elements/_step_text_element.html.erb +++ b/app/views/reports/elements/_step_text_element.html.erb @@ -8,7 +8,7 @@ <% end %>
    - <% unless @settings['exclude_metadata'] %> + <% unless @settings['exclude_timestamps'] %>
    <%= t("projects.reports.elements.step_text.user_time", timestamp: l(timestamp, format: :full)) %>
    diff --git a/app/views/reports/wizard/_third_step.html.erb b/app/views/reports/wizard/_third_step.html.erb index d56af9b24b..327c1d8573 100644 --- a/app/views/reports/wizard/_third_step.html.erb +++ b/app/views/reports/wizard/_third_step.html.erb @@ -184,7 +184,7 @@ <%= t("projects.reports.wizard.third_step.additional_content") %>
      -
    • +
    • /> @@ -197,10 +197,20 @@
    • - /> + /> + + + <%= t("projects.reports.wizard.third_step.exclude_task_metadata") %> +
      +
      +
    • +
    • +
      + + /> - <%= t("projects.reports.wizard.third_step.exclude_metadata") %> + <%= t("projects.reports.wizard.third_step.exclude_timestamps") %>
    • diff --git a/config/locales/en.yml b/config/locales/en.yml index 3e481c9a8f..f24bc62a74 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -853,7 +853,8 @@ en: results_comments: "Result comments" additional_content: "Additional content" task_activity: "Include task activity" - exclude_metadata: "Exclude metadata" + exclude_task_metadata: "Exclude task metadata" + exclude_timestamps: "Exclude timestamps" archived: "[archived]" deleted: "[deleted]" From c128f2f0035dcd0dd4dfa32d0edc900402861503 Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Thu, 5 Sep 2024 15:08:29 +0200 Subject: [PATCH 11/28] Check presence of template zip URL [SCI-10999] --- config/initializers/report_template_loader.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/report_template_loader.rb b/config/initializers/report_template_loader.rb index 1af443d047..3806518334 100644 --- a/config/initializers/report_template_loader.rb +++ b/config/initializers/report_template_loader.rb @@ -5,7 +5,7 @@ template_zip_url_string = ENV.fetch('REPORT_TEMPLATES_ZIP_URL', nil) -return unless template_zip_url_string +return unless template_zip_url_string.present? template_zip_url = URI.parse(template_zip_url_string) contents = case template_zip_url.scheme From 2ccf1abc91612793762770a6bc62e9c261d32c21 Mon Sep 17 00:00:00 2001 From: Andrej Date: Thu, 5 Sep 2024 16:21:39 +0200 Subject: [PATCH 12/28] Remove tag for attached files in docx [SCI-11027] --- app/services/reports/docx/draw_result_asset.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/services/reports/docx/draw_result_asset.rb b/app/services/reports/docx/draw_result_asset.rb index 7eac0dff94..fc690977f9 100644 --- a/app/services/reports/docx/draw_result_asset.rb +++ b/app/services/reports/docx/draw_result_asset.rb @@ -29,10 +29,6 @@ def draw_result_asset(result, settings) text ' ' + I18n.t('projects.reports.elements.result_asset.user_time', user: result.user.full_name, timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] end - - if settings.dig(:task, :file_results_previews) && ActiveStorageFileUtil.previewable_document?(asset&.file&.blob) - text " #{I18n.t('projects.reports.elements.result_asset.full_preview_attached')}", color: color[:gray] - end end draw_result_comments(result) if @settings.dig('task', 'result_comments') From a05c88569b5220477836c529458175972038ff33 Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Thu, 5 Sep 2024 17:21:24 +0200 Subject: [PATCH 13/28] Require docx template files on initialization [SCI-10999] --- config/initializers/report_template_loader.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/initializers/report_template_loader.rb b/config/initializers/report_template_loader.rb index 3806518334..6461315f68 100644 --- a/config/initializers/report_template_loader.rb +++ b/config/initializers/report_template_loader.rb @@ -5,7 +5,7 @@ template_zip_url_string = ENV.fetch('REPORT_TEMPLATES_ZIP_URL', nil) -return unless template_zip_url_string.present? +return if template_zip_url_string.blank? template_zip_url = URI.parse(template_zip_url_string) contents = case template_zip_url.scheme @@ -33,5 +33,7 @@ path.open('wb') do |f| f.write(entry.get_input_stream.read) end + + require path if entry.name.ends_with?('.rb') end end From 8095b0731a3dca2ab272694ca79570d046f1b390 Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Fri, 6 Sep 2024 11:15:34 +0200 Subject: [PATCH 14/28] Move template loading to a script [SCI-10999] --- .../load_report_templates | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) rename config/initializers/report_template_loader.rb => bin/load_report_templates (54%) mode change 100644 => 100755 diff --git a/config/initializers/report_template_loader.rb b/bin/load_report_templates old mode 100644 new mode 100755 similarity index 54% rename from config/initializers/report_template_loader.rb rename to bin/load_report_templates index 6461315f68..8bb1c4f05d --- a/config/initializers/report_template_loader.rb +++ b/bin/load_report_templates @@ -1,39 +1,42 @@ -# frozen_string_literal: true +#!/usr/bin/env ruby require 'httparty' -require 'active_storage/service/s3_service' +require 'zip' template_zip_url_string = ENV.fetch('REPORT_TEMPLATES_ZIP_URL', nil) -return if template_zip_url_string.blank? +return if template_zip_url_string.nil? || template_zip_url_string.empty? template_zip_url = URI.parse(template_zip_url_string) contents = case template_zip_url.scheme when 'https' HTTParty.get(template_zip_url).body when 's3' - ActiveStorage::Service::S3Service.new( - bucket: template_zip_url.host - ).download(template_zip_url.path[1..]) + system("AWS_PAGER=\"\" aws s3api get-object --bucket #{template_zip_url.host} --key #{template_zip_url.path[1..]} ./report_templates.zip") + File.read('./report_templates.zip') end +puts "Loaded report templates zip from #{template_zip_url_string}" + root_folder = nil Zip::File.open_buffer(StringIO.new(contents)) do |zip| + puts 'Extracting report templates...' + zip.each do |entry| # set root zip folder root_folder = entry.name and next if entry.name.count('/') == 1 # create path while omitting root zip folder - path = Rails.root.join('app', 'views', 'reports', entry.name.sub(root_folder, '')) + path = Pathname.new("#{ENV.fetch('APP_HOME', '.')}/app/views/reports/#{entry.name.sub(root_folder, '')}") path.dirname.mkpath # don't try and write file if entry is a folder - next if entry.name.ends_with?('/') + next if entry.name.end_with?('/') path.open('wb') do |f| f.write(entry.get_input_stream.read) end - require path if entry.name.ends_with?('.rb') + puts "Extracted #{path}" end end From 9d7a0c268de3efbfbcba485bbc388da999f594af Mon Sep 17 00:00:00 2001 From: Andrej Date: Mon, 9 Sep 2024 11:37:37 +0200 Subject: [PATCH 15/28] Exclude timestamps for docx reports for task results [SCI-11017] --- app/views/reports/elements/_my_module_element.html.erb | 8 +++++--- .../elements/_my_module_result_asset_element.html.erb | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/views/reports/elements/_my_module_element.html.erb b/app/views/reports/elements/_my_module_element.html.erb index 17bcaf304f..b8778e7a7e 100644 --- a/app/views/reports/elements/_my_module_element.html.erb +++ b/app/views/reports/elements/_my_module_element.html.erb @@ -94,9 +94,11 @@ <% if @settings.dig('task', 'file_results') %> <%= render partial: 'reports/elements/my_module_result_asset_element', locals: { result: result, report: report, export_all: export_all } %> -
      - <%= t('projects.reports.elements.result.user_time', user: result.user.full_name, timestamp: l(result.created_at, format: :full)) %> -
      + <% unless @settings['exclude_timestamps'] %> +
      + <%= t('projects.reports.elements.result.user_time', user: result.user.full_name, timestamp: l(result.created_at, format: :full)) %> +
      + <% end %> <% end %>
      diff --git a/app/views/reports/elements/_my_module_result_asset_element.html.erb b/app/views/reports/elements/_my_module_result_asset_element.html.erb index de71933c62..f4cd9e0724 100644 --- a/app/views/reports/elements/_my_module_result_asset_element.html.erb +++ b/app/views/reports/elements/_my_module_result_asset_element.html.erb @@ -24,7 +24,7 @@ <%= link_to t('projects.reports.elements.download'), asset_download_url(asset, disposition: 'attachment'), class: 'download-link', target: :_blank %> <% end %> -
      +
      <% unless @settings['exclude_timestamps'] %> <%= t("projects.reports.elements.result_asset.user_time", user: result.user.full_name, timestamp: l(timestamp, format: :full)) %> From 8bc8ccb2f7ccc3f903b1e26545ee3d68385488c1 Mon Sep 17 00:00:00 2001 From: Andrej Date: Wed, 18 Sep 2024 15:43:17 +0200 Subject: [PATCH 16/28] Improve rendering of docx tables [SCI-11056] --- app/helpers/input_sanitize_helper.rb | 3 ++- app/services/reports/docx_renderer.rb | 7 +++++ .../reports/html_to_word_converter.rb | 27 ++++++++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/app/helpers/input_sanitize_helper.rb b/app/helpers/input_sanitize_helper.rb index e30a236661..7b479bbbd4 100644 --- a/app/helpers/input_sanitize_helper.rb +++ b/app/helpers/input_sanitize_helper.rb @@ -40,11 +40,12 @@ def custom_auto_link(text, options = {}) preview_repository = options.fetch(:preview_repository, false) format_opt = wrapper_tag.merge(sanitize: false) base64_encoded_imgs = options.fetch(:base64_encoded_imgs, false) - text = simple_format(text, {}, format_opt) if simple_f # allow base64 images when sanitizing if base64_encoded_imgs is true sanitizer_config = Constants::INPUT_SANITIZE_CONFIG.deep_dup + text = sanitize_input(text, tags, sanitizer_config: sanitizer_config) + text = simple_format(text, {}, format_opt) if simple_f if text =~ SmartAnnotations::TagToHtml::USER_REGEX || text =~ SmartAnnotations::TagToHtml::REGEX text = smart_annotation_parser(text, team, base64_encoded_imgs, preview_repository) diff --git a/app/services/reports/docx_renderer.rb b/app/services/reports/docx_renderer.rb index 91872dc46e..dd027bc4bb 100644 --- a/app/services/reports/docx_renderer.rb +++ b/app/services/reports/docx_renderer.rb @@ -130,6 +130,13 @@ def self.render_table_element(docx, element, options = {}) row[:data].each do |cell| docx_cell = Caracal::Core::Models::TableCellModel.new do |c| cell.each do |content| + c.background content[:style][:background] if content.dig(:style, :background).present? + if content.dig(:style, :vertical_align).present? && content[:style][:vertical_align] != :middle + c.vertical_align content[:style][:vertical_align] + else + c.vertical_align :center + end + if content[:type] == 'p' Reports::DocxRenderer.render_p_element(c, content, options.merge({ skip_br: true })) elsif content[:type] == 'table' diff --git a/app/services/reports/html_to_word_converter.rb b/app/services/reports/html_to_word_converter.rb index f4e312f8e8..07a0c09190 100644 --- a/app/services/reports/html_to_word_converter.rb +++ b/app/services/reports/html_to_word_converter.rb @@ -208,7 +208,7 @@ def paragraph_styling(elem) if style style_keys.each do |key| - style_el = style.value.split(';').select { |i| (i.include? key) }[0] + style_el = style.value.split(';').find { |i| i.strip.start_with?(key) } next unless style_el value = style_el.split(':')[1].strip if style_el @@ -259,6 +259,29 @@ def image_styling(elem, dimension) } end + def table_cell_styling(elem) + style = elem.attributes['style'] + result = {} + style_keys = %w(background-color vertical-align) + + if style + style_keys.each do |key| + style_el = style.value.split(';').find { |i| (i.include? key) } + next unless style_el + + value = style_el.split(':')[1].strip if style_el + + case key + when 'background-color' + result[:background] = normalized_hex_color(value) + when 'vertical-align' + result[:vertical_align] = value.to_sym + end + end + end + result + end + def tiny_mce_table_element(table_element) # array of elements rows = table_element.css('tbody').first.children.map do |row| @@ -267,11 +290,13 @@ def tiny_mce_table_element(table_element) cells = row.children.map do |cell| next unless cell.name == 'td' + style = table_cell_styling(cell) # Parse cell content formated_cell = recursive_children(cell.children, [], true) # Combine text elements to single paragraph formated_cell = combine_docx_elements(formated_cell) + formated_cell.each { |element| element[:style] = style } if style.present? formated_cell end.reject(&:blank?) { type: 'tr', data: cells } From e53ea89f1409aa8fd591c7cb4f65af43537bff08 Mon Sep 17 00:00:00 2001 From: Andrej Date: Fri, 27 Sep 2024 16:03:05 +0200 Subject: [PATCH 17/28] Fix carcal version [SCI-11024] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 4f4b947cf0..bd0d3f156d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -24,7 +24,7 @@ GIT GIT remote: https://github.com/scinote-eln/caracal.git - revision: f30bd2d26229c8118cc392c3a18409cb9a12ae02 + revision: 7f5a653b23af51f38c9ecaf855fdffa6bc5427b2 branch: custom-docx-reports specs: caracal (1.4.2) From a3d549495b2c73d73c808512ca5c33f8bcef9ef7 Mon Sep 17 00:00:00 2001 From: Andrej Date: Tue, 1 Oct 2024 07:52:54 +0200 Subject: [PATCH 18/28] Fix adding backgroung color to docx tables [SCI-11119] --- app/services/reports/html_to_word_converter.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/reports/html_to_word_converter.rb b/app/services/reports/html_to_word_converter.rb index 07a0c09190..6d589a020e 100644 --- a/app/services/reports/html_to_word_converter.rb +++ b/app/services/reports/html_to_word_converter.rb @@ -262,7 +262,7 @@ def image_styling(elem, dimension) def table_cell_styling(elem) style = elem.attributes['style'] result = {} - style_keys = %w(background-color vertical-align) + style_keys = %w(background-color vertical-align background) if style style_keys.each do |key| @@ -272,7 +272,7 @@ def table_cell_styling(elem) value = style_el.split(':')[1].strip if style_el case key - when 'background-color' + when 'background-color', 'background' result[:background] = normalized_hex_color(value) when 'vertical-align' result[:vertical_align] = value.to_sym From 1a04e249ba00e956ab3d023fcbebcd7d1b72039b Mon Sep 17 00:00:00 2001 From: Andrej Date: Tue, 1 Oct 2024 11:07:12 +0200 Subject: [PATCH 19/28] Add support for inventory columns selection for docx report [SCI-11095] --- app/assets/javascripts/reports/new.js | 37 ++++++++++- app/assets/stylesheets/reports/new.scss | 9 +++ app/models/my_module.rb | 16 ++--- app/models/report.rb | 12 +++- .../reports/docx/draw_my_module_repository.rb | 3 +- .../reports/docx/repository_helper.rb | 14 ++-- app/views/reports/wizard/_third_step.html.erb | 66 +++++++++++++------ config/locales/en.yml | 5 ++ 8 files changed, 127 insertions(+), 35 deletions(-) diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js index 98023b3f05..bcc8ad5d39 100644 --- a/app/assets/javascripts/reports/new.js +++ b/app/assets/javascripts/reports/new.js @@ -968,6 +968,16 @@ function reportHandsonTableConverter() { } (function() { + function getSelectedRepositoryColumnValues(element, selectedAll = false) { + const values = []; + $(element).find('option').each((_, option) => { + if ($(option).attr('selected-value') || selectedAll) { + values.push(option.value); + } + }); + return values; + } + function getReportData() { var reportData = {}; @@ -1046,8 +1056,17 @@ function reportHandsonTableConverter() { reportData.report.settings.task[e.value] = e.checked; }); reportData.report.settings.task.repositories = []; - $.each($('.task-contents-container .repositories-contents .repositories-setting:checked'), function(i, e) { - reportData.report.settings.task.repositories.push(parseInt(e.value, 10)); + reportData.report.settings.task.excluded_repository_columns = {}; + + $.each($('.task-contents-container .repositories-contents .repositories-setting:checked'), (_, e) => { + const value = parseInt(e.value, 10); + const $repositoryColumn = $(e).parent().siblings('.repository-columns')[0]; + const selectedValues = dropdownSelector.getValues($repositoryColumn); + const excludedValues = getSelectedRepositoryColumnValues($repositoryColumn, true) + .filter((item) => !selectedValues.includes(item)) + .map((el) => parseInt(el, 10)); + reportData.report.settings.task.repositories.push(value); + reportData.report.settings.task.excluded_repository_columns[value] = excludedValues; }); reportData.report.settings.task.result_order = dropdownSelector.getValues('#taskResultsOrder'); @@ -1359,6 +1378,20 @@ function reportHandsonTableConverter() { if (dropdownSelector.getValues('#docxTemplateSelector').length > 0) { loadDocxTemplate(); } + + $('.repository-columns').each((_, element) => { + const elementId = `#${$(element).attr('id')}`; + const elements = getSelectedRepositoryColumnValues(elementId); + + dropdownSelector.init(elementId, { + selectAppearance: 'simple', + optionClass: 'checkbox-icon' + }); + + if (elements.length) { + dropdownSelector.selectValues(elementId, elements); + } + }); } function loadTemplate() { diff --git a/app/assets/stylesheets/reports/new.scss b/app/assets/stylesheets/reports/new.scss index b5258df6ee..8b50742d8b 100644 --- a/app/assets/stylesheets/reports/new.scss +++ b/app/assets/stylesheets/reports/new.scss @@ -260,6 +260,15 @@ } // scss-lint:enable ImportantRule + .repositories-contents { + .dropdown-selector-container { + display: inline-flex; + flex-shrink: 0; + margin-left: auto; + width: 200px; + } + } + .project-selector-container { background: $color-white; box-shadow: $modal-shadow; diff --git a/app/models/my_module.rb b/app/models/my_module.rb index 36b7578ff4..bca3c406e9 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -391,17 +391,17 @@ def repository_json_hot(repository, order) { data: data, headers: headers } end - def repository_docx_json(repository) - headers = [ - I18n.t('repositories.table.id'), - I18n.t('repositories.table.row_name'), - I18n.t('repositories.table.added_on'), - I18n.t('repositories.table.added_by') - ] + def repository_docx_json(repository, excluded_columns) + headers = Report.default_repository_columns.filter_map do |key, value| + value unless excluded_columns.include?(key.to_s.to_i) + end + custom_columns = [] return false unless repository repository.repository_columns.order(:id).each do |column| + next if excluded_columns.include?(column.id) + if column.data_type == 'RepositoryStockValue' if repository.has_stock_consumption? headers.push(I18n.t('repositories.table.row_consumption')) @@ -416,7 +416,7 @@ def repository_docx_json(repository) records = repository.assigned_rows(self) .select(:id, :name, :created_at, :created_by_id, :repository_id, :parent_id, :archived) - { headers: headers, rows: records, custom_columns: custom_columns } + { headers: headers, rows: records, custom_columns: custom_columns, excluded_columns: excluded_columns } end def deep_clone(current_user) diff --git a/app/models/report.rb b/app/models/report.rb index 2d9a859084..61f092e33d 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -64,7 +64,8 @@ class Report < ApplicationRecord result_comments: true, result_order: 'new', activities: true, - repositories: [] + repositories: [], + excluded_repository_columns: {} } }.freeze @@ -126,4 +127,13 @@ def self.generate_whole_project_report(project, current_user, current_team) ReportActions::ReportContent.new(report, content, {}, current_user).save_with_content report end + + def self.default_repository_columns + { + '-1': I18n.t('repositories.table.id'), + '-2': I18n.t('repositories.table.row_name'), + '-3': I18n.t('repositories.table.added_on'), + '-4': I18n.t('repositories.table.added_by') + } + end end diff --git a/app/services/reports/docx/draw_my_module_repository.rb b/app/services/reports/docx/draw_my_module_repository.rb index e6560c46e0..a82b44b404 100644 --- a/app/services/reports/docx/draw_my_module_repository.rb +++ b/app/services/reports/docx/draw_my_module_repository.rb @@ -5,11 +5,12 @@ def draw_my_module_repository(subject) my_module = subject.my_module repository = subject.repository repository = assigned_repository_or_snapshot(my_module, repository) + excluded_repository_columns = @settings.dig(:task, :excluded_repository_columns, repository.id.to_s) || {} return unless repository && can_read_experiment?(@user, my_module.experiment) && (repository.is_a?(RepositorySnapshot) || can_read_repository?(@user, repository)) - repository_data = my_module.repository_docx_json(repository) + repository_data = my_module.repository_docx_json(repository, excluded_repository_columns) return false unless repository_data[:rows].any? && can_read_repository?(@user, repository) diff --git a/app/services/reports/docx/repository_helper.rb b/app/services/reports/docx/repository_helper.rb index 50b6938912..d962fd97d9 100644 --- a/app/services/reports/docx/repository_helper.rb +++ b/app/services/reports/docx/repository_helper.rb @@ -6,12 +6,16 @@ module Reports::Docx::RepositoryHelper def prepare_row_columns(repository_data, my_module = nil, repository = nil) result = [repository_data[:headers]] + excluded_columns = repository_data[:excluded_columns] + repository_data[:rows].each do |record| row = [] - row.push(record.code) - row.push(escape_input(record.archived ? "#{record.name} [#{I18n.t('general.archived')}]" : record.name)) - row.push(I18n.l(record.created_at, format: :full)) - row.push(escape_input(record.created_by.full_name)) + row.push(record.code) unless excluded_columns.include?(-1) + unless excluded_columns.include?(-2) + row.push(escape_input(record.archived ? "#{record.name} [#{I18n.t('general.archived')}]" : record.name)) + end + row.push(I18n.l(record.created_at, format: :full)) unless excluded_columns.include?(-3) + row.push(escape_input(record.created_by.full_name)) unless excluded_columns.include?(-4) cell_values = {} custom_cells = record.repository_cells @@ -38,6 +42,8 @@ def prepare_row_columns(repository_data, my_module = nil, repository = nil) end repository_data[:custom_columns].each do |column_id| + next if excluded_columns.include?(column_id) + value = cell_values[column_id] row.push(value) end diff --git a/app/views/reports/wizard/_third_step.html.erb b/app/views/reports/wizard/_third_step.html.erb index 327c1d8573..2cbf865db6 100644 --- a/app/views/reports/wizard/_third_step.html.erb +++ b/app/views/reports/wizard/_third_step.html.erb @@ -55,7 +55,10 @@
      - <%= t("projects.reports.wizard.third_step.assigned_items_description") %> +
      +

      <%= t("projects.reports.wizard.third_step.assigned_items_description") %>

      +

      <%= t("projects.reports.wizard.third_step.assigned_items_repository_items_description_html") %>

      +
      • @@ -68,25 +71,50 @@
          <% @repositories.each do |repository| %>
        • - - /> - - - <%= repository.name %> - <% if repository.archived? %> - - <%= t("projects.reports.wizard.third_step.archived") %> +
          + + /> + - <% elsif repository.is_a?(RepositorySnapshot) %> - - <%= t("projects.reports.wizard.third_step.deleted") %> - - <% end %> + <%= repository.name %> + <% if repository.archived? %> + + <%= t("projects.reports.wizard.third_step.archived") %> + + <% elsif repository.is_a?(RepositorySnapshot) %> + + <%= t("projects.reports.wizard.third_step.deleted") %> + + <% end %> + +
        • <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index e3d65629d2..371aa7200a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -844,6 +844,7 @@ en: step_comments: "Step comments" assigned_items: "Assigned items" assigned_items_description: "Inventories selected below will only contain the items that you assigned to the tasks directly." + assigned_items_repository_items_description_html: "You can customize inventory columns only for the docx report. The stock management column by default reflects item consumption." include_all_assigned_iitems: "Include all assigned items from the following inventories" results: "Results" all_results: "Include all results elements" @@ -866,6 +867,10 @@ en: exclude_timestamps: "Exclude timestamps" archived: "[archived]" deleted: "[deleted]" + repository_column: + placeholder: 'Select columns' + all_selected: 'All columns selected' + selected: 'columns selected' new: report_name_placeholder: "Name your report" From 680502558f790a058b4a9cf34cfebcc61713c93d Mon Sep 17 00:00:00 2001 From: Andrej Date: Thu, 3 Oct 2024 09:46:44 +0200 Subject: [PATCH 20/28] Fix caracal version [SCI-11124] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index bd0d3f156d..abcf533535 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -24,7 +24,7 @@ GIT GIT remote: https://github.com/scinote-eln/caracal.git - revision: 7f5a653b23af51f38c9ecaf855fdffa6bc5427b2 + revision: 9b5613c12092c4988d8394054fe966ed3f4f093c branch: custom-docx-reports specs: caracal (1.4.2) From e2c49c7e619378cb384c9b8306df823cf57ffac4 Mon Sep 17 00:00:00 2001 From: Andrej Date: Mon, 7 Oct 2024 14:45:04 +0200 Subject: [PATCH 21/28] Remove some empty in docx reports [SCI-11056] --- app/services/reports/docx/draw_experiment.rb | 17 +++++----- app/services/reports/docx/draw_my_module.rb | 24 +++++++------ .../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, 69 insertions(+), 56 deletions(-) diff --git a/app/services/reports/docx/draw_experiment.rb b/app/services/reports/docx/draw_experiment.rb index 50b55e3479..ebe3ae7ca3 100644 --- a/app/services/reports/docx/draw_experiment.rb +++ b/app/services/reports/docx/draw_experiment.rb @@ -15,14 +15,15 @@ def draw_experiment(subject) 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 3f48772bcb..bd859baab4 100644 --- a/app/services/reports/docx/draw_my_module.rb +++ b/app/services/reports/docx/draw_my_module.rb @@ -16,14 +16,15 @@ def draw_my_module(subject, without_results: false, without_repositories: false) 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 @@ def draw_my_module(subject, without_results: false, without_repositories: false) filter_steps_for_report(my_module.protocol.steps, @settings).order(:position).each do |step| draw_step(step) end + @docx.p - draw_results(my_module) unless without_results + unless without_results + draw_results(my_module) + @docx.p + end - @docx.p 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 9092b088d3..0f3b56dbea 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 @@ def draw_my_module_protocol(my_module) 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 3fc68ef1f3..ebec9ad139 100644 --- a/app/services/reports/docx/draw_result_comments.rb +++ b/app/services/reports/docx/draw_result_comments.rb @@ -8,8 +8,10 @@ def draw_result_comments(result) @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 @@ def draw_result_comments(result) 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 bd73c48e98..f919cc8a40 100644 --- a/app/services/reports/docx/draw_result_table.rb +++ b/app/services/reports/docx/draw_result_table.rb @@ -40,8 +40,8 @@ def draw_result_table(element) 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 252bf68d81..baf9bc9f3d 100644 --- a/app/services/reports/docx/draw_result_text.rb +++ b/app/services/reports/docx/draw_result_text.rb @@ -6,12 +6,15 @@ def draw_result_text(element) 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 376911fc46..579a24c4e5 100644 --- a/app/services/reports/docx/draw_step.rb +++ b/app/services/reports/docx/draw_step.rb @@ -11,21 +11,24 @@ def draw_step(step) @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 @@ def draw_step(step) 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 14987e6987..5b6569919e 100644 --- a/app/services/reports/docx/draw_step_asset.rb +++ b/app/services/reports/docx/draw_step_asset.rb @@ -23,8 +23,8 @@ def draw_step_asset(asset) 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 ffd2f81923..5c510c9f98 100644 --- a/app/services/reports/docx/draw_step_checklist.rb +++ b/app/services/reports/docx/draw_step_checklist.rb @@ -16,8 +16,8 @@ def draw_step_checklist(checklist) 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 87d0abc5f6..f9733eaeb1 100644 --- a/app/services/reports/docx/draw_step_comments.rb +++ b/app/services/reports/docx/draw_step_comments.rb @@ -8,8 +8,10 @@ def draw_step_comments(step) @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 @@ def draw_step_comments(step) 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 f7c115691c..3565c200e6 100644 --- a/app/services/reports/docx/draw_step_table.rb +++ b/app/services/reports/docx/draw_step_table.rb @@ -39,8 +39,8 @@ def draw_step_table(table, table_type) 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 66f0ed84c2..5fc3646393 100644 --- a/app/services/reports/docx/draw_step_text.rb +++ b/app/services/reports/docx/draw_step_text.rb @@ -6,12 +6,16 @@ def draw_step_text(element) 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? From f99c701ab67912cf3aa79884bd72d0fe909d7fa0 Mon Sep 17 00:00:00 2001 From: Andrej Date: Mon, 14 Oct 2024 16:49:41 +0200 Subject: [PATCH 22/28] Fix report wizard for selecting of deleted inventories [SCI-11173] --- app/views/reports/wizard/_third_step.html.erb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/views/reports/wizard/_third_step.html.erb b/app/views/reports/wizard/_third_step.html.erb index 2cbf865db6..9d66ed661b 100644 --- a/app/views/reports/wizard/_third_step.html.erb +++ b/app/views/reports/wizard/_third_step.html.erb @@ -78,7 +78,8 @@ value="<%= repository.is_a?(RepositorySnapshot) ? repository.parent_id : repository.id %>" <%= 'checked' if report.new_record? || @project_contents[:repositories].include?(repository.id) || - (repository.is_a?(Repository) && repository.repository_snapshots.exists?(id: @project_contents[:repositories])) %> /> + (repository.is_a?(Repository) && repository.repository_snapshots.exists?(id: @project_contents[:repositories])) || + (repository.is_a?(RepositorySnapshot) && @project_contents[:repositories].include?(repository.parent_id)) %> /> <%= repository.name %> @@ -101,14 +102,20 @@ > <% Report.default_repository_columns.each do |key, value| %> <% end %> <% repository.repository_columns.find_each do |repository_column| %> From 76d4e7ca7676c713b21da74700181a3a71cce092 Mon Sep 17 00:00:00 2001 From: Andrej Date: Tue, 15 Oct 2024 15:51:55 +0200 Subject: [PATCH 23/28] Update caracal version [SCI-11144] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index abcf533535..05c8ada658 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -24,7 +24,7 @@ GIT GIT remote: https://github.com/scinote-eln/caracal.git - revision: 9b5613c12092c4988d8394054fe966ed3f4f093c + revision: 54c21353798569476a1eaa73b5fd3e275ac85419 branch: custom-docx-reports specs: caracal (1.4.2) From 8d6c0b4380f4c8fb708c3bb9c86b9ef9e8f5c514 Mon Sep 17 00:00:00 2001 From: Martin Artnik <85488244+artoscinote@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:38:35 +0200 Subject: [PATCH 24/28] Change download path for report templates --- bin/load_report_templates | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/load_report_templates b/bin/load_report_templates index 8bb1c4f05d..e0190f3068 100755 --- a/bin/load_report_templates +++ b/bin/load_report_templates @@ -12,8 +12,8 @@ contents = case template_zip_url.scheme when 'https' HTTParty.get(template_zip_url).body when 's3' - system("AWS_PAGER=\"\" aws s3api get-object --bucket #{template_zip_url.host} --key #{template_zip_url.path[1..]} ./report_templates.zip") - File.read('./report_templates.zip') + system("AWS_PAGER=\"\" aws s3api get-object --bucket #{template_zip_url.host} --key #{template_zip_url.path[1..]} #{ENV.fetch('APP_HOME', '.')}/app/views/reports/report_templates.zip") + File.read("#{ENV.fetch('APP_HOME', '.')}/app/views/reports/report_templates.zip") end puts "Loaded report templates zip from #{template_zip_url_string}" From 2e2308e866b20f757d3d58b5a680d84ba2200b08 Mon Sep 17 00:00:00 2001 From: Andrej Date: Fri, 25 Oct 2024 10:30:33 +0200 Subject: [PATCH 25/28] Add option to add task name into results [SCI-11220] --- app/services/reports/docx/draw_results.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/services/reports/docx/draw_results.rb b/app/services/reports/docx/draw_results.rb index ffa3980814..a708c262e0 100644 --- a/app/services/reports/docx/draw_results.rb +++ b/app/services/reports/docx/draw_results.rb @@ -1,12 +1,21 @@ # frozen_string_literal: true module Reports::Docx::DrawResults - def draw_results(my_module) + def draw_results(my_module, with_my_module_name: false) color = @color settings = @settings + scinote_url = @scinote_url + link_style = @link_style return unless can_read_my_module?(@user, my_module) if my_module.results.any? && (%w(file_results table_results text_results).any? { |k| @settings.dig('task', k) }) + if with_my_module_name + @docx.h3 do + link my_module.name, + scinote_url + Rails.application.routes.url_helpers.protocols_my_module_path(my_module), + link_style + end + end @docx.h4 I18n.t('Results') order_results_for_report(my_module.results, @settings.dig('task', 'result_order')).each do |result| @docx.p do From 3815e5e78dfb1f0719b3c95e5525c3002c1e8995 Mon Sep 17 00:00:00 2001 From: Andrej Date: Fri, 25 Oct 2024 11:36:27 +0200 Subject: [PATCH 26/28] Add select/deselect button for repository column selection on report wizard [SCI-11219] --- app/views/reports/wizard/_third_step.html.erb | 1 + config/locales/en.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/app/views/reports/wizard/_third_step.html.erb b/app/views/reports/wizard/_third_step.html.erb index 9d66ed661b..a1f8216f7e 100644 --- a/app/views/reports/wizard/_third_step.html.erb +++ b/app/views/reports/wizard/_third_step.html.erb @@ -98,6 +98,7 @@ data-placeholder="<%= t("projects.reports.wizard.third_step.repository_column.placeholder") %>" data-select-multiple-all-selected="<%= t("projects.reports.wizard.third_step.repository_column.all_selected") %>" data-select-multiple-name="<%= t("projects.reports.wizard.third_step.repository_column.selected") %>" + data-select-all-button="<%= t("projects.reports.wizard.third_step.repository_column.select_deselect_all") %>" multiple > <% Report.default_repository_columns.each do |key, value| %> diff --git a/config/locales/en.yml b/config/locales/en.yml index d8a9904cf2..880b00f850 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -872,6 +872,7 @@ en: archived: "[archived]" deleted: "[deleted]" repository_column: + select_deselect_all: 'Select/deselect all' placeholder: 'Select columns' all_selected: 'All columns selected' selected: 'columns selected' From c2b7c12497dbd2a9ff4271e8bc3120e7a8342cd2 Mon Sep 17 00:00:00 2001 From: Andrej Date: Fri, 25 Oct 2024 12:46:58 +0200 Subject: [PATCH 27/28] Add default text if not repository columns are selected for reports [SCI-11211] --- app/services/reports/docx/draw_my_module_repository.rb | 7 ++++++- app/services/reports/docx/repository_helper.rb | 2 ++ config/locales/en.yml | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/services/reports/docx/draw_my_module_repository.rb b/app/services/reports/docx/draw_my_module_repository.rb index b5102a25a2..11f1ed0c84 100644 --- a/app/services/reports/docx/draw_my_module_repository.rb +++ b/app/services/reports/docx/draw_my_module_repository.rb @@ -20,7 +20,12 @@ def draw_my_module_repository(subject) @docx.p I18n.t('projects.reports.elements.module_repository.name', repository: repository.name, my_module: my_module.name), bold: true, size: Constants::REPORT_DOCX_STEP_ELEMENTS_TITLE_SIZE - @docx.table table, border_size: Constants::REPORT_DOCX_TABLE_BORDER_SIZE + + if table.present? + @docx.table table, border_size: Constants::REPORT_DOCX_TABLE_BORDER_SIZE + else + @docx.p I18n.t('projects.reports.elements.module_repository.no_columns'), italic: true + end @docx.p @docx.p diff --git a/app/services/reports/docx/repository_helper.rb b/app/services/reports/docx/repository_helper.rb index 26d2a43b64..d8166ca9bd 100644 --- a/app/services/reports/docx/repository_helper.rb +++ b/app/services/reports/docx/repository_helper.rb @@ -5,6 +5,8 @@ module Reports::Docx::RepositoryHelper include ActionView::Helpers::NumberHelper def prepare_row_columns_for_docx(repository_data, my_module = nil, repository = nil) + return if repository_data[:headers].blank? + result = [repository_data[:headers]] excluded_columns = repository_data[:excluded_columns] diff --git a/config/locales/en.yml b/config/locales/en.yml index 880b00f850..5e1c931a82 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -978,6 +978,7 @@ en: name: "%{repository} of task %{my_module}" table_name: "%{name}" no_items: "No items" + no_columns: "No columns selected" result: user_time: "Added on %{timestamp} by %{user}." result_asset: From 2d6d47bf692c73c086eacbeefcf1a1879b5087c7 Mon Sep 17 00:00:00 2001 From: Andrej Date: Wed, 30 Oct 2024 11:12:55 +0100 Subject: [PATCH 28/28] Fix look of the select all button [SCI-11219] --- app/assets/javascripts/sitewide/dropdown_selector.js | 2 +- app/assets/stylesheets/shared/dropdown_selector.scss | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/sitewide/dropdown_selector.js b/app/assets/javascripts/sitewide/dropdown_selector.js index b78704270b..41902a5046 100644 --- a/app/assets/javascripts/sitewide/dropdown_selector.js +++ b/app/assets/javascripts/sitewide/dropdown_selector.js @@ -353,7 +353,7 @@ var dropdownSelector = (function() { // If we setup Select All we draw it and add correspond logic if (selectElement.data('select-all-button')) { - $(``) + $(``) .appendTo(dropdownContainer.find('.dropdown-container')) .click(() => { // For AJAX dropdown we will use only "Deselect All" diff --git a/app/assets/stylesheets/shared/dropdown_selector.scss b/app/assets/stylesheets/shared/dropdown_selector.scss index ef119838a8..21c9ff9e8c 100644 --- a/app/assets/stylesheets/shared/dropdown_selector.scss +++ b/app/assets/stylesheets/shared/dropdown_selector.scss @@ -175,6 +175,10 @@ top: 0; width: 100%; z-index: 5; + + &:hover { + background: $color-concrete; + } } .dropdown-blank {