Add dynamic form elements in report wizard step 1 [SCI-5591]

This commit is contained in:
Oleksii Kriuchykhin 2021-04-06 13:56:24 +02:00
parent 7115234002
commit a9ac8452f2
51 changed files with 681 additions and 115 deletions

View file

@ -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'

View file

@ -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

View file

@ -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);
});
}
});
}

View file

@ -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) {

View file

@ -0,0 +1,5 @@
# frozen_string_literal: true
class ApplicationComponent < ViewComponent::Base
def initialize; end
end

View file

@ -0,0 +1,4 @@
<div>
<%= check_box_tag @name, true %>
<%= @label %>
</div>

View file

@ -0,0 +1,6 @@
# frozen_string_literal: true
module Reports
class CheckboxInputComponent < TemplateValueComponent
end
end

View file

@ -0,0 +1,8 @@
<% if @editing %>
<div class="sci-input-container">
<%= label_tag @name, @label %>
<%= date_field_tag @name, @value, placeholder: @placeholder, class: 'sci-input-field' %>
</div>
<% else %>
<%= @value %>
<% end %>

View file

@ -0,0 +1,6 @@
# frozen_string_literal: true
module Reports
class DateInputComponent < TemplateValueComponent
end
end

View file

@ -0,0 +1,8 @@
<% if @editing %>
<div class="sci-input-container">
<%= label_tag @name, @label %>
<%= text_area_tag @name, @value, placeholder: @placeholder, class: 'sci-input-field' %>
</div>
<% else %>
<%= @value %>
<% end %>

View file

@ -0,0 +1,6 @@
# frozen_string_literal: true
module Reports
class LargeTextInputComponent < TemplateValueComponent
end
end

View file

@ -0,0 +1,11 @@
<div>
<%= label_tag "#{@name}[]", @label %>
<ul>
<% @items.each do |key, value| %>
<li>
<%= check_box_tag "#{@name}[]", key %>
<%= value %>
</li>
<% end %>
</ul>
</div>

View file

@ -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

View file

@ -0,0 +1,8 @@
<% if @editing %>
<div class="sci-input-container">
<%= label_tag @name, @label %>
<%= select_tag @name, options_from_collection_for_select(@team_members, :id, :name), placeholder: @placeholder, class: 'sci-input-field' %>
</div>
<% else %>
<%= @value %>
<% end %>

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,8 @@
<% if @editing %>
<div class="sci-input-container">
<%= label_tag @name, @label %>
<%= text_field_tag @name, @value, placeholder: @placeholder, class: 'sci-input-field input-large' %>
</div>
<% else %>
<%= @value %>
<% end %>

View file

@ -0,0 +1,6 @@
# frozen_string_literal: true
module Reports
class TextInputComponent < TemplateValueComponent
end
end

View file

@ -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

View file

@ -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

View file

@ -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: "<a href='#{report_path}'>#{sanitize_input(report.name)}</a>",
team_name: sanitize_input(report.team.name))
)
notification.create_user_notification(user)
ensure
file.close
file.unlink
end
end
end
end

View file

@ -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)

View file

@ -0,0 +1,5 @@
# frozen_string_literal: true
class ReportTemplateValue < ApplicationRecord
belongs_to :report
end

View file

@ -0,0 +1,21 @@
<h1>
<%= t('projects.reports.wizard.first_step.values_editor.title') %>
</h1>
<h3>
<%= t('projects.reports.wizard.first_step.values_editor.description') %>
</h3>
<h1>
<%= t('projects.reports.wizard.first_step.values_editor.header') %>
</h1>
<%= yield :header %>
<h1>
<%= t('projects.reports.wizard.first_step.values_editor.cover') %>
</h1>
<%= yield :cover %>
<h1>
<%= t('projects.reports.wizard.first_step.values_editor.footer') %>
</h1>
<%= yield :footer %>

View file

