@measurequick/measurequick-report-generator 1.2.18 → 1.2.19

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.18",
3
+ "version": "1.2.19",
4
4
  "description": "Generates PDF documents for various MeasureQuick applications.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,57 +5,46 @@ 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("Photos Report"); console.log(payload);
9
- let docs = [], forms = [], page = photos6, size = "Small";
8
+ export async function getReport(payload) {
9
+
10
+ // Layout Configuration
11
+ let docs = [], forms = [], page = photos6, pSize = "Small";
10
12
  if (payload.meta.pdf_settings.maxPhotosPerPage == 4) {
11
13
  page = photos4;
12
- size = "Mid";
14
+ pSize = "Mid";
13
15
  } else if (payload.meta.pdf_settings.maxPhotosPerPage == 2) {
14
16
  page = photos2;
15
- size = "Large";
17
+ pSize = "Large";
16
18
  }
17
- let keys = ["project", "equipment", "site", "customer"];
18
- let lastTag, currentTag;
19
- for (let k = 0; k < keys.length; k++) {
20
- let photoCount = 0, pageCount = 0, sectionNum = 0, count = 0;
21
- if (payload.photos[keys[k]]) {
22
- currentTag = keys[k];
23
- let sections = Object.keys(payload.photos[keys[k]]);
24
- for (const [section, data] of Object.entries(payload.photos[keys[k]])) photoCount += data.photos.length;
25
- pageCount = Math.ceil(photoCount / payload.meta.pdf_settings.maxPhotosPerPage);
26
- for (let i = 0; i < pageCount; i++) {
27
- const doc = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
28
- const form = doc.getForm();
29
- form.getTextField("Header").setText(`${util.capitalizeFirstLetter(keys[k])} Photos`);
30
- const mqLogoBytes = util._base64ToArrayBuffer(base64.mqLogo);
31
- const mqLogo = await doc.embedPng(mqLogoBytes);
32
- form.getButton("FullWidthLogo").setImage(mqLogo);
33
- docs.push(doc);
34
- forms.push(form);
35
- for (let j = 1; j <= payload.meta.pdf_settings.maxPhotosPerPage; j++) {
36
- let image;
37
- if (!payload.photos[keys[k]][sections[sectionNum]].photos[count]) {
38
- count = 0;
39
- sectionNum++;
40
- if (!payload.photos[keys[k]][sections[sectionNum]]) break;
41
- }
42
- let photo;
43
- if (payload.photos[keys[k]][sections[sectionNum]].photos[count]) {
44
- photo = payload.photos[keys[k]][sections[sectionNum]].photos[count].base64;
45
- count++;
46
- if (photo.includes("image/jpeg")) image = await doc.embedJpg(util._base64ToArrayBuffer(photo));
47
- else if (photo.includes("image/png")) image = await doc.embedPng(util._base64ToArrayBuffer(photo));
48
- if (image) form.getButton(`photo${size}${j}`).setImage(image);
49
- let firstPhoto = (lastTag != currentTag);
50
- lastTag = currentTag;
51
- let notes = payload.photos[keys[k]][sections[sectionNum]].name;
52
- if (payload.photos[keys[k]][sections[sectionNum]].hasNotes && firstPhoto) notes += ": " + payload.photos[keys[k]][sections[sectionNum]].notes;
53
- form.getTextField(`Notes${j}`).setText(`${notes}`);
54
- }
55
- }
56
- }
19
+
20
+ // Process All Photos
21
+ let previousPhotoCollectionName;
22
+ let photoCollectionNames = ["project", "equipment", "site", "customer"];
23
+ for (let pcnIndex = 0; pcnIndex < photoCollectionNames.length; pcnIndex++) {
24
+ let photoCollectionName = photoCollectionNames[pcnIndex];
25
+ let photoCollection = payload.photos[photoCollectionName];
26
+ let photoSectionKeys = Object.keys(photoCollection);
27
+ for (let pskIndex = 0; pskIndex < photoSectionKeys.length; pskIndex++) {
28
+ let photoSectionKey = photoSectionKeys[pskIndex];
29
+ let photoSection = photoCollection[photoSectionKey];
30
+ let photos = photoSection.photos;
31
+ if (!photos || photos.length == 0) break;
32
+ for (let pIndex = 0; pIndex < photos.length; pIndex++) {
33
+ let photo = photos[pIndex];
34
+ 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));
37
+ if (imageToSet) form.getButton(`photo${pSize}${pIndex}`).setImage(imageToSet);
38
+ let photoSubText = photoSection.name;
39
+ let isFirstPhotoOfSection = previousPhotoSectionName == photoCollectionName;
40
+ if (isFirstPhotoOfSection && photoSection.hasNotes) photoSubText += `: ${photoSection.notes}`;
41
+ form.getTextField(`Notes${pIndex}`).setText(`${photoSubText}`);
42
+ previousPhotoCollectionName = photoCollectionName;
57
43
  }
44
+ }
58
45
  }
46
+
47
+ // Prepare Deliverable
59
48
  forms.forEach(form => { form.flatten() });
60
49
  let pdfDoc = await PDFDocument.create();
61
50
  for (let i = 0; i < docs.length; i++) {
@@ -64,6 +53,3 @@ export async function getReport(payload) { console.log("Photos Report"); console
64
53
  }
65
54
  return await pdfDoc.saveAsBase64({ dataUri: true });
66
55
  }
67
-
68
- // MAX # of Characters for 2-Photo Pages: 95 Characters
69
- // MAX # of Characters for 4-Photo & 6-Photo Pages: 42 Characters