From a9ac8452f29a5dabc3e8f783152e5dccf1c96535 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Tue, 6 Apr 2021 13:56:24 +0200 Subject: [PATCH] Add dynamic form elements in report wizard step 1 [SCI-5591] --- Gemfile | 1 + Gemfile.lock | 3 + app/assets/javascripts/reports/new.js | 8 +- app/assets/stylesheets/reports/new.scss | 28 +++++++ app/components/application_component.rb | 5 ++ .../reports/checkbox_input_component.html.erb | 4 + .../reports/checkbox_input_component.rb | 6 ++ .../reports/date_input_component.html.erb | 8 ++ .../reports/date_input_component.rb | 6 ++ .../large_text_input_component.html.erb | 8 ++ .../reports/large_text_input_component.rb | 6 ++ .../multi_checkbox_input_component.html.erb | 11 +++ .../reports/multi_checkbox_input_component.rb | 10 +++ .../team_member_input_component.html.erb | 8 ++ .../reports/team_member_input_component.rb | 10 +++ .../reports/template_value_component.rb | 14 ++++ .../reports/text_input_component.html.erb | 8 ++ .../reports/text_input_component.rb | 6 ++ .../active_storage/check_blob_permissions.rb | 6 ++ app/controllers/reports_controller.rb | 32 +++++-- app/jobs/reports/pdf_job.rb | 58 +++++++++++++ app/models/report.rb | 1 + app/models/report_template_value.rb | 5 ++ .../reports/template_values_editor.html.erb | 21 +++++ app/views/reports/new.html.erb | 4 +- .../_project_template_selector.html.erb | 26 ------ .../{_report.html.erb => cover.html.erb} | 84 +++++++++++-------- .../templates/template_1/edit.html.erb | 47 +++++++++++ .../{_footer.html.erb => footer.html.erb} | 6 +- .../{_header.html.erb => header.html.erb} | 4 +- app/views/reports/wizard/_first_step.html.erb | 5 ++ .../wizard/_no_template_values.html.erb | 6 ++ .../_project_template_selector.html.erb | 28 +++++++ bin/rails | 4 +- bin/rake | 4 +- bin/setup | 8 +- bin/yarn | 12 ++- config.ru | 3 +- config/boot.rb | 4 +- config/environments/development.rb | 16 +++- config/environments/production.rb | 32 ++++++- config/environments/test.rb | 9 ++ config/initializers/backtrace_silencers.rb | 7 +- config/initializers/extends.rb | 4 + .../initializers/filter_parameter_logging.rb | 4 +- .../new_framework_defaults_6_1.rb | 67 +++++++++++++++ config/initializers/permissions_policy.rb | 11 +++ config/locales/en.yml | 36 ++++---- config/routes.rb | 3 +- ...210325152257_add_report_template_values.rb | 15 ++++ db/structure.sql | 74 +++++++++++++++- 51 files changed, 681 insertions(+), 115 deletions(-) create mode 100644 app/components/application_component.rb create mode 100644 app/components/reports/checkbox_input_component.html.erb create mode 100644 app/components/reports/checkbox_input_component.rb create mode 100644 app/components/reports/date_input_component.html.erb create mode 100644 app/components/reports/date_input_component.rb create mode 100644 app/components/reports/large_text_input_component.html.erb create mode 100644 app/components/reports/large_text_input_component.rb create mode 100644 app/components/reports/multi_checkbox_input_component.html.erb create mode 100644 app/components/reports/multi_checkbox_input_component.rb create mode 100644 app/components/reports/team_member_input_component.html.erb create mode 100644 app/components/reports/team_member_input_component.rb create mode 100644 app/components/reports/template_value_component.rb create mode 100644 app/components/reports/text_input_component.html.erb create mode 100644 app/components/reports/text_input_component.rb create mode 100644 app/jobs/reports/pdf_job.rb create mode 100644 app/models/report_template_value.rb create mode 100644 app/views/layouts/reports/template_values_editor.html.erb delete mode 100644 app/views/reports/report_wizard/_project_template_selector.html.erb rename app/views/reports/templates/template_1/{_report.html.erb => cover.html.erb} (61%) create mode 100644 app/views/reports/templates/template_1/edit.html.erb rename app/views/reports/templates/template_1/{_footer.html.erb => footer.html.erb} (74%) rename app/views/reports/templates/template_1/{_header.html.erb => header.html.erb} (76%) create mode 100644 app/views/reports/wizard/_first_step.html.erb create mode 100644 app/views/reports/wizard/_no_template_values.html.erb create mode 100644 app/views/reports/wizard/_project_template_selector.html.erb create mode 100644 config/initializers/new_framework_defaults_6_1.rb create mode 100644 config/initializers/permissions_policy.rb create mode 100644 db/migrate/20210325152257_add_report_template_values.rb diff --git a/Gemfile b/Gemfile index 5549a753d..baf832869 100644 --- a/Gemfile +++ b/Gemfile @@ -13,6 +13,7 @@ gem 'figaro' gem 'pg', '~> 1.1' gem 'pg_search' # PostgreSQL full text search gem 'rails', '~> 6.1.1' +gem 'view_component', require: 'view_component/engine' gem 'recaptcha', require: 'recaptcha/rails' gem 'sanitize', '~> 5.2' gem 'sassc-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 71174506d..0e585e182 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -597,6 +597,8 @@ GEM underscore-rails (1.8.3) unicode-display_width (1.7.0) uniform_notifier (1.13.2) + view_component (2.28.0) + activesupport (>= 5.0.0, < 7.0) warden (1.2.9) rack (>= 2.0.9) webmock (3.11.1) @@ -726,6 +728,7 @@ DEPENDENCIES tzinfo-data uglifier (>= 1.3.0) underscore-rails + view_component webmock webpacker (~> 4.0.0) whacamole diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js index d8e24e01d..c41da5c22 100644 --- a/app/assets/javascripts/reports/new.js +++ b/app/assets/javascripts/reports/new.js @@ -1005,7 +1005,13 @@ function reportHandsonTableConverter() { closeOnSelect: true, noEmptyOption: true, selectAppearance: 'simple', - disableSearch: true + disableSearch: true, + onChange: function() { + let template = $('#templateSelector').val(); + $.get($('#templateSelector').data('valuesEditorPath'), { template: template }, function(result) { + $('.report-template-values-container').html(result.html); + }); + } }); } diff --git a/app/assets/stylesheets/reports/new.scss b/app/assets/stylesheets/reports/new.scss index c950347c4..5166c56be 100644 --- a/app/assets/stylesheets/reports/new.scss +++ b/app/assets/stylesheets/reports/new.scss @@ -231,6 +231,34 @@ padding: .5em; } } + + .report-template-values-container { + background: $color-white; + box-shadow: $modal-shadow; + margin: 2em 20%; + padding: 1em 2em; + width: 60%; + + .description { + @include font-main; + } + + .project-selector, + .template-selector { + display: inline-block; + margin-bottom: 1em; + width: 100%; + + label { + @include font-small; + } + } + + #projectDescription { + height: 110px; + padding: .5em; + } + } } @media (max-width: 960px) { diff --git a/app/components/application_component.rb b/app/components/application_component.rb new file mode 100644 index 000000000..8b5827dc2 --- /dev/null +++ b/app/components/application_component.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class ApplicationComponent < ViewComponent::Base + def initialize; end +end diff --git a/app/components/reports/checkbox_input_component.html.erb b/app/components/reports/checkbox_input_component.html.erb new file mode 100644 index 000000000..5fcb429e6 --- /dev/null +++ b/app/components/reports/checkbox_input_component.html.erb @@ -0,0 +1,4 @@ +
+ <%= check_box_tag @name, true %> + <%= @label %> +
diff --git a/app/components/reports/checkbox_input_component.rb b/app/components/reports/checkbox_input_component.rb new file mode 100644 index 000000000..ba6d3eb25 --- /dev/null +++ b/app/components/reports/checkbox_input_component.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +module Reports + class CheckboxInputComponent < TemplateValueComponent + end +end diff --git a/app/components/reports/date_input_component.html.erb b/app/components/reports/date_input_component.html.erb new file mode 100644 index 000000000..1c0fd5c28 --- /dev/null +++ b/app/components/reports/date_input_component.html.erb @@ -0,0 +1,8 @@ +<% if @editing %> +
+ <%= label_tag @name, @label %> + <%= date_field_tag @name, @value, placeholder: @placeholder, class: 'sci-input-field' %> +
+<% else %> + <%= @value %> +<% end %> diff --git a/app/components/reports/date_input_component.rb b/app/components/reports/date_input_component.rb new file mode 100644 index 000000000..eedbcdff8 --- /dev/null +++ b/app/components/reports/date_input_component.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +module Reports + class DateInputComponent < TemplateValueComponent + end +end diff --git a/app/components/reports/large_text_input_component.html.erb b/app/components/reports/large_text_input_component.html.erb new file mode 100644 index 000000000..7d2d5a063 --- /dev/null +++ b/app/components/reports/large_text_input_component.html.erb @@ -0,0 +1,8 @@ +<% if @editing %> +
+ <%= label_tag @name, @label %> + <%= text_area_tag @name, @value, placeholder: @placeholder, class: 'sci-input-field' %> +
+<% else %> + <%= @value %> +<% end %> diff --git a/app/components/reports/large_text_input_component.rb b/app/components/reports/large_text_input_component.rb new file mode 100644 index 000000000..3ec7f23c3 --- /dev/null +++ b/app/components/reports/large_text_input_component.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +module Reports + class LargeTextInputComponent < TemplateValueComponent + end +end diff --git a/app/components/reports/multi_checkbox_input_component.html.erb b/app/components/reports/multi_checkbox_input_component.html.erb new file mode 100644 index 000000000..2bf1bb9d1 --- /dev/null +++ b/app/components/reports/multi_checkbox_input_component.html.erb @@ -0,0 +1,11 @@ +
+ <%= label_tag "#{@name}[]", @label %> + +
diff --git a/app/components/reports/multi_checkbox_input_component.rb b/app/components/reports/multi_checkbox_input_component.rb new file mode 100644 index 000000000..edabf7e5c --- /dev/null +++ b/app/components/reports/multi_checkbox_input_component.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Reports + class MultiCheckboxInputComponent < TemplateValueComponent + def initialize(report:, name:, label:, placeholder: nil, editing: false, items: {}) + super(report: report, name: name, label: label, placeholder: placeholder, editing: editing) + @items = items + end + end +end diff --git a/app/components/reports/team_member_input_component.html.erb b/app/components/reports/team_member_input_component.html.erb new file mode 100644 index 000000000..8f2476d2f --- /dev/null +++ b/app/components/reports/team_member_input_component.html.erb @@ -0,0 +1,8 @@ +<% if @editing %> +
+ <%= label_tag @name, @label %> + <%= select_tag @name, options_from_collection_for_select(@team_members, :id, :name), placeholder: @placeholder, class: 'sci-input-field' %> +
+<% else %> + <%= @value %> +<% end %> diff --git a/app/components/reports/team_member_input_component.rb b/app/components/reports/team_member_input_component.rb new file mode 100644 index 000000000..ec5dbc2ed --- /dev/null +++ b/app/components/reports/team_member_input_component.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Reports + class TeamMemberInputComponent < TemplateValueComponent + def initialize(report:, name:, label:, placeholder: nil, editing: true, team:) + super(report: report, name: name, label: label, placeholder: placeholder, editing: editing) + @team_members = team.users + end + end +end diff --git a/app/components/reports/template_value_component.rb b/app/components/reports/template_value_component.rb new file mode 100644 index 000000000..686390d76 --- /dev/null +++ b/app/components/reports/template_value_component.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Reports + class TemplateValueComponent < ApplicationComponent + def initialize(report:, name:, label:, placeholder: nil, editing: true) + @report = report + @name = name + @label = label + @placeholder = placeholder + @editing = editing + @value = @report.report_template_values.find_by(view_component: self.class.name.demodulize, name: name)&.value + end + end +end diff --git a/app/components/reports/text_input_component.html.erb b/app/components/reports/text_input_component.html.erb new file mode 100644 index 000000000..4d7cb2390 --- /dev/null +++ b/app/components/reports/text_input_component.html.erb @@ -0,0 +1,8 @@ +<% if @editing %> +
+ <%= label_tag @name, @label %> + <%= text_field_tag @name, @value, placeholder: @placeholder, class: 'sci-input-field input-large' %> +
+<% else %> + <%= @value %> +<% end %> diff --git a/app/components/reports/text_input_component.rb b/app/components/reports/text_input_component.rb new file mode 100644 index 000000000..9fade95d7 --- /dev/null +++ b/app/components/reports/text_input_component.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +module Reports + class TextInputComponent < TemplateValueComponent + end +end diff --git a/app/controllers/concerns/active_storage/check_blob_permissions.rb b/app/controllers/concerns/active_storage/check_blob_permissions.rb index f5e423da0..08daa8c5d 100644 --- a/app/controllers/concerns/active_storage/check_blob_permissions.rb +++ b/app/controllers/concerns/active_storage/check_blob_permissions.rb @@ -21,6 +21,8 @@ module ActiveStorage check_tinymce_asset_read_permissions when 'Experiment' check_experiment_read_permissions + when 'Report' + check_report_read_permissions when 'User' # No read restrictions for avatars true @@ -74,6 +76,10 @@ module ActiveStorage render_403 && return unless can_read_experiment?(@blob.attachments.first.record) end + def check_report_read_permissions + render_403 && return unless can_read_project?(@blob.attachments.first.record.project) + end + def check_zip_export_read_permissions render_403 unless @blob.attachments.first.record.user == current_user end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index a91624940..ee2f59797 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -25,7 +25,7 @@ class ReportsController < ApplicationController before_action :load_vars, only: %i(edit update) before_action :load_vars_nested, only: BEFORE_ACTION_METHODS - before_action :load_visible_projects, only: :new + before_action :load_visible_projects, only: %i(new edit) before_action :load_available_repositories, only: %i(new edit available_repositories) @@ -49,7 +49,30 @@ class ReportsController < ApplicationController # Report grouped by modules def new - @templates = [['Scinote Template', 1]] + @templates = Extends::REPORT_TEMPLATES + end + + def new_template_values + template = Extends::REPORT_TEMPLATES[params[:template].to_sym] + return render_404 if template.blank? + + respond_to do |format| + format.json do + if lookup_context.template_exists?("reports/templates/#{template}/edit.html.erb") + render json: { + html: render_to_string( + template: "reports/templates/#{template}/edit.html.erb", + layout: 'reports/template_values_editor', + locals: { report: Report.new } + ) + } + else + render json: { + html: render_to_string(partial: 'reports/wizard/no_template_values.html.erb') + } + end + end + end end # Creating new report from the _save modal of the new page @@ -88,6 +111,7 @@ class ReportsController < ApplicationController # cleans all the deleted report current_team_switch(@report.project.team) @report.cleanup_report + @templates = Extends::REPORT_TEMPLATES render 'reports/new.html.erb' end @@ -447,10 +471,6 @@ class ReportsController < ApplicationController end end - def visible_projects - render json: { projects: @visible_projects }, status: :ok - end - def available_repositories render json: { results: @available_repositories }, status: :ok end diff --git a/app/jobs/reports/pdf_job.rb b/app/jobs/reports/pdf_job.rb new file mode 100644 index 000000000..311f2ce27 --- /dev/null +++ b/app/jobs/reports/pdf_job.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +module Reports + class PdfJob < ApplicationJob + include InputSanitizeHelper + + queue_as :reports + + def perform(report, template, user) + file = Tempfile.new(['report', '.pdf'], binmode: true) + begin + template_name = Extends::REPORT_TEMPLATES[template.to_sym] + + raise StandardError if template_name.blank? + + # TODO, replace with actual content generation + content = I18n.t('projects.reports.new.no_content_for_PDF_html') + + ActionController::Renderer::RACK_KEY_TRANSLATION['warden'] ||= 'warden' + proxy = Warden::Proxy.new({}, Warden::Manager.new({})) + proxy.set_user(user, scope: :user, store: false) + renderer = ApplicationController.renderer.new(warden: proxy) + + file << renderer.render( + pdf: 'report', header: { html: { template: "reports/templates/#{template_name}/header", + locals: { report: report }, + layout: 'reports/footer_header.html.erb' } }, + cover: renderer.render_to_string("reports/templates/#{template_name}/cover.html.erb", + layout: false, + locals: { report: report }), + footer: { html: { template: "reports/templates/#{template_name}/footer", + locals: { report: report }, + layout: 'reports/footer_header.html.erb' } }, + locals: { content: content }, + disable_javascript: true, + template: 'reports/report.pdf.erb' + ) + + file.rewind + report.pdf_file.attach(io: file, filename: 'report.pdf') + report.update!(pdf_file_processing: false) + + report_path = Rails.application.routes.url_helpers.reports_path + notification = Notification.create( + type_of: :deliver, + title: I18n.t('projects.reports.index.generation.completed_notification_title'), + message: I18n.t('projects.reports.index.generation.completed_notification_message', + report_link: "#{sanitize_input(report.name)}", + team_name: sanitize_input(report.team.name)) + ) + notification.create_user_notification(user) + ensure + file.close + file.unlink + end + end + end +end diff --git a/app/models/report.rb b/app/models/report.rb index 244316211..18cb1e64b 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -24,6 +24,7 @@ class Report < ApplicationRecord foreign_key: 'last_modified_by_id', class_name: 'User', optional: true + has_many :report_template_values, dependent: :destroy # Report either has many report elements (if grouped by timestamp), # or many module elements (if grouped by module) diff --git a/app/models/report_template_value.rb b/app/models/report_template_value.rb new file mode 100644 index 000000000..6e4e546a2 --- /dev/null +++ b/app/models/report_template_value.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class ReportTemplateValue < ApplicationRecord + belongs_to :report +end diff --git a/app/views/layouts/reports/template_values_editor.html.erb b/app/views/layouts/reports/template_values_editor.html.erb new file mode 100644 index 000000000..e9dc8454a --- /dev/null +++ b/app/views/layouts/reports/template_values_editor.html.erb @@ -0,0 +1,21 @@ +

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

