From 452547564e0c610642ba8c37a691e7e8f4ef3490 Mon Sep 17 00:00:00 2001 From: Andrej Date: Tue, 30 Jul 2024 10:41:06 +0200 Subject: [PATCH 01/96] Enable protocol template renaming [SCI-10851] --- app/controllers/protocols_controller.rb | 1 - app/models/protocol.rb | 8 -------- config/locales/en.yml | 1 - 3 files changed, 10 deletions(-) diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index b0ade7fb4..63a782d59 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -909,7 +909,6 @@ class ProtocolsController < ApplicationController end def set_inline_name_editing - return unless @protocol.initial_draft? return unless can_manage_protocol_draft_in_repository?(@protocol) @inline_editable_title_config = { diff --git a/app/models/protocol.rb b/app/models/protocol.rb index a1a69b3d8..f26da6f07 100644 --- a/app/models/protocol.rb +++ b/app/models/protocol.rb @@ -70,12 +70,10 @@ class Protocol < ApplicationRecord with_options if: :in_repository_published_version? do validates :parent, presence: true validate :parent_type_constraint - validate :versions_same_name_constraint end with_options if: :in_repository_draft? do # Only one draft can exist for each protocol validate :ensure_single_draft - validate :versions_same_name_constraint end with_options if: -> { in_repository? && !parent && !archived_changed?(from: false) } do |protocol| # Active protocol must have unique name inside its team @@ -797,12 +795,6 @@ class Protocol < ApplicationRecord end end - def versions_same_name_constraint - if parent.present? && !parent.name.eql?(name) - errors.add(:base, I18n.t('activerecord.errors.models.protocol.wrong_version_name')) - end - end - def version_number_constraint if Protocol.where(protocol_type: Protocol::REPOSITORY_TYPES) .where.not(id: id) diff --git a/config/locales/en.yml b/config/locales/en.yml index a6e68a6b6..9eb819df6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -166,7 +166,6 @@ en: protocol: unchangable: "Published protocols can not be changed!" wrong_parent_type: "Protocol can only be linked to published protocol!" - wrong_version_name: "Protocol versions should have same name!" wrong_version_number: "Protocol version number should be sequential!" wrong_parent_draft_number: "Procol can have only 1 draft" attributes: From 5841fbdda13c22953818324e90e56bd90d924dd3 Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 9 Aug 2024 12:01:05 +0200 Subject: [PATCH 02/96] Add basic support for custom templates docx [SCI-10967] --- Gemfile | 4 +- Gemfile.lock | 18 +- app/assets/javascripts/reports/new.js | 79 +++++++- .../repositories_input_component.html.erb | 11 + .../reports/repositories_input_component.rb | 18 ++ app/controllers/reports_controller.rb | 42 +++- app/jobs/reports/docx_job.rb | 2 + app/services/reports/docx.rb | 18 +- app/services/reports/docx/draw_my_module.rb | 26 +-- app/services/reports/docx/draw_results.rb | 30 +++ app/services/reports/docx/draw_step.rb | 2 +- app/services/reports/docx/private_methods.rb | 10 - .../reports/docx/repository_helper.rb | 4 +- .../reports/template_values_editor.html.erb | 75 ++++--- .../docx_templates/custom_template/docx.rb | 188 ++++++++++++++++++ .../custom_template/edit.html.erb | 57 ++++++ .../docx_templates/custom_template/name.txt | 1 + .../docx_templates/scinote_template/docx.rb | 19 ++ .../docx_templates/scinote_template/name.txt | 1 + app/views/reports/wizard/_first_step.html.erb | 4 +- .../_project_template_selector.html.erb | 12 ++ config/initializers/extends.rb | 1 + config/initializers/report_templates.rb | 14 ++ config/locales/en.yml | 4 +- config/routes.rb | 1 + 25 files changed, 553 insertions(+), 88 deletions(-) create mode 100644 app/components/reports/repositories_input_component.html.erb create mode 100644 app/components/reports/repositories_input_component.rb create mode 100644 app/services/reports/docx/draw_results.rb create mode 100644 app/views/reports/docx_templates/custom_template/docx.rb create mode 100644 app/views/reports/docx_templates/custom_template/edit.html.erb create mode 100644 app/views/reports/docx_templates/custom_template/name.txt create mode 100644 app/views/reports/docx_templates/scinote_template/docx.rb create mode 100644 app/views/reports/docx_templates/scinote_template/name.txt diff --git a/Gemfile b/Gemfile index 675d300cf..453dea286 100644 --- a/Gemfile +++ b/Gemfile @@ -47,8 +47,8 @@ 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', git: 'https://github.com/scinote-eln/caracal.git', branch: 'rubyzip2' # Build docx report +gem 'caracal_the_curve', '~> 1.4', '>= 1.4.6' gem 'caxlsx' # Build XLSX files gem 'deface', '~> 1.9' gem 'down', '~> 5.0' diff --git a/Gemfile.lock b/Gemfile.lock index dc2d6db14..5a29368f2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,16 +22,6 @@ GIT docile (>= 1.1.0) rails (>= 4) -GIT - remote: https://github.com/scinote-eln/caracal.git - revision: f8e4c279adfee7801eb1024e1d6a18bb06c9c76a - branch: rubyzip2 - specs: - caracal (1.4.1) - nokogiri (~> 1.6) - rubyzip (>= 2.3) - tilt (>= 1.4) - GIT remote: https://github.com/scinote-eln/img2zpl revision: 23d61cfc3e90ac4caa62dd08546fa0d7590a5140 @@ -227,6 +217,10 @@ 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) @@ -725,7 +719,7 @@ GEM tailwindcss-rails (2.4.0-x86_64-linux) railties (>= 6.0.0) thor (1.3.1) - tilt (2.2.0) + tilt (2.4.0) timecop (0.9.6) timeout (0.4.1) turbolinks (5.2.1) @@ -805,7 +799,7 @@ DEPENDENCIES canaid! capybara capybara-email - caracal! + caracal_the_curve (~> 1.4, >= 1.4.6) caxlsx cssbundling-rails cucumber-rails diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js index a7aba901e..ad280af9f 100644 --- a/app/assets/javascripts/reports/new.js +++ b/app/assets/javascripts/reports/new.js @@ -1036,6 +1036,7 @@ function reportHandsonTableConverter() { // Settings reportData.report.settings.template = dropdownSelector.getValues('#templateSelector'); + reportData.report.settings.docx_template = dropdownSelector.getValues('#docxTemplateSelector'); reportData.report.settings.all_tasks = $('.project-contents-container .select-all-my-modules-checkbox') .prop('checked'); $.each($('.task-contents-container .content-element .protocol-setting'), function(i, e) { @@ -1254,7 +1255,8 @@ function reportHandsonTableConverter() { function reCheckContinueButton() { if (dropdownSelector.getValues('#projectSelector').length > 0 - && dropdownSelector.getValues('#templateSelector').length > 0) { + && dropdownSelector.getValues('#templateSelector').length > 0 + && dropdownSelector.getValues('#docxTemplateSelector').length > 0) { $('.continue-button').attr('disabled', false); } else { $('.continue-button').attr('disabled', true); @@ -1276,9 +1278,12 @@ function reportHandsonTableConverter() { } if (dropdownSelector.getValues('#projectSelector').length > 0) { dropdownSelector.enableSelector('#templateSelector'); + dropdownSelector.enableSelector('#docxTemplateSelector'); } else { dropdownSelector.selectValues('#templateSelector', ''); dropdownSelector.disableSelector('#templateSelector'); + dropdownSelector.selectValues('#docxTemplateSelector', ''); + dropdownSelector.disableSelector('#docxTemplateSelector'); } reCheckContinueButton(); } @@ -1292,12 +1297,12 @@ function reportHandsonTableConverter() { disableSearch: true, onSelect: function() { if (dropdownSelector.getValues('#templateSelector').length === 0) { - $('.report-template-values-container').html('').addClass('hidden'); + $('.report-template-values-container.pdf').html('').addClass('hidden'); reCheckContinueButton(); return; } - let filledFieldsCount = $('.report-template-values-container') + let filledFieldsCount = $('.report-template-values-container.pdf') .find('input.sci-input-field, textarea.sci-input-field').filter(function() { return !!this.value; }).length; @@ -1311,9 +1316,39 @@ function reportHandsonTableConverter() { } }); + dropdownSelector.init('#docxTemplateSelector', { + singleSelect: true, + closeOnSelect: true, + noEmptyOption: true, + selectAppearance: 'simple', + disableSearch: true, + onSelect: function() { + if (dropdownSelector.getValues('#docxTemplateSelector').length === 0) { + $('.report-template-values-container.docx').html('').addClass('hidden'); + reCheckContinueButton(); + return; + } + + let filledFieldsCount = $('.report-template-values-container.docx') + .find('input.sci-input-field, textarea.sci-input-field').filter(function() { + return !!this.value; + }).length; + + if (filledFieldsCount === 0) { + loadDocxTemplate(); + } else { + $('#templateReportWarningModal').modal('show'); + } + reCheckContinueButton(); + } + }); + if (dropdownSelector.getValues('#templateSelector').length > 0) { loadTemplate(); } + if (dropdownSelector.getValues('#docxTemplateSelector').length > 0) { + loadDocxTemplate(); + } } function loadTemplate() { @@ -1325,8 +1360,38 @@ function reportHandsonTableConverter() { $('#templateSelector').data('selected-template', template); $.get($('#templateSelector').data('valuesEditorPath'), params, function(result) { - $('.report-template-values-container').removeClass('hidden'); - $('.report-template-values-container').html(result.html); + $('.report-template-values-container.pdf').removeClass('hidden'); + $('.report-template-values-container.pdf').html(result.html); + + $('.section').each(function() { + var section = $(this); + var collapseButton = section.find('.sn-icon-down'); + var valuesContainer = section.find('.values-container'); + + if (valuesContainer.children().length === 0) { + collapseButton.hide(); + } + }); + + $('.report-template-value-dropdown').each(function() { + dropdownSelector.init($(this), { + noEmptyOption: true + }); + }); + }); + } + + function loadDocxTemplate() { + let template = $('#docxTemplateSelector').val(); + let params = { + project_id: dropdownSelector.getValues('#projectSelector'), + template: template + }; + + $('#docxTemplateSelector').data('selected-template', template); + $.get($('#docxTemplateSelector').data('valuesEditorPath'), params, function(result) { + $('.report-template-values-container.docx').removeClass('hidden'); + $('.report-template-values-container.docx').html(result.html); $('.section').each(function() { var section = $(this); @@ -1448,7 +1513,9 @@ function reportHandsonTableConverter() { .on('hide.bs.modal', function() { if (!$('#templateReportWarningModal').hasClass('skip-hide-event')) { let previousTemplate = $('#templateSelector').data('selected-template'); + let previousDocxTemplate = $('#docxTemplateSelector').data('selected-template'); dropdownSelector.selectValues('#templateSelector', previousTemplate); + dropdownSelector.selectValues('#docxTemplateSelector', previousDocxTemplate); } $('#templateReportWarningModal').removeClass('skip-hide-event'); }); @@ -1461,7 +1528,7 @@ function reportHandsonTableConverter() { $('#reportWizardEditWarning').modal('show'); $('.experiment-contents').sortable(); - + initNameContainerFocus(); initGenerateButton(); initReportWizard(); diff --git a/app/components/reports/repositories_input_component.html.erb b/app/components/reports/repositories_input_component.html.erb new file mode 100644 index 000000000..9906b3b2c --- /dev/null +++ b/app/components/reports/repositories_input_component.html.erb @@ -0,0 +1,11 @@ +<% if @editing %> +
+ <%= label_tag @name, @label %> + <%= select_tag @name, options_from_collection_for_select(@repositories, :id, :name, @value), placeholder: @placeholder, class: 'sci-input-field report-template-value-dropdown', data: { type: 'RepositoriesInputComponent' }, multiple: true %> +
+<% else %> + <% @project_members.where(id: @value).each do |member| %> + <%= member.public_send(@displayed_field) %> +
+ <% end %> +<% end %> diff --git a/app/components/reports/repositories_input_component.rb b/app/components/reports/repositories_input_component.rb new file mode 100644 index 000000000..c7909d8c7 --- /dev/null +++ b/app/components/reports/repositories_input_component.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Reports + class RepositoriesInputComponent < TemplateValueComponent + def initialize(report:, name:, label:, placeholder: nil, editing: true, displayed_field: :name) + 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 } + snapshots_of_deleted = RepositorySnapshot.left_outer_joins(:original_repository) + .where(team: report.team) + .where.not(original_repository: live_repositories) + .select('DISTINCT ON ("repositories"."parent_id") "repositories".*') + .sort_by { |r| r.name.downcase } + @repositories = live_repositories + snapshots_of_deleted + @displayed_field = displayed_field + end + end +end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index c148511f3..2e5b20a39 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -7,13 +7,13 @@ class ReportsController < ApplicationController before_action :load_vars, only: %i(edit update document_preview generate_pdf generate_docx status save_pdf_to_inventory_modal save_pdf_to_inventory_item) before_action :load_vars_nested, only: %i(create edit update generate_pdf - generate_docx new_template_values project_contents) + generate_docx new_template_values new_docx_template_values project_contents) before_action :load_wizard_vars, only: %i(new edit) before_action :load_available_repositories, only: %i(index save_pdf_to_inventory_modal available_repositories) before_action :check_project_read_permissions, only: %i(create edit update generate_pdf - generate_docx new_template_values project_contents) + generate_docx new_template_values new_docx_template_values project_contents) before_action :check_read_permissions, except: %i(index new create edit update destroy actions_toolbar generate_pdf - generate_docx new_template_values project_contents + generate_docx new_template_values project_contents new_docx_template_values available_repositories) before_action :check_create_permissions, only: %i(new create) before_action :check_manage_permissions, only: %i(edit update generate_pdf generate_docx) @@ -37,6 +37,7 @@ class ReportsController < ApplicationController # Report grouped by modules def new @templates = Extends::REPORT_TEMPLATES + @docx_templates = Extends::DOCX_REPORT_TEMPLATES @report = current_team.reports.new end @@ -73,6 +74,39 @@ class ReportsController < ApplicationController end end + def new_docx_template_values + if Extends::DOCX_REPORT_TEMPLATES.key?(params[:template]&.to_sym) + template = params[:template] + else + return render_404 + end + + report = current_team.reports.where(project: @project).find_by(id: params[:report_id]) + if report.present? + return render_403 unless can_manage_report?(report) + else + return render_403 unless can_create_reports?(current_team) + + report = current_team.reports.new(project: @project) + end + + if lookup_context.any_templates?("reports/docx_templates/#{template}/edit") + render json: { + html: render_to_string( + template: "reports/docx_templates/#{template}/edit", + layout: 'reports/template_values_editor', + locals: { report: report }, + formats: :html + ) + } + else + render json: { + html: render_to_string(partial: 'reports/wizard/no_template_values', + formats: :html) + } + end + end + # Creating new report from the _save modal of the new page def create @report = Report.new(report_params) @@ -102,6 +136,7 @@ class ReportsController < ApplicationController def edit @edit = true @active_template = @report.settings[:template] + @active_docx_template = @report.settings[:docx_template] @report.settings = Report::DEFAULT_SETTINGS if @report.settings.blank? @project_contents = { @@ -312,6 +347,7 @@ class ReportsController < ApplicationController def load_wizard_vars @templates = Extends::REPORT_TEMPLATES + @docx_templates = Extends::DOCX_REPORT_TEMPLATES live_repositories = Repository.accessible_by_teams(current_team).sort_by { |r| r.name.downcase } snapshots_of_deleted = RepositorySnapshot.left_outer_joins(:original_repository) .where(team: current_team) diff --git a/app/jobs/reports/docx_job.rb b/app/jobs/reports/docx_job.rb index 51043ff37..1165653eb 100644 --- a/app/jobs/reports/docx_job.rb +++ b/app/jobs/reports/docx_job.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'caracal' + module Reports class DocxJob < ApplicationJob extend InputSanitizeHelper diff --git a/app/services/reports/docx.rb b/app/services/reports/docx.rb index 7a0251371..46445f338 100644 --- a/app/services/reports/docx.rb +++ b/app/services/reports/docx.rb @@ -2,6 +2,10 @@ # rubocop:disable Style/ClassAndModuleChildren +Dir[Rails.root.join('app/views/reports/docx_templates/**/docx.rb')].each do |file| + require file +end + class Reports::Docx include ActionView::Helpers::TextHelper include ActionView::Helpers::UrlHelper @@ -26,15 +30,23 @@ class Reports::Docx @link_style = {} @color = {} @scinote_url = options[:scinote_url][0..-2] + @template = @settings[:docx_template] || 'scinote_template' + + extend "#{@template.camelize}Docx".constantize end def draw initial_document_load - @report.root_elements.each do |subject| - public_send("draw_#{subject.type_of}", subject) - end + prepare_docx + @docx end + + private + + def get_template_value(name) + @report.report_template_values.find_by(name: name)&.value + end end # rubocop:enable Style/ClassAndModuleChildren diff --git a/app/services/reports/docx/draw_my_module.rb b/app/services/reports/docx/draw_my_module.rb index ddfefd7df..e85ccf701 100644 --- a/app/services/reports/docx/draw_my_module.rb +++ b/app/services/reports/docx/draw_my_module.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Reports::Docx::DrawMyModule - def draw_my_module(subject) + def draw_my_module(subject, without_results: false, without_repositories: false) color = @color link_style = @link_style scinote_url = @scinote_url @@ -70,30 +70,12 @@ module Reports::Docx::DrawMyModule draw_step(step) end - if my_module.results.any? && (%w(file_results table_results text_results).any? { |k| @settings.dig('task', k) }) - @docx.h4 I18n.t('Results') - order_results_for_report(my_module.results, @settings.dig('task', 'result_order')).each do |result| - @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] - end - draw_result_asset(result, @settings) if @settings.dig('task', 'file_results') - result.result_orderable_elements.each do |element| - if @settings.dig('task', 'table_results') && element.orderable_type == 'ResultTable' - draw_result_table(element) - elsif @settings.dig('task', 'text_results') && element.orderable_type == 'ResultText' - draw_result_text(element) - end - end - draw_result_comments(result) if @settings.dig('task', 'result_comments') - end - end + draw_results(my_module) unless without_results @docx.p subject.children.active.each do |child| + next if without_repositories && child.type_of == 'my_module_repository' + public_send("draw_#{child.type_of}", child) end diff --git a/app/services/reports/docx/draw_results.rb b/app/services/reports/docx/draw_results.rb new file mode 100644 index 000000000..0baedb9cf --- /dev/null +++ b/app/services/reports/docx/draw_results.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Reports::Docx::DrawResults + def draw_results(my_module) + color = @color + 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) }) + @docx.h4 I18n.t('Results') + order_results_for_report(my_module.results, @settings.dig('task', 'result_order')).each do |result| + @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] + end + draw_result_asset(result, @settings) if @settings.dig('task', 'file_results') + result.result_orderable_elements.each do |element| + if @settings.dig('task', 'table_results') && element.orderable_type == 'ResultTable' + draw_result_table(element) + elsif @settings.dig('task', 'text_results') && element.orderable_type == 'ResultText' + draw_result_text(element) + end + end + draw_result_comments(result) if @settings.dig('task', 'result_comments') + end + end + end +end diff --git a/app/services/reports/docx/draw_step.rb b/app/services/reports/docx/draw_step.rb index c6cc90660..6d4e27da6 100644 --- a/app/services/reports/docx/draw_step.rb +++ b/app/services/reports/docx/draw_step.rb @@ -7,7 +7,7 @@ module Reports::Docx::DrawStep user = (step.completed? && step.last_modified_by) || step.user timestamp = step.completed ? step.completed_on : step.created_at @docx.p - @docx.h5( + @docx.h4( "#{I18n.t('projects.reports.elements.step.step_pos', pos: step.position_plus_one)} #{step.name}" ) @docx.p do diff --git a/app/services/reports/docx/private_methods.rb b/app/services/reports/docx/private_methods.rb index 8e5db9780..1136bc635 100644 --- a/app/services/reports/docx/private_methods.rb +++ b/app/services/reports/docx/private_methods.rb @@ -16,16 +16,6 @@ module Reports::Docx::PrivateMethods bottom Constants::REPORT_DOCX_MARGIN_BOTTOM end - @docx.page_numbers true, align: :right - - insert_logo - - @docx.p do - text I18n.t('projects.reports.new.generate_PDF.generated_on', timestamp: I18n.l(Time.zone.now, format: :full)) - end - - @docx.hr - generate_html_styles end diff --git a/app/services/reports/docx/repository_helper.rb b/app/services/reports/docx/repository_helper.rb index f24065fd9..50b693891 100644 --- a/app/services/reports/docx/repository_helper.rb +++ b/app/services/reports/docx/repository_helper.rb @@ -4,7 +4,7 @@ module Reports::Docx::RepositoryHelper include InputSanitizeHelper include ActionView::Helpers::NumberHelper - def prepare_row_columns(repository_data, my_module, repository) + def prepare_row_columns(repository_data, my_module = nil, repository = nil) result = [repository_data[:headers]] repository_data[:rows].each do |record| row = [] @@ -16,7 +16,7 @@ module Reports::Docx::RepositoryHelper cell_values = {} custom_cells = record.repository_cells custom_cells.each do |cell| - if cell.value.instance_of? RepositoryStockValue + if cell.value.instance_of?(RepositoryStockValue) && my_module if repository.is_a?(RepositorySnapshot) consumed_stock = record.repository_stock_consumption_cell&.value&.formatted || 0 cell_values[cell.repository_column_id] = consumed_stock diff --git a/app/views/layouts/reports/template_values_editor.html.erb b/app/views/layouts/reports/template_values_editor.html.erb index 1f9352e83..225c32a4a 100644 --- a/app/views/layouts/reports/template_values_editor.html.erb +++ b/app/views/layouts/reports/template_values_editor.html.erb @@ -17,32 +17,57 @@ <%= t('projects.reports.wizard.first_step.values_editor.description') %> -
-

