@measurequick/measurequick-report-generator 1.2.45 → 1.2.46
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
|
@@ -5,10 +5,10 @@ import * as photos6 from '../base-64/photos6.js';
|
|
|
5
5
|
import * as base64 from '../base-64/icons.js';
|
|
6
6
|
import * as util from '../util.js';
|
|
7
7
|
|
|
8
|
-
export async function getReport(payload) {
|
|
8
|
+
export async function getReport(payload) {
|
|
9
9
|
|
|
10
10
|
const mqLogoBytes = util._base64ToArrayBuffer(base64.mqLogo);
|
|
11
|
-
let maxPhotosPerPage = payload.meta.pdf_settings.maxPhotosPerPage
|
|
11
|
+
let maxPhotosPerPage = payload.meta.pdf_settings.maxPhotosPerPage;
|
|
12
12
|
|
|
13
13
|
// Layout Configuration
|
|
14
14
|
let docs = [], forms = [], page = photos6, pSize = "Small";
|
|
@@ -21,44 +21,42 @@ export async function getReport(payload) { console.log("PAYLOAD " + JSON.stringi
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
// Process All Photos
|
|
24
|
+
let previousPhotoSectionName;
|
|
24
25
|
let docIndex = 0;
|
|
25
|
-
let
|
|
26
|
-
|
|
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
|
-
console.log(arrPhotos);
|
|
32
|
-
arrPhotos.sort((a, b) => (a.section > b.section) ? 1 : -1);
|
|
33
|
-
console.log(arrPhotos);
|
|
26
|
+
let photoSectionKeys = Object.keys(payload.photos.project);
|
|
27
|
+
if (photoSectionKeys && photoSectionKeys.length > 0) {
|
|
34
28
|
docs[docIndex] = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
|
|
35
29
|
forms[docIndex] = docs[docIndex].getForm();
|
|
36
30
|
forms[docIndex].getButton("FullWidthLogo").setImage(await docs[docIndex].embedPng(mqLogoBytes));
|
|
37
31
|
forms[docIndex].getTextField("Header").setText(`Project Photos`);
|
|
38
32
|
let photoPosition = 1;
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
let
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
33
|
+
for (let pskIndex = 0; pskIndex < photoSectionKeys.length; pskIndex++) { // Iterate over X user-defined photo sections within each photo collection
|
|
34
|
+
let photoSectionKey = photoSectionKeys[pskIndex];
|
|
35
|
+
let photoSection = payload.photos.project[photoSectionKey];
|
|
36
|
+
let photoSectionName = photoSection.name;
|
|
37
|
+
let photos = photoSection.photos;
|
|
38
|
+
if (photos && photos.length > 0) {
|
|
39
|
+
for (let pIndex = 1; pIndex <= photos.length; pIndex++) { // Iterate over X user-defined photos within each photo section
|
|
40
|
+
let photo = photos[pIndex-1];
|
|
41
|
+
if (photoPosition > maxPhotosPerPage) { // Need a new page
|
|
42
|
+
photoPosition = 1;
|
|
43
|
+
docIndex++;
|
|
44
|
+
docs[docIndex] = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
|
|
45
|
+
forms[docIndex] = docs[docIndex].getForm();
|
|
46
|
+
forms[docIndex].getButton("FullWidthLogo").setImage(await docs[docIndex].embedPng(mqLogoBytes));
|
|
47
|
+
forms[docIndex].getTextField("Header").setText(`Project Photos`);
|
|
48
|
+
}
|
|
49
|
+
let imageToSet;
|
|
50
|
+
if (photo.base64.includes("image/jpeg")) imageToSet = await docs[docIndex].embedJpg(util._base64ToArrayBuffer(photo.base64));
|
|
51
|
+
else if (photo.base64.includes("image/png")) imageToSet = await docs[docIndex].embedPng(util._base64ToArrayBuffer(photo.base64));
|
|
52
|
+
if (imageToSet) forms[docIndex].getButton(`photo${pSize}${photoPosition}`).setImage(imageToSet);
|
|
53
|
+
let photoSubText = photoSection.name;
|
|
54
|
+
let isFirstPhotoOfSection = previousPhotoSectionName !== photoSectionName;
|
|
55
|
+
if (isFirstPhotoOfSection && photoSection.hasNotes && photoSection.notes) photoSubText += `: ${photoSection.notes}`;
|
|
56
|
+
forms[docIndex].getTextField(`Notes${photoPosition}`).setText(`${photoSubText}`);
|
|
57
|
+
photoPosition++;
|
|
58
|
+
previousPhotoSectionName = photoSectionName;
|
|
52
59
|
}
|
|
53
|
-
let imageToSet;
|
|
54
|
-
if ((photo.base64 && photo.base64.includes("image/jpeg")) || photo.fileType == 'jpg') imageToSet = await docs[docIndex].embedJpg(util._base64ToArrayBuffer(photo.base64));
|
|
55
|
-
else if ((photo.base64 && photo.base64.includes("image/png")) || photo.fileType == 'png') imageToSet = await docs[docIndex].embedPng(util._base64ToArrayBuffer(photo.base64));
|
|
56
|
-
if (imageToSet) forms[docIndex].getButton(`photo${pSize}${photoPosition}`).setImage(imageToSet);
|
|
57
|
-
photoPosition++;
|
|
58
|
-
let caption = photo.section;
|
|
59
|
-
if (prevSection == currSection) caption += photo.notes;
|
|
60
|
-
forms[docIndex].getTextField(`Notes${photoPosition}`).setText(caption);
|
|
61
|
-
prevSection = currSection;
|
|
62
60
|
}
|
|
63
61
|
}
|
|
64
62
|
docIndex++;
|