@measurequick/measurequick-report-generator 1.2.78 → 1.2.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// global.PNG = require('png-js');
|
|
2
|
+
// global.window = {document: {createElementNS: () => {return {}} }};
|
|
3
|
+
// global.navigator = {};
|
|
4
|
+
// global.atob = require('atob');
|
|
5
|
+
// global.btoa = () => {};
|
|
6
|
+
//
|
|
7
|
+
// var fs = require('fs'),
|
|
8
|
+
// express = require('express'),
|
|
9
|
+
// jsPDF = require('jspdf/dist/jspdf.node.min'),
|
|
10
|
+
// app = require('express')(),
|
|
11
|
+
// http = require('http').Server(app),
|
|
12
|
+
// bodyParser = require('body-parser'),
|
|
13
|
+
// Jimp = require('jimp'),
|
|
14
|
+
// util = require('util'),
|
|
15
|
+
// log_file = fs.createWriteStream(__dirname + '/debug.log', {flags : 'w'}),
|
|
16
|
+
// log_stdout = process.stdout;
|
|
17
|
+
//
|
|
18
|
+
// console.log = function(d) { //
|
|
19
|
+
// log_file.write(util.format(d) + '\n');
|
|
20
|
+
// log_stdout.write(util.format(d) + '\n');
|
|
21
|
+
// };
|
|
22
|
+
//
|
|
23
|
+
// export async function getReport(payload) { console.log("Cover Page - Payload:"); console.log(payload);
|
|
24
|
+
// try {
|
|
25
|
+
//
|
|
26
|
+
//
|
|
27
|
+
// return doc.output('datauristring');
|
|
28
|
+
// } catch (error) { console.log(error) }
|
|
29
|
+
// }
|
|
@@ -86,6 +86,16 @@ export async function getReport(payload) { console.log("Full Report"); console.l
|
|
|
86
86
|
}
|
|
87
87
|
} catch (e) {}
|
|
88
88
|
|
|
89
|
+
/******** BLUVAC REPORT (1 PAGE) *********/
|
|
90
|
+
if (payload.project.evacuation_pdf && payload.meta.pdf_settings.includeBluvacReport) {
|
|
91
|
+
try {
|
|
92
|
+
let bluvacReportBase64 = payload.project.evacuation_pdf;
|
|
93
|
+
const bluvacReportDoc = bluvacReportBase64 ? await PDFDocument.load(util._base64ToArrayBuffer(bluvacReportBase64)) : false;
|
|
94
|
+
const [_bluvacReportDoc] = bluvacReportDoc ? await coreDoc.copyPages(bluvacReportDoc, [0]) : false;
|
|
95
|
+
if (_bluvacReportDoc) coreDoc.insertPage(coreDoc.getPages().length, _bluvacReportDoc);
|
|
96
|
+
} catch (e) {}
|
|
97
|
+
}
|
|
98
|
+
|
|
89
99
|
/******** CORRECTIVE MEASURES (1 PAGE) *********/
|
|
90
100
|
try {
|
|
91
101
|
let correctiveMeasuresBase64 = await correctiveMeasures.getReport(payload);
|
|
@@ -62,6 +62,45 @@ export async function getReport(payload) { console.log("Photo Page(s) - Payload
|
|
|
62
62
|
docIndex++;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
photoSectionKeys = Object.keys(payload.photos.equipment);
|
|
66
|
+
if (photoSectionKeys && photoSectionKeys.length > 0) {
|
|
67
|
+
docs[docIndex] = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
|
|
68
|
+
forms[docIndex] = docs[docIndex].getForm();
|
|
69
|
+
forms[docIndex].getButton("FullWidthLogo").setImage(await docs[docIndex].embedPng(mqLogoBytes));
|
|
70
|
+
forms[docIndex].getTextField("Header").setText(`Equipment Photos`);
|
|
71
|
+
let photoPosition = 1;
|
|
72
|
+
for (let pskIndex = 0; pskIndex < photoSectionKeys.length; pskIndex++) { // Iterate over X user-defined photo sections within each photo collection
|
|
73
|
+
let photoSectionKey = photoSectionKeys[pskIndex];
|
|
74
|
+
let photoSection = payload.photos.equipment[photoSectionKey];
|
|
75
|
+
let photoSectionName = photoSection.name;
|
|
76
|
+
let photos = photoSection.photos;
|
|
77
|
+
if (photos && photos.length > 0) {
|
|
78
|
+
for (let pIndex = 1; pIndex <= photos.length; pIndex++) { // Iterate over X user-defined photos within each photo section
|
|
79
|
+
let photo = photos[pIndex-1];
|
|
80
|
+
if (photoPosition > maxPhotosPerPage) { // Need a new page
|
|
81
|
+
photoPosition = 1;
|
|
82
|
+
docIndex++;
|
|
83
|
+
docs[docIndex] = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
|
|
84
|
+
forms[docIndex] = docs[docIndex].getForm();
|
|
85
|
+
forms[docIndex].getButton("FullWidthLogo").setImage(await docs[docIndex].embedPng(mqLogoBytes));
|
|
86
|
+
forms[docIndex].getTextField("Header").setText(`Equipment Photos`);
|
|
87
|
+
}
|
|
88
|
+
let imageToSet;
|
|
89
|
+
if (photo.base64.includes("image/jpeg")) imageToSet = await docs[docIndex].embedJpg(util._base64ToArrayBuffer(photo.base64));
|
|
90
|
+
else if (photo.base64.includes("image/png")) imageToSet = await docs[docIndex].embedPng(util._base64ToArrayBuffer(photo.base64));
|
|
91
|
+
if (imageToSet) forms[docIndex].getButton(`photo${pSize}${photoPosition}`).setImage(imageToSet);
|
|
92
|
+
let photoSubText = photoSection.name;
|
|
93
|
+
let isFirstPhotoOfSection = previousPhotoSectionName !== photoSectionName;
|
|
94
|
+
if (isFirstPhotoOfSection && photoSection.hasNotes && photoSection.notes) photoSubText += `: ${photoSection.notes}`;
|
|
95
|
+
forms[docIndex].getTextField(`Notes${photoPosition}`).setText(`${photoSubText}`);
|
|
96
|
+
photoPosition++;
|
|
97
|
+
previousPhotoSectionName = photoSectionName;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
docIndex++;
|
|
102
|
+
}
|
|
103
|
+
|
|
65
104
|
// Prepare Deliverable
|
|
66
105
|
forms.forEach(form => { form.flatten() });
|
|
67
106
|
let pdfDoc = await PDFDocument.create();
|