@measurequick/measurequick-report-generator 1.0.50 → 1.0.53
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/index.js +9 -210
- package/jspdf/mq-report-generator.js +459 -0
- package/package.json +3 -2
- package/pdflib/mq-system-vitals-report-generator.js +165 -0
- package/{assets → templates/js}/request.js +506 -207
- package/templates/js/templates.js +662 -0
- package/templates/pdf/MQ-system-vitals-report.pdf +0 -0
- package/assets/templates.js +0 -268
- /package/{assets → templates/js}/graphics.js +0 -0
package/index.js
CHANGED
|
@@ -1,213 +1,12 @@
|
|
|
1
|
+
import * as mqReportGenerator from "./jspdf/mq-report-generator.js";
|
|
2
|
+
import * as mqSystemVitalsReportGenerator from "./pdflib/mq-system-vitals-report-generator.js";
|
|
1
3
|
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export function getReport(data=null) {
|
|
11
|
-
try {
|
|
12
|
-
if (data == null) reportData = JSON.parse(JSON.stringify(request.body));
|
|
13
|
-
else reportData = JSON.parse(JSON.stringify(data));
|
|
14
|
-
|
|
15
|
-
printBoilerPlate(reportData.meta.reportTheme);
|
|
16
|
-
|
|
17
|
-
var profilePicture = reportData.meta.profilePicturePlacement == "header" ? reportData.staticPhotos.profilePicture : null;
|
|
18
|
-
var companyLogo = reportData.meta.companyLogoPlacement == "header" ? reportData.staticPhotos.companyLogo : null;
|
|
19
|
-
printHeaderData(reportData.meta.reportName, reportData.meta.techName, profilePicture, companyLogo);
|
|
20
|
-
|
|
21
|
-
printBodyData(reportData.staticPhotos.geolocationMap);
|
|
22
|
-
|
|
23
|
-
profilePicture = reportData.meta.profilePicturePlacement == "footer" ? reportData.staticPhotos.profilePicture : null;
|
|
24
|
-
companyLogo = reportData.meta.companyLogoPlacement == "footer" ? reportData.staticPhotos.companyLogo : null;
|
|
25
|
-
printFooterData(reportData.meta.techName, profilePicture, companyLogo);
|
|
26
|
-
|
|
27
|
-
printPhotoSections();
|
|
28
|
-
|
|
29
|
-
printInfoPage();
|
|
30
|
-
|
|
31
|
-
return doc.output("datauristring");
|
|
32
|
-
} catch (e) {
|
|
33
|
-
return doc.output("datauristring");
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function printBoilerPlate(theme) {
|
|
38
|
-
doc.addImage(graphics.headerMeasureQuick, "JPEG", 0, 0, 8.5, 1);
|
|
39
|
-
doc.addImage(graphics.footerMeasureQuick, "JPEG", 0, 7.75, 8.5, 4.5);
|
|
40
|
-
doc.addImage(graphics.companyLogoMeasureQuickLight, "JPEG", .25, 10, 2.15625, .5);
|
|
41
|
-
|
|
42
|
-
doc.setLineWidth(0.025);
|
|
43
|
-
doc.setDrawColor(0);
|
|
44
|
-
doc.setFillColor(242, 242, 242);
|
|
45
|
-
doc.rect(.125, 1.125, 2.667, 3, "F");
|
|
46
|
-
doc.rect(2.917, 1.125, 2.667, 3, "F");
|
|
47
|
-
doc.rect(5.709, 1.125, 2.667, 3, "F");
|
|
48
|
-
doc.rect(.125, 4.25, 4.0625, 3.375, "F");
|
|
49
|
-
|
|
50
|
-
doc.addImage(graphics.iconSunshine, "JPEG", .4585, 1.625, 2, 2);
|
|
51
|
-
doc.addImage(graphics.iconHouse, "JPEG", 3.252, 1.625, 2, 2);
|
|
52
|
-
doc.addImage(graphics.iconInfo, "JPEG", 6.044, 1.625, 2, 2);
|
|
53
|
-
doc.addImage(graphics.iconPerformance, "JPEG", 1.15625, 4.9375, 2, 2);
|
|
54
|
-
|
|
55
|
-
doc.setFontSize(6.5);
|
|
56
|
-
doc.setFontStyle("bolditalic");
|
|
57
|
-
doc.setTextColor(255, 255, 255);
|
|
58
|
-
var disclaimer = `Disclaimer: This report was prepared by your service technician who is solely responsible for its content. This report is provided “as-is” excluding all warranties expressed or implied including without limitation the warranty of merchantability. ©2017-${new Date().getFullYear()} Manifold Cloud Services Ltd.`;
|
|
59
|
-
disclaimer = doc.splitTextToSize(disclaimer.toUpperCase(), 8);
|
|
60
|
-
doc.text(disclaimer, .125, 10.66);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function printHeaderData(reportName, techName, profilePicture, companyLogo) {
|
|
64
|
-
var size = 13;
|
|
65
|
-
var width = doc.getStringUnitWidth(reportName) * size / 72;
|
|
66
|
-
while (width > 4.5){
|
|
67
|
-
size -= .5;
|
|
68
|
-
width = doc.getStringUnitWidth(reportName) * size / 72;
|
|
69
|
-
}
|
|
70
|
-
doc.setFontSize(size);
|
|
71
|
-
doc.setFontStyle("bold");
|
|
72
|
-
doc.text(reportName, 0.25, .75);
|
|
73
|
-
doc.setFontSize(8);
|
|
74
|
-
if (profilePicture) printProfilePicture("header", techName, profilePicture);
|
|
75
|
-
if (companyLogo) printCompanyLogo("header", companyLogo);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function printBodyData(geolocationMap) {
|
|
79
|
-
doc.setTextColor(0, 0, 0);
|
|
80
|
-
printMap(geolocationMap);
|
|
81
|
-
printSingleBodySection(templates.outdoorMeasurements, .25, 2.317, 1.33);
|
|
82
|
-
printSingleBodySection(templates.indoorMeasurements, 3.042, 5.109, 1.33);
|
|
83
|
-
printSingleBodySection(templates.systemInfo, 5.834, 7.9, 1.33);
|
|
84
|
-
printSingleBodySection(templates.performanceData, .25, 2, 4.435);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function printSingleBodySection(dataPoints, xLeft, xRight, y) {
|
|
88
|
-
var yTop = y + .22;
|
|
89
|
-
var s = .2;
|
|
90
|
-
var dataPoint;
|
|
91
|
-
var val;
|
|
92
|
-
var units;
|
|
93
|
-
var text;
|
|
94
|
-
var i = 1;
|
|
95
|
-
var printIcons = true;
|
|
96
|
-
for (let key in dataPoints) {
|
|
97
|
-
if (key == "headerLabel") {
|
|
98
|
-
printIcons = !(dataPoints.headerLabel == "Performance Calculations");
|
|
99
|
-
doc.setFontStyle("bold");
|
|
100
|
-
doc.setFontSize(9);
|
|
101
|
-
doc.text(dataPoints.headerLabel, xLeft, y);
|
|
102
|
-
doc.setFontStyle("normal");
|
|
103
|
-
doc.setFontSize(8);
|
|
104
|
-
y += .22;
|
|
105
|
-
} else if (key.includes("subHeaderLabel")) {
|
|
106
|
-
doc.setFontStyle("bold");
|
|
107
|
-
doc.text(dataPoints[`subHeaderLabel${i}`], xLeft, y);
|
|
108
|
-
doc.setFontStyle("normal");
|
|
109
|
-
y += .22;
|
|
110
|
-
i++;
|
|
111
|
-
} else if (key == "columnBreak") {
|
|
112
|
-
xLeft += 2;
|
|
113
|
-
xRight += 2;
|
|
114
|
-
y = yTop;
|
|
115
|
-
} else if (key == "rowBreak") {
|
|
116
|
-
y += .3;
|
|
117
|
-
} else {
|
|
118
|
-
dataPoint = dataPoints[key];
|
|
119
|
-
val = reportData.values[key];
|
|
120
|
-
units = "";
|
|
121
|
-
if (dataPoint.hasOwnProperty("units")) {
|
|
122
|
-
units = Array.isArray(dataPoint.units) ? ` (${dataPoint.units[0]} / ${dataPoint.units[1]})` : ` (${dataPoint.units})`;
|
|
123
|
-
}
|
|
124
|
-
text = dataPoint.hasOwnProperty("secondaryValue") ? `${val} / ${reportData.values[dataPoint.secondaryValue]}` : val;
|
|
125
|
-
doc.text(`${dataPoint.label}${units}:`, xLeft, y);
|
|
126
|
-
doc.text(text, alignRight(text, xRight, 8), y);
|
|
127
|
-
if (printIcons) doc.addImage(graphics[reportData.rangeIcons[key]], "JPEG", xRight + .05, y - .12, .16, .16);
|
|
128
|
-
if (printIcons) doc.addImage(graphics[reportData.toolIcons[key]], "JPEG", xRight+.25, y - .12, .16, .16);
|
|
129
|
-
y += s;
|
|
130
|
-
}
|
|
4
|
+
export function generateReport(reportType, payload) {
|
|
5
|
+
if (reportType == "mqStandard") reportType = "mqCooling";
|
|
6
|
+
switch (reportType) {
|
|
7
|
+
case "mqCooling":
|
|
8
|
+
case "mqHeating": return mqReportGenerator.generateReport(reportType, payload);
|
|
9
|
+
case "mqSystemVitalsFillable": return mqSystemVitalsReportGenerator.generateReport(payload);
|
|
10
|
+
default: return false;
|
|
131
11
|
}
|
|
132
12
|
}
|
|
133
|
-
|
|
134
|
-
function printMap(geolocationMap) {
|
|
135
|
-
doc.addImage(geolocationMap, "PNG", 4.3125, 4.25, 4.0625, 3.375);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function printProfilePicture(picturePlacement, techName, profilePicture) {
|
|
139
|
-
var coords = templates.profilePictureCoordinates[picturePlacement];
|
|
140
|
-
doc.addImage(profilePicture, "JPEG", coords.x, coords.y, coords.w, coords.h);
|
|
141
|
-
doc.text(techName, alignRight(techName, 8.4, 8), coords.y + 1.2);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function printCompanyLogo(logoPlacement, companyLogo) {
|
|
145
|
-
var coords = templates.companyLogoCoordinates[logoPlacement];
|
|
146
|
-
doc.addImage(companyLogo, "JPEG", coords.x, coords.y, coords.w, coords.h);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function printFooterData(techName, profilePicture, companyLogo) {
|
|
150
|
-
if (profilePicture) printProfilePicture("footer", techName, profilePicture);
|
|
151
|
-
if (companyLogo) printCompanyLogo("footer", companyLogo);
|
|
152
|
-
|
|
153
|
-
doc.setTextColor(255, 255, 255);
|
|
154
|
-
|
|
155
|
-
var s = .2;
|
|
156
|
-
var x = .2;
|
|
157
|
-
var y = 8;
|
|
158
|
-
var key;
|
|
159
|
-
|
|
160
|
-
doc.setFontType("bold");
|
|
161
|
-
doc.setFontSize(12);
|
|
162
|
-
doc.text("Customer", x, y);
|
|
163
|
-
doc.text(reportData.footerData.systemName, x + 2.5, y);
|
|
164
|
-
doc.setFontType("normal");
|
|
165
|
-
doc.setFontSize(10);
|
|
166
|
-
|
|
167
|
-
y += s;
|
|
168
|
-
|
|
169
|
-
for (let key in reportData.footerData) {
|
|
170
|
-
if (key == "columnBreak") {
|
|
171
|
-
x += 2.5;
|
|
172
|
-
y = 8 + s;
|
|
173
|
-
} else if (key.includes("subHeaderLabel")) {
|
|
174
|
-
doc.setFontType("bold");
|
|
175
|
-
doc.text(`${reportData.footerData[key]}`, x, y);
|
|
176
|
-
doc.setFontType("normal");
|
|
177
|
-
y += s;
|
|
178
|
-
} else {
|
|
179
|
-
doc.text(`${reportData.footerData[key]}`, x, y);
|
|
180
|
-
y += s;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function printDiagnosticPage() {
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function printPhotoSections() {
|
|
190
|
-
doc.setFontSize(16);
|
|
191
|
-
doc.setFontColor(0, 0, 0);
|
|
192
|
-
var x = 0;
|
|
193
|
-
var y = 1;
|
|
194
|
-
doc.addPage(8.5, 11);
|
|
195
|
-
for (var i = 0; i < reportData.dynamicPhotos; i++) {
|
|
196
|
-
doc.text(reportData.dynamicPhotos[i]);
|
|
197
|
-
y += 1;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function printInfoPage() {
|
|
202
|
-
doc.addPage(8.5, 11);
|
|
203
|
-
doc.setTextColor(0, 0, 0);
|
|
204
|
-
if (reportData.meta.reportType == "cooling") {
|
|
205
|
-
doc.text(templates.coolingInfoPage.body, 1, 1);
|
|
206
|
-
} else if (reportData.meta.reportType == "heating") {
|
|
207
|
-
doc.text(templates.heatingInfoPage.body, 1, 1);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function alignRight(text, rightAlign, fontSize) {
|
|
212
|
-
return rightAlign - doc.getStringUnitWidth(text) * fontSize / 72;
|
|
213
|
-
}
|
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import * as graphics from "../templates/js/graphics.js";
|
|
2
|
+
import * as templates from "../templates/js/templates.js";
|
|
3
|
+
import * as request from "../templates/js/request.js";
|
|
4
|
+
|
|
5
|
+
let jsPDF = require("jspdf");
|
|
6
|
+
let doc = new jsPDF(templates.docOptions);
|
|
7
|
+
let reportData;
|
|
8
|
+
let currentSnapshot;
|
|
9
|
+
|
|
10
|
+
export function generateReport(reportType, payload) {
|
|
11
|
+
console.log("reportType " + reportType);
|
|
12
|
+
console.log(payload);
|
|
13
|
+
try {
|
|
14
|
+
reportData = JSON.parse(JSON.stringify(payload));
|
|
15
|
+
let testNumber = 0;
|
|
16
|
+
for (currentSnapshot in reportData.snapshots) {
|
|
17
|
+
if (testNumber > 0) doc.addPage();
|
|
18
|
+
printBoilerPlateStandard();
|
|
19
|
+
printHeaderData();
|
|
20
|
+
printBodyData(currentSnapshot);
|
|
21
|
+
printFooterData();
|
|
22
|
+
resizeAndPrintStaticImages();
|
|
23
|
+
testNumber++;
|
|
24
|
+
}
|
|
25
|
+
printDiagnosticPage();
|
|
26
|
+
printInfoPage();
|
|
27
|
+
printPhotoPages();
|
|
28
|
+
return doc.output("datauristring");
|
|
29
|
+
} catch (e) {
|
|
30
|
+
return doc.output("datauristring");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function printBoilerPlateStandard() {
|
|
35
|
+
doc.addImage(graphics.headerMeasureQuick, "JPEG", 0, 0, 8.5, 1);
|
|
36
|
+
doc.addImage(graphics.footerMeasureQuick, "JPEG", 0, 7.75, 8.5, 4.5);
|
|
37
|
+
let mqLogo = graphics.companyLogoMeasureQuickLight;
|
|
38
|
+
if (reportData.meta.reportTheme == "light")
|
|
39
|
+
mqLogo = graphics.companyLogoMeasureQuickDark;
|
|
40
|
+
doc.addImage(mqLogo, "JPEG", .25, 10, 2.15625, .5);
|
|
41
|
+
doc.setLineWidth(0.025);
|
|
42
|
+
doc.setDrawColor(0);
|
|
43
|
+
doc.setFillColor(242, 242, 242);
|
|
44
|
+
doc.rect(.125, 1.125, 2.667, 3, "F");
|
|
45
|
+
doc.rect(2.917, 1.125, 2.667, 3, "F");
|
|
46
|
+
doc.rect(5.709, 1.125, 2.667, 3, "F");
|
|
47
|
+
doc.rect(.125, 4.25, 4.0625, 3.375, "F");
|
|
48
|
+
let bgIcons = templates[`${reportData.meta.reportType}BgIcons`];
|
|
49
|
+
doc.addImage(graphics[bgIcons.iconSection1], "JPEG", .4585, 1.625, 2, 2);
|
|
50
|
+
doc.addImage(graphics[bgIcons.iconSection2], "JPEG", 3.252, 1.625, 2, 2);
|
|
51
|
+
doc.addImage(graphics[bgIcons.iconSection3], "JPEG", 6.044, 1.625, 2, 2);
|
|
52
|
+
doc.addImage(graphics[bgIcons.iconSection4], "JPEG", 1.15625, 4.9375, 2, 2);
|
|
53
|
+
doc.setFontStyle("bold");
|
|
54
|
+
doc.setFontSize(9);
|
|
55
|
+
let headers = templates[`${reportData.meta.reportType}Headers`];
|
|
56
|
+
doc.text(headers.headerSection1, .25, 1.33);
|
|
57
|
+
doc.text(headers.headerSection2, 3.042, 1.33);
|
|
58
|
+
doc.text(headers.headerSection3, 5.834, 1.33);
|
|
59
|
+
doc.text(headers.headerSection4, .25, 4.435);
|
|
60
|
+
doc.setFontSize(8);
|
|
61
|
+
doc.text(headers.headerSection4Subsection1, .25, 4.655);
|
|
62
|
+
doc.text(headers.headerSection4Subsection2, 2.25, 4.655);
|
|
63
|
+
doc.text(headers.headerSection4Subsection3, 2.25, 5.655);
|
|
64
|
+
doc.setFontSize(6.5);
|
|
65
|
+
doc.setFontStyle("bolditalic");
|
|
66
|
+
doc.setTextColor(255, 255, 255);
|
|
67
|
+
let disclaimer = `Disclaimer: This report was prepared by your service technician who is solely responsible for its content. This report is provided “as-is” excluding all warranties expressed or implied including without limitation the warranty of merchantability. ©2017-${new Date().getFullYear()} Manifold Cloud Services Ltd.`;
|
|
68
|
+
disclaimer = doc.splitTextToSize(disclaimer.toUpperCase(), 8);
|
|
69
|
+
doc.text(disclaimer, .125, 10.66);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function printBoilerPlateDiagnostic() {
|
|
73
|
+
doc.addImage(graphics.headerMeasureQuick, "JPEG", 0, 0, 8.5, 1);
|
|
74
|
+
doc.setLineWidth(0.025);
|
|
75
|
+
doc.setDrawColor(0);
|
|
76
|
+
doc.setFillColor(242, 242, 242);
|
|
77
|
+
doc.setTextColor(0, 0, 0);
|
|
78
|
+
doc.setFontSize(9);
|
|
79
|
+
doc.setFontStyle('bold');
|
|
80
|
+
doc.rect(.125, 3.3, 8.25, 7.6, "F");
|
|
81
|
+
doc.rect(.125, .6, 4.0625, 2.6, "F");
|
|
82
|
+
doc.rect(4.3125, .6, 4.0625, 2.6, "F");
|
|
83
|
+
doc.text("System Diagnostics", 4.4375, .8);
|
|
84
|
+
doc.text("Subsystem Review", .25, .8);
|
|
85
|
+
doc.text('Corrective Actions', .25, 3.5);
|
|
86
|
+
doc.setFontSize(8);
|
|
87
|
+
doc.setFontStyle('normal');
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function printHeaderData() {
|
|
92
|
+
let size = 13.5;
|
|
93
|
+
do { size -= .5; } while ((doc.getStringUnitWidth(reportData.meta.reportName) * size / 72) > 4.5);
|
|
94
|
+
doc.setFontSize(size);
|
|
95
|
+
doc.setFontStyle("bold");
|
|
96
|
+
doc.text(reportData.meta.reportName, 0.25, .75);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function printBodyData(currentSnapshot) {
|
|
100
|
+
doc.setTextColor(0, 0, 0);
|
|
101
|
+
doc.setFontType("normal");
|
|
102
|
+
doc.setFontSize(8);
|
|
103
|
+
if (reportData.meta.reportType == "mqCooling") {
|
|
104
|
+
printBodySection(currentSnapshot, "outdoorMeasurements", .25, 2.317, 1.55);
|
|
105
|
+
printBodySection(currentSnapshot, "indoorMeasurements", 3.042, 5.109, 1.55);
|
|
106
|
+
printBodySection(currentSnapshot, "systemProfileWeatherData", 5.834, 7.9, 1.55);
|
|
107
|
+
printBodySection(currentSnapshot, "performanceData", .25, 2, 4.855);
|
|
108
|
+
} else if (reportData.meta.reportType == "mqHeating") {
|
|
109
|
+
printBodySection(currentSnapshot, "combustion", .25, 2.317, 1.55);
|
|
110
|
+
printBodySection(currentSnapshot, "electricalMeasurements", 3.042, 5.109, 1.55);
|
|
111
|
+
printBodySection(currentSnapshot, "systemProfileWeatherDataGas", 5.834, 7.9, 1.55);
|
|
112
|
+
printBodySection(currentSnapshot, "performanceMetrics", .25, 2, 4.855);
|
|
113
|
+
}
|
|
114
|
+
printGeolocationMap();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function printBodySection(currentSnapshot, measurementSection, xLeft, xRight, y) {
|
|
118
|
+
console.log("David: " + measurementSection + ": " + JSON.stringify(reportData.snapshots[currentSnapshot]));
|
|
119
|
+
let dataPoints = JSON.parse(reportData.snapshots[currentSnapshot][measurementSection]);
|
|
120
|
+
let printRangeIcons = true;
|
|
121
|
+
let units = "";
|
|
122
|
+
let labelText = "";
|
|
123
|
+
let valueText = "";
|
|
124
|
+
let yTop = y;
|
|
125
|
+
let s = .18;
|
|
126
|
+
let sMultiplier = measurementSection == "performanceData" ? 2 : 1;
|
|
127
|
+
|
|
128
|
+
for (let key in dataPoints.values) {
|
|
129
|
+
let dataPoint = dataPoints.values[key];
|
|
130
|
+
let valueBeforeEditing = dataPoint;
|
|
131
|
+
let templateRef = templates[measurementSection][key];
|
|
132
|
+
if (templateRef) {
|
|
133
|
+
if (templateRef.hasOwnProperty("units"))
|
|
134
|
+
units = Array.isArray(templateRef.units) ? `(${templateRef.units[0]} / ${templateRef.units[1]})` : `(${templateRef.units})`;
|
|
135
|
+
else units = "";
|
|
136
|
+
labelText = `${templateRef.label} ${units}:`;
|
|
137
|
+
if (templateRef.hasOwnProperty("roundTo")) {
|
|
138
|
+
dataPoint *= 1;
|
|
139
|
+
dataPoint = dataPoint.toFixed(templateRef.roundTo);
|
|
140
|
+
}
|
|
141
|
+
if (templateRef.hasOwnProperty("secondaryValue")) {
|
|
142
|
+
let secondaryDataPoint = dataPoints.values[templateRef.secondaryValue];
|
|
143
|
+
if (templateRef.hasOwnProperty("roundTo")) {
|
|
144
|
+
secondaryDataPoint *= 1;
|
|
145
|
+
secondaryDataPoint = secondaryDataPoint.toFixed(templateRef.roundTo);
|
|
146
|
+
}
|
|
147
|
+
valueText = `${dataPoint} / ${secondaryDataPoint}`;
|
|
148
|
+
} else valueText = `${dataPoint}`;
|
|
149
|
+
if (templateRef.label) doc.text(labelText, xLeft, y);
|
|
150
|
+
doc.text(valueText, alignRight(valueText, xRight, 8), y);
|
|
151
|
+
if (printRangeIcons) {
|
|
152
|
+
let rangeIconRef = getRangeIcon(key, valueBeforeEditing, currentSnapshot);
|
|
153
|
+
if (rangeIconRef) doc.addImage(graphics[rangeIconRef], "JPEG", xRight + .05, y - .12, .16, .16);
|
|
154
|
+
}
|
|
155
|
+
let toolIconRef = getToolIcon(reportData.snapshots[currentSnapshot].toolIcons[key]);
|
|
156
|
+
if (toolIconRef) doc.addImage(graphics[toolIconRef], "JPEG", xRight + .25, y - .12, .16, .16);
|
|
157
|
+
y += (s * sMultiplier);
|
|
158
|
+
} else if (key == "newColumn") {
|
|
159
|
+
sMultiplier = 1;
|
|
160
|
+
xLeft = 2.25;
|
|
161
|
+
xRight = 3.9;
|
|
162
|
+
y = yTop;
|
|
163
|
+
} else if (key == "newRow") {
|
|
164
|
+
y += .35;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function printGeolocationMap() {
|
|
170
|
+
doc.addImage(reportData.staticPhotos.geolocationMap, "PNG", 4.3125, 4.25, 4.0625, 3.375);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function printProfilePicture() {
|
|
174
|
+
let coords = templates.profilePictureCoordinates[reportData.meta.profilePicturePlacement];
|
|
175
|
+
doc.addImage(reportData.staticPhotos.profilePicture, "JPEG", coords.x, coords.y, coords.w, coords.h);
|
|
176
|
+
doc.text(reportData.meta.techName, alignRight(reportData.meta.techName, 8.4, 8), coords.y + 1.2);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function printCompanyLogo() {
|
|
180
|
+
let coords = templates.companyLogoCoordinates[reportData.meta.companyLogoPlacement];
|
|
181
|
+
doc.addImage(reportData.staticPhotos.companyLogo, "JPEG", coords.x, coords.y, coords.w, coords.h);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function printFooterData() {
|
|
185
|
+
let s = .15;
|
|
186
|
+
let x = .2;
|
|
187
|
+
let y = 8;
|
|
188
|
+
let equipmentLabels = ["Make", "Model", "Serial"];
|
|
189
|
+
let i = -1;
|
|
190
|
+
doc.setTextColor(255, 255, 255);
|
|
191
|
+
doc.setFontType("bold");
|
|
192
|
+
doc.setFontSize(12);
|
|
193
|
+
doc.text("Customer", x, y);
|
|
194
|
+
doc.text("Equipment", x + 2.5, y);
|
|
195
|
+
doc.setFontSize(8);
|
|
196
|
+
y += .2;
|
|
197
|
+
doc.setFontSize(10);
|
|
198
|
+
y += .05;
|
|
199
|
+
let footer = JSON.parse(reportData.footerData);
|
|
200
|
+
for (let key in footer) {
|
|
201
|
+
doc.setFontType("normal");
|
|
202
|
+
if (key.includes("header")) {
|
|
203
|
+
i = 0;
|
|
204
|
+
doc.setFontStyle("bold");
|
|
205
|
+
y += .1;
|
|
206
|
+
} else if (key == "systemCoords") {
|
|
207
|
+
s = .12;
|
|
208
|
+
x += 2.5;
|
|
209
|
+
y = 8.2;
|
|
210
|
+
doc.setFontStyle("bold");
|
|
211
|
+
doc.setFontSize(8);
|
|
212
|
+
doc.text("ID", x, y);
|
|
213
|
+
doc.setFontStyle("normal");
|
|
214
|
+
y += s;
|
|
215
|
+
}
|
|
216
|
+
let prefix = "";
|
|
217
|
+
if (i > -1) {
|
|
218
|
+
prefix = `${equipmentLabels[i]}: `;
|
|
219
|
+
i++;
|
|
220
|
+
}
|
|
221
|
+
doc.text(`${prefix}${footer[key]}`, x, y);
|
|
222
|
+
y += s;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function printDiagnosticPage() {
|
|
227
|
+
doc.addPage();
|
|
228
|
+
printBoilerPlateDiagnostic();
|
|
229
|
+
printSubsystemReview();
|
|
230
|
+
printSystemDiagnostics();
|
|
231
|
+
printCorrectiveActions();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function printSubsystemReview() {
|
|
235
|
+
let y = 1;
|
|
236
|
+
let templateRef = templates[`${reportData.meta.reportType}SubsystemReview`];
|
|
237
|
+
console.log("templateRef is " + templateRef);
|
|
238
|
+
let ssr = JSON.parse(reportData.subsystemReview);
|
|
239
|
+
for (let i = 0; i < Object.keys(ssr).length; i++) {
|
|
240
|
+
let key = Object.keys(ssr)[i];
|
|
241
|
+
console.log("key is " + key);
|
|
242
|
+
doc.text(templateRef[key], .25, y);
|
|
243
|
+
doc.text(ssr[key], 3, y);
|
|
244
|
+
y += .15;
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function printSystemDiagnostics() {
|
|
249
|
+
let y = 1;
|
|
250
|
+
console.log("DIAG: " + reportData.systemDiagnostics);
|
|
251
|
+
let diagnostics = JSON.parse(reportData.systemDiagnostics);
|
|
252
|
+
for (let i = 0; i < Object.keys(diagnostics).length; i++) {
|
|
253
|
+
let key = Object.keys(diagnostics)[i];
|
|
254
|
+
let score = diagnostics[key].score;
|
|
255
|
+
let diagnosticIcon = graphics.iconFlagGreen;
|
|
256
|
+
if (type === 'stability') icon = stability;
|
|
257
|
+
else if (score > 1 && score < 10) diagnosticIcon = graphics.iconFlagRed;
|
|
258
|
+
else if (score >= 10 && score < 15) diagnosticIcon = graphics.iconFlagYellow;
|
|
259
|
+
else if (score >= 15) diagnosticIcon = graphics.iconFlagBlack;
|
|
260
|
+
if (diagnosticIcon) doc.addImage(graphics[diagnosticIcon], "JPEG", 7.8, y, .25, .25);
|
|
261
|
+
y += .2;
|
|
262
|
+
doc.text(diagnostics[key].title, 4.4375, y);
|
|
263
|
+
doc.text(`${diagnostics[key].score}`, 7.5, y);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function printCorrectiveActions() {
|
|
268
|
+
let y = 3.8;
|
|
269
|
+
doc.setFontSize(9);
|
|
270
|
+
let ca = JSON.parse(reportData.correctiveActions);
|
|
271
|
+
for (let i = 0; i < Object.keys(ca).length; i++) {
|
|
272
|
+
let sectionKey = Object.keys(ca)[i];
|
|
273
|
+
for (let j = 0; j < Object.keys(ca[sectionKey]).length; j++) {
|
|
274
|
+
let actionKey = Object.keys(ca[sectionKey])[j];
|
|
275
|
+
let action = ca[sectionKey][actionKey];
|
|
276
|
+
if (actionKey == "header") {
|
|
277
|
+
doc.setFontSize(10);
|
|
278
|
+
doc.setFontStyle("bold");
|
|
279
|
+
doc.text(action, .25, y);
|
|
280
|
+
} else {
|
|
281
|
+
doc.setFontSize(8);
|
|
282
|
+
doc.setFontStyle("normal");
|
|
283
|
+
doc.text(actionKey, .25, y);
|
|
284
|
+
}
|
|
285
|
+
y += .18;
|
|
286
|
+
}
|
|
287
|
+
y += .1;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function printPhotoPages() {
|
|
292
|
+
let photoSectionMapping = ["project", "equipment", "site", "customer"];
|
|
293
|
+
let x, y, header, currentQuadrant, currentSection;
|
|
294
|
+
for (let i = 0; i < 4; i++) { // loops through the 4 main sections of photos, listed above (photoSectionMapping)
|
|
295
|
+
currentSection = reportData[`${photoSectionMapping[i]}Photos`];
|
|
296
|
+
if (Object.keys(currentSection).length > 0) doc.addPage();
|
|
297
|
+
else break;
|
|
298
|
+
currentQuadrant = 1;
|
|
299
|
+
x = templates.photoCoordinates[`quadrant${currentQuadrant}`].x;
|
|
300
|
+
y = templates.photoCoordinates[`quadrant${currentQuadrant}`].y;
|
|
301
|
+
doc.setFontStyle("bold");
|
|
302
|
+
doc.text(`${photoSectionMapping[i][0].toUpperCase()}${photoSectionMapping[i].slice(1)} Photos`, x, y - .2);
|
|
303
|
+
doc.setFontStyle("normal");
|
|
304
|
+
for (let key in currentSection) { // loops through the "subsections" of each main photo section
|
|
305
|
+
if (currentSection[key].photos) {
|
|
306
|
+
for (let j = 0; j < currentSection[key].photos.length; j++) { // loops through the photos[] array within each subsection, of each main photo section
|
|
307
|
+
let currentPhoto = currentSection[key].photos[j];
|
|
308
|
+
if (currentQuadrant === 3) {
|
|
309
|
+
doc.setLineWidth(0.025);
|
|
310
|
+
doc.setDrawColor(194, 197, 204);
|
|
311
|
+
doc.line(.25, 5.5, 8.25, 5.5);
|
|
312
|
+
} else if (currentQuadrant === 5) {
|
|
313
|
+
doc.addPage();
|
|
314
|
+
currentQuadrant = 1;
|
|
315
|
+
}
|
|
316
|
+
x = templates.photoCoordinates[`quadrant${currentQuadrant}`].x;
|
|
317
|
+
y = templates.photoCoordinates[`quadrant${currentQuadrant}`].y;
|
|
318
|
+
if (currentPhoto.base64) {
|
|
319
|
+
doc.text(getPhotoSectionNameFromTag(currentPhoto.tag), x, y);
|
|
320
|
+
let wPicMax = 3.75,
|
|
321
|
+
hPicMax = 4,
|
|
322
|
+
wPic = wPicMax,
|
|
323
|
+
hPic = hPicMax,
|
|
324
|
+
r = currentPhoto.aspect_ratio * 1;
|
|
325
|
+
if (r >= 1) { // logo is a landscape image
|
|
326
|
+
wPic = wPicMax;
|
|
327
|
+
hPic = wPic / r;
|
|
328
|
+
if (hPic > hPicMax) { // calculated h is too large for the available space
|
|
329
|
+
hPic = hPicMax;
|
|
330
|
+
wPic = hPic * r;
|
|
331
|
+
}
|
|
332
|
+
} else { // logo is a portrait image
|
|
333
|
+
hPic = hPicMax;
|
|
334
|
+
wPic = hPic * r;
|
|
335
|
+
if (wPic > wPicMax) { // calculated w is too large for the available space
|
|
336
|
+
wPic = wPicMax;
|
|
337
|
+
hPic = wPic / r;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
doc.addImage(currentPhoto.base64, "JPEG", x, y + .1, wPic, hPic);
|
|
341
|
+
}
|
|
342
|
+
currentQuadrant++;
|
|
343
|
+
}
|
|
344
|
+
// if (currentSection[key].hasNotes && currentSection[key].notes != "") {
|
|
345
|
+
// let notes = doc.splitTextToSize(`${currentSection[key].notes}`, 7.5);
|
|
346
|
+
// doc.setFontStyle("bold");
|
|
347
|
+
// doc.text("Notes:", x, y + hPic + .3);
|
|
348
|
+
// doc.setFontStyle("normal");
|
|
349
|
+
// doc.text(notes, x, y + hPic + .4);
|
|
350
|
+
// }
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function printInfoPage() {
|
|
357
|
+
let infoPage = templates[`${reportData.meta.reportType}InfoPage`];
|
|
358
|
+
doc.addPage();
|
|
359
|
+
doc.setTextColor(0, 0, 0);
|
|
360
|
+
doc.setFontStyle("bold");
|
|
361
|
+
doc.setFontSize(14);
|
|
362
|
+
doc.text(infoPage.header, .5, .6);
|
|
363
|
+
doc.setFontSize(12);
|
|
364
|
+
for (let i = 0; i < infoPage.subheader.length; i++) {
|
|
365
|
+
let y = infoPage.y[i];
|
|
366
|
+
if (y == .6) doc.addPage();
|
|
367
|
+
doc.setFontStyle("bold");
|
|
368
|
+
doc.text(infoPage.subheader[i], .5, y);
|
|
369
|
+
y += .2;
|
|
370
|
+
doc.setFontStyle("normal");
|
|
371
|
+
doc.text(doc.splitTextToSize(infoPage.body[i], 7.5), .5, y);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function getPhotoSectionNameFromTag(tag) {
|
|
376
|
+
let tagPrefixRemoved = tag.substr(tag.indexOf('_'));
|
|
377
|
+
let tagUnderscoresReplaced = tagPrefixRemoved.replaceAll('_', ' ');
|
|
378
|
+
let sectionName = `${tagUnderscoresReplaced.charAt(0).toUpperCase()}${tagUnderscoresReplaced.slice(1)}`;
|
|
379
|
+
return sectionName;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function resizeAndPrintStaticImages() {
|
|
383
|
+
let wMax = 2.25,
|
|
384
|
+
hMax = .7,
|
|
385
|
+
x_profile = 6.9,
|
|
386
|
+
y_profile = 8.13,
|
|
387
|
+
size_profile = 1.25,
|
|
388
|
+
x_name = 8.15,
|
|
389
|
+
y_name = 8.025,
|
|
390
|
+
r = reportData.meta.companyLogoAspectRatio,
|
|
391
|
+
xOffset = 0,
|
|
392
|
+
yOffset = 0,
|
|
393
|
+
w = 0,
|
|
394
|
+
h = 0,
|
|
395
|
+
x = 6,
|
|
396
|
+
y = .2;
|
|
397
|
+
if (reportData.meta.companyLogoPlacement !== "header") {
|
|
398
|
+
x = 6;
|
|
399
|
+
y = 8;
|
|
400
|
+
x_profile = 7.375;
|
|
401
|
+
y_profile = .15;
|
|
402
|
+
size_profile = reportData.meta.reportTheme === 'dark' ? .8 : .9;
|
|
403
|
+
x_name = 7.25;
|
|
404
|
+
y_name = .5;
|
|
405
|
+
wMax = 2.25;
|
|
406
|
+
hMax = .8
|
|
407
|
+
}
|
|
408
|
+
if (r >= 1) {
|
|
409
|
+
w = wMax;
|
|
410
|
+
h = w / r;
|
|
411
|
+
if (h > hMax) {
|
|
412
|
+
h = hMax;
|
|
413
|
+
w = h * r;
|
|
414
|
+
}
|
|
415
|
+
} else {
|
|
416
|
+
h = hMax;
|
|
417
|
+
w = h * r;
|
|
418
|
+
if (w > wMax) {
|
|
419
|
+
w = wMax;
|
|
420
|
+
h = w / r;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
if (w < wMax) x = 8.5 - .25 - w;
|
|
424
|
+
doc.setFontSize(12);
|
|
425
|
+
doc.setFontType("bold");
|
|
426
|
+
doc.setTextColor(255, 255, 255);
|
|
427
|
+
if (reportData.meta.companyLogoPlacement == "Header" && h < hMax)
|
|
428
|
+
y = y + ((hMax - h) / 2);
|
|
429
|
+
doc.addImage(reportData.staticPhotos.companyLogo, "JPEG", x, y, w, h);
|
|
430
|
+
doc.addImage(reportData.staticPhotos.profilePicture, "JPEG", x_profile, y_profile, size_profile, size_profile);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function getToolIcon(measurementSource) {
|
|
434
|
+
switch (measurementSource) {
|
|
435
|
+
case "Fieldpiece": return "companyLogoFieldpiece";
|
|
436
|
+
default: return null;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function getRangeIcon(key, actualValue, currentSnapshot) {
|
|
441
|
+
let ranges = JSON.parse(reportData.snapshots[currentSnapshot].rangeIcons);
|
|
442
|
+
let target = null, low = null, high = null;
|
|
443
|
+
let rangeIconRef = null;
|
|
444
|
+
if (ranges[key]) {
|
|
445
|
+
target = parseFloat(ranges[key]);
|
|
446
|
+
if (ranges[`${key}_ideal_low`]) low = target - parseFloat(ranges[`${key}_ideal_low`]);
|
|
447
|
+
if (ranges[`${key}_ideal_high`]) high = target + parseFloat(ranges[`${key}_ideal_high`]);
|
|
448
|
+
if (target && low && high) {
|
|
449
|
+
if (actualValue < low) rangeIconRef = "iconRangeLow";
|
|
450
|
+
else if (actualValue > high) rangeIconRef = "iconRangeHigh";
|
|
451
|
+
else rangeIconRef = "iconRangeNormal";
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return rangeIconRef;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function alignRight(text, rightAlign, fontSize) {
|
|
458
|
+
return rightAlign - doc.getStringUnitWidth(text) * fontSize / 72;
|
|
459
|
+
}
|