@measurequick/measurequick-report-generator 1.2.39 → 1.2.40

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measurequick/measurequick-report-generator",
3
- "version": "1.2.39",
3
+ "version": "1.2.40",
4
4
  "description": "Generates PDF documents for various MeasureQuick applications.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,56 +21,45 @@ export async function getReport(payload) {
21
21
  }
22
22
 
23
23
  // Process All Photos
24
- let previousPhotoSectionName;
25
- let photoCollectionNames = ["project", "equipment", "site", "customer"];
26
- let docIndex = 0;
27
- for (let pcnIndex = 0; pcnIndex < photoCollectionNames.length; pcnIndex++) { // Iterate over all 4 photo photo collections
28
- let photoCollectionName = photoCollectionNames[pcnIndex];
29
- let photoCollection = payload.photos[photoCollectionName];
30
- let photoSectionKeys = Object.keys(photoCollection);
31
- if (!photoSectionKeys || photoSectionKeys.length == 0) {}
32
- else {
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(`${util.capitalizeFirstLetter(photoCollectionName)} Photos`);
37
- let photoPosition = 1;
38
- for (let pskIndex = 0; pskIndex < photoSectionKeys.length; pskIndex++) { // Iterate over X user-defined photo sections within each photo collection
39
- let photoSectionKey = photoSectionKeys[pskIndex];
40
- let photoSection = photoCollection[photoSectionKey];
41
- let photoSectionName = photoSection.name;
42
- console.log(`Starting Section ${photoSectionName}`);
43
- let photos = photoSection.photos;
44
- if (!photos || photos.length == 0) {}
45
- else {
46
- for (let pIndex = 1; pIndex <= photos.length; pIndex++) { // Iterate over X user-defined photos within each photo section
47
- let photo = photos[pIndex-1];
48
- if (photoPosition > maxPhotosPerPage) { // Need a new page
49
- photoPosition = 1;
50
- docIndex++;
51
- docs[docIndex] = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
52
- forms[docIndex] = docs[docIndex].getForm();
53
- forms[docIndex].getButton("FullWidthLogo").setImage(await docs[docIndex].embedPng(mqLogoBytes));
54
- forms[docIndex].getTextField("Header").setText(`${util.capitalizeFirstLetter(photoCollectionName)} Photos`);
55
- }
56
- let imageToSet;
57
- if (photo.base64.includes("image/jpeg")) imageToSet = await docs[docIndex].embedJpg(util._base64ToArrayBuffer(photo.base64));
58
- else if (photo.base64.includes("image/png")) imageToSet = await docs[docIndex].embedPng(util._base64ToArrayBuffer(photo.base64));
59
- if (imageToSet) {
60
- console.log(`Printing ${photo.tag} in Position #${photoPosition} on Page #${docIndex+1}`);
61
- forms[docIndex].getButton(`photo${pSize}${photoPosition}`).setImage(imageToSet);
62
- }
63
- let photoSubText = photoSection.name;
64
- let isFirstPhotoOfSection = previousPhotoSectionName !== photoSectionName;
65
- if (isFirstPhotoOfSection && photoSection.hasNotes && photoSection.notes) photoSubText += `: ${photoSection.notes}`;
66
- forms[docIndex].getTextField(`Notes${photoPosition}`).setText(`${photoSubText}`);
67
- photoPosition++;
68
- previousPhotoSectionName = photoCollectionName;
69
- }
70
- }
24
+ let previousPhotoSectionName;
25
+ let docIndex = 0;
26
+ let photoSectionKeys = Object.keys(payload.photos);
27
+ if (photoSectionKeys && photoSectionKeys.length > 0) {
28
+ docs[docIndex] = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
29
+ forms[docIndex] = docs[docIndex].getForm();
30
+ forms[docIndex].getButton("FullWidthLogo").setImage(await docs[docIndex].embedPng(mqLogoBytes));
31
+ forms[docIndex].getTextField("Header").setText(`Project Photos`);
32
+ let photoPosition = 1;
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[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`);
71
48
  }
72
- docIndex++;
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;
73
59
  }
60
+ }
61
+ }
62
+ docIndex++;
74
63
  }
75
64
 
76
65
  // Prepare Deliverable