Merge pull request #3241 from aignatov-bio/ai-sci-5571-add-template-partial-to-report

Add template partials to reports [SCI-5571]
This commit is contained in:
Alex Kriuchykhin 2021-03-31 11:36:56 +02:00 committed by GitHub
commit c9688a58f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 468 additions and 5 deletions

View file

@ -0,0 +1,18 @@
/* eslint-disable no-unused-vars */
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);
var i;
for (i = 0; i < elements.length; i += 1) {
elements[i].textContent = vars[key];
}
});
}

View file

@ -144,14 +144,24 @@ 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},
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 },
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

View file

@ -0,0 +1,10 @@
<!doctype html>
<html>
<head>
<meta charset='utf-8' />
<%= wicked_pdf_javascript_include_tag "reports/template_helpers" %>
</head>
<body onload="pageNumbers()">
<%= yield %>
</body>
</html>

View file

@ -0,0 +1,73 @@
<style>
body {
height: 95px;
}
table {
border-collapse: collapse;
border-spacing: 0;
height: 80px;
table-layout: fixed;
width: 100%
}
table td {
border: 2px solid black;
font-size: 12px;
padding: .25em;
text-align: left;
vertical-align: top;
}
table td.pagination {
font-size: 14px;
font-weight: bold;
text-align: center;
vertical-align: middle;
white-space: nowrap;
}
.info-row {
height: 15px;
}
.info-row td {
font-weight: bold;
text-align: center;
vertical-align: middle;
}
</style>
<table>
<tr>
<td colspan=3>
<div class="cell-label">
<b>ANALYST(S)</b>
</div>
<div class="cell-value">
<%= template[:analysts] %>
</div>
</td>
<td colspan=2>
<div class="cell-label">
<b>ANALYST EMPLOYEE NO.</b>
</div>
<div class="cell-value">
<%= template[:analyst_number] %>
</div>
</td>
<td colspan=3>
<div class="cell-label">
<b>CHECKED BY:</b>
</div>
<div class="cell-value">
<%= template[:checked_by] %>
</div>
</td>
<td colspan=2 class="pagination">
PAGE <span class="page"></span> OF <span class="topage"></span>
</td>
</tr>
<tr class="info-row">
<td colspan="10">Single-Sided</td>
</tr>
</table>

View file

@ -0,0 +1,52 @@
<style>
body {
height: 95px;
}
table {
border-collapse: collapse;
border-spacing: 0;
height: 80px;
table-layout: fixed;
width: 100%
}
table td {
border: 2px solid black;
font-size: 12px;
padding: .25em;
text-align: left;
vertical-align: top;
}
table td.title {
font-size: 14px;
font-weight: bold;
text-align: center;
vertical-align: middle;
white-space: nowrap;
}
</style>
<table>
<tr>
<td class="title " class="topage">
GENERAL CONTINUATION SHEET
</td>
<td>
<div class="cell-label">
<b>PRODUCT</b>
</div>
<div class="cell-value">
<%= template[:product] %>
</div>
</td>
<td>
<div class="cell-label">
<b>SAMPLE NUMBER</b>
</div>
<div class="cell-value">
<%= template[:sample_number] %>
</div>
</td>
</tr>
</table>

View file