+

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

+ +

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

+<%= yield :header %> + +

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

+<%= yield :cover %> + +

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

+<%= yield :footer %> diff --git a/app/views/reports/new.html.erb b/app/views/reports/new.html.erb index a7f92c7b3..b1cdf6c1c 100644 --- a/app/views/reports/new.html.erb +++ b/app/views/reports/new.html.erb @@ -16,7 +16,7 @@
- <%= render partial: 'reports/report_wizard/project_template_selector' %> + <%= render partial: 'reports/wizard/first_step' %>
Step 2 @@ -43,7 +43,7 @@

- <%= t("projects.reports.new.wizard_statuses.step_#{i + 1}") %> + <%= t("projects.reports.wizard.statuses.step_#{i + 1}") %>
diff --git a/app/views/reports/report_wizard/_project_template_selector.html.erb b/app/views/reports/report_wizard/_project_template_selector.html.erb deleted file mode 100644 index da5a51cdf..000000000 --- a/app/views/reports/report_wizard/_project_template_selector.html.erb +++ /dev/null @@ -1,26 +0,0 @@ -
-

<%= t('projects.reports.new.select_project_title') %>

-

- <%= t('projects.reports.new.select_project_description') %> -

-
-
-
- <%= label_tag :projectSelector, t('projects.reports.new.select_project') %> - <%= select_tag :projectSelector, options_from_collection_for_select(@visible_projects, :id, :name), data: { placeholder: t('projects.reports.new.select_project') } %> -
- -
- <%= label_tag :templateSelector, t('projects.reports.new.select_template') %> - <%= select_tag :templateSelector, options_for_select(@templates), data: { placeholder: t('projects.reports.new.select_template') } %> -
-
-
-
- <%= label_tag :projectDescription, t('projects.reports.new.report_description') %> - <%= text_area_tag :projectDescription, '', placeholder: t('projects.reports.new.report_description_placeholder'), class: 'sci-input-field' %> -
-
-
- -
diff --git a/app/views/reports/templates/template_1/_report.html.erb b/app/views/reports/templates/template_1/cover.html.erb similarity index 61% rename from app/views/reports/templates/template_1/_report.html.erb rename to app/views/reports/templates/template_1/cover.html.erb index a6ccbb77d..56ba711b1 100644 --- a/app/views/reports/templates/template_1/_report.html.erb +++ b/app/views/reports/templates/template_1/cover.html.erb @@ -105,20 +105,18 @@ 3. SEALS
- - - INTACT - - - - NONE - - - - BROKEN - + <%= render Reports::MultiCheckboxInputComponent.new( + report: report, + name: :seals, + label: 'Seals', + items: { + intact: 'INTACT', + broken: 'BROKEN', + none: 'NONE' + } + ) %> @@ -128,7 +126,7 @@ 4. DATE RECEIVED
- <%= template[:date_recieved] %> + <%= render Reports::DateInputComponent.new(report: report, name: :date_recieved, label: 'Date recieved', editing: false) %>
@@ -136,7 +134,7 @@ 5.RECEIVED FROM
- <%= template[:recieved_from] %> + <%= render Reports::TextInputComponent.new(report: report, name: :recieved_from, label: 'Received from', editing: false) %>
@@ -144,7 +142,7 @@ 6. DISTRICT OR LABORATORY
- <%= template[:district_laboratory] %> + <%= render Reports::TextInputComponent.new(report: report, name: :district_laboratory, label: 'District or laboratory', editing: false) %>
@@ -154,7 +152,7 @@ 7. DESCRIPTION OF SAMPLE
- <%= template[:sample_description] %> + <%= render Reports::LargeTextInputComponent.new(report: report, name: :sample_description, label: 'Descripton of sample', editing: false) %>
@@ -168,21 +166,37 @@ - + - + - - + +
- + <%= render Reports::CheckboxInputComponent.new(report: report, name: :not_applicable, label: 'Not applicable', editing: false) %> NOT APPLICABLE DECLARE/UNIT <%= template.dig(:net_contents, :declare_unit) %> + DECLARE/UNIT + <%= render Reports::TextInputComponent.new(report: report, name: :declare_unit, label: 'Declare unit', editing: false) %> + +
- + <%= render Reports::CheckboxInputComponent.new(report: report, name: :not_determined, label: 'Not determined', editing: false) %> NOT DETERMINED AMOUNT FOUND <%= template.dig(:net_contents, :amount_found) %>AMOUNT FOUND + + <%= render Reports::TextInputComponent.new(report: report, name: :amount_found, label: 'Amount found', editing: false) %> + +
<%= template.dig(:net_contents, :units_examined) %> UNITS EXAMINED% of DECLARED <%= template.dig(:net_contents, :declared_percent) %> + + <%= render Reports::TextInputComponent.new(report: report, name: :units_examined, label: 'Units examined', editing: false) %> + UNITS EXAMINED + % of DECLARED + + <%= render Reports::TextInputComponent.new(report: report, name: :percent_of_declared, label: 'Percent of declared', editing: false) %> + +
@@ -195,17 +209,21 @@ @@ -218,7 +236,7 @@ 10. SUMMARY OF ANALYSIS
- <%= template[:analysis_summary] %> + <%= render Reports::LargeTextInputComponent.new(report: report, name: :analysis_summary, label: 'Summary of analysis', editing: false) %>
@@ -235,10 +253,10 @@ @@ -261,7 +279,7 @@ b. DATE
- <%= template.dig(:worksheet_check, :date) %> + <%= render Reports::DateInputComponent.new(report: report, name: :worksheet_check_date, label: 'Worksheet check date', editing: false) %>
@@ -271,7 +289,7 @@ b.
- <%= template.dig(:analyst_signature, :b) %> + <%= render Reports::TextInputComponent.new(report: report, name: :analyst_signature_b, label: 'Analyst signature B', editing: false) %>
@@ -289,7 +307,7 @@ c.
- <%= template.dig(:analyst_signature, :c) %> + <%= render Reports::TextInputComponent.new(report: report, name: :analyst_signature_c, label: 'Analyst signature C', editing: false) %>
diff --git a/app/views/reports/wizard/_first_step.html.erb b/app/views/reports/wizard/_first_step.html.erb new file mode 100644 index 000000000..69b0a3242 --- /dev/null +++ b/app/views/reports/wizard/_first_step.html.erb @@ -0,0 +1,5 @@ +
+ <%= render partial: 'reports/wizard/project_template_selector' %> +
+
+
diff --git a/app/views/reports/wizard/_no_template_values.html.erb b/app/views/reports/wizard/_no_template_values.html.erb new file mode 100644 index 000000000..bed919b36 --- /dev/null +++ b/app/views/reports/wizard/_no_template_values.html.erb @@ -0,0 +1,6 @@ +

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