- - <%= t('projects.reports.wizard.first_step.values_editor.header') %> -

-
- <%= yield :header %> -
-
+<% + toc = yield :toc + header = yield :header + cover = yield :cover + footer = yield :footer +%> -
-

- - <%= t('projects.reports.wizard.first_step.values_editor.cover') %> -

-
- <%= yield :cover %> +<% if toc.present? %> +
+

+ + <%= t('projects.reports.wizard.first_step.values_editor.toc') %> +

+
+ <%= toc %> +
-
+<% end %> -
-

- - <%= t('projects.reports.wizard.first_step.values_editor.footer') %> -

-
- <%= yield :footer %> +<% if header.present? %> +
+

+ + <%= t('projects.reports.wizard.first_step.values_editor.header') %> +

+
+ <%= yield header %> +
-
+<% end %> + +<% if cover.present? %> +
+

+ + <%= t('projects.reports.wizard.first_step.values_editor.cover') %> +

+
+ <%= cover %> +
+
+<% end %> + +<% if footer.present? %> +
+

+ + <%= t('projects.reports.wizard.first_step.values_editor.footer') %> +

+
+ <%= footer %> +
+
+<% end %> diff --git a/app/views/reports/docx_templates/custom_template/docx.rb b/app/views/reports/docx_templates/custom_template/docx.rb new file mode 100644 index 000000000..b2e16276a --- /dev/null +++ b/app/views/reports/docx_templates/custom_template/docx.rb @@ -0,0 +1,188 @@ +# 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 new file mode 100644 index 000000000..6bef2a79e --- /dev/null +++ b/app/views/reports/docx_templates/custom_template/edit.html.erb @@ -0,0 +1,57 @@ +<% 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 new file mode 100644 index 000000000..0ad39c916 --- /dev/null +++ b/app/views/reports/docx_templates/custom_template/name.txt @@ -0,0 +1 @@ +Custom Template diff --git a/app/views/reports/docx_templates/scinote_template/docx.rb b/app/views/reports/docx_templates/scinote_template/docx.rb new file mode 100644 index 000000000..5b5e05312 --- /dev/null +++ b/app/views/reports/docx_templates/scinote_template/docx.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module ScinoteTemplateDocx + def prepare_docx + @docx.page_numbers true, align: :right + + insert_logo + + @docx.p do + text I18n.t('projects.reports.new.generate_PDF.generated_on', timestamp: I18n.l(Time.zone.now, format: :full)) + end + + @docx.hr + + @report.root_elements.each do |subject| + public_send("draw_#{subject.type_of}", subject) + end + end +end diff --git a/app/views/reports/docx_templates/scinote_template/name.txt b/app/views/reports/docx_templates/scinote_template/name.txt new file mode 100644 index 000000000..9c7a580cc --- /dev/null +++ b/app/views/reports/docx_templates/scinote_template/name.txt @@ -0,0 +1 @@ +SciNote Template diff --git a/app/views/reports/wizard/_first_step.html.erb b/app/views/reports/wizard/_first_step.html.erb index 5d9cda6fc..1fba29ada 100644 --- a/app/views/reports/wizard/_first_step.html.erb +++ b/app/views/reports/wizard/_first_step.html.erb @@ -1,5 +1,7 @@
<%= render partial: 'reports/wizard/project_template_selector', locals: {report: report} %>
-
"> +
"> +
+
">
diff --git a/app/views/reports/wizard/_project_template_selector.html.erb b/app/views/reports/wizard/_project_template_selector.html.erb index f29b6e7d6..3a7500e6a 100644 --- a/app/views/reports/wizard/_project_template_selector.html.erb +++ b/app/views/reports/wizard/_project_template_selector.html.erb @@ -23,6 +23,18 @@ values_editor_path: reports_new_template_values_path(report_id: report.id) } %>
+
+ <%= label_tag :docxTemplateSelector, t('projects.reports.wizard.first_step.select_docx_template') %> + <%= select_tag :docxTemplateSelector, + options_for_select(@docx_templates.invert, @active_docx_template), + prompt: t('projects.reports.wizard.first_step.select_docx_template'), + data: { + 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], + values_editor_path: reports_new_docx_template_values_path(report_id: report.id) + } %> +
diff --git a/config/initializers/extends.rb b/config/initializers/extends.rb index d7ae79061..0fab450eb 100644 --- a/config/initializers/extends.rb +++ b/config/initializers/extends.rb @@ -542,6 +542,7 @@ class Extends ] REPORT_TEMPLATES = {} + DOCX_REPORT_TEMPLATES = {} NOTIFIABLE_ACTIVITIES = %w( assign_user_to_project diff --git a/config/initializers/report_templates.rb b/config/initializers/report_templates.rb index e482295cd..0760dadda 100644 --- a/config/initializers/report_templates.rb +++ b/config/initializers/report_templates.rb @@ -13,3 +13,17 @@ Dir.chdir(Rails.root.join('app/views/reports/templates')) do end end end + +Dir.chdir(Rails.root.join('app/views/reports/docx_templates')) do + templates = Dir.glob('*').select { |entry| File.directory?(entry) } + templates.each do |template| + next if Extends::DOCX_REPORT_TEMPLATES[template.to_sym].present? + + Extends::DOCX_REPORT_TEMPLATES[template.to_sym] = + if File.file?("#{template}/name.txt") + File.open("#{template}/name.txt").read.strip + else + template + end + end +end diff --git a/config/locales/en.yml b/config/locales/en.yml index 909bdfcfd..4e5d25a02 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -798,7 +798,8 @@ en: select_project_title: "Select project and report template" select_project_description: "You are about to create a new report. Please select a project for which you would like to create a report, and choose the report design template. Only projects with at least 1 task are displayed." select_project: "Select a project" - select_template: "Select your template" + select_template: "Select your PDF template" + select_docx_template: "Select your DOCX template" report_description: "Report description (optional)" report_description_placeholder: "In this report you can see..." values_editor: @@ -807,6 +808,7 @@ en: header: "Header" cover: "Title page" footer: "Footer" + toc: "Table of contents" no_values_title: "No additional data required" no_values_description: "SciNote template doesn’t need any additional input for it to be successfully generated." second_step: diff --git a/config/routes.rb b/config/routes.rb index 49db07eb4..fdb9be508 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -266,6 +266,7 @@ Rails.application.routes.draw do end get 'reports/datatable', to: 'reports#datatable' get 'reports/new_template_values', to: 'reports#new_template_values', defaults: { format: 'json' } + get 'reports/new_docx_template_values', to: 'reports#new_docx_template_values', defaults: { format: 'json' } get 'reports/available_repositories', to: 'reports#available_repositories', defaults: { format: 'json' } get 'available_asset_type_columns', From b4bcd69683cc4e9f9b50c2ca1ce7f980e95d1e45 Mon Sep 17 00:00:00 2001 From: Anton Date: Tue, 13 Aug 2024 14:14:00 +0200 Subject: [PATCH 03/96] 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 ad280af9f..28e407826 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 86804dc9a..8ef08378e 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 43d9fd665..562495418 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 9fd76c321..88755ca91 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 65c9a3e43..71857134b 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 2464735b8..749b20985 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 b3b96926f..d65b63a96 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 f0b636cd2..15f6d32ea 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 54ad6a629..735afe95e 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 2842a7adf..75ea45762 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 f4d625d1a..9a7917aa3 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 e3334f08c..1cc9c8b3c 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 01c274f89..9a62410c3 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 642eb9db5..d56af9b24 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 4e5d25a02..55582e52c 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 04/96] 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 | 39 +++++++++++-------- .../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, 114 insertions(+), 75 deletions(-) diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js index 28e407826..519bae098 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 e02d018a7..d7355ab36 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 @@ module Reports::Docx::DrawExperiment 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 e85ccf701..a174a6171 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 @@ module Reports::Docx::DrawMyModule 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 @@ module Reports::Docx::DrawMyModule 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)}" - end - end - - if tags.present? + unless settings['exclude_metadata'] + status = my_module.my_module_status @docx.p do - text I18n.t('projects.reports.elements.module.tags_header') - tags.each do |tag| - text ' ' - text "[#{tag.name}]", color: tag.color.delete('#') + 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 + + 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 2096569ff..04d03800c 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 @@ module Reports::Docx::DrawMyModuleProtocol 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 defa8e36e..56e2b6569 100644 --- a/app/services/reports/docx/draw_project_header.rb +++ b/app/services/reports/docx/draw_project_header.rb @@ -15,10 +15,12 @@ module Reports::Docx::DrawProjectHeader 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 030de2591..80520c4c7 100644 --- a/app/services/reports/docx/draw_result_asset.rb +++ b/app/services/reports/docx/draw_result_asset.rb @@ -25,8 +25,10 @@ module Reports::Docx::DrawResultAsset 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 661d41a46..0d3923623 100644 --- a/app/services/reports/docx/draw_result_table.rb +++ b/app/services/reports/docx/draw_result_table.rb @@ -5,6 +5,7 @@ module Reports::Docx::DrawResultTable 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 @@ module Reports::Docx::DrawResultTable @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 2ab606a7e..1dbfe17d5 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 0baedb9cf..c35942da8 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 @@ module Reports::Docx::DrawResults @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 6d4e27da6..b2892ba6a 100644 --- a/app/services/reports/docx/draw_step.rb +++ b/app/services/reports/docx/draw_step.rb @@ -6,6 +6,7 @@ module Reports::Docx::DrawStep 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 @@ module Reports::Docx::DrawStep 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 8d83ca221..fab9c36f6 100644 --- a/app/services/reports/docx/draw_step_asset.rb +++ b/app/services/reports/docx/draw_step_asset.rb @@ -5,6 +5,7 @@ module Reports::Docx::DrawStepAsset 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 @@ module Reports::Docx::DrawStepAsset 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 e2662e60e..c6e946e5b 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 @@ module Reports::Docx::DrawStepChecklist 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 a0826741a..8b3b4909b 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 @@ module Reports::Docx::DrawStepTable @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 978386a94..6218595a0 100644 --- a/app/services/reports/docx/draw_step_text.rb +++ b/app/services/reports/docx/draw_step_text.rb @@ -5,11 +5,14 @@ module Reports::Docx::DrawStepText 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 8ef08378e..475c96b7b 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 562495418..5ad3cee73 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 88755ca91..1aa86ecb1 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 71857134b..5485a789d 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 749b20985..e5fd49f52 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 d65b63a96..94e02fa52 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 15f6d32ea..2be53b1a9 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 735afe95e..9e355d6d9 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 75ea45762..880ab97ee 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 9a7917aa3..1951fde55 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 1cc9c8b3c..dfda2ac14 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 9a62410c3..8c8ff72eb 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 a44a2ec67..c7f72cd5c 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 05/96] Update caracal version [SCI-10985] --- Gemfile | 3 +-- Gemfile.lock | 16 +++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 453dea286..62c5bdb79 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 5a29368f2..0baa4846f 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 06/96] 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 c7909d8c7..f168cc396 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 b2892ba6a..ef762fcb9 100644 --- a/app/services/reports/docx/draw_step.rb +++ b/app/services/reports/docx/draw_step.rb @@ -17,8 +17,8 @@ module Reports::Docx::DrawStep 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 b2e16276a..000000000 --- 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 6bef2a79e..000000000 --- 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 0ad39c916..000000000 --- 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 07/96] 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 519bae098..168aab5de 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 bb13046b4..7bb30bfe8 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 @@ class ReportsController < ApplicationController 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 @@ class ReportsController < ApplicationController 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 @@ class ReportsController < ApplicationController 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 @@ class ReportsController < ApplicationController 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 @@ class ReportsController < ApplicationController .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 @@ class ReportsController < ApplicationController 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 7dcc85929..5a05d13e2 100644 --- a/app/helpers/reports_helper.rb +++ b/app/helpers/reports_helper.rb @@ -106,4 +106,8 @@ module ReportsHelper 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 46445f338..72e6ce339 100644 --- a/app/services/reports/docx.rb +++ b/app/services/reports/docx.rb @@ -30,7 +30,7 @@ class Reports::Docx @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 225c32a4a..841b024ef 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 55582e52c..3e481c9a8 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 08/96] 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 037850e82..09abcdc32 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 09/96] 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 168aab5de..73abc4cfa 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 10/96] 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 0355c4064..b5258df6e 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 11/96] 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 000000000..1af443d04 --- /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 12/96] 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 73abc4cfa..98023b3f0 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 0d1fbc97d..2d9a85908 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 d7355ab36..50b55e347 100644 --- a/app/services/reports/docx/draw_experiment.rb +++ b/app/services/reports/docx/draw_experiment.rb @@ -16,7 +16,7 @@ module Reports::Docx::DrawExperiment 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 a174a6171..3f48772bc 100644 --- a/app/services/reports/docx/draw_my_module.rb +++ b/app/services/reports/docx/draw_my_module.rb @@ -17,7 +17,7 @@ module Reports::Docx::DrawMyModule 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 @@ module Reports::Docx::DrawMyModule 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 04d03800c..9092b088d 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 @@ module Reports::Docx::DrawMyModuleProtocol 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 56e2b6569..c0bbffeef 100644 --- a/app/services/reports/docx/draw_project_header.rb +++ b/app/services/reports/docx/draw_project_header.rb @@ -15,7 +15,7 @@ module Reports::Docx::DrawProjectHeader 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 80520c4c7..7eac0dff9 100644 --- a/app/services/reports/docx/draw_result_asset.rb +++ b/app/services/reports/docx/draw_result_asset.rb @@ -25,7 +25,7 @@ module Reports::Docx::DrawResultAsset 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 0d3923623..bd73c48e9 100644 --- a/app/services/reports/docx/draw_result_table.rb +++ b/app/services/reports/docx/draw_result_table.rb @@ -41,7 +41,7 @@ module Reports::Docx::DrawResultTable @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 1dbfe17d5..252bf68d8 100644 --- a/app/services/reports/docx/draw_result_text.rb +++ b/app/services/reports/docx/draw_result_text.rb @@ -9,7 +9,7 @@ module Reports::Docx::DrawResultText @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 c35942da8..ffa398081 100644 --- a/app/services/reports/docx/draw_results.rb +++ b/app/services/reports/docx/draw_results.rb @@ -12,7 +12,7 @@ module Reports::Docx::DrawResults @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 ef762fcb9..376911fc4 100644 --- a/app/services/reports/docx/draw_step.rb +++ b/app/services/reports/docx/draw_step.rb @@ -12,13 +12,15 @@ module Reports::Docx::DrawStep "#{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 fab9c36f6..14987e698 100644 --- a/app/services/reports/docx/draw_step_asset.rb +++ b/app/services/reports/docx/draw_step_asset.rb @@ -24,7 +24,7 @@ module Reports::Docx::DrawStepAsset 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 c6e946e5b..ffd2f8192 100644 --- a/app/services/reports/docx/draw_step_checklist.rb +++ b/app/services/reports/docx/draw_step_checklist.rb @@ -17,7 +17,7 @@ module Reports::Docx::DrawStepChecklist 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 8b3b4909b..f7c115691 100644 --- a/app/services/reports/docx/draw_step_table.rb +++ b/app/services/reports/docx/draw_step_table.rb @@ -40,7 +40,7 @@ module Reports::Docx::DrawStepTable @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 6218595a0..66f0ed84c 100644 --- a/app/services/reports/docx/draw_step_text.rb +++ b/app/services/reports/docx/draw_step_text.rb @@ -9,7 +9,7 @@ module Reports::Docx::DrawStepText @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 475c96b7b..0020d7ec7 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 5ad3cee73..17bcaf304 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 1aa86ecb1..67f2c3adc 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 5485a789d..de71933c6 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 e5fd49f52..dbcced513 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 94e02fa52..0dff3eb67 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 2be53b1a9..fa330886d 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 9e355d6d9..c6d3b9636 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 880ab97ee..04d8313e4 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 1951fde55..02549a31b 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 dfda2ac14..813c91766 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 8c8ff72eb..6e42a7487 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 d56af9b24..327c1d857 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") %>