@measurequick/measurequick-report-generator 1.2.37 → 1.2.39

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