+

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

diff --git a/app/views/reports/wizard/_project_template_selector.html.erb b/app/views/reports/wizard/_project_template_selector.html.erb new file mode 100644 index 000000000..ce66776cb --- /dev/null +++ b/app/views/reports/wizard/_project_template_selector.html.erb @@ -0,0 +1,28 @@ +

<%= t('projects.reports.wizard.first_step.select_project_title') %>

+

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

+
+
+
+ <%= label_tag :projectSelector, t('projects.reports.wizard.first_step.select_project') %> + <%= select_tag :projectSelector, options_from_collection_for_select(@visible_projects, :id, :name), data: { placeholder: t('projects.reports.wizard.first_step.select_project') } %> +
+ +
+ <%= label_tag :templateSelector, t('projects.reports.wizard.first_step.select_template') %> + <%= select_tag :templateSelector, + options_for_select(@templates), + data: { + placeholder: t('projects.reports.wizard.first_step.select_template'), + values_editor_path: reports_new_template_values_path + } %> +
+
+
+
+ <%= label_tag :projectDescription, t('projects.reports.wizard.first_step.report_description') %> + <%= text_area_tag :projectDescription, '', placeholder: t('projects.reports.wizard.first_step.report_description_placeholder'), class: 'sci-input-field' %> +
+
+
diff --git a/bin/rails b/bin/rails index 073966023..6fb4e4051 100755 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,4 @@ #!/usr/bin/env ruby APP_PATH = File.expand_path('../config/application', __dir__) -require_relative '../config/boot' -require 'rails/commands' +require_relative "../config/boot" +require "rails/commands" diff --git a/bin/rake b/bin/rake index 17240489f..4fbf10b96 100755 --- a/bin/rake +++ b/bin/rake @@ -1,4 +1,4 @@ #!/usr/bin/env ruby -require_relative '../config/boot' -require 'rake' +require_relative "../config/boot" +require "rake" Rake.application.run diff --git a/bin/setup b/bin/setup index 5853b5ea8..90700ac4f 100755 --- a/bin/setup +++ b/bin/setup @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -require 'fileutils' +require "fileutils" # path to your application root. APP_ROOT = File.expand_path('..', __dir__) @@ -9,8 +9,8 @@ def system!(*args) end FileUtils.chdir APP_ROOT do - # This script is a way to setup or update your development environment automatically. - # This script is idempotent, so that you can run it at anytime and get an expectable outcome. + # This script is a way to set up or update your development environment automatically. + # This script is idempotent, so that you can run it at any time and get an expectable outcome. # Add necessary setup steps to this file. puts '== Installing dependencies ==' @@ -18,7 +18,7 @@ FileUtils.chdir APP_ROOT do system('bundle check') || system!('bundle install') # Install JavaScript dependencies - # system('bin/yarn') + system! 'bin/yarn' # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') diff --git a/bin/yarn b/bin/yarn index 460dd565b..4700a9e63 100755 --- a/bin/yarn +++ b/bin/yarn @@ -1,9 +1,15 @@ #!/usr/bin/env ruby APP_ROOT = File.expand_path('..', __dir__) Dir.chdir(APP_ROOT) do - begin - exec "yarnpkg", *ARGV - rescue Errno::ENOENT + yarn = ENV["PATH"].split(File::PATH_SEPARATOR). + select { |dir| File.expand_path(dir) != __dir__ }. + product(["yarn", "yarn.exe"]). + map { |dir, file| File.expand_path(file, dir) }. + find { |file| File.executable?(file) } + + if yarn + exec yarn, *ARGV + else $stderr.puts "Yarn executable was not detected in the system." $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" exit 1 diff --git a/config.ru b/config.ru index bd83b2541..4afdd9c0b 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,5 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) +require_relative "config/environment" run Rails.application +Rails.application.load_server diff --git a/config/boot.rb b/config/boot.rb index b9e460cef..3cda23b4d 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,4 +1,4 @@ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) -require 'bundler/setup' # Set up gems listed in the Gemfile. -require 'bootsnap/setup' # Speed up boot time by caching expensive operations. +require "bundler/setup" # Set up gems listed in the Gemfile. +require "bootsnap/setup" # Speed up boot time by caching expensive operations. diff --git a/config/environments/development.rb b/config/environments/development.rb index f0641f6e0..9ef4dd11b 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/integer/time' + Rails.application.configure do # Verifies that versions and hashed value of the package contents in the project's package.json config.webpacker.check_yarn_integrity = true @@ -52,6 +54,12 @@ Rails.application.configure do # Store uploaded files on the local file system (see config/storage.yml for options) config.active_storage.service = ENV['ACTIVESTORAGE_SERVICE'] || :local + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false @@ -90,11 +98,17 @@ Rails.application.configure do BetterErrors::Middleware.allow_ip! ENV['TRUSTED_IP'] if ENV['TRUSTED_IP'] # Suppress logger output for asset requests. - config.assets.quiet = false + config.assets.quiet = true # Raises error for missing translations config.action_view.raise_on_missing_translations = true + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true + + # Uncomment if you wish to allow Action Cable access from any origin. + # config.action_cable.disable_request_forgery_protection = true + # Enable/disable Deface config.deface.enabled = ENV['DEFACE_ENABLED'] != 'false' diff --git a/config/environments/production.rb b/config/environments/production.rb index 71952274e..746e7ed23 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -51,6 +51,11 @@ Rails.application.configure do # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). # config.require_master_key = true + # Log disallowed deprecations. + config.active_support.disallowed_deprecation = :log + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] # Compress JavaScripts and CSS. config.assets.js_compressor = Uglifier.new(harmony: true) @@ -85,9 +90,6 @@ Rails.application.configure do # Prepend all log lines with the following tags. config.log_tags = [ :request_id ] - - - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true @@ -125,12 +127,36 @@ Rails.application.configure do # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false + if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end + # Inserts middleware to perform automatic connection switching. + # The `database_selector` hash is used to pass options to the DatabaseSelector + # middleware. The `delay` is used to determine how long to wait after a write + # to send a subsequent read to the primary. + # + # The `database_resolver` class is used by the middleware to determine which + # database is appropriate to use based on the time delay. + # + # The `database_resolver_context` class is used by the middleware to set + # timestamps for the last write to the primary. The resolver uses the context + # class timestamps to determine how long to wait before reading from the + # replica. + # + # By default Rails will store a last write timestamp in the session. The + # DatabaseSelector middleware is designed as such you can define your own + # strategy for connection switching and pass that into the middleware through + # these configuration options. + # config.active_record.database_selector = { delay: 2.seconds } + # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver + # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session + # Use a different cache store in production. config.cache_store = :memory_store, { size: (ENV['RAILS_MEM_CACHE_SIZE_MB'] || 32).to_i.megabytes } diff --git a/config/environments/test.rb b/config/environments/test.rb index 163000877..8db68488b 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -43,6 +43,12 @@ Rails.application.configure do # Store uploaded files on the local file system in a temporary directory config.active_storage.service = :test + # Log disallowed deprecations. + config.active_support.disallowed_deprecation = :log + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. @@ -71,6 +77,9 @@ Rails.application.configure do # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true + # Enable/disable Deface config.deface.enabled = ENV['DEFACE_ENABLED'] != 'false' diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index 8117bb34b..11016743a 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -1,7 +1,7 @@ # Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. -# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } +# Rails.backtrace_cleaner.add_silencer { |line| /my_noisy_library/.match?(line) } # Silence the WOPI method override to prevent "trapping" of stack/backtrace # See https://stackoverflow.com/questions/29498145 @@ -9,5 +9,6 @@ Rails.backtrace_cleaner.add_silencer do |line| line =~ %r{app/middlewares/wopi_method_override} end -# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. -# Rails.backtrace_cleaner.remove_silencers! +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code +# by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'". +Rails.backtrace_cleaner.remove_silencers! if ENV['BACKTRACE'] diff --git a/config/initializers/extends.rb b/config/initializers/extends.rb index 0f848b35c..7b53d5e83 100644 --- a/config/initializers/extends.rb +++ b/config/initializers/extends.rb @@ -419,4 +419,8 @@ class Extends { name: 'In progress', color: '#0065ff', consequences: ['MyModuleStatusConsequences::Uncompletion'] }, { name: 'Completed', color: '#00b900', consequences: ['MyModuleStatusConsequences::Completion'] } ] + + REPORT_TEMPLATES = { + template_1: 'template_1' + } end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 156ba453d..208fba72b 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,4 +1,6 @@ # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. -Rails.application.config.filter_parameters += [:password, :image, /^avatar$/] +Rails.application.config.filter_parameters += [ + :password, :image, /^avatar$/, :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +] diff --git a/config/initializers/new_framework_defaults_6_1.rb b/config/initializers/new_framework_defaults_6_1.rb new file mode 100644 index 000000000..9526b835a --- /dev/null +++ b/config/initializers/new_framework_defaults_6_1.rb @@ -0,0 +1,67 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 6.1 upgrade. +# +# Once upgraded flip defaults one by one to migrate to the new default. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. + +# Support for inversing belongs_to -> has_many Active Record associations. +# Rails.application.config.active_record.has_many_inversing = true + +# Track Active Storage variants in the database. +# Rails.application.config.active_storage.track_variants = true + +# Apply random variation to the delay when retrying failed jobs. +# Rails.application.config.active_job.retry_jitter = 0.15 + +# Stop executing `after_enqueue`/`after_perform` callbacks if +# `before_enqueue`/`before_perform` respectively halts with `throw :abort`. +# Rails.application.config.active_job.skip_after_callbacks_if_terminated = true + +# Specify cookies SameSite protection level: either :none, :lax, or :strict. +# +# This change is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 6.1. +# Rails.application.config.action_dispatch.cookies_same_site_protection = :lax + +# Generate CSRF tokens that are encoded in URL-safe Base64. +# +# This change is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 6.1. +# Rails.application.config.action_controller.urlsafe_csrf_tokens = true + +# Specify whether `ActiveSupport::TimeZone.utc_to_local` returns a time with an +# UTC offset or a UTC time. +# ActiveSupport.utc_to_local_returns_utc_offset_times = true + +# Change the default HTTP status code to `308` when redirecting non-GET/HEAD +# requests to HTTPS in `ActionDispatch::SSL` middleware. +# Rails.application.config.action_dispatch.ssl_default_redirect_status = 308 + +# Use new connection handling API. For most applications this won't have any +# effect. For applications using multiple databases, this new API provides +# support for granular connection swapping. +# Rails.application.config.active_record.legacy_connection_handling = false + +# Make `form_with` generate non-remote forms by default. +# Rails.application.config.action_view.form_with_generates_remote_forms = false + +# Set the default queue name for the analysis job to the queue adapter default. +# Rails.application.config.active_storage.queues.analysis = nil + +# Set the default queue name for the purge job to the queue adapter default. +# Rails.application.config.active_storage.queues.purge = nil + +# Set the default queue name for the incineration job to the queue adapter default. +# Rails.application.config.action_mailbox.queues.incineration = nil + +# Set the default queue name for the routing job to the queue adapter default. +# Rails.application.config.action_mailbox.queues.routing = nil + +# Set the default queue name for the mail deliver job to the queue adapter default. +# Rails.application.config.action_mailer.deliver_later_queue_name = nil + +# Generate a `Link` header that gives a hint to modern browsers about +# preloading assets when using `javascript_include_tag` and `stylesheet_link_tag`. +# Rails.application.config.action_view.preload_links_header = true diff --git a/config/initializers/permissions_policy.rb b/config/initializers/permissions_policy.rb new file mode 100644 index 000000000..00f64d71b --- /dev/null +++ b/config/initializers/permissions_policy.rb @@ -0,0 +1,11 @@ +# Define an application-wide HTTP permissions policy. For further +# information see https://developers.google.com/web/updates/2018/06/feature-policy +# +# Rails.application.config.permissions_policy do |f| +# f.camera :none +# f.gyroscope :none +# f.microphone :none +# f.usb :none +# f.fullscreen :self +# f.payment :self, "https://secure.example.com" +# end diff --git a/config/locales/en.yml b/config/locales/en.yml index 15aac0d10..2de621e11 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -512,32 +512,34 @@ en: error: "Error" generating: "Generating" generate: "Generate" - modal_new: - projects: "Projects" - head_title: "Create new report" - no_projects: "No projects available." - message: "You are about to create a new report. Please select a project from which you would like to create a report." - create: "Create" modal_delete: head_title: "Delete report/s" message: "Are you sure to delete selected report/s?" delete: "Delete" - new: - report_name_placeholder: "Name your report" - wizard_statuses: + wizard: + statuses: step_1: "Select project" step_2: "Select tasks" step_3: "Select task contents" + first_step: + select_project_title: "Select project and report template" + select_project_description: "You are about to create a new report. Please select a project from which you would like to create a report, and a report template to define the desing of the report. Only projects with at least 1 task are displayed." + select_project: "Select project" + select_template: "Select template" + report_description: "Report description (optional)" + report_description_placeholder: "In this report you can see..." + values_editor: + title: "Enter template data" + 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" + no_values_title: "No additional data requiered" + no_values_description: "SciNote template doesn’t need any additional input for it to be succesfully generated." + new: + report_name_placeholder: "Name your report" continue_button: "Continue" generate_button: "Start generating" - select_project_title: "Select project and report template" - select_project_description: "You are about to create a new report. Please select a project from which you would like to create a report, and a report template to define the desing of the report. Only projects with at least 1 task are displayed." - select_project: "Select project" - select_template: "Select template" - report_description: "Report description (optional)" - report_description_placeholder: "In this report you can see..." - - head_title: "%{project} | New report" nav_title: "Report for: " nav_print: "Print" diff --git a/config/routes.rb b/config/routes.rb index 31683c625..0ed5723b0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -196,8 +196,7 @@ Rails.application.routes.draw do resources :reports, only: [:index, :new] get 'reports/datatable', to: 'reports#datatable' - post 'reports/visible_projects', to: 'reports#visible_projects', - defaults: { format: 'json' } + get 'reports/new_template_values', to: 'reports#new_template_values', defaults: { format: 'json' } post 'reports/available_repositories', to: 'reports#available_repositories', defaults: { format: 'json' } post 'reports/save_pdf_to_inventory_item', diff --git a/db/migrate/20210325152257_add_report_template_values.rb b/db/migrate/20210325152257_add_report_template_values.rb new file mode 100644 index 000000000..204900f53 --- /dev/null +++ b/db/migrate/20210325152257_add_report_template_values.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AddReportTemplateValues < ActiveRecord::Migration[6.1] + def change + create_table :report_template_values do |t| + t.references :report, null: false, index: true, foreign_key: true + t.string :view_component, null: false + t.string :name, null: false + t.jsonb :value, null: false, default: {} + t.timestamps + + t.index %i(view_component name), name: 'index_report_template_values_on_view_component_name' + end + end +end diff --git a/db/structure.sql b/db/structure.sql index 427f6bd4c..22d563f42 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1259,6 +1259,40 @@ CREATE SEQUENCE public.report_elements_id_seq ALTER SEQUENCE public.report_elements_id_seq OWNED BY public.report_elements.id; +-- +-- Name: report_template_values; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.report_template_values ( + id bigint NOT NULL, + report_id bigint NOT NULL, + view_component character varying NOT NULL, + name character varying NOT NULL, + value jsonb DEFAULT '{}'::jsonb NOT NULL, + created_at timestamp(6) without time zone NOT NULL, + updated_at timestamp(6) without time zone NOT NULL +); + + +-- +-- Name: report_template_values_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.report_template_values_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: report_template_values_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.report_template_values_id_seq OWNED BY public.report_template_values.id; + + -- -- Name: reports; Type: TABLE; Schema: public; Owner: - -- @@ -3072,6 +3106,13 @@ ALTER TABLE ONLY public.protocols ALTER COLUMN id SET DEFAULT nextval('public.pr ALTER TABLE ONLY public.report_elements ALTER COLUMN id SET DEFAULT nextval('public.report_elements_id_seq'::regclass); +-- +-- Name: report_template_values id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.report_template_values ALTER COLUMN id SET DEFAULT nextval('public.report_template_values_id_seq'::regclass); + + -- -- Name: reports id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3650,6 +3691,14 @@ ALTER TABLE ONLY public.report_elements ADD CONSTRAINT report_elements_pkey PRIMARY KEY (id); +-- +-- Name: report_template_values report_template_values_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.report_template_values + ADD CONSTRAINT report_template_values_pkey PRIMARY KEY (id); + + -- -- Name: reports reports_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -4810,6 +4859,20 @@ CREATE INDEX index_report_elements_on_step_id ON public.report_elements USING bt CREATE INDEX index_report_elements_on_table_id ON public.report_elements USING btree (table_id); +-- +-- Name: index_report_template_values_on_report_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_report_template_values_on_report_id ON public.report_template_values USING btree (report_id); + + +-- +-- Name: index_report_template_values_on_view_component_name; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_report_template_values_on_view_component_name ON public.report_template_values USING btree (view_component, name); + + -- -- Name: index_reports_on_description; Type: INDEX; Schema: public; Owner: - -- @@ -5982,6 +6045,14 @@ ALTER TABLE ONLY public.repository_number_values ADD CONSTRAINT fk_rails_3df53c9b27 FOREIGN KEY (created_by_id) REFERENCES public.users(id); +-- +-- Name: report_template_values fk_rails_423a0bad87; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.report_template_values + ADD CONSTRAINT fk_rails_423a0bad87 FOREIGN KEY (report_id) REFERENCES public.reports(id); + + -- -- Name: my_modules fk_rails_4768515e2e; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -7159,6 +7230,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20210128105457'), ('20210128105458'), ('20210217114042'), -('20210312185911'); +('20210312185911'), +('20210325152257');
- <%= template.dig(:labeling, :originals_submitted) %> ORIGINAL(S) SUBMITTED + + <%= render Reports::TextInputComponent.new(report: report, name: :originals_submitted, label: 'Original(s) submitted', editing: false) %> + ORIGINAL(S) SUBMITTED
- <%= template.dig(:labeling, :copies_submitted) %> COPIES SUBMITTED + + <%= render Reports::TextInputComponent.new(report: report, name: :copies_submitted, label: 'Copies submitted', editing: false) %> + COPIES SUBMITTED
- + <%= render Reports::CheckboxInputComponent.new(report: report, name: :labeling_none, label: 'None', editing: false) %> NONE
- 12. a. ANALYST SIGNATURE (Broke Seal ) + 12. a. ANALYST SIGNATURE (Broke Seal <%= render Reports::CheckboxInputComponent.new(report: report, name: :analyst_signature_broke, label: 'Broke seal', editing: false) %>)
- <%= template.dig(:analyst_signature, :a) %> + <%= render Reports::TextInputComponent.new(report: report, name: :analyst_signature_a, label: 'Analyst signature A', editing: false) %>
@@ -251,7 +269,7 @@ a. BY
- <%= template.dig(:worksheet_check, :by) %> + <%= render Reports::TextInputComponent.new(report: report, name: :worksheet_check_by, label: 'Worksheet check by', editing: false) %>
@@ -279,7 +297,7 @@ 13. DATE REPORTED
- <%= template[:date_reported] %> + <%= render Reports::DateInputComponent.new(report: report, name: :date_reported, label: 'Date reported', editing: false) %>
diff --git a/app/views/reports/templates/template_1/edit.html.erb b/app/views/reports/templates/template_1/edit.html.erb new file mode 100644 index 000000000..49eec9e98 --- /dev/null +++ b/app/views/reports/templates/template_1/edit.html.erb @@ -0,0 +1,47 @@ +<% content_for :header do %> + <%= render Reports::TextInputComponent.new(report: report, name: :product, label: 'Product') %> + <%= render Reports::TextInputComponent.new(report: report, name: :sample_number, label: 'Sample number') %> +<% end %> + +<% content_for :cover do %> + <%= render Reports::MultiCheckboxInputComponent.new( + report: report, + name: :seals, + label: 'Seals', + items: { + intact: 'Intact', + broken: 'Broken', + none: 'None' + } + ) %> + <%= render Reports::DateInputComponent.new(report: report, name: :date_recieved, label: 'Date recieved') %> + <%= render Reports::TextInputComponent.new(report: report, name: :recieved_from, label: 'Received from') %> + <%= render Reports::TextInputComponent.new(report: report, name: :district_laboratory, label: 'District or laboratory') %> + <%= render Reports::LargeTextInputComponent.new(report: report, name: :sample_description, label: 'Descripton of sample') %> + + <%= render Reports::TextInputComponent.new(report: report, name: :units_examined, label: 'Units examined') %> + <%= render Reports::TextInputComponent.new(report: report, name: :declare_unit, label: 'Declare unit') %> + <%= render Reports::TextInputComponent.new(report: report, name: :amount_found, label: 'Amount found') %> + <%= render Reports::TextInputComponent.new(report: report, name: :percent_of_declared, label: 'Percent of declared') %> + <%= render Reports::CheckboxInputComponent.new(report: report, name: :not_applicable, label: 'Not applicable') %> + <%= render Reports::CheckboxInputComponent.new(report: report, name: :not_determined, label: 'Not determined') %> + + <%= render Reports::TextInputComponent.new(report: report, name: :originals_submitted, label: 'Original(s) submitted') %> + <%= render Reports::TextInputComponent.new(report: report, name: :copies_submitted, label: 'Copies submitted') %> + <%= render Reports::CheckboxInputComponent.new(report: report, name: :labeling_none, label: 'None') %> + <%= render Reports::LargeTextInputComponent.new(report: report, name: :analysis_summary, label: 'Summary of analysis') %> + + <%= render Reports::CheckboxInputComponent.new(report: report, name: :analyst_signature_broke, label: 'Broke seal') %> + <%= render Reports::TextInputComponent.new(report: report, name: :analyst_signature_a, label: 'Analyst signature A') %> + <%= render Reports::TextInputComponent.new(report: report, name: :analyst_signature_b, label: 'Analyst signature B') %> + <%= render Reports::TextInputComponent.new(report: report, name: :analyst_signature_c, label: 'Analyst signature C') %> + <%= render Reports::TextInputComponent.new(report: report, name: :worksheet_check_by, label: 'Worksheet check by') %> + <%= render Reports::DateInputComponent.new(report: report, name: :worksheet_check_date, label: 'Worksheet check date') %> + <%= render Reports::DateInputComponent.new(report: report, name: :date_reported, label: 'Date reported') %> +<% end %> + +<% content_for :footer do %> + <%= render Reports::TeamMemberInputComponent.new(report: report, name: :analyst, label: 'Analyst', team: current_team) %> + <%= render Reports::TextInputComponent.new(report: report, name: :analyst_number, label: 'Employee number') %> + <%= render Reports::TeamMemberInputComponent.new(report: report, name: :checked_by, label: 'Checked by', team: current_team) %> +<% end %> diff --git a/app/views/reports/templates/template_1/_footer.html.erb b/app/views/reports/templates/template_1/footer.html.erb similarity index 74% rename from app/views/reports/templates/template_1/_footer.html.erb rename to app/views/reports/templates/template_1/footer.html.erb index b57aa1432..39973e5fb 100644 --- a/app/views/reports/templates/template_1/_footer.html.erb +++ b/app/views/reports/templates/template_1/footer.html.erb @@ -44,7 +44,7 @@ ANALYST(S)
- <%= template[:analysts] %> + <%= render Reports::TeamMemberInputComponent.new(report: report, name: :analyst, label: 'Analyst', editing: false, team: current_team) %>
@@ -52,7 +52,7 @@ ANALYST EMPLOYEE NO.
- <%= template[:analyst_number] %> + <%= render Reports::TextInputComponent.new(report: report, name: :analyst_number, label: 'Employee number', editing: false) %>
@@ -60,7 +60,7 @@ CHECKED BY:
- <%= template[:checked_by] %> + <%= render Reports::TeamMemberInputComponent.new(report: report, name: :checked_by, label: 'Checked by', editing: false, team: current_team) %>
diff --git a/app/views/reports/templates/template_1/_header.html.erb b/app/views/reports/templates/template_1/header.html.erb similarity index 76% rename from app/views/reports/templates/template_1/_header.html.erb rename to app/views/reports/templates/template_1/header.html.erb index fa0df479f..709b38d76 100644 --- a/app/views/reports/templates/template_1/_header.html.erb +++ b/app/views/reports/templates/template_1/header.html.erb @@ -37,7 +37,7 @@ PRODUCT
- <%= template[:product] %> + <%= render Reports::TextInputComponent.new(report: report, name: :product, label: 'Product', editing: false) %>
@@ -45,7 +45,7 @@ SAMPLE NUMBER
- <%= template[:sample_number] %> + <%= render Reports::TextInputComponent.new(report: report, name: :sample_number, label: 'Sample number', editing: false) %>