@measurequick/measurequick-report-generator 1.2.46 → 1.2.48
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/index.js +2 -0
- package/package.json +1 -1
- package/report-gen-scripts/photos-report-s3.js +72 -0
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import * as measurementsReport from "./report-gen-scripts/measurements-repo
|
|
|
5
5
|
import * as measurementDetails from "./report-gen-scripts/measurement-details.js";
|
|
6
6
|
import * as correctiveMeasures from "./report-gen-scripts/corrective-measures.js";
|
|
7
7
|
import * as photosReport from "./report-gen-scripts/photos-report.js";
|
|
8
|
+
import * as photosReportS3 from "./report-gen-scripts/photos-report-s3.js";
|
|
8
9
|
import * as ptcsHeatPumpReport from "./report-gen-scripts/ptcs-heat-pump-report.js";
|
|
9
10
|
import * as systemReviewReport from "./report-gen-scripts/system-review-report.js";
|
|
10
11
|
import * as vitalsCoolingReport from "./report-gen-scripts/vitals-cooling-report.js";
|
|
@@ -19,6 +20,7 @@ export function getReport(payload) {
|
|
|
19
20
|
case "MeasurementDetails": return measurementDetails.getReport(payload);
|
|
20
21
|
case "CorrectiveMeasures": return correctiveMeasures.getReport(payload);
|
|
21
22
|
case "PhotosReport": return photosReport.getReport(payload);
|
|
23
|
+
case "PhotosReportS3": return photosReportS3.getReport(payload);
|
|
22
24
|
case "PtcsHeatPumpReport": return ptcsHeatPumpReport.getReport(payload);
|
|
23
25
|
case "SystemReviewReport": return systemReviewReport.getReport(payload);
|
|
24
26
|
case "VitalsCoolingReport": return vitalsCoolingReport.getReport(payload, false);
|
package/package.json
CHANGED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { PDFDocument } from 'pdf-lib';
|
|
2
|
+
import * as photos2 from '../base-64/photos2.js';
|
|
3
|
+
import * as photos4 from '../base-64/photos4.js';
|
|
4
|
+
import * as photos6 from '../base-64/photos6.js';
|
|
5
|
+
import * as base64 from '../base-64/icons.js';
|
|
6
|
+
import * as util from '../util.js';
|
|
7
|
+
|
|
8
|
+
export async function getReport(payload) { console.log("photos-report-s3 -> getReport() ->"); console.log(payload);
|
|
9
|
+
|
|
10
|
+
const mqLogoBytes = util._base64ToArrayBuffer(base64.mqLogo);
|
|
11
|
+
let maxPhotosPerPage = payload.meta.pdf_settings.maxPhotosPerPage ? payload.meta.pdf_settings.maxPhotosPerPage : 2;
|
|
12
|
+
|
|
13
|
+
// Layout Configuration
|
|
14
|
+
let docs = [], forms = [], page = photos6, pSize = "Small";
|
|
15
|
+
if (maxPhotosPerPage == 4) {
|
|
16
|
+
page = photos4;
|
|
17
|
+
pSize = "Mid";
|
|
18
|
+
} else if (maxPhotosPerPage == 2) {
|
|
19
|
+
page = photos2;
|
|
20
|
+
pSize = "Large";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Process All Photos
|
|
24
|
+
let docIndex = 0;
|
|
25
|
+
let photos = payload.photos.project;
|
|
26
|
+
delete photos.unsynced;
|
|
27
|
+
if (photos && Object.keys(photos) && Object.keys(photos).length > 0) {
|
|
28
|
+
let s3ReferenceIds = Object.keys(photos);
|
|
29
|
+
let arrPhotos = [];
|
|
30
|
+
for (let i = 0; i < s3ReferenceIds.length; i++) { if (s3ReferenceIds[i] !== 'unsynced') arrPhotos.push(photos[s3ReferenceIds[i]]); }
|
|
31
|
+
arrPhotos.sort((a, b) => (a.section > b.section) ? 1 : -1);
|
|
32
|
+
console.log(arrPhotos);
|
|
33
|
+
docs[docIndex] = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
|
|
34
|
+
forms[docIndex] = docs[docIndex].getForm();
|
|
35
|
+
forms[docIndex].getButton("FullWidthLogo").setImage(await docs[docIndex].embedPng(mqLogoBytes));
|
|
36
|
+
forms[docIndex].getTextField("Header").setText(`Project Photos`);
|
|
37
|
+
let photoPosition = 1;
|
|
38
|
+
let prevSection, currSection;
|
|
39
|
+
for (let s3IdIndex = 0; s3IdIndex < s3ReferenceIds.length; s3IdIndex++) {
|
|
40
|
+
let s3ReferenceId = s3ReferenceIds[s3IdIndex];
|
|
41
|
+
let photo = photos[s3ReferenceId];
|
|
42
|
+
currSection = photo.section;
|
|
43
|
+
if (photoPosition > maxPhotosPerPage) {
|
|
44
|
+
photoPosition = 1;
|
|
45
|
+
docIndex++;
|
|
46
|
+
docs[docIndex] = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
|
|
47
|
+
forms[docIndex] = docs[docIndex].getForm();
|
|
48
|
+
forms[docIndex].getButton("FullWidthLogo").setImage(await docs[docIndex].embedPng(mqLogoBytes));
|
|
49
|
+
forms[docIndex].getTextField("Header").setText(`Project Photos`);
|
|
50
|
+
}
|
|
51
|
+
let imageToSet;
|
|
52
|
+
if (photo.base64 && photo.base64.includes("image/jpeg")) imageToSet = await docs[docIndex].embedJpg(util._base64ToArrayBuffer(photo.base64));
|
|
53
|
+
else if (photo.base64 && photo.base64.includes("image/png")) imageToSet = await docs[docIndex].embedPng(util._base64ToArrayBuffer(photo.base64));
|
|
54
|
+
if (imageToSet) forms[docIndex].getButton(`photo${pSize}${photoPosition}`).setImage(imageToSet);
|
|
55
|
+
let caption = photo.section;
|
|
56
|
+
if (prevSection == currSection) caption += photo.notes;
|
|
57
|
+
forms[docIndex].getTextField(`Notes${photoPosition}`).setText(caption);
|
|
58
|
+
photoPosition++;
|
|
59
|
+
prevSection = currSection;
|
|
60
|
+
}
|
|
61
|
+
docIndex++;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Prepare Deliverable
|
|
65
|
+
forms.forEach(form => { form.flatten() });
|
|
66
|
+
let pdfDoc = await PDFDocument.create();
|
|
67
|
+
for (let i = 0; i < docs.length; i++) {
|
|
68
|
+
const [nextPage] = await pdfDoc.copyPages(docs[i], [0]);
|
|
69
|
+
pdfDoc.insertPage(i, nextPage);
|
|
70
|
+
}
|
|
71
|
+
return await pdfDoc.saveAsBase64({ dataUri: true });
|
|
72
|
+
}
|