@measurequick/measurequick-report-generator 1.2.44 → 1.2.45

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.44",
3
+ "version": "1.2.45",
4
4
  "description": "Generates PDF documents for various MeasureQuick applications.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,10 +5,10 @@ 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) {
8
+ export async function getReport(payload) { console.log("PAYLOAD " + JSON.stringify(payload));
9
9
 
10
10
  const mqLogoBytes = util._base64ToArrayBuffer(base64.mqLogo);
11
- let maxPhotosPerPage = payload.meta.pdf_settings.maxPhotosPerPage;
11
+ let maxPhotosPerPage = payload.meta.pdf_settings.maxPhotosPerPage ? payload.meta.pdf_settings.maxPhotosPerPage : 2;
12
12
 
13
13
  // Layout Configuration
14
14
  let docs = [], forms = [], page = photos6, pSize = "Small";
@@ -21,42 +21,44 @@ export async function getReport(payload) {
21
21
  }
22
22
 
23
23
  // Process All Photos
24
- let previousPhotoSectionName;
25
24
  let docIndex = 0;
26
- let photoSectionKeys = Object.keys(payload.photos);
27
- if (photoSectionKeys && photoSectionKeys.length > 0) {
25
+ let photos = payload.photos;
26
+ console.log(JSON.stringify(photos));
27
+ if (photos && Object.keys(photos) && Object.keys(photos).length > 0) {
28
+ let s3ReferenceIds = Object.keys(photos);
29
+ let arrPhotos = [];
30
+ for (let i = 0; i < s3ReferenceIds.length; i++) { if (s3ReferenceIds[i] !== 'unsynced') arrPhotos.push(photos[s3ReferenceIds[i]]); }
31
+ console.log(arrPhotos);
32
+ arrPhotos.sort((a, b) => (a.section > b.section) ? 1 : -1);
33
+ console.log(arrPhotos);
28
34
  docs[docIndex] = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
29
35
  forms[docIndex] = docs[docIndex].getForm();
30
36
  forms[docIndex].getButton("FullWidthLogo").setImage(await docs[docIndex].embedPng(mqLogoBytes));
31
37
  forms[docIndex].getTextField("Header").setText(`Project Photos`);
32
38
  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`);
48
- }
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;
39
+ let prevSection, currSection;
40
+ for (let s3IdIndex = 0; s3IdIndex < s3ReferenceIds.length; s3IdIndex++) {
41
+ let s3ReferenceId = s3ReferenceIds[s3IdIndex];
42
+ if (s3ReferenceId !== "unsynced") {
43
+ let photo = photos[s3ReferenceId];
44
+ currSection = photo.section;
45
+ if (photoPosition > maxPhotosPerPage) {
46
+ photoPosition = 1;
47
+ docIndex++;
48
+ docs[docIndex] = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
49
+ forms[docIndex] = docs[docIndex].getForm();
50
+ forms[docIndex].getButton("FullWidthLogo").setImage(await docs[docIndex].embedPng(mqLogoBytes));
51
+ forms[docIndex].getTextField("Header").setText(`Project Photos`);
59
52
  }
53
+ let imageToSet;
54
+ if ((photo.base64 && photo.base64.includes("image/jpeg")) || photo.fileType == 'jpg') imageToSet = await docs[docIndex].embedJpg(util._base64ToArrayBuffer(photo.base64));
55
+ else if ((photo.base64 && photo.base64.includes("image/png")) || photo.fileType == 'png') imageToSet = await docs[docIndex].embedPng(util._base64ToArrayBuffer(photo.base64));
56
+ if (imageToSet) forms[docIndex].getButton(`photo${pSize}${photoPosition}`).setImage(imageToSet);
57
+ photoPosition++;
58
+ let caption = photo.section;
59
+ if (prevSection == currSection) caption += photo.notes;
60
+ forms[docIndex].getTextField(`Notes${photoPosition}`).setText(caption);
61
+ prevSection = currSection;
60
62
  }
61
63
  }
62
64
  docIndex++;