@measurequick/measurequick-report-generator 1.2.19 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measurequick/measurequick-report-generator",
3
- "version": "1.2.19",
3
+ "version": "1.2.20",
4
4
  "description": "Generates PDF documents for various MeasureQuick applications.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -7,12 +7,15 @@ import * as util from '../util.js';
7
7
 
8
8
  export async function getReport(payload) {
9
9
 
10
+ const mqLogoBytes = util._base64ToArrayBuffer(base64.mqLogo);
11
+ let maxPhotosPerPage = payload.meta.pdf_settings.maxPhotosPerPage;
12
+
10
13
  // Layout Configuration
11
14
  let docs = [], forms = [], page = photos6, pSize = "Small";
12
- if (payload.meta.pdf_settings.maxPhotosPerPage == 4) {
15
+ if (maxPhotosPerPage == 4) {
13
16
  page = photos4;
14
17
  pSize = "Mid";
15
- } else if (payload.meta.pdf_settings.maxPhotosPerPage == 2) {
18
+ } else if (maxPhotosPerPage == 2) {
16
19
  page = photos2;
17
20
  pSize = "Large";
18
21
  }
@@ -20,25 +23,42 @@ export async function getReport(payload) {
20
23
  // Process All Photos
21
24
  let previousPhotoCollectionName;
22
25
  let photoCollectionNames = ["project", "equipment", "site", "customer"];
23
- for (let pcnIndex = 0; pcnIndex < photoCollectionNames.length; pcnIndex++) {
26
+ for (let pcnIndex = 0; pcnIndex < photoCollectionNames.length; pcnIndex++) { // Iterate over all 4 photo photo collections
24
27
  let photoCollectionName = photoCollectionNames[pcnIndex];
25
28
  let photoCollection = payload.photos[photoCollectionName];
26
29
  let photoSectionKeys = Object.keys(photoCollection);
27
- for (let pskIndex = 0; pskIndex < photoSectionKeys.length; pskIndex++) {
30
+ for (let pskIndex = 0; pskIndex < photoSectionKeys.length; pskIndex++) { // Iterate over X user-defined photo sections within each photo collection
28
31
  let photoSectionKey = photoSectionKeys[pskIndex];
29
32
  let photoSection = photoCollection[photoSectionKey];
30
33
  let photos = photoSection.photos;
31
34
  if (!photos || photos.length == 0) break;
32
- for (let pIndex = 0; pIndex < photos.length; pIndex++) {
33
- let photo = photos[pIndex];
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
+ }
34
53
  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));
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));
37
56
  if (imageToSet) form.getButton(`photo${pSize}${pIndex}`).setImage(imageToSet);
38
57
  let photoSubText = photoSection.name;
39
- let isFirstPhotoOfSection = previousPhotoSectionName == photoCollectionName;
58
+ let isFirstPhotoOfSection = previousPhotoCollectionName == photoCollectionName;
40
59
  if (isFirstPhotoOfSection && photoSection.hasNotes) photoSubText += `: ${photoSection.notes}`;
41
60
  form.getTextField(`Notes${pIndex}`).setText(`${photoSubText}`);
61
+ photoPosition++;
42
62
  previousPhotoCollectionName = photoCollectionName;
43
63
  }
44
64
  }