From ad8e404bcab042922763d5a78cd54faa1ce4263d Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Tue, 30 Mar 2021 13:40:36 +0200 Subject: [PATCH 1/3] Add template partials to reports [SCI-5571] --- app/controllers/reports_controller.rb | 16 +- .../templates/template_1/_footer.html.erb | 93 ++++++ .../templates/template_1/_header.html.erb | 61 ++++ .../templates/template_1/_report.html.erb | 300 ++++++++++++++++++ 4 files changed, 465 insertions(+), 5 deletions(-) create mode 100644 app/views/reports/templates/template_1/_footer.html.erb create mode 100644 app/views/reports/templates/template_1/_header.html.erb create mode 100644 app/views/reports/templates/template_1/_report.html.erb diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 836106386..9599f551c 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -146,14 +146,20 @@ class ReportsController < ApplicationController def generate content = params[:data] content = I18n.t('projects.reports.new.no_content_for_PDF_html') if content.blank? + + template = {} + respond_to do |format| format.pdf do - render pdf: 'report', header: { html: { template: 'reports/header.pdf.erb' }}, - footer: { html: { template: 'reports/footer.pdf.erb', - locals: { current_time: I18n.l(Time.zone.now, format: :full) }}}, + render pdf: 'report', header: { html: { template: 'reports/templates/template_1/_header.html.erb', locals: {template: template} }}, + footer: { html: { template: 'reports/templates/template_1/_footer.html.erb', locals: {template: template} }}, locals: { content: content }, - template: 'reports/report.pdf.erb', - disable_javascript: true + cover: render_to_string(partial: 'reports/templates/template_1/report.html.erb', + locals: { + template: template + }), + disable_javascript: true, + template: 'reports/report.pdf.erb' end format.docx do @user = current_user diff --git a/app/views/reports/templates/template_1/_footer.html.erb b/app/views/reports/templates/template_1/_footer.html.erb new file mode 100644 index 000000000..c7a4d0f52 --- /dev/null +++ b/app/views/reports/templates/template_1/_footer.html.erb @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + +
+
+ ANALYST(S) +
+
+ <%= template[:analysts] %> +
+
+
+ ANALYST EMPLOYEE NO. +
+
+ <%= template[:analyst_number] %> +
+
+
+ CHECKED BY: +
+
+ <%= template[:checked_by] %> +
+
+ PAGE OF +
Single-Sided
+ + diff --git a/app/views/reports/templates/template_1/_header.html.erb b/app/views/reports/templates/template_1/_header.html.erb new file mode 100644 index 000000000..cd617006a --- /dev/null +++ b/app/views/reports/templates/template_1/_header.html.erb @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + +
+ GENERAL CONTINUATION SHEET + +
+ PRODUCT +
+
+ <%= template[:product] %> +
+
+
+ SAMPLE NUMBER +
+
+ <%= template[:sample_number] %> +
+
+ + diff --git a/app/views/reports/templates/template_1/_report.html.erb b/app/views/reports/templates/template_1/_report.html.erb new file mode 100644 index 000000000..a6ccbb77d --- /dev/null +++ b/app/views/reports/templates/template_1/_report.html.erb @@ -0,0 +1,300 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ ANALYST WORKSHEET + +
+ 1. PRODUCT +
+
+ <%= template[:product] %> +
+
+
+ 2. SAMPLE NUMBER +
+
+ <%= template[:sample_number] %> +
+
+ + + + + + + + + + +
+
+ 3. SEALS +
+
+ + INTACT +
+ + NONE + + + BROKEN +
+
+
+ 4. DATE RECEIVED +
+
+ <%= template[:date_recieved] %> +
+
+
+ 5.RECEIVED FROM +
+
+ <%= template[:recieved_from] %> +
+
+
+ 6. DISTRICT OR LABORATORY +
+
+ <%= template[:district_laboratory] %> +
+
+
+ 7. DESCRIPTION OF SAMPLE +
+
+ <%= template[:sample_description] %> +
+
+
+ 8. NET CONTENTS +
+
+ + + + + + + + + + + + + +
+ + NOT APPLICABLE + DECLARE/UNIT <%= template.dig(:net_contents, :declare_unit) %>
+ + NOT DETERMINED + AMOUNT FOUND <%= template.dig(:net_contents, :amount_found) %>
<%= template.dig(:net_contents, :units_examined) %> UNITS EXAMINED% of DECLARED <%= template.dig(:net_contents, :declared_percent) %>
+
+
+ 9. LABELING +
+
+ + + + + + + + + + +
+ <%= template.dig(:labeling, :originals_submitted) %> ORIGINAL(S) SUBMITTED +
+ <%= template.dig(:labeling, :copies_submitted) %> COPIES SUBMITTED +
+ + NONE +
+
+
+ 10. SUMMARY OF ANALYSIS +
+
+ <%= template[:analysis_summary] %> +
+
+
+ 11. RESERVE SAMPLE +
+
+ <%= template[:reserve_sample] %> +
+
+
+ 12. a. ANALYST SIGNATURE (Broke Seal ) +
+
+ <%= template.dig(:analyst_signature, :a) %> +
+
+
+ 13. WORKSHEET CHECK +
+
+
+ a. BY +
+
+ <%= template.dig(:worksheet_check, :by) %> +
+
+
+ b. DATE +
+
+ <%= template.dig(:worksheet_check, :date) %> +
+
+
+ b. +
+
+ <%= template.dig(:analyst_signature, :b) %> +
+
+
+ 13. DATE REPORTED +
+
+ <%= template[:date_reported] %> +
+
+
+ c. +
+
+ <%= template.dig(:analyst_signature, :c) %> +
+
+ PAGE 1 OF +
+
From ecca155fabeb57e26fcf66677cb56b5124ea98bf Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Tue, 30 Mar 2021 23:43:06 +0200 Subject: [PATCH 2/3] Added layout for footer and header [SCI-5571] --- .../javascripts/reports/template_helpers.js | 16 ++ app/controllers/reports_controller.rb | 8 +- .../layouts/reports/footer_header.html.erb | 10 ++ .../templates/template_1/_footer.html.erb | 156 ++++++++---------- .../templates/template_1/_header.html.erb | 107 ++++++------ 5 files changed, 149 insertions(+), 148 deletions(-) create mode 100644 app/assets/javascripts/reports/template_helpers.js create mode 100644 app/views/layouts/reports/footer_header.html.erb diff --git a/app/assets/javascripts/reports/template_helpers.js b/app/assets/javascripts/reports/template_helpers.js new file mode 100644 index 000000000..7fa19d456 --- /dev/null +++ b/app/assets/javascripts/reports/template_helpers.js @@ -0,0 +1,16 @@ +function pageNumbers() { + var vars = {}; + var paramsKey = ['frompage', 'topage', 'page', 'webpage', 'section', 'subsection', 'subsubsection']; + var params = document.location.search.substring(1).split('&'); + + params.forEach(function(p) { + var param = p.split('=', 2); + vars[param[0]] = decodeURIComponent(param[1]); + }); + paramsKey.forEach(function(key) { + var elements = document.getElementsByClassName(key); + for(var i = 0; i < elements.length; i += 1) { + elements[i].textContent = vars[key]; + } + }); +} diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 9599f551c..0a1fca2a0 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -151,8 +151,12 @@ class ReportsController < ApplicationController respond_to do |format| format.pdf do - render pdf: 'report', header: { html: { template: 'reports/templates/template_1/_header.html.erb', locals: {template: template} }}, - footer: { html: { template: 'reports/templates/template_1/_footer.html.erb', locals: {template: template} }}, + render pdf: 'report', header: { html: { template: 'reports/templates/template_1/_header.html.erb', + locals: {template: template}, + layout: 'reports/footer_header.html.erb'}}, + footer: { html: { template: 'reports/templates/template_1/_footer.html.erb', + locals: {template: template}, + layout: 'reports/footer_header.html.erb'}}, locals: { content: content }, cover: render_to_string(partial: 'reports/templates/template_1/report.html.erb', locals: { diff --git a/app/views/layouts/reports/footer_header.html.erb b/app/views/layouts/reports/footer_header.html.erb new file mode 100644 index 000000000..b2ddb0b6c --- /dev/null +++ b/app/views/layouts/reports/footer_header.html.erb @@ -0,0 +1,10 @@ + + + + + <%= wicked_pdf_javascript_include_tag "reports/template_helpers" %> + + + <%= yield %> + + diff --git a/app/views/reports/templates/template_1/_footer.html.erb b/app/views/reports/templates/template_1/_footer.html.erb index c7a4d0f52..b57aa1432 100644 --- a/app/views/reports/templates/template_1/_footer.html.erb +++ b/app/views/reports/templates/template_1/_footer.html.erb @@ -1,93 +1,73 @@ - - - - - - - - - - - - - - - - - - -
-
- ANALYST(S) -
-
- <%= template[:analysts] %> -
-
-
- ANALYST EMPLOYEE NO. -
-
- <%= template[:analyst_number] %> -
-
-
- CHECKED BY: -
-
- <%= template[:checked_by] %> -
-
- PAGE OF -
Single-Sided
- - + .info-row td { + font-weight: bold; + text-align: center; + vertical-align: middle; + } + + + + + + + + + + + +
+
+ ANALYST(S) +
+
+ <%= template[:analysts] %> +
+
+
+ ANALYST EMPLOYEE NO. +
+
+ <%= template[:analyst_number] %> +
+
+
+ CHECKED BY: +
+
+ <%= template[:checked_by] %> +
+
+ PAGE OF +
Single-Sided
diff --git a/app/views/reports/templates/template_1/_header.html.erb b/app/views/reports/templates/template_1/_header.html.erb index cd617006a..fa0df479f 100644 --- a/app/views/reports/templates/template_1/_header.html.erb +++ b/app/views/reports/templates/template_1/_header.html.erb @@ -1,61 +1,52 @@ - - - - + - - - - - - - - -
- GENERAL CONTINUATION SHEET - -
- PRODUCT -
-
- <%= template[:product] %> -
-
-
- SAMPLE NUMBER -
-
- <%= template[:sample_number] %> -
-
- - + table td.title { + font-size: 14px; + font-weight: bold; + text-align: center; + vertical-align: middle; + white-space: nowrap; + } + + + + + + + +
+ GENERAL CONTINUATION SHEET + +
+ PRODUCT +
+
+ <%= template[:product] %> +
+
+
+ SAMPLE NUMBER +
+
+ <%= template[:sample_number] %> +
+
From d04858d26e63e13404b5c2d9a35bfe765ca9692d Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Tue, 30 Mar 2021 23:47:34 +0200 Subject: [PATCH 3/3] Fix markup [SCI-5571] --- app/assets/javascripts/reports/template_helpers.js | 4 +++- app/controllers/reports_controller.rb | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/reports/template_helpers.js b/app/assets/javascripts/reports/template_helpers.js index 7fa19d456..25b022fc7 100644 --- a/app/assets/javascripts/reports/template_helpers.js +++ b/app/assets/javascripts/reports/template_helpers.js @@ -1,3 +1,4 @@ +/* eslint-disable no-unused-vars */ function pageNumbers() { var vars = {}; var paramsKey = ['frompage', 'topage', 'page', 'webpage', 'section', 'subsection', 'subsubsection']; @@ -9,7 +10,8 @@ function pageNumbers() { }); paramsKey.forEach(function(key) { var elements = document.getElementsByClassName(key); - for(var i = 0; i < elements.length; i += 1) { + var i; + for (i = 0; i < elements.length; i += 1) { elements[i].textContent = vars[key]; } }); diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 0a1fca2a0..361263408 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -152,11 +152,11 @@ class ReportsController < ApplicationController respond_to do |format| format.pdf do render pdf: 'report', header: { html: { template: 'reports/templates/template_1/_header.html.erb', - locals: {template: template}, - layout: 'reports/footer_header.html.erb'}}, + locals: { template: template}, + layout: 'reports/footer_header.html.erb' } }, footer: { html: { template: 'reports/templates/template_1/_footer.html.erb', - locals: {template: template}, - layout: 'reports/footer_header.html.erb'}}, + locals: { template: template}, + layout: 'reports/footer_header.html.erb' } }, locals: { content: content }, cover: render_to_string(partial: 'reports/templates/template_1/report.html.erb', locals: {