@ -16,7 +16,7 @@
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="new-report-step-1">
<%= render partial: 'reports/report_wizard/project_template_selector' %>
<%= render partial: 'reports/wizard/first_step' %>
</div>
<div role="tabpanel" class="tab-pane" id="new-report-step-2">
Step 2
@ -43,7 +43,7 @@
<div class="step-dot"></div><br>
<div class="step-name">
<span class=name-wrapper>
<%= t("projects.reports.new.wizard_statuses.step_#{i + 1}") %>
<%= t("projects.reports.wizard.statuses.step_#{i + 1}") %>
</span>
</div>
</div>

View file

@ -1,26 +0,0 @@
<div class="project-selector-container">
<h1><%= t('projects.reports.new.select_project_title') %></h1>
<p class="description">
<%= t('projects.reports.new.select_project_description') %>
</p>
<div class="row">
<div class="col-md-6">
<div class='project-selector'>
<%= 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') } %>
</div>
<div class='template-selector'>
<%= label_tag :templateSelector, t('projects.reports.new.select_template') %>
<%= select_tag :templateSelector, options_for_select(@templates), data: { placeholder: t('projects.reports.new.select_template') } %>
</div>
</div>
<div class="col-md-6">
<div class="sci-input-container">
<%= 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' %>
</div>
</div>
</div>
</div>

View file

@ -105,20 +105,18 @@
3. SEALS
</div>
</td>
<td>
<span class="template-checkbox <%= 'selected' if template.dig(:seals, :intact) %>"></span>
INTACT
</td>
</tr>
<tr>
<td>
<span class="template-checkbox <%= 'selected' if template.dig(:seals, :none) %>"></span>
NONE
</td>
<td>
<span class="template-checkbox <%= 'selected' if template.dig(:seals, :broken) %>"></span>
BROKEN
</td>
<%= render Reports::MultiCheckboxInputComponent.new(
report: report,
name: :seals,
label: 'Seals',
items: {
intact: 'INTACT',
broken: 'BROKEN',
none: 'NONE'
}
) %>
</tr>
<tr></tr>
</table>
@ -128,7 +126,7 @@
4. DATE RECEIVED
</div>
<div class="cell-value">
<%= template[:date_recieved] %>
<%= render Reports::DateInputComponent.new(report: report, name: :date_recieved, label: 'Date recieved', editing: false) %>
</div>
</td>
<td colspan=4>
@ -136,7 +134,7 @@
5.RECEIVED FROM
</div>
<div class="cell-value">
<%= template[:recieved_from] %>
<%= render Reports::TextInputComponent.new(report: report, name: :recieved_from, label: 'Received from', editing: false) %>
</div>
</td>
<td colspan=5>
@ -144,7 +142,7 @@
6. DISTRICT OR LABORATORY
</div>
<div class="cell-value">
<%= template[:district_laboratory] %>
<%= render Reports::TextInputComponent.new(report: report, name: :district_laboratory, label: 'District or laboratory', editing: false) %>
</div>
</td>
</tr>
@ -154,7 +152,7 @@
7. DESCRIPTION OF SAMPLE
</div>
<div class="cell-value">
<%= template[:sample_description] %>
<%= render Reports::LargeTextInputComponent.new(report: report, name: :sample_description, label: 'Descripton of sample', editing: false) %>
</div>
</td>
</tr>
@ -168,21 +166,37 @@
<table class="net-contents-table">
<tr>
<td>
<span class="template-checkbox <%= 'selected' if template.dig(:net_contents, :not_applicable) %>"></span>
<%= render Reports::CheckboxInputComponent.new(report: report, name: :not_applicable, label: 'Not applicable', editing: false) %>
NOT APPLICABLE
</td>
<td>DECLARE/UNIT <b><%= template.dig(:net_contents, :declare_unit) %></b></td>
<td>
DECLARE/UNIT <b>
<%= render Reports::TextInputComponent.new(report: report, name: :declare_unit, label: 'Declare unit', editing: false) %>
</b>
</td>
</tr>
<tr>
<td>
<span class="template-checkbox <%= 'selected' if template.dig(:net_contents, :not_determined) %>"></span>
<%= render Reports::CheckboxInputComponent.new(report: report, name: :not_determined, label: 'Not determined', editing: false) %>
NOT DETERMINED
</td>
<td>AMOUNT FOUND <b><%= template.dig(:net_contents, :amount_found) %></b></td>
<td>AMOUNT FOUND
<b>
<%= render Reports::TextInputComponent.new(report: report, name: :amount_found, label: 'Amount found', editing: false) %>
</b>
</td>
</tr>
<tr>
<td><b><%= template.dig(:net_contents, :units_examined) %></b> UNITS EXAMINED</td>
<td>% of DECLARED <b><%= template.dig(:net_contents, :declared_percent) %></b></td>
<td>
<b>
<%= render Reports::TextInputComponent.new(report: report, name: :units_examined, label: 'Units examined', editing: false) %>
</b> UNITS EXAMINED
</td>
<td>% of DECLARED
<b>
<%= render Reports::TextInputComponent.new(report: report, name: :percent_of_declared, label: 'Percent of declared', editing: false) %>
</b>
</td>
</tr>
</table>
</td>
@ -195,17 +209,21 @@
<table class="net-contents-table">
<tr>
<td>
<b><%= template.dig(:labeling, :originals_submitted) %></b> ORIGINAL(S) SUBMITTED
<b>
<%= render Reports::TextInputComponent.new(report: report, name: :originals_submitted, label: 'Original(s) submitted', editing: false) %>
</b> ORIGINAL(S) SUBMITTED
</td>
</tr>
<tr>
<td>
<b><%= template.dig(:labeling, :copies_submitted) %></b> COPIES SUBMITTED
<b>
<%= render Reports::TextInputComponent.new(report: report, name: :copies_submitted, label: 'Copies submitted', editing: false) %>
</b> COPIES SUBMITTED
</td>
</tr>
<tr>
<td>
<span class="template-checkbox <%= 'selected' if template.dig(:labeling, :none) %>"></span>
<%= render Reports::CheckboxInputComponent.new(report: report, name: :labeling_none, label: 'None', editing: false) %>
NONE
</td>
</tr>
@ -218,7 +236,7 @@
10. SUMMARY OF ANALYSIS
</div>
<div class="cell-value">
<%= template[:analysis_summary] %>
<%= render Reports::LargeTextInputComponent.new(report: report, name: :analysis_summary, label: 'Summary of analysis', editing: false) %>
</div>
</td>
</tr>
@ -235,10 +253,10 @@
<tr class="fixed-height">
<td colspan=8 rowspan=2>
<div class="cell-label">
12. a. ANALYST SIGNATURE (Broke Seal <span class="template-checkbox <%= 'selected' if template.dig(:analyst_signature, :broke) %>"></span>)
12. a. ANALYST SIGNATURE (Broke Seal <%= render Reports::CheckboxInputComponent.new(report: report, name: :analyst_signature_broke, label: 'Broke seal', editing: false) %>)
</div>
<div class="cell-value">
<%= template.dig(:analyst_signature, :a) %>
<%= render Reports::TextInputComponent.new(report: report, name: :analyst_signature_a, label: 'Analyst signature A', editing: false) %>
</div>
</td>
<td colspan=3 rowspan=2>
@ -251,7 +269,7 @@
a. BY
</div>
<div class="cell-value">
<%= template.dig(:worksheet_check, :by) %>
<%= render Reports::TextInputComponent.new(report: report, name: :worksheet_check_by, label: 'Worksheet check by', editing: false) %>
</div>
</td>
</tr>
@ -261,7 +279,7 @@
b. DATE
</div>
<div class="cell-value">
<%= template.dig(:worksheet_check, :date) %>
<%= render Reports::DateInputComponent.new(report: report, name: :worksheet_check_date, label: 'Worksheet check date', editing: false) %>
</div>
</td>
</tr>
@ -271,7 +289,7 @@
b.
</div>
<div class="cell-value">
<%= template.dig(:analyst_signature, :b) %>
<%= render Reports::TextInputComponent.new(report: report, name: :analyst_signature_b, label: 'Analyst signature B', editing: false) %>
</div>
</td>
<td colspan=8>
@ -279,7 +297,7 @@
13. DATE REPORTED
</div>
<div class="cell-value">
<%= template[:date_reported] %>
<%= render Reports::DateInputComponent.new(report: report, name: :date_reported, label: 'Date reported', editing: false) %>
</div>
</td>
</tr>
@ -289,7 +307,7 @@
c.
</div>
<div class="cell-value">
<%= template.dig(:analyst_signature, :c) %>
<%= render Reports::TextInputComponent.new(report: report, name: :analyst_signature_c, label: 'Analyst signature C', editing: false) %>
</div>
</td>
<td colspan=8 class="pagination-cell">

View file

@ -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 %>

View file

@ -44,7 +44,7 @@
<b>ANALYST(S)</b>
</div>
<div class="cell-value">
<%= template[:analysts] %>
<%= render Reports::TeamMemberInputComponent.new(report: report, name: :analyst, label: 'Analyst', editing: false, team: current_team) %>
</div>
</td>
<td colspan=2>
@ -52,7 +52,7 @@
<b>ANALYST EMPLOYEE NO.</b>
</div>
<div class="cell-value">
<%= template[:analyst_number] %>
<%= render Reports::TextInputComponent.new(report: report, name: :analyst_number, label: 'Employee number', editing: false) %>
</div>
</td>
<td colspan=3>
@ -60,7 +60,7 @@
<b>CHECKED BY:</b>
</div>
<div class="cell-value">
<%= template[:checked_by] %>
<%= render Reports::TeamMemberInputComponent.new(report: report, name: :checked_by, label: 'Checked by', editing: false, team: current_team) %>
</div>
</td>
<td colspan=2 class="pagination">

View file

@ -37,7 +37,7 @@
<b>PRODUCT</b>
</div>
<div class="cell-value">
<%= template[:product] %>
<%= render Reports::TextInputComponent.new(report: report, name: :product, label: 'Product', editing: false) %>
</div>
</td>
<td>
@ -45,7 +45,7 @@
<b>SAMPLE NUMBER</b>
</div>
<div class="cell-value">
<%= template[:sample_number] %>
<%= render Reports::TextInputComponent.new(report: report, name: :sample_number, label: 'Sample number', editing: false) %>
</div>
</td>
</tr>

View file

@ -0,0 +1,5 @@
<div class="project-selector-container">
<%= render partial: 'reports/wizard/project_template_selector' %>
</div>
<div class="report-template-values-container">
</div>

View file

@ -0,0 +1,6 @@
<h1>
<%= t('projects.reports.wizard.first_step.values_editor.no_values_title') %>
</h1>
<h3>
<%= t('projects.reports.wizard.first_step.values_editor.no_values_description') %>
</h3>

View file

@ -0,0 +1,28 @@
<h1><%= t('projects.reports.wizard.first_step.select_project_title') %></h1>
<p class="description">
<%= t('projects.reports.wizard.first_step.select_project_description') %>
</p>
<div class="row">
<div class="col-md-6">
<div class='project-selector'>
<%= 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') } %>
</div>
<div class='template-selector'>
<%= 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
} %>
</div>
</div>
<div class="col-md-6">
<div class="sci-input-container">
<%= 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' %>
</div>
</div>
</div>

View file

@ -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"

View file

@ -1,4 +1,4 @@
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
require_relative "../config/boot"
require "rake"
Rake.application.run

View file

@ -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')

View file

@ -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

View file

@ -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

View file

@ -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.

View file

@ -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'

View file

@ -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 }

View file

@ -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'

View file

@ -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']

View file

@ -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

View file

@ -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
]

View file

@ -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

View file

@ -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

View file

@ -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 doesnt 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"

View file

@ -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',

View file

@ -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

View file

@ -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');