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