Skip to content

Commit

Permalink
correct bugfix for 6.0.0 - 6.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
herman26 committed Oct 4, 2021
1 parent 557fdbd commit f00cb79
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 144 deletions.
6 changes: 3 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ module.exports = {
docY.doc.addPage(); // create blank page for page of contents
}
if (pageSetup.addBasicResponseHeader && !pageSetup.hasCover) {
docY = await logic.addHeadline(docY, "RESULTS", false, "list");
docY = await logic.addHeadline(docY, "RESULTS", "list");
}
}
docY = await logic.addPageDetail(docY, reportContent["dataFound"], reportContent.newPageHeaders, pageOfContents, pageSetup.hasCover);
docY.doc = await logic.addPageFooter(docY, requestID, reportMeta.disclaimer);
docY.doc = await logic.addPageFooter(docY, requestID);
return await logic.finalizePDFDocument(docY.doc, requestID, reportMeta, pageOfContents, pageSetup.hasCover);
},
generateNoResultsReport: async (reportContent, reportMeta) => {
Expand All @@ -65,7 +65,7 @@ module.exports = {
const pageOfContents = null;
let docY = logic.createPDFDocument(requestID, reportMeta.reportName, pageOfContents, pageSetup.hasCover);
docY = await logic.defaultTop(docY, reportContent);
docY.doc = await logic.addPageFooter(docY, requestID, reportMeta.disclaimer);
docY.doc = await logic.addPageFooter(docY, requestID);
return await logic.finalizePDFDocument(docY.doc, requestID, reportMeta, pageOfContents, pageSetup.hasCover);
},
};
7 changes: 4 additions & 3 deletions app/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ const PDFDocumentLineType = {
DEFAULT_LINE: 0,
HEADER_LINE: 1,
KEY_VALUE_LINE: 2,
EMPTY_LINE: 3,
EMPTY_LINE: 3, // this line forces an empty line as the next line on the page
ADDRESS_LINE: 4,
COLUMN_INFO: 5,
META_INFO: 6,
SINGLE_COLUMN: 7,
DOUBLE_COLUMN: 8,
END_LINE: 9,
END_LINE: 9, // this line forces an invisible line, that ends a section
GRID: 10,
TABLE_OF_CONTENTS_LINE: 11,
KEY_LINK_LINE: 12,
INDICATIVE_BAR_LINE: 13,
IMAGE_LINE: 14,
PAGE_BREAK: 15,
PAGE_BREAK: 15, // this line forces the line to be the last line on the page, forcing a page break
CHART_LINE: 16,
H0_LINE: 17,
H1_LINE: 18,
Expand Down Expand Up @@ -65,6 +65,7 @@ const PD = {
HEIGHT: 841.89,
MARGIN: 20,
PADDING: 10,
PAD_FOR_IMAGE_TEXT: 30,
};

const PDColors = {
Expand Down
6 changes: 3 additions & 3 deletions app/library-override/pdfkit-customized.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class PDFDocumentCustomized extends PDFDocument {
}

table(table, arg0, arg1, arg2, type) {
if (type === constants.PDFTableType.COVER) {
console.log("Cover Table being created");
}
// if (type === constants.PDFTableType.COVER) {
// console.log("Cover Table being created");
// }
let startX = this.page.margins.left;
let startY = this.y;
let options = {};
Expand Down
48 changes: 17 additions & 31 deletions app/line-types/base-logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,52 +84,38 @@ function populateHeaderLine(doc, headerColor, text, value, x, xAdditionalWidth,
}

function populateHLine(doc, text, value, x, y, hType, options = false) {
doc.x = constants.PD.MARGIN;

if (doc.y == 0) {
doc.y = (constants.TOP_OF_PAGE_Y / 2 );
} // if the header is flush with page, set a top margin

if (hType == constants.PDFDocumentLineType.H1_LINE) {
doc.roundedRect(constants.PD.MARGIN, doc.y, (constants.PD.WIDTH - (constants.PD.MARGIN) * 2), 26, 2)
doc
.roundedRect(constants.PD.MARGIN, y, (constants.PD.WIDTH - (constants.PD.MARGIN) * 2), 26, 2)
.fill(constants.PDColors.BG_LIGHT, "#000");

doc.image(`${constants.PACKAGE_PATH}images/icon-clock.png`, (constants.PD.MARGIN + constants.PD.PADDING ), (doc.y + 7), {height: 12});
doc.x += constants.PD.PADDING + 10;
doc.image(`${constants.PACKAGE_PATH}images/icon-clock.png`,
x, (y + 7), {
height: 12,
},
);

doc.fillColor(constants.PDColors.TEXT_DARK)
doc
.fillColor(constants.PDColors.TEXT_DARK)
.fontSize(10)
.text(text, (doc.x + constants.PD.PADDING), (doc.y - 13) );

doc.y = doc.y + 20;

return doc;
.text(text, (constants.PD.MARGIN + constants.PD.PAD_FOR_IMAGE_TEXT), (y + 6) );
} else if (hType == constants.PDFDocumentLineType.H2_LINE) {
doc.fillColor(constants.PDColors.TEXT_DARK)
doc
.fillColor(constants.PDColors.TEXT_DARK)
.fontSize(10)
.text(text, (doc.x), (doc.y) );

doc.y -= 10;
.text(text, x, y);

doc = underline(doc, doc.x, doc.y, 3);

doc.y += 25;

return doc;
doc = underline(doc, x, y + 5, 3);
} else if (hType == constants.PDFDocumentLineType.H3_LINE) {
doc.fillColor(constants.PDColors.TEXT_DARK)
doc
.fillColor(constants.PDColors.TEXT_DARK)
.fontSize(9)
.text(text, (doc.x), (doc.y) );

doc.y += 7;

return doc;
.text(text, x, y);
}

return doc;
}


// underline: underlines a line on the PDF doc
function underline(doc, x, y, thickness = 0.5) {
return doc.moveTo(x, y + constants.INCREMENT_UNDERLINE)
Expand Down
4 changes: 3 additions & 1 deletion app/line-types/empty-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ module.exports = {
generateLineThatIsEmpty,
};

function generateLineThatIsEmpty(doc, y, incrementY, getDocY) {
function generateLineThatIsEmpty(doc, y, getDocY) {
const incrementY = constants.INCREMENT_MAIN_Y;

const docY = getDocY(doc, y, incrementY, 1, false);
doc = docY.doc;
y = docY.y;
Expand Down
20 changes: 17 additions & 3 deletions app/line-types/h-line.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
"use strict";

const constants = require("../constants");
const sectionTypeLogic = require("./base-logic");

module.exports = {
generateLineThatIsH,
};

function generateLineThatIsH(doc, x, y, text, value, lineType, options = false) {
doc = sectionTypeLogic.populateHLine(doc, text, value, x, doc.y, lineType, options);
function generateLineThatIsH(doc, x, y, text, value, lineType, getDocY, options = false) {
const incrementY = constants.INCREMENT_MAIN_Y;

return sectionTypeLogic.docYResponse(doc, doc.y);
const docY = getDocY(doc, y, incrementY, 1, false);
doc = docY.doc;
y = docY.y;

doc = sectionTypeLogic.populateHLine(doc, text, value, x, y, lineType, options);

if (lineType == constants.PDFDocumentLineType.H1_LINE) {
y += incrementY + incrementY / 2;
} else if (lineType == constants.PDFDocumentLineType.H2_LINE) {
y += incrementY + incrementY / 2;
} else if (lineType == constants.PDFDocumentLineType.H3_LINE) {
y += incrementY;
}
return sectionTypeLogic.docYResponse(doc, y);
}
2 changes: 0 additions & 2 deletions app/line-types/image-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ async function generateLineThatIsImage(doc, x, y, value, incrementY, getDocY, op
const docY = getDocY(doc, y, incrementY, 1, false);
doc = docY.doc;
y = docY.y;
// value = examplePayload();
// console.log(value);
return await populateImage(doc, x, y, incrementY, value, options);
}

Expand Down
8 changes: 4 additions & 4 deletions app/logic-line-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function addLine(lineDocY, text, value, lineType, isFancyHeader, font, opt
switch (lineType) {
case constants.PDFDocumentLineType.EMPTY_LINE:
case constants.PDFDocumentLineType.END_LINE: {
const sectionResponse = emptyLine.generateLineThatIsEmpty(doc, y, incrementY, getDocY);
const sectionResponse = emptyLine.generateLineThatIsEmpty(doc, y, getDocY);
doc = sectionResponse.doc;
y = sectionResponse.y;
break;
Expand All @@ -68,19 +68,19 @@ async function addLine(lineDocY, text, value, lineType, isFancyHeader, font, opt
break;
}
case constants.PDFDocumentLineType.H1_LINE: {
const sectionResponse = hLine.generateLineThatIsH(doc, x, y, text, value, constants.PDFDocumentLineType.H1_LINE, options);
const sectionResponse = hLine.generateLineThatIsH(doc, x, y, text, value, constants.PDFDocumentLineType.H1_LINE, getDocY, options);
doc = sectionResponse.doc;
y = sectionResponse.y;
break;
}
case constants.PDFDocumentLineType.H2_LINE: {
const sectionResponse = hLine.generateLineThatIsH(doc, x, y, text, value, constants.PDFDocumentLineType.H2_LINE, options);
const sectionResponse = hLine.generateLineThatIsH(doc, x, y, text, value, constants.PDFDocumentLineType.H2_LINE, getDocY, options);
doc = sectionResponse.doc;
y = sectionResponse.y;
break;
}
case constants.PDFDocumentLineType.H3_LINE: {
const sectionResponse = hLine.generateLineThatIsH(doc, x, y, text, value, constants.PDFDocumentLineType.H3_LINE, options);
const sectionResponse = hLine.generateLineThatIsH(doc, x, y, text, value, constants.PDFDocumentLineType.H3_LINE, getDocY, options);
doc = sectionResponse.doc;
y = sectionResponse.y;
break;
Expand Down
52 changes: 28 additions & 24 deletions app/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const constants = require("./constants");
const setupPDFType = require("./logic-pdf-type").setupPDFType;
const addLine = require("./logic-line-core").addLine;
const {PDF_TEXT} = require("./constants");
const sectionTypeLogic = require("./line-types/base-logic");

AWS.config.update({region: configs.AWS_DEFAULT_REGION});
const AWS_S3_REPORTS_BUCKET = configs.AWS_S3_REPORTS_BUCKET;
Expand Down Expand Up @@ -84,7 +85,7 @@ async function defaultTop(docY, reportContent) {

const searchParams = reportContent["searchParams"];
if (Object.keys(searchParams).length) {
docY = await addHeadline(docY, "DATA SUBMITTED", false, "clock");
docY = await addHeadline(docY, "DATA SUBMITTED", "clock");
docY = await addPageDetail(docY, searchParams, null);
docY = await addLine(docY, null, null, constants.PDFDocumentLineType.EMPTY_LINE, false);
}
Expand All @@ -98,71 +99,74 @@ async function addDefaultLine(docY, text, value) {
async function addPageDetail(docY, data, newPageHeaders, pageOfContents) {
for (const prop in data) {
if (Object.prototype.hasOwnProperty.call(data, prop)) {
let isFancyHeader = false;
let isNewPageHeader = false;
const row = data[prop];

let populatedHeader = false;
// if page headers object was set, go in the below piece
if (newPageHeaders !== null && newPageHeaders !== undefined) {
// if header is listed as a new page header, add new page header line
if (newPageHeaders.includes(row.header)) {
if (docY.y > constants.TOP_OF_PAGE_Y) {
docY.doc.addPage();
// docY.doc.fillColor(constants.PDFColors.NORMAL_COLOR);
docY.y = constants.TOP_OF_PAGE_Y;
}
isFancyHeader = true;
isNewPageHeader = true;
if (pageOfContents !== null) {
pageOfContents.addPageDetails(row.header);
}
docY = await addLine(docY, row.header, row.value, row.lineType, isFancyHeader);
populatedHeader = true;
docY = await addLine(docY, row.header, row.value, row.lineType, isNewPageHeader);
}
}
if (!populatedHeader) {
docY = await addLine(docY, row.text, row.value, row.lineType, isFancyHeader);

// if not new page header, add
if (!isNewPageHeader) {
docY = await addLine(docY, row.text, row.value, row.lineType, isNewPageHeader);
}
}
}
return docY;
}

/**
* Adds a headline.
*
**/
async function addHeadline(docY, text, type = "H2", icon = false) {
docY.doc.x = constants.PD.MARGIN;

* Adds a default design report header
* @param {*} docY
* @param {*} text
* @param {*} icon
* @returns
*/
async function addHeadline(docY, text, icon = false) {
docY.doc.roundedRect(constants.PD.MARGIN, docY.y, (constants.PD.WIDTH - (constants.PD.MARGIN) * 2), 26, 2)
.fill(constants.PDColors.BG_LIGHT, "#000");

if (icon) {
docY.doc.image(`${constants.PACKAGE_PATH}images/icon-${icon}.png`, (constants.PD.MARGIN + constants.PD.PADDING ), (docY.y + 7), {height: 12});
docY.doc.x += constants.PD.PADDING + 10;
}

docY.doc.fillColor(constants.PDColors.TEXT_DARK)
docY.doc
.fillColor(constants.PDColors.TEXT_DARK)
.fontSize(10)
.text(text, (docY.doc.x + constants.PD.PADDING), (docY.y + 6) );
.text(text, (constants.PD.MARGIN + constants.PD.PAD_FOR_IMAGE_TEXT), (docY.y + 6) );

docY.y += 40;
docY.doc.y += constants.PD.MARGIN;
const doc = docY.doc;
let y = docY.y;
y += 40;

return docY;
return sectionTypeLogic.docYResponse(doc, y);
}

/**
* Adds the page footer.
*
**/
async function addPageFooter(docY, requestID, disclaimer) {
async function addPageFooter(docY, requestID) {
const footerClearance = (docY.doc.page.height - 100);

if (docY.y > footerClearance) {
// create new page so footer can be displayed (otherwise it will be placed on top of data)
docY.doc.addPage();
docY.y = constants.TOP_OF_PAGE_Y;
}
const doc = addDisclaimer(docY.doc, disclaimer);
const doc = addDisclaimer(docY.doc);
const page = doc.page;

doc
Expand Down Expand Up @@ -238,7 +242,7 @@ async function generateQRCode(data) {
/**
* Generate the Disclaimer text included on the PDF Report.
*/
function addDisclaimer(doc, disclaimer) {
function addDisclaimer(doc) {
const page = doc.page;

const PDF_REPORT_DISCLAIMER = PDF_TEXT.DISCLAIMER;
Expand Down
Loading

0 comments on commit f00cb79

Please sign in to comment.