@measurequick/measurequick-report-generator 1.2.18 → 1.2.20
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,57 +5,66 @@ 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) {
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
export async function getReport(payload) {
|
|
9
|
+
|
|
10
|
+
const mqLogoBytes = util._base64ToArrayBuffer(base64.mqLogo);
|
|
11
|
+
let maxPhotosPerPage = payload.meta.pdf_settings.maxPhotosPerPage;
|
|
12
|
+
|
|
13
|
+
// Layout Configuration
|
|
14
|
+
let docs = [], forms = [], page = photos6, pSize = "Small";
|
|
15
|
+
if (maxPhotosPerPage == 4) {
|
|
11
16
|
page = photos4;
|
|
12
|
-
|
|
13
|
-
} else if (
|
|
17
|
+
pSize = "Mid";
|
|
18
|
+
} else if (maxPhotosPerPage == 2) {
|
|
14
19
|
page = photos2;
|
|
15
|
-
|
|
20
|
+
pSize = "Large";
|
|
16
21
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
22
|
+
|
|
23
|
+
// Process All Photos
|
|
24
|
+
let previousPhotoCollectionName;
|
|
25
|
+
let photoCollectionNames = ["project", "equipment", "site", "customer"];
|
|
26
|
+
for (let pcnIndex = 0; pcnIndex < photoCollectionNames.length; pcnIndex++) { // Iterate over all 4 photo photo collections
|
|
27
|
+
let photoCollectionName = photoCollectionNames[pcnIndex];
|
|
28
|
+
let photoCollection = payload.photos[photoCollectionName];
|
|
29
|
+
let photoSectionKeys = Object.keys(photoCollection);
|
|
30
|
+
for (let pskIndex = 0; pskIndex < photoSectionKeys.length; pskIndex++) { // Iterate over X user-defined photo sections within each photo collection
|
|
31
|
+
let photoSectionKey = photoSectionKeys[pskIndex];
|
|
32
|
+
let photoSection = photoCollection[photoSectionKey];
|
|
33
|
+
let photos = photoSection.photos;
|
|
34
|
+
if (!photos || photos.length == 0) break;
|
|
35
|
+
let photoPosition = 1;
|
|
36
|
+
let doc = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
|
|
37
|
+
let form = doc.getForm();
|
|
38
|
+
docs.push(doc);
|
|
39
|
+
forms.push(form);
|
|
40
|
+
form.getButton("FullWidthLogo").setImage(await doc.embedPng(mqLogoBytes));
|
|
41
|
+
form.getTextField("Header").setText(`${util.capitalizeFirstLetter(photoCollectionName)} Photos`);
|
|
42
|
+
for (let pIndex = 1; pIndex <= photos.length; pIndex++) { // Iterate over X user-defined photos within each photo section
|
|
43
|
+
let photo = photos[pIndex-1];
|
|
44
|
+
if (photoPosition > maxPhotosPerPage) { // Need a new page
|
|
45
|
+
photoPosition = 1;
|
|
46
|
+
doc = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
|
|
47
|
+
form = doc.getForm();
|
|
48
|
+
docs.push(doc);
|
|
49
|
+
forms.push(form);
|
|
50
|
+
form.getButton("FullWidthLogo").setImage(await doc.embedPng(mqLogoBytes));
|
|
51
|
+
form.getTextField("Header").setText(`${util.capitalizeFirstLetter(photoCollectionName)} Photos`);
|
|
52
|
+
}
|
|
53
|
+
let imageToSet;
|
|
54
|
+
if (photo.base64.includes("image/jpeg")) imageToSet = await doc.embedJpg(util._base64ToArrayBuffer(photo.base64));
|
|
55
|
+
else if (photo.base64.includes("image/png")) imageToSet = await doc.embedPng(util._base64ToArrayBuffer(photo.base64));
|
|
56
|
+
if (imageToSet) form.getButton(`photo${pSize}${pIndex}`).setImage(imageToSet);
|
|
57
|
+
let photoSubText = photoSection.name;
|
|
58
|
+
let isFirstPhotoOfSection = previousPhotoCollectionName == photoCollectionName;
|
|
59
|
+
if (isFirstPhotoOfSection && photoSection.hasNotes) photoSubText += `: ${photoSection.notes}`;
|
|
60
|
+
form.getTextField(`Notes${pIndex}`).setText(`${photoSubText}`);
|
|
61
|
+
photoPosition++;
|
|
62
|
+
previousPhotoCollectionName = photoCollectionName;
|
|
57
63
|
}
|
|
64
|
+
}
|
|
58
65
|
}
|
|
66
|
+
|
|
67
|
+
// Prepare Deliverable
|
|
59
68
|
forms.forEach(form => { form.flatten() });
|
|
60
69
|
let pdfDoc = await PDFDocument.create();
|
|
61
70
|
for (let i = 0; i < docs.length; i++) {
|
|
@@ -64,6 +73,3 @@ export async function getReport(payload) { console.log("Photos Report"); console
|
|
|
64
73
|
}
|
|
65
74
|
return await pdfDoc.saveAsBase64({ dataUri: true });
|
|
66
75
|
}
|
|
67
|
-
|
|
68
|
-
// MAX # of Characters for 2-Photo Pages: 95 Characters
|
|
69
|
-
// MAX # of Characters for 4-Photo & 6-Photo Pages: 42 Characters
|