@measurequick/measurequick-report-generator 1.2.41 → 1.2.43

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