@ -0,0 +1,300 @@
<div class="report-template-index">
<style type="text/css" scoped>
.report-template-index .template-table {
height: 297mm;
width: 100%;
font-size: 12px;
border-collapse: collapse;
border-spacing: 0;
table-layout: fixed;
}
.report-template-index .template-checkbox {
border: 1px solid black;
display: inline-block;
height: 16px;
margin-bottom: -3px;
margin-right: .25em;
position: relative;
width: 16px;
}
.report-template-index .template-checkbox.selected {
background: black;
}
.report-template-index .template-table > tbody > tr > td {
border: 2px solid black;
padding: .25em;
text-align: left;
vertical-align: top;
}
.report-template-index .cell-label {
font-weight: bold;
}
.report-template-index .template-table > tbody > tr > td.title {
font-size: 14px;
font-weight: bold;
text-align: center;
vertical-align: middle;
white-space: nowrap;
}
.report-template-index tr.fixed-height {
height: 5em;
}
.report-template-index .seals-table {
height: 100%;
width: 100%;
}
.report-template-index .seals-table td {
font-size: 12px;
line-height: 16px;
vertical-align: top;
}
.report-template-index .net-contents-table {
font-size: 12px;
height: 100%;
width: 100%;
}
.report-template-index .template-table > tbody > tr > td.pagination-cell {
font-size: 14px;
font-weight: bold;
text-align: center;
vertical-align: middle;
white-space: nowrap;
}
</style>
<table class="template-table">
<tr class="fixed-height">
<td colspan=4 class="title">
ANALYST WORKSHEET
</td>
<td colspan=7>
<div class="cell-label">
1. PRODUCT
</div>
<div class="cell-value">
<%= template[:product] %>
</div>
</td>
<td colspan=5>
<div class="cell-label">
2. SAMPLE NUMBER
</div>
<div class="cell-value">
<%= template[:sample_number] %>
</div>
</td>
</tr>
<tr class="fixed-height">
<td colspan=4>
<table class="seals-table">
<tr>
<td>
<div class="cell-label">
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>
</tr>
<tr></tr>
</table>
</td>
<td colspan=3>
<div class="cell-label">
4. DATE RECEIVED
</div>
<div class="cell-value">
<%= template[:date_recieved] %>
</div>
</td>
<td colspan=4>
<div class="cell-label">
5.RECEIVED FROM
</div>
<div class="cell-value">
<%= template[:recieved_from] %>
</div>
</td>
<td colspan=5>
<div class="cell-label">
6. DISTRICT OR LABORATORY
</div>
<div class="cell-value">
<%= template[:district_laboratory] %>
</div>
</td>
</tr>
<tr>
<td colspan=16>
<div class="cell-label">
7. DESCRIPTION OF SAMPLE
</div>
<div class="cell-value">
<%= template[:sample_description] %>
</div>
</td>
</tr>
<tr class="fixed-height">
<td colspan=2>
<div class="cell-label">
8. NET CONTENTS
</div>
</td>
<td colspan=7>
<table class="net-contents-table">
<tr>
<td>
<span class="template-checkbox <%= 'selected' if template.dig(:net_contents, :not_applicable) %>"></span>
NOT APPLICABLE
</td>
<td>DECLARE/UNIT <b><%= template.dig(:net_contents, :declare_unit) %></b></td>
</tr>
<tr>
<td>
<span class="template-checkbox <%= 'selected' if template.dig(:net_contents, :not_determined) %>"></span>
NOT DETERMINED
</td>
<td>AMOUNT FOUND <b><%= template.dig(:net_contents, :amount_found) %></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>
</tr>
</table>
</td>
<td colspan=2>
<div class="cell-label">
9. LABELING
</div>
</td>
<td colspan=5>
<table class="net-contents-table">
<tr>
<td>
<b><%= template.dig(:labeling, :originals_submitted) %></b> ORIGINAL(S) SUBMITTED
</td>
</tr>
<tr>
<td>
<b><%= template.dig(:labeling, :copies_submitted) %></b> COPIES SUBMITTED
</td>
</tr>
<tr>
<td>
<span class="template-checkbox <%= 'selected' if template.dig(:labeling, :none) %>"></span>
NONE
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan=16>
<div class="cell-label">
10. SUMMARY OF ANALYSIS
</div>
<div class="cell-value">
<%= template[:analysis_summary] %>
</div>
</td>
</tr>
<tr class="fixed-height">
<td colspan=16>
<div class="cell-label">
11. RESERVE SAMPLE
</div>
<div class="cell-value">
<%= template[:reserve_sample] %>
</div>
</td>
</tr>
<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>)
</div>
<div class="cell-value">
<%= template.dig(:analyst_signature, :a) %>
</div>
</td>
<td colspan=3 rowspan=2>
<div class="cell-label">
13. WORKSHEET CHECK
</div>
</td>
<td colspan=5>
<div class="cell-label">
a. BY
</div>
<div class="cell-value">
<%= template.dig(:worksheet_check, :by) %>
</div>
</td>
</tr>
<tr class="fixed-height">
<td colspan=5>
<div class="cell-label">
b. DATE
</div>
<div class="cell-value">
<%= template.dig(:worksheet_check, :date) %>
</div>
</td>
</tr>
<tr class="fixed-height">
<td colspan=8>
<div class="cell-label">
b.
</div>
<div class="cell-value">
<%= template.dig(:analyst_signature, :b) %>
</div>
</td>
<td colspan=8>
<div class="cell-label">
13. DATE REPORTED
</div>
<div class="cell-value">
<%= template[:date_reported] %>
</div>
</td>
</tr>
<tr class="fixed-height">
<td colspan=8>
<div class="cell-label">
c.
</div>
<div class="cell-value">
<%= template.dig(:analyst_signature, :c) %>
</div>
</td>
<td colspan=8 class="pagination-cell">
PAGE 1 OF
</td>
</tr>
</table>
</div>