@lighthouse/common 4.30.1-canary.3 → 4.30.2
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/.vscode/settings.json +3 -0
- package/dist/helpers/get-audit-items-data/index.js +0 -1
- package/dist/pdf/audit/index.js +13 -28
- package/dist/pdf/helpers/build-audit-content/index.js +4 -13
- package/dist/pdf/helpers/index.js +12 -26
- package/dist/pdf/helpers/table/index.js +0 -8
- package/dist/scheduling/helpers/generateScheduleEnd.js +2 -1
- package/lib/helpers/get-audit-items-data/index.js +0 -1
- package/lib/helpers/get-audit-items-data/index.js.map +1 -1
- package/lib/pdf/audit/index.js +12 -31
- package/lib/pdf/audit/index.js.map +1 -1
- package/lib/pdf/helpers/build-audit-content/index.js +4 -11
- package/lib/pdf/helpers/build-audit-content/index.js.map +1 -1
- package/lib/pdf/helpers/index.js +1 -2
- package/lib/pdf/helpers/index.js.map +1 -1
- package/lib/pdf/helpers/table/index.js +0 -6
- package/lib/pdf/helpers/table/index.js.map +1 -1
- package/lib/scheduling/helpers/generateScheduleEnd.js +2 -1
- package/lib/scheduling/helpers/generateScheduleEnd.js.map +1 -1
- package/package.json +1 -1
- package/dist/pdf/helpers/build-audit-follow-ups/index.js +0 -150
- package/lib/pdf/helpers/build-audit-follow-ups/index.js +0 -150
- package/lib/pdf/helpers/build-audit-follow-ups/index.js.map +0 -1
- package/mise.toml +0 -3
package/dist/pdf/audit/index.js
CHANGED
|
@@ -44,14 +44,14 @@ function buildAuditPdf(pdfOptions, data) {
|
|
|
44
44
|
entity,
|
|
45
45
|
timezone
|
|
46
46
|
} = data;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
47
|
+
const {
|
|
48
|
+
flags = {}
|
|
49
|
+
} = pdfOptions;
|
|
50
50
|
const sequenceId = entity.sequenceId;
|
|
51
51
|
const timestamp = entity.createdAt;
|
|
52
52
|
const title = entity.title || 'Unknown';
|
|
53
53
|
const fileTitle = `Audit Report - ${title}`;
|
|
54
|
-
return generateContent(data).then(content => (0, _helpers.generateDefinition)({
|
|
54
|
+
return generateContent(data, flags).then(content => (0, _helpers.generateDefinition)({
|
|
55
55
|
content,
|
|
56
56
|
fileTitle,
|
|
57
57
|
sequenceId,
|
|
@@ -64,24 +64,18 @@ function buildAuditPdf(pdfOptions, data) {
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
function generateContent(data) {
|
|
67
|
+
function generateContent(data, flags) {
|
|
68
68
|
const {
|
|
69
69
|
entity
|
|
70
70
|
} = data;
|
|
71
71
|
const {
|
|
72
|
-
followUps = [],
|
|
73
72
|
footerFields = {},
|
|
74
73
|
gps = {},
|
|
75
74
|
headerFields = {},
|
|
76
75
|
score = {},
|
|
77
|
-
timezone,
|
|
78
76
|
title = 'Unknown'
|
|
79
77
|
} = entity;
|
|
80
78
|
const entityDetails = (0, _helpers2.getAuditEntryDetails)(data);
|
|
81
|
-
const hasFollowUps = !!entity.followUps;
|
|
82
|
-
console.log('buildAuditPdf', {
|
|
83
|
-
hasFollowUps
|
|
84
|
-
});
|
|
85
79
|
const {
|
|
86
80
|
gpsText,
|
|
87
81
|
groupedData,
|
|
@@ -133,7 +127,9 @@ function generateContent(data) {
|
|
|
133
127
|
secondRow = [headerSubTitle, scoreServiceLevelSubTitle];
|
|
134
128
|
headerAddress = (0, _helpers.text)(address, {
|
|
135
129
|
style: 'small'
|
|
136
|
-
});
|
|
130
|
+
}); // TODO: Determine if we always want 2 decimal places or not
|
|
131
|
+
// If so apply `.toFixed(2)`
|
|
132
|
+
|
|
137
133
|
const truncatedTargetPercent = (0, _lodash.round)(target, 2);
|
|
138
134
|
const scoreTargetText = `(Target - ${truncatedTargetPercent}%)`;
|
|
139
135
|
const scoreTargetSubTitle = (0, _helpers.text)(scoreTargetText, {
|
|
@@ -160,8 +156,7 @@ function generateContent(data) {
|
|
|
160
156
|
body,
|
|
161
157
|
layout: 'noBorders',
|
|
162
158
|
style: 'titleTable',
|
|
163
|
-
widths: ['*', 100]
|
|
164
|
-
margin: [0, 0, 0, 30]
|
|
159
|
+
widths: ['*', 100]
|
|
165
160
|
});
|
|
166
161
|
const totalScoreTable = (0, _helpers.twoColumnTable)({
|
|
167
162
|
body: [[scoreTitle, scoreBreakdown], [scorePercentage]],
|
|
@@ -172,28 +167,18 @@ function generateContent(data) {
|
|
|
172
167
|
margin: [0, 10, 0, 0]
|
|
173
168
|
});
|
|
174
169
|
const hLineBottom = (0, _helpers.horizontalLine)();
|
|
175
|
-
const followUpItems = hasFollowUps ? (0, _helpers.buildAuditFollowUps)(followUps, {
|
|
176
|
-
timezone
|
|
177
|
-
}) : [];
|
|
178
170
|
const promises = {
|
|
179
|
-
entry: (0, _helpers.buildAuditContent)(groupedData.items,
|
|
180
|
-
hasFollowUps
|
|
181
|
-
}),
|
|
171
|
+
entry: (0, _helpers.buildAuditContent)(groupedData.items),
|
|
182
172
|
footerTemplate: (0, _helpers.buildTemplateContent)(footerFields.formGroups, data),
|
|
183
173
|
headerTemplate: (0, _helpers.buildTemplateContent)(headerFields.formGroups, data)
|
|
184
174
|
};
|
|
185
|
-
const auditItemsTitle = hasFollowUps ? [{
|
|
186
|
-
text: 'Audit Items',
|
|
187
|
-
style: {
|
|
188
|
-
font: 'Gotham',
|
|
189
|
-
lineHeight: 1.1
|
|
190
|
-
}
|
|
191
|
-
}, hLineTop] : [];
|
|
192
175
|
return _bluebird.default.props(promises).then(({
|
|
193
176
|
entry,
|
|
194
177
|
footerTemplate,
|
|
195
178
|
headerTemplate
|
|
196
|
-
}) =>
|
|
179
|
+
}) => {
|
|
180
|
+
return [titleTable, ...headerTemplate, ...entry, hLineTop, totalScoreTable, hLineBottom, ...footerTemplate];
|
|
181
|
+
}).catch(err => {
|
|
197
182
|
throw new Error(`GenerateContentError: ${err.message}`);
|
|
198
183
|
});
|
|
199
184
|
}
|
|
@@ -17,10 +17,7 @@ var _ = require("../");
|
|
|
17
17
|
|
|
18
18
|
var _table = require("../table");
|
|
19
19
|
|
|
20
|
-
const buildAuditContent = _bluebird.default.method(
|
|
21
|
-
const {
|
|
22
|
-
hasFollowUps
|
|
23
|
-
} = options;
|
|
20
|
+
const buildAuditContent = _bluebird.default.method(items => {
|
|
24
21
|
return _bluebird.default.map(items, group => {
|
|
25
22
|
return _bluebird.default.map(group.items, (item, index) => {
|
|
26
23
|
return _bluebird.default.map(item.assets, ({
|
|
@@ -37,17 +34,11 @@ const buildAuditContent = _bluebird.default.method((items, options) => {
|
|
|
37
34
|
const rows = [];
|
|
38
35
|
const fillColor = index % 2 === 0 ? _table.WHITE : _table.LIGHT_BLUE;
|
|
39
36
|
const hasImages = !(0, _lodash.isEmpty)(rowImages);
|
|
40
|
-
const hasComments = !(0, _lodash.isEmpty)(item.comments);
|
|
41
|
-
|
|
42
|
-
const label = hasFollowUps ? {
|
|
43
|
-
text: item.label,
|
|
44
|
-
fillColor,
|
|
45
|
-
id: item.questionId
|
|
46
|
-
} : {
|
|
37
|
+
const hasComments = !(0, _lodash.isEmpty)(item.comments);
|
|
38
|
+
rows.push([{
|
|
47
39
|
text: item.label,
|
|
48
40
|
fillColor
|
|
49
|
-
}
|
|
50
|
-
rows.push([label, {
|
|
41
|
+
}, {
|
|
51
42
|
text: item.scoreLabel,
|
|
52
43
|
fillColor
|
|
53
44
|
}, {
|
|
@@ -9,12 +9,6 @@ Object.defineProperty(exports, "buildAuditContent", {
|
|
|
9
9
|
return _buildAuditContent.buildAuditContent;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
Object.defineProperty(exports, "buildAuditFollowUps", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _buildAuditFollowUps.buildAuditFollowUps;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
12
|
Object.defineProperty(exports, "buildLocationScansContent", {
|
|
19
13
|
enumerable: true,
|
|
20
14
|
get: function () {
|
|
@@ -123,46 +117,40 @@ Object.defineProperty(exports, "imageTables", {
|
|
|
123
117
|
return _table.imageTables;
|
|
124
118
|
}
|
|
125
119
|
});
|
|
126
|
-
Object.defineProperty(exports, "
|
|
127
|
-
enumerable: true,
|
|
128
|
-
get: function () {
|
|
129
|
-
return _table.sixColumnTable;
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
Object.defineProperty(exports, "summaryFieldsTable", {
|
|
120
|
+
Object.defineProperty(exports, "table", {
|
|
133
121
|
enumerable: true,
|
|
134
122
|
get: function () {
|
|
135
|
-
return _table.
|
|
123
|
+
return _table.table;
|
|
136
124
|
}
|
|
137
125
|
});
|
|
138
|
-
Object.defineProperty(exports, "
|
|
126
|
+
Object.defineProperty(exports, "twoColumnTable", {
|
|
139
127
|
enumerable: true,
|
|
140
128
|
get: function () {
|
|
141
|
-
return _table.
|
|
129
|
+
return _table.twoColumnTable;
|
|
142
130
|
}
|
|
143
131
|
});
|
|
144
|
-
Object.defineProperty(exports, "
|
|
132
|
+
Object.defineProperty(exports, "threeColumnTable", {
|
|
145
133
|
enumerable: true,
|
|
146
134
|
get: function () {
|
|
147
|
-
return _table.
|
|
135
|
+
return _table.threeColumnTable;
|
|
148
136
|
}
|
|
149
137
|
});
|
|
150
|
-
Object.defineProperty(exports, "
|
|
138
|
+
Object.defineProperty(exports, "summaryFieldsTable", {
|
|
151
139
|
enumerable: true,
|
|
152
140
|
get: function () {
|
|
153
|
-
return _table.
|
|
141
|
+
return _table.summaryFieldsTable;
|
|
154
142
|
}
|
|
155
143
|
});
|
|
156
|
-
Object.defineProperty(exports, "
|
|
144
|
+
Object.defineProperty(exports, "summaryStatTable", {
|
|
157
145
|
enumerable: true,
|
|
158
146
|
get: function () {
|
|
159
|
-
return _table.
|
|
147
|
+
return _table.summaryStatTable;
|
|
160
148
|
}
|
|
161
149
|
});
|
|
162
|
-
Object.defineProperty(exports, "
|
|
150
|
+
Object.defineProperty(exports, "summaryWrapperTable", {
|
|
163
151
|
enumerable: true,
|
|
164
152
|
get: function () {
|
|
165
|
-
return _table.
|
|
153
|
+
return _table.summaryWrapperTable;
|
|
166
154
|
}
|
|
167
155
|
});
|
|
168
156
|
Object.defineProperty(exports, "zebraFillColor", {
|
|
@@ -180,8 +168,6 @@ Object.defineProperty(exports, "text", {
|
|
|
180
168
|
|
|
181
169
|
var _buildAuditContent = require("./build-audit-content");
|
|
182
170
|
|
|
183
|
-
var _buildAuditFollowUps = require("./build-audit-follow-ups");
|
|
184
|
-
|
|
185
171
|
var _buildLocationScansContent = require("./build-location-scans-content");
|
|
186
172
|
|
|
187
173
|
var _buildTemplateContent = require("./build-template-content");
|
|
@@ -13,7 +13,6 @@ exports.table = table;
|
|
|
13
13
|
exports.twoColumnTable = twoColumnTable;
|
|
14
14
|
exports.threeColumnTable = threeColumnTable;
|
|
15
15
|
exports.fourColumnTable = fourColumnTable;
|
|
16
|
-
exports.sixColumnTable = sixColumnTable;
|
|
17
16
|
exports.zebraFillColor = zebraFillColor;
|
|
18
17
|
exports.WHITE = exports.LIGHT_BLUE = exports.GRAY = void 0;
|
|
19
18
|
|
|
@@ -207,13 +206,6 @@ function fourColumnTable(options) {
|
|
|
207
206
|
return table(tableOptions);
|
|
208
207
|
}
|
|
209
208
|
|
|
210
|
-
function sixColumnTable(options) {
|
|
211
|
-
const tableOptions = (0, _lodash.defaults)({}, options, {
|
|
212
|
-
widths: ['16.7%', '16.66%', '16.66%', '16.66%', '16.66%', '16.66%']
|
|
213
|
-
});
|
|
214
|
-
return table(tableOptions);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
209
|
function zebraFillColor(index) {
|
|
218
210
|
return index % 2 === 0 ? WHITE : LIGHT_BLUE;
|
|
219
211
|
}
|
|
@@ -28,9 +28,10 @@ function generateScheduleEnd({
|
|
|
28
28
|
const isFrequencyLessThanWeek = (0, _fp.includes)(frequencyUnit, [_scheduling.Unit.Millisecond, _scheduling.Unit.Second, _scheduling.Unit.Minute, _scheduling.Unit.Hour, _scheduling.Unit.Day]);
|
|
29
29
|
|
|
30
30
|
const mStart = _momentTimezone.default.tz(start, timezone); // NOTE: if frequency unit less than a week we must set end to jump a week
|
|
31
|
+
// plus the interval length of the schedule frequency
|
|
31
32
|
// so that we can ensure that we are within a service interval
|
|
32
33
|
|
|
33
34
|
|
|
34
|
-
const end = isFrequencyLessThanWeek ? mStart.add(
|
|
35
|
+
const end = isFrequencyLessThanWeek ? mStart.add(2, _scheduling.Unit.Week).valueOf() : mStart.add(frequencyValue * 2, frequencyUnit).valueOf();
|
|
35
36
|
return end;
|
|
36
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/helpers/get-audit-items-data/index.js"],"names":["find","groupBy","map","get","round","buildFetchUrl","getAuditItemsData","items","data","settings","awsS3BaseUrl","cloudinaryBaseUrl","entity","groupScores","groupedItems","auditData","overallActualScore","overallMaximumScore","groupIndex","key","skipped","group","title","label","groupData","groupMaximumScore","groupActualScore","groupResultScore","groupPercentageResultScore","currentGroupScores","max","actual","result","percentageResult","item","itemIndex","hasScore","score","assetCount","assets","length","asset","assetIndex","assetUrl","fit","height","width","quality","link","thumbnailUrl","comments","matchingScore","scores","value","scoreLabel","scoreWeight","weight"
|
|
1
|
+
{"version":3,"sources":["../../../src/helpers/get-audit-items-data/index.js"],"names":["find","groupBy","map","get","round","buildFetchUrl","getAuditItemsData","items","data","settings","awsS3BaseUrl","cloudinaryBaseUrl","entity","groupScores","groupedItems","auditData","overallActualScore","overallMaximumScore","groupIndex","key","skipped","group","title","label","groupData","groupMaximumScore","groupActualScore","groupResultScore","groupPercentageResultScore","currentGroupScores","max","actual","result","percentageResult","item","itemIndex","hasScore","score","assetCount","assets","length","asset","assetIndex","assetUrl","fit","height","width","quality","link","thumbnailUrl","comments","matchingScore","scores","value","scoreLabel","scoreWeight","weight"],"mappings":"AAAA,SAASA,IAAT,EAAeC,OAAf,EAAwBC,GAAxB,EAA6BC,GAA7B,EAAkCC,KAAlC,QAA+C,QAA/C;AAEA,SAASC,aAAT,QAA8B,KAA9B;AAEA,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chUrl } from '../'\n\nexport function getAuditItemsData(items, data) {\n const {\n settings: { awsS3BaseUrl, cloudinaryBaseUrl } = {},\n entity: { groupScores } = {},\n } = data\n\n const groupedItems = groupBy(items, 'group.id')\n\n const auditData = {\n overallActualScore: 0,\n overallMaximumScore: 0,\n }\n\n auditData.items = map(groupedItems, (items, groupIndex) => {\n const key = groupIndex\n const skipped = !!items[0].group.skipped\n const title = items[0].group.label\n\n const groupData = {\n key,\n groupMaximumScore: 0,\n groupActualScore: 0,\n groupResultScore: 0,\n groupPercentageResultScore: 0,\n skipped,\n title,\n }\n\n const currentGroupScores = get(groupScores, key)\n\n if (currentGroupScores) {\n groupData.groupMaximumScore = round(currentGroupScores.max, 2)\n groupData.groupActualScore = round(currentGroupScores.actual, 2)\n groupData.groupResultScore = currentGroupScores.result\n groupData.groupPercentageResultScore = currentGroupScores.percentageResult\n }\n\n groupData.items = items.map((item, itemIndex) => {\n // NOTE: we handle scores of -1, 0 and 1\n // -1 scores are skipped from group max and actual score\n // 0 and 1 must be included in the final scores\n const hasScore = item.score !== null && item.score !== -1\n\n const assetCount = item.assets.length\n\n const assets = item.assets.map((asset, assetIndex) => {\n const assetUrl = buildFetchUrl(asset, {\n awsS3BaseUrl,\n cloudinaryBaseUrl,\n fit: true,\n height: 400,\n width: 600,\n quality: 50,\n })\n\n const link = `${awsS3BaseUrl}/${asset}`\n\n const thumbnailUrl = buildFetchUrl(asset, {\n awsS3BaseUrl,\n cloudinaryBaseUrl,\n width: 100,\n quality: 50,\n })\n\n const key = `${groupIndex}-item-asset-${assetIndex}`\n\n return {\n assetUrl,\n key,\n link,\n thumbnailUrl,\n }\n })\n\n const comments = item.comments\n const label = item.label\n const score = item.score\n\n const key = `${groupIndex}-item-${itemIndex}`\n const matchingScore = find(item.scores, { value: score })\n\n // NOTE: ensure we have a score otherwise fallback to - value\n const scoreLabel =\n hasScore && matchingScore && !skipped ? matchingScore.label : '-'\n const scoreWeight = hasScore && !skipped ? item.scoreWeight : '-'\n const weight = hasScore ? item.weight : '-'\n\n return {\n assetCount,\n assets,\n comments,\n key,\n label,\n score,\n scoreLabel,\n scoreWeight,\n weight,\n }\n })\n\n return groupData\n })\n\n return auditData\n}\n"],"file":"index.js"}
|
package/lib/pdf/audit/index.js
CHANGED
|
@@ -7,7 +7,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
7
7
|
|
|
8
8
|
import Promise from 'bluebird';
|
|
9
9
|
import { isEmpty, round } from 'lodash';
|
|
10
|
-
import { buildAuditContent,
|
|
10
|
+
import { buildAuditContent, buildTemplateContent, generateDefinition, getFormattedAddress, horizontalLine, text, twoColumnTable } from '../helpers';
|
|
11
11
|
import { getAuditEntryDetails } from '../../helpers';
|
|
12
12
|
/**
|
|
13
13
|
* buildAuditPdf
|
|
@@ -37,14 +37,13 @@ import { getAuditEntryDetails } from '../../helpers';
|
|
|
37
37
|
export function buildAuditPdf(pdfOptions, data) {
|
|
38
38
|
var entity = data.entity,
|
|
39
39
|
timezone = data.timezone;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
40
|
+
var _pdfOptions$flags = pdfOptions.flags,
|
|
41
|
+
flags = _pdfOptions$flags === void 0 ? {} : _pdfOptions$flags;
|
|
43
42
|
var sequenceId = entity.sequenceId;
|
|
44
43
|
var timestamp = entity.createdAt;
|
|
45
44
|
var title = entity.title || 'Unknown';
|
|
46
45
|
var fileTitle = "Audit Report - ".concat(title);
|
|
47
|
-
return generateContent(data).then(function (content) {
|
|
46
|
+
return generateContent(data, flags).then(function (content) {
|
|
48
47
|
return generateDefinition(_objectSpread({
|
|
49
48
|
content: content,
|
|
50
49
|
fileTitle: fileTitle,
|
|
@@ -58,11 +57,9 @@ export function buildAuditPdf(pdfOptions, data) {
|
|
|
58
57
|
});
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
function generateContent(data) {
|
|
60
|
+
function generateContent(data, flags) {
|
|
62
61
|
var entity = data.entity;
|
|
63
|
-
var _entity$
|
|
64
|
-
followUps = _entity$followUps === void 0 ? [] : _entity$followUps,
|
|
65
|
-
_entity$footerFields = entity.footerFields,
|
|
62
|
+
var _entity$footerFields = entity.footerFields,
|
|
66
63
|
footerFields = _entity$footerFields === void 0 ? {} : _entity$footerFields,
|
|
67
64
|
_entity$gps = entity.gps,
|
|
68
65
|
gps = _entity$gps === void 0 ? {} : _entity$gps,
|
|
@@ -70,14 +67,9 @@ function generateContent(data) {
|
|
|
70
67
|
headerFields = _entity$headerFields === void 0 ? {} : _entity$headerFields,
|
|
71
68
|
_entity$score = entity.score,
|
|
72
69
|
score = _entity$score === void 0 ? {} : _entity$score,
|
|
73
|
-
timezone = entity.timezone,
|
|
74
70
|
_entity$title = entity.title,
|
|
75
71
|
title = _entity$title === void 0 ? 'Unknown' : _entity$title;
|
|
76
72
|
var entityDetails = getAuditEntryDetails(data);
|
|
77
|
-
var hasFollowUps = !!entity.followUps;
|
|
78
|
-
console.log('buildAuditPdf', {
|
|
79
|
-
hasFollowUps: hasFollowUps
|
|
80
|
-
});
|
|
81
73
|
var gpsText = entityDetails.gpsText,
|
|
82
74
|
groupedData = entityDetails.groupedData,
|
|
83
75
|
locationText = entityDetails.locationText,
|
|
@@ -127,7 +119,9 @@ function generateContent(data) {
|
|
|
127
119
|
secondRow = [headerSubTitle, scoreServiceLevelSubTitle];
|
|
128
120
|
headerAddress = text(address, {
|
|
129
121
|
style: 'small'
|
|
130
|
-
});
|
|
122
|
+
}); // TODO: Determine if we always want 2 decimal places or not
|
|
123
|
+
// If so apply `.toFixed(2)`
|
|
124
|
+
|
|
131
125
|
var truncatedTargetPercent = round(target, 2);
|
|
132
126
|
var scoreTargetText = "(Target - ".concat(truncatedTargetPercent, "%)");
|
|
133
127
|
var scoreTargetSubTitle = text(scoreTargetText, {
|
|
@@ -154,8 +148,7 @@ function generateContent(data) {
|
|
|
154
148
|
body: body,
|
|
155
149
|
layout: 'noBorders',
|
|
156
150
|
style: 'titleTable',
|
|
157
|
-
widths: ['*', 100]
|
|
158
|
-
margin: [0, 0, 0, 30]
|
|
151
|
+
widths: ['*', 100]
|
|
159
152
|
});
|
|
160
153
|
var totalScoreTable = twoColumnTable({
|
|
161
154
|
body: [[scoreTitle, scoreBreakdown], [scorePercentage]],
|
|
@@ -166,28 +159,16 @@ function generateContent(data) {
|
|
|
166
159
|
margin: [0, 10, 0, 0]
|
|
167
160
|
});
|
|
168
161
|
var hLineBottom = horizontalLine();
|
|
169
|
-
var followUpItems = hasFollowUps ? buildAuditFollowUps(followUps, {
|
|
170
|
-
timezone: timezone
|
|
171
|
-
}) : [];
|
|
172
162
|
var promises = {
|
|
173
|
-
entry: buildAuditContent(groupedData.items,
|
|
174
|
-
hasFollowUps: hasFollowUps
|
|
175
|
-
}),
|
|
163
|
+
entry: buildAuditContent(groupedData.items),
|
|
176
164
|
footerTemplate: buildTemplateContent(footerFields.formGroups, data),
|
|
177
165
|
headerTemplate: buildTemplateContent(headerFields.formGroups, data)
|
|
178
166
|
};
|
|
179
|
-
var auditItemsTitle = hasFollowUps ? [{
|
|
180
|
-
text: 'Audit Items',
|
|
181
|
-
style: {
|
|
182
|
-
font: 'Gotham',
|
|
183
|
-
lineHeight: 1.1
|
|
184
|
-
}
|
|
185
|
-
}, hLineTop] : [];
|
|
186
167
|
return Promise.props(promises).then(function (_ref) {
|
|
187
168
|
var entry = _ref.entry,
|
|
188
169
|
footerTemplate = _ref.footerTemplate,
|
|
189
170
|
headerTemplate = _ref.headerTemplate;
|
|
190
|
-
return [titleTable].concat(_toConsumableArray(headerTemplate),
|
|
171
|
+
return [titleTable].concat(_toConsumableArray(headerTemplate), _toConsumableArray(entry), [hLineTop, totalScoreTable, hLineBottom], _toConsumableArray(footerTemplate));
|
|
191
172
|
}).catch(function (err) {
|
|
192
173
|
throw new Error("GenerateContentError: ".concat(err.message));
|
|
193
174
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/pdf/audit/index.js"],"names":["Promise","isEmpty","round","buildAuditContent","buildAuditFollowUps","buildTemplateContent","generateDefinition","getFormattedAddress","horizontalLine","text","twoColumnTable","getAuditEntryDetails","buildAuditPdf","pdfOptions","data","entity","timezone","console","log","version","sequenceId","timestamp","createdAt","title","fileTitle","generateContent","then","content","type","catch","err","Error","message","followUps","footerFields","gps","headerFields","score","entityDetails","hasFollowUps","gpsText","groupedData","locationText","referenceValue","timezoneHourTime","scoreText","target","targetServiceLevel","renderTargetFields","headerTitle","style","headerScore","alignment","firstRow","subTitle","headerSubTitle","colSpan","secondRow","reverseGeocoded","address","renderHeaderAddress","dummyColumn","headerAddress","renderThirdRow","thirdRow","serviceLevelBelow","serviceLevelText","scoreServiceLevelSubTitle","truncatedTargetPercent","scoreTargetText","scoreTargetSubTitle","scoreBreakdown","actual","max","scorePercentage","scoreTitle","body","titleTable","layout","widths","margin","totalScoreTable","hLineTop","hLineBottom","followUpItems","promises","entry","items","footerTemplate","formGroups","headerTemplate","auditItemsTitle","font","lineHeight","props"],"mappings":";;;;;;;AAAA,OAAOA,OAAP,MAAoB,UAApB;AACA,SAASC,OAAT,EAAkBC,KAAlB,QAA+B,QAA/B;AAEA,SACEC,iBADF,EAEEC,mBAFF,EAGEC,oBAHF,EAIEC,kBAJF,EAKEC,mBALF,EAMEC,cANF,EAOEC,IAPF,EAQEC,cARF,QASO,YATP;AAWA,SAASC,oBAAT,QAAqC,eAArC;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,OAAO,SAASC,aAAT,CAAuBC,UAAvB,EAAmCC,IAAnC,EAAyC;AAAA,MACtCC,MADsC,GACjBD,IADiB,CACtCC,MADsC;AAAA,MAC9BC,QAD8B,GACjBF,IADiB,CAC9BE,QAD8B;AAG9CC,EAAAA,OAAO,CAACC,GAAR,CAAY,eAAZ,EAA6B;AAC3BC,IAAAA,OAAO,EAAE;AADkB,GAA7B;AAIA,MAAMC,UAAU,GAAGL,MAAM,CAACK,UAA1B;AACA,MAAMC,SAAS,GAAGN,MAAM,CAAC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3D,IADI,CACC;AAAA,QAAG4D,KAAH,QAAGA,KAAH;AAAA,QAAUE,cAAV,QAAUA,cAAV;AAAA,QAA0BE,cAA1B,QAA0BA,cAA1B;AAAA,YACJb,UADI,4BAEDa,cAFC,IAGJN,aAHI,GAIDO,eAJC,qBAKDL,KALC,IAMJJ,QANI,EAOJD,eAPI,EAQJE,WARI,sBASDK,cATC;AAAA,GADD,EAYJ3D,KAZI,CAYE,UAAAC,GAAG,EAAI;AACZ,UAAM,IAAIC,KAAJ,iCAAmCD,GAAG,CAACE,OAAvC,EAAN;AACD,GAdI,CAAP;AAeD","sourcesContent":["import Promise from 'bluebird'\nimport { isEmpty, round } from 'lodash'\n\nimport {\n buildAuditContent,\n buildAuditFollowUps,\n buildTemplateContent,\n generateDefinition,\n getFormattedAddress,\n horizontalLine,\n text,\n twoColumnTable,\n} from '../helpers'\n\nimport { getAuditEntryDetails } from '../../helpers'\n\n/**\n * buildAuditPdf\n *\n * @param {object} pdfOptions - the pdf options\n * @param {string} pdfOptions.fileTitle - pdf file title\n * @param {function} pdfOptions.footer - function executed to generate footer\n * @param {function} pdfOptions.header - function executed to generate header\n * @param {string} pdfOptions.logoUrl - pdf logo url\n * @param {array} pdfOptions.pageMargins - pdf page margins\n * @param {string} pdfOptions.pageOrientation - pdf page orientation\n * @param {string} pdfOptions.pageSize - pdf page size\n * @param {object} pdfOptions.styles - pdf styles\n * @param {object} pdfOptions.title - pdf title\n * @param {object} pdfOptions.flags - flags to conditionally render parts of the pdf\n * @param {object} data - pdf data\n * @param {object} data.entity - audit document\n * @param {object} data.locations - locations documents\n * @param {object} data.settings - settings properties\n * @param {string} data.settings.awsS3BaseUrl - aws S3 base url\n * @param {string} data.settings.cloudinaryBaseUrl - cloudinary base url\n * @param {string} data.timezone - timezone string\n * @param {object} data.users - application user documents\n * @returns {Promise} returns pdfmake definition object\n */\nexport function buildAuditPdf(pdfOptions, data) {\n const { entity, timezone } = data\n\n console.log('buildAuditPdf', {\n version: '4.30.1-canary.3',\n })\n \n const sequenceId = entity.sequenceId\n const timestamp = entity.createdAt\n const title = entity.title || 'Unknown'\n const fileTitle = `Audit Report - ${title}`\n\n return generateContent(data)\n .then(content =>\n generateDefinition({\n content,\n fileTitle,\n sequenceId,\n timestamp,\n timezone,\n type: 'Audit',\n ...pdfOptions,\n })\n )\n .catch(err => {\n throw new Error(`BuildAuditPdfError: ${err.message}`)\n })\n}\n\nfunction generateContent(data) {\n const { entity } = data\n\n const {\n followUps = [],\n footerFields = {},\n gps = {},\n headerFields = {},\n score = {},\n timezone,\n title = 'Unknown',\n } = entity\n\n const entityDetails = getAuditEntryDetails(data)\n const hasFollowUps = !!entity.followUps\n \n console.log('buildAuditPdf', {\n hasFollowUps,\n })\n\n const {\n gpsText,\n groupedData,\n locationText,\n referenceValue,\n timezoneHourTime,\n scoreText,\n target,\n targetServiceLevel,\n } = entityDetails\n\n const renderTargetFields = !!targetServiceLevel\n const headerTitle = text(title, { style: 'title' })\n const headerScore = text(scoreText, { alignment: 'right', style: 'title' })\n const firstRow = [headerTitle, headerScore]\n const subTitle = `${locationText ||\n gpsText} - ${timezoneHourTime} by ${referenceValue}`\n\n let headerSubTitle = text(subTitle, { colSpan: 2, style: 'subTitle' })\n let secondRow = [headerSubTitle]\n\n const reverseGeocoded = gps.reverseGeocoded\n const address = !isEmpty(reverseGeocoded)\n ? getFormattedAddress(reverseGeocoded)\n : ''\n const renderHeaderAddress = !isEmpty(reverseGeocoded)\n const dummyColumn = text(' ', { style: 'small' })\n\n let headerAddress = text(address, { colSpan: 2, style: 'small' })\n const renderThirdRow = renderHeaderAddress || renderTargetFields\n let thirdRow = renderHeaderAddress ? [headerAddress] : []\n\n if (renderTargetFields) {\n headerSubTitle = text(subTitle, { style: 'subTitle' })\n\n const serviceLevelBelow = targetServiceLevel === 'below'\n const serviceLevelText =\n targetServiceLevel === 'above'\n ? 'Above Target'\n : targetServiceLevel === 'on'\n ? 'On Target'\n : targetServiceLevel === 'below'\n ? 'Below Target'\n : ''\n\n const scoreServiceLevelSubTitle = text(serviceLevelText, {\n alignment: 'right',\n style: serviceLevelBelow ? 'serviceLevelBelow' : 'serviceLevelAboveOrOn',\n })\n\n secondRow = [headerSubTitle, scoreServiceLevelSubTitle]\n headerAddress = text(address, { style: 'small' })\n\n const truncatedTargetPercent = round(target, 2)\n const scoreTargetText = `(Target - ${truncatedTargetPercent}%)`\n const scoreTargetSubTitle = text(scoreTargetText, {\n alignment: 'right',\n style: 'subTitle',\n })\n\n thirdRow = renderHeaderAddress\n ? [headerAddress, scoreTargetSubTitle]\n : [dummyColumn, scoreTargetSubTitle]\n }\n\n const scoreBreakdown = text(\n `${round(score.actual, 2)} / ${round(score.max, 2)}`,\n {\n alignment: 'right',\n style: 'totalScore',\n }\n )\n const scorePercentage = text(scoreText, {\n alignment: 'right',\n colSpan: 2,\n style: 'totalAuditScore',\n })\n const scoreTitle = text('Total Score', { style: 'totalScore' })\n\n const body = renderThirdRow\n ? [firstRow, secondRow, thirdRow]\n : [firstRow, secondRow]\n\n const titleTable = twoColumnTable({\n body,\n layout: 'noBorders',\n style: 'titleTable',\n widths: ['*', 100],\n margin: [0, 0, 0, 30],\n })\n\n const totalScoreTable = twoColumnTable({\n body: [[scoreTitle, scoreBreakdown], [scorePercentage]],\n layout: 'noBorders',\n widths: ['*', 100],\n })\n\n const hLineTop = horizontalLine({ margin: [0, 10, 0, 0] })\n const hLineBottom = horizontalLine()\n\n const followUpItems = hasFollowUps\n ? buildAuditFollowUps(followUps, { timezone })\n : []\n\n const promises = {\n entry: buildAuditContent(groupedData.items, { hasFollowUps }),\n footerTemplate: buildTemplateContent(footerFields.formGroups, data),\n headerTemplate: buildTemplateContent(headerFields.formGroups, data),\n }\n\n const auditItemsTitle = hasFollowUps\n ? [\n {\n text: 'Audit Items',\n style: {\n font: 'Gotham',\n lineHeight: 1.1,\n },\n },\n hLineTop,\n ]\n : []\n\n return Promise.props(promises)\n .then(({ entry, footerTemplate, headerTemplate }) => [\n titleTable,\n ...headerTemplate,\n followUpItems,\n ...auditItemsTitle,\n ...entry,\n hLineTop,\n totalScoreTable,\n hLineBottom,\n ...footerTemplate,\n ])\n .catch(err => {\n throw new Error(`GenerateContentError: ${err.message}`)\n })\n}\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/pdf/audit/index.js"],"names":["Promise","isEmpty","round","buildAuditContent","buildTemplateContent","generateDefinition","getFormattedAddress","horizontalLine","text","twoColumnTable","getAuditEntryDetails","buildAuditPdf","pdfOptions","data","entity","timezone","flags","sequenceId","timestamp","createdAt","title","fileTitle","generateContent","then","content","type","catch","err","Error","message","footerFields","gps","headerFields","score","entityDetails","gpsText","groupedData","locationText","referenceValue","timezoneHourTime","scoreText","target","targetServiceLevel","renderTargetFields","headerTitle","style","headerScore","alignment","firstRow","subTitle","headerSubTitle","colSpan","secondRow","reverseGeocoded","address","renderHeaderAddress","dummyColumn","headerAddress","renderThirdRow","thirdRow","serviceLevelBelow","serviceLevelText","scoreServiceLevelSubTitle","truncatedTargetPercent","scoreTargetText","scoreTargetSubTitle","scoreBreakdown","actual","max","scorePercentage","scoreTitle","body","titleTable","layout","widths","totalScoreTable","hLineTop","margin","hLineBottom","promises","entry","items","footerTemplate","formGroups","headerTemplate","props"],"mappings":";;;;;;;AAAA,OAAOA,OAAP,MAAoB,UAApB;AACA,SAASC,OAAT,EAAkBC,KAAlB,QAA+B,QAA/B;AAEA,SACEC,iBADF,EAEEC,oBAFF,EAGEC,kBAHF,EAIEC,mBAJF,EAKEC,cALF,EAMEC,IANF,EAOEC,cAPF,QAQO,YARP;AAUA,SAASC,oBAAT,QAAqC,eAArC;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,OAAO,SAASC,aAAT,CAAuBC,UAAvB,EAAmCC,IAAnC,EAAyC;AAAA,MACtCC,MADsC,GACjBD,IADiB,CACtCC,MADsC;AAAA,MAC9BC,QAD8B,GACjBF,IADiB,CAC9BE,QAD8B;AAAA,0BAEvBH,UAFuB,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+B;AAErCI,IAAAA,MAAM,EAAE,WAF6B;AAGrCC,IAAAA,MAAM,EAAE,CAAC,GAAD,EAAM,GAAN;AAH6B,GAAD,CAAtC;AAMA,MAAME,QAAQ,GAAGrE,cAAc,CAAC;AAAEsE,IAAAA,MAAM,EAAE,CAAC,CAAD,EAAI,EAAJ,EAAQ,CAAR,EAAW,CAAX;AAAV,GAAD,CAA/B;AACA,MAAMC,WAAW,GAAGvE,cAAc,EAAlC;AAEA,MAAMwE,QAAQ,GAAG;AACfC,IAAAA,KAAK,EAAE7E,iBAAiB,CAACiC,WAAW,CAAC6C,KAAb,CADT;AAEfC,IAAAA,cAAc,EAAE9E,oBAAoB,CAAC0B,YAAY,CAACqD,UAAd,EAA0BtE,IAA1B,CAFrB;AAGfuE,IAAAA,cAAc,EAAEhF,oBAAoB,CAAC4B,YAAY,CAACmD,UAAd,EAA0BtE,IAA1B;AAHrB,GAAjB;AAMA,SAAOb,OAAO,CAACqF,KAAR,CAAcN,QAAd,EACJxD,IADI,CACC,gBAA+C;AAAA,QAA5CyD,KAA4C,QAA5CA,KAA4C;AAAA,QAArCE,cAAqC,QAArCA,cAAqC;AAAA,QAArBE,cAAqB,QAArBA,cAAqB;AACnD,YACEZ,UADF,4BAEKY,cAFL,sBAGKJ,KAHL,IAIEJ,QAJF,EAKED,eALF,EAMEG,WANF,sBAOKI,cAPL;AASD,GAXI,EAYJxD,KAZI,CAYE,UAAAC,GAAG,EAAI;AACZ,UAAM,IAAIC,KAAJ,iCAAmCD,GAAG,CAACE,OAAvC,EAAN;AACD,GAdI,CAAP;AAeD","sourcesContent":["import Promise from 'bluebird'\nimport { isEmpty, round } from 'lodash'\n\nimport {\n buildAuditContent,\n buildTemplateContent,\n generateDefinition,\n getFormattedAddress,\n horizontalLine,\n text,\n twoColumnTable,\n} from '../helpers'\n\nimport { getAuditEntryDetails } from '../../helpers'\n\n/**\n * buildAuditPdf\n *\n * @param {object} pdfOptions - the pdf options\n * @param {string} pdfOptions.fileTitle - pdf file title\n * @param {function} pdfOptions.footer - function executed to generate footer\n * @param {function} pdfOptions.header - function executed to generate header\n * @param {string} pdfOptions.logoUrl - pdf logo url\n * @param {array} pdfOptions.pageMargins - pdf page margins\n * @param {string} pdfOptions.pageOrientation - pdf page orientation\n * @param {string} pdfOptions.pageSize - pdf page size\n * @param {object} pdfOptions.styles - pdf styles\n * @param {object} pdfOptions.title - pdf title\n * @param {object} pdfOptions.flags - flags to conditionally render parts of the pdf\n * @param {object} data - pdf data\n * @param {object} data.entity - audit document\n * @param {object} data.locations - locations documents\n * @param {object} data.settings - settings properties\n * @param {string} data.settings.awsS3BaseUrl - aws S3 base url\n * @param {string} data.settings.cloudinaryBaseUrl - cloudinary base url\n * @param {string} data.timezone - timezone string\n * @param {object} data.users - application user documents\n * @returns {Promise} returns pdfmake definition object\n */\nexport function buildAuditPdf(pdfOptions, data) {\n const { entity, timezone } = data\n const { flags = {} } = pdfOptions\n\n const sequenceId = entity.sequenceId\n const timestamp = entity.createdAt\n const title = entity.title || 'Unknown'\n\n const fileTitle = `Audit Report - ${title}`\n\n return generateContent(data, flags)\n .then(content =>\n generateDefinition({\n content,\n fileTitle,\n sequenceId,\n timestamp,\n timezone,\n type: 'Audit',\n ...pdfOptions,\n })\n )\n .catch(err => {\n throw new Error(`BuildAuditPdfError: ${err.message}`)\n })\n}\n\nfunction generateContent(data, flags) {\n const { entity } = data\n\n const {\n footerFields = {},\n gps = {},\n headerFields = {},\n score = {},\n title = 'Unknown',\n } = entity\n\n const entityDetails = getAuditEntryDetails(data)\n\n const {\n gpsText,\n groupedData,\n locationText,\n referenceValue,\n timezoneHourTime,\n scoreText,\n target,\n targetServiceLevel,\n } = entityDetails\n\n const renderTargetFields = !!targetServiceLevel\n const headerTitle = text(title, { style: 'title' })\n const headerScore = text(scoreText, { alignment: 'right', style: 'title' })\n const firstRow = [headerTitle, headerScore]\n const subTitle = `${locationText ||\n gpsText} - ${timezoneHourTime} by ${referenceValue}`\n\n let headerSubTitle = text(subTitle, { colSpan: 2, style: 'subTitle' })\n let secondRow = [headerSubTitle]\n\n const reverseGeocoded = gps.reverseGeocoded\n const address = !isEmpty(reverseGeocoded)\n ? getFormattedAddress(reverseGeocoded)\n : ''\n const renderHeaderAddress = !isEmpty(reverseGeocoded)\n const dummyColumn = text(' ', { style: 'small' })\n\n let headerAddress = text(address, { colSpan: 2, style: 'small' })\n const renderThirdRow = renderHeaderAddress || renderTargetFields\n let thirdRow = renderHeaderAddress ? [headerAddress] : []\n\n if (renderTargetFields) {\n headerSubTitle = text(subTitle, { style: 'subTitle' })\n\n const serviceLevelBelow = targetServiceLevel === 'below'\n const serviceLevelText =\n targetServiceLevel === 'above'\n ? 'Above Target'\n : targetServiceLevel === 'on'\n ? 'On Target'\n : targetServiceLevel === 'below'\n ? 'Below Target'\n : ''\n\n const scoreServiceLevelSubTitle = text(serviceLevelText, {\n alignment: 'right',\n style: serviceLevelBelow ? 'serviceLevelBelow' : 'serviceLevelAboveOrOn',\n })\n\n secondRow = [headerSubTitle, scoreServiceLevelSubTitle]\n\n headerAddress = text(address, { style: 'small' })\n\n // TODO: Determine if we always want 2 decimal places or not\n // If so apply `.toFixed(2)`\n const truncatedTargetPercent = round(target, 2)\n\n const scoreTargetText = `(Target - ${truncatedTargetPercent}%)`\n const scoreTargetSubTitle = text(scoreTargetText, {\n alignment: 'right',\n style: 'subTitle',\n })\n\n thirdRow = renderHeaderAddress\n ? [headerAddress, scoreTargetSubTitle]\n : [dummyColumn, scoreTargetSubTitle]\n }\n\n const scoreBreakdown = text(\n `${round(score.actual, 2)} / ${round(score.max, 2)}`,\n {\n alignment: 'right',\n style: 'totalScore',\n }\n )\n const scorePercentage = text(scoreText, {\n alignment: 'right',\n colSpan: 2,\n style: 'totalAuditScore',\n })\n const scoreTitle = text('Total Score', { style: 'totalScore' })\n\n const body = renderThirdRow\n ? [firstRow, secondRow, thirdRow]\n : [firstRow, secondRow]\n\n const titleTable = twoColumnTable({\n body,\n layout: 'noBorders',\n style: 'titleTable',\n widths: ['*', 100],\n })\n\n const totalScoreTable = twoColumnTable({\n body: [[scoreTitle, scoreBreakdown], [scorePercentage]],\n layout: 'noBorders',\n widths: ['*', 100],\n })\n\n const hLineTop = horizontalLine({ margin: [0, 10, 0, 0] })\n const hLineBottom = horizontalLine()\n\n const promises = {\n entry: buildAuditContent(groupedData.items),\n footerTemplate: buildTemplateContent(footerFields.formGroups, data),\n headerTemplate: buildTemplateContent(headerFields.formGroups, data),\n }\n\n return Promise.props(promises)\n .then(({ entry, footerTemplate, headerTemplate }) => {\n return [\n titleTable,\n ...headerTemplate,\n ...entry,\n hLineTop,\n totalScoreTable,\n hLineBottom,\n ...footerTemplate,\n ]\n })\n .catch(err => {\n throw new Error(`GenerateContentError: ${err.message}`)\n })\n}\n"],"file":"index.js"}
|
|
@@ -4,8 +4,7 @@ import Promise from 'bluebird';
|
|
|
4
4
|
import { fetchImage } from '../../../helpers';
|
|
5
5
|
import { fourColumnTable, horizontalLine, imageTables, table, text } from '../';
|
|
6
6
|
import { LIGHT_BLUE, WHITE } from '../table';
|
|
7
|
-
export var buildAuditContent = Promise.method(function (items
|
|
8
|
-
var hasFollowUps = options.hasFollowUps;
|
|
7
|
+
export var buildAuditContent = Promise.method(function (items) {
|
|
9
8
|
return Promise.map(items, function (group) {
|
|
10
9
|
return Promise.map(group.items, function (item, index) {
|
|
11
10
|
return Promise.map(item.assets, function (_ref) {
|
|
@@ -23,17 +22,11 @@ export var buildAuditContent = Promise.method(function (items, options) {
|
|
|
23
22
|
var rows = [];
|
|
24
23
|
var fillColor = index % 2 === 0 ? WHITE : LIGHT_BLUE;
|
|
25
24
|
var hasImages = !isEmpty(rowImages);
|
|
26
|
-
var hasComments = !isEmpty(item.comments);
|
|
27
|
-
|
|
28
|
-
var label = hasFollowUps ? {
|
|
29
|
-
text: item.label,
|
|
30
|
-
fillColor: fillColor,
|
|
31
|
-
id: item.questionId
|
|
32
|
-
} : {
|
|
25
|
+
var hasComments = !isEmpty(item.comments);
|
|
26
|
+
rows.push([{
|
|
33
27
|
text: item.label,
|
|
34
28
|
fillColor: fillColor
|
|
35
|
-
}
|
|
36
|
-
rows.push([label, {
|
|
29
|
+
}, {
|
|
37
30
|
text: item.scoreLabel,
|
|
38
31
|
fillColor: fillColor
|
|
39
32
|
}, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/pdf/helpers/build-audit-content/index.js"],"names":["flatten","isEmpty","round","Promise","fetchImage","fourColumnTable","horizontalLine","imageTables","table","text","LIGHT_BLUE","WHITE","buildAuditContent","method","items","
|
|
1
|
+
{"version":3,"sources":["../../../../src/pdf/helpers/build-audit-content/index.js"],"names":["flatten","isEmpty","round","Promise","fetchImage","fourColumnTable","horizontalLine","imageTables","table","text","LIGHT_BLUE","WHITE","buildAuditContent","method","items","map","group","item","index","assets","assetUrl","link","then","base64String","alignment","fit","image","rowImages","rows","fillColor","hasImages","hasComments","comments","push","label","scoreLabel","weight","scoreWeight","imageRow","colSpan","stack","commentsRow","margin","style","groupTableRows","actual","groupActualScore","max","groupMaximumScore","resultText","groupPercentageResultScore","skipped","groupScoreText","bold","headerText","title","groupHeaderTable","body","layout","widths","groupTableHeader","groupTable","headerRows","hLine"],"mappings":";AAAA,SAASA,OAAT,EAAkBC,OAAlB,EAA2BC,KAA3B,QAAwC,QAAxC;AACA,OAAOC,OAAP,MAAoB,UAApB;AAEA,SAASC,UAAT,QAA2B,kBAA3B;AAEA,SAASC,eAAT,EAA0BC,cAA1B,EAA0CC,WAA1C,EAAuDC,KAAvD,EAA8DC,IAA9D,QAA0E,KAA1E;AACA,SAASC,UAAT,EAAqBC,KAArB,QAAkC,UAAlC;AAEA,OAAO,IAAMC,iBAAiB,GAAGT,OAAO,CAACU,MAAR,CAAe,UAAAC,KAAK,EAAI;AACvD,SAAOX,OAAO,CAACY,GAAR,CAAYD,KAAZ,EAAmB,UAAAE,KAAK,EAAI;AACjC,WAAOb,OAAO,CAACY,GAAR,CAAYC,KA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B","sourcesContent":["import { flatten, isEmpty, round } from 'lodash'\nimport Promise from 'bluebird'\n\nimport { fetchImage } from '../../../helpers'\n\nimport { fourColumnTable, horizontalLine, imageTables, table, text } from '../'\nimport { LIGHT_BLUE, WHITE } from '../table'\n\nexport const buildAuditContent = Promise.method(items => {\n return Promise.map(items, group => {\n return Promise.map(group.items, (item, index) => {\n return Promise.map(item.assets, ({ assetUrl, link }) => {\n return fetchImage(assetUrl).then(base64String => ({\n alignment: 'center',\n fit: [210, 210],\n image: base64String,\n link,\n }))\n }).then(rowImages => {\n const rows = []\n\n const fillColor = index % 2 === 0 ? WHITE : LIGHT_BLUE\n const hasImages = !isEmpty(rowImages)\n const hasComments = !isEmpty(item.comments)\n\n rows.push([\n { text: item.label, fillColor },\n { text: item.scoreLabel, fillColor },\n { alignment: 'center', text: item.weight, fillColor },\n { alignment: 'right', text: item.scoreWeight, fillColor },\n ])\n\n if (hasImages) {\n const imageRow = [\n {\n colSpan: 4,\n fillColor,\n stack: imageTables(rowImages),\n },\n ]\n\n rows.push(imageRow)\n }\n\n if (hasComments) {\n const commentsRow = [\n {\n colSpan: 4,\n fillColor,\n margin: [0, -10, 0, 0],\n stack: [\n { text: 'Comments:', style: 'commentsHeader' },\n { text: item.comments },\n ],\n },\n ]\n\n rows.push(commentsRow)\n }\n\n return rows\n })\n }).then(groupTableRows => {\n const actual = round(group.groupActualScore, 2)\n const max = round(group.groupMaximumScore, 2)\n const resultText = `${group.groupPercentageResultScore}%`\n\n const { skipped } = group\n\n const groupScoreText = skipped\n ? null\n : text(`${actual} / ${max} (${resultText})`, {\n alignment: 'right',\n bold: true,\n })\n const headerText = text(group.title)\n\n const groupHeaderTable = table({\n body: [[headerText, groupScoreText]],\n layout: 'noBorders',\n style: 'groupHeaderTable',\n widths: ['*', '*'],\n })\n\n const groupTableHeader = [\n text('Question', { bold: true }),\n text('Answer', { bold: true }),\n text('Weight', { alignment: 'center', bold: true }),\n text('Score', { alignment: 'right', bold: true }),\n ]\n\n const groupTable = fourColumnTable({\n headerRows: 0,\n // NOTE: must flatten here as we have arrays of rows\n body: [groupTableHeader, ...flatten(groupTableRows)],\n widths: ['60%', '24%', '8%', '8%'],\n })\n\n const hLine = horizontalLine()\n\n return [groupHeaderTable, hLine, groupTable]\n })\n })\n})\n"],"file":"index.js"}
|
package/lib/pdf/helpers/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { buildAuditContent } from './build-audit-content';
|
|
2
|
-
export { buildAuditFollowUps } from './build-audit-follow-ups';
|
|
3
2
|
export { buildLocationScansContent, buildLocationScansBoundaries } from './build-location-scans-content';
|
|
4
3
|
export { buildTemplateContent } from './build-template-content';
|
|
5
4
|
export { defaultFooter } from './default-footer';
|
|
@@ -11,6 +10,6 @@ export { generateDefinition } from './generate-definition';
|
|
|
11
10
|
export { horizontalLine } from './horizontal-line';
|
|
12
11
|
export { convertToPdfMake, getStyleAttributes, parseHtml, toPdf } from './html-transformer';
|
|
13
12
|
export { parseValue } from './parse-value';
|
|
14
|
-
export { fourColumnTable, imageTables,
|
|
13
|
+
export { fourColumnTable, imageTables, table, twoColumnTable, threeColumnTable, summaryFieldsTable, summaryStatTable, summaryWrapperTable, zebraFillColor } from './table';
|
|
15
14
|
export { text } from './text';
|
|
16
15
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/pdf/helpers/index.js"],"names":["buildAuditContent","
|
|
1
|
+
{"version":3,"sources":["../../../src/pdf/helpers/index.js"],"names":["buildAuditContent","buildLocationScansContent","buildLocationScansBoundaries","buildTemplateContent","defaultFooter","defaultHeader","defaultStyles","buildSummaryField","buildTemplateFieldRow","getFormattedAddress","generateDefinition","horizontalLine","convertToPdfMake","getStyleAttributes","parseHtml","toPdf","parseValue","fourColumnTable","imageTables","table","twoColumnTable","threeColumnTable","summaryFieldsTable","summaryStatTable","summaryWrapperTable","zebraFillColor","text"],"mappings":"AAAA,SAASA,iBAAT,QAAkC,uBAAlC;AACA,SACEC,yBADF,EAEEC,4BAFF,QAGO,gCAHP;AAIA,SAASC,oBAAT,QAAqC,0BAArC;AACA,SAASC,aAAT,QAA8B,kBAA9B;AACA,SAASC,aAAT,QAA8B,kBAA9B;AACA,SAASC,aAAT,QAA8B,kBAA9B;AACA,SAASC,iBAAT,EAA4BC,qBAA5B,QAAyD,UAAzD;AACA,SAASC,mBAAT,QAAoC,2BAApC;AACA,SAASC,kBAAT,QAAmC,uBAAnC;AACA,SAASC,cAAT,QAA+B,mBAA/B;AACA,SACEC,gBADF,EAEEC,kBAFF,EAGEC,SAHF,EAIEC,KAJF,QAKO,oBALP;AAMA,SAASC,UAAT,QAA2B,eAA3B;AACA,SACEC,eADF,EAEEC,WAFF,EAGEC,KAHF,EAIEC,cAJF,EAKEC,gBALF,EAMEC,kBANF,EAOEC,gBAPF,EAQEC,mBARF,EASEC,cATF,QAUO,SAVP;AAWA,SAASC,IAAT,QAAqB,QAArB","sourcesContent":["export { buildAuditContent } from './build-audit-content'\nexport {\n buildLocationScansContent,\n buildLocationScansBoundaries,\n} from './build-location-scans-content'\nexport { buildTemplateContent } from './build-template-content'\nexport { defaultFooter } from './default-footer'\nexport { defaultHeader } from './default-header'\nexport { defaultStyles } from './default-styles'\nexport { buildSummaryField, buildTemplateFieldRow } from './fields'\nexport { getFormattedAddress } from './format-location-address'\nexport { generateDefinition } from './generate-definition'\nexport { horizontalLine } from './horizontal-line'\nexport {\n convertToPdfMake,\n getStyleAttributes,\n parseHtml,\n toPdf,\n} from './html-transformer'\nexport { parseValue } from './parse-value'\nexport {\n fourColumnTable,\n imageTables,\n table,\n twoColumnTable,\n threeColumnTable,\n summaryFieldsTable,\n summaryStatTable,\n summaryWrapperTable,\n zebraFillColor,\n} from './table'\nexport { text } from './text'\n"],"file":"index.js"}
|
|
@@ -265,12 +265,6 @@ export function fourColumnTable(options) {
|
|
|
265
265
|
});
|
|
266
266
|
return table(tableOptions);
|
|
267
267
|
}
|
|
268
|
-
export function sixColumnTable(options) {
|
|
269
|
-
var tableOptions = defaults({}, options, {
|
|
270
|
-
widths: ['16.7%', '16.66%', '16.66%', '16.66%', '16.66%', '16.66%']
|
|
271
|
-
});
|
|
272
|
-
return table(tableOptions);
|
|
273
|
-
}
|
|
274
268
|
export function zebraFillColor(index) {
|
|
275
269
|
return index % 2 === 0 ? WHITE : LIGHT_BLUE;
|
|
276
270
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/pdf/helpers/table/index.js"],"names":["chunk","concat","defaults","fill","map","slice","take","Promise","DEFAULT_IMAGE_COLUMN_LENGTH","DEFAULT_SUMMARY_FIELDS_COLUMN_LENGTH","buildSummaryField","text","defaultLayout","fillColor","zebraFillColor","hLineWidth","paddingLeft","paddingRight","paddingTop","paddingBottom","vLineWidth","GRAY","LIGHT_BLUE","WHITE","imageTables","images","imageRows","tables","imageRow","index","defaultRow","Array","row","length","isMiddleRow","margin","headerRows","table","body","widths","layout","hLineColor","vLineColor","summaryFieldsTable","fields","settings","timezone","tableHeader","label","bold","fontSize","defaultHeaders","field","tableRow","headers","summaryFieldTable","colSpan","dontBreakRows","summaryStatTable","options","tableOptions","summaryWrapperTable","style","definition","twoColumnTable","threeColumnTable","fourColumnTable","sixColumnTable"],"mappings":";;;AAAA,SAASA,KAAT,EAAgBC,MAAhB,EAAwBC,QAAxB,EAAkCC,IAAlC,EAAwCC,GAAxC,EAA6CC,KAA7C,EAAoDC,IAApD,QAAgE,QAAhE;AACA,OAAOC,OAAP,MAAoB,UAApB;AAEA,SACEC,2BADF,EAEEC,oCAFF,QAGO,oBAHP;AAIA,SAASC,iBAAT,EAA4BC,IAA5B,QAAwC,KAAxC;AAEA,IAAMC,aAAa,GAAG;AACpBC,EAAAA,SAAS,EAAEC,cADS;AAEpBC,EAAAA,UAAU,EAAE;AAAA,WAAM,CAAN;AAAA,GAFQ;AAGpBC,EAAAA,WAAW,EAAE;AAAA,WAAM,CAAN;AAAA,GAH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T_SUMMARY_FIELDS_COLUMN_LENGTH,\n} from '../../../constants'\nimport { buildSummaryField, text } from '../'\n\nconst defaultLayout = {\n fillColor: zebraFillColor,\n hLineWidth: () => 0,\n paddingLeft: () => 5,\n paddingRight: () => 5,\n paddingTop: () => 5,\n paddingBottom: () => 5,\n vLineWidth: () => 0,\n}\n\nexport const GRAY = '#DDDDDD'\nexport const LIGHT_BLUE = '#F0FBFF'\nexport const WHITE = '#FFFFFF'\n\nexport function imageTables(images) {\n const imageRows = chunk(images, DEFAULT_IMAGE_COLUMN_LENGTH)\n const tables = map(imageRows, (imageRow, index) => {\n const defaultRow = fill(Array(DEFAULT_IMAGE_COLUMN_LENGTH), { text: '' })\n const row = concat(imageRow, slice(defaultRow, imageRow.length))\n\n const isMiddleRow = index !== 1 && index !== imageRows.length\n const margin = isMiddleRow ? 5 : 0\n\n return [\n {\n headerRows: 0,\n table: {\n body: [[...row]],\n widths: ['*', '*'],\n },\n layout: {\n hLineColor: () => GRAY,\n hLineWidth: () => 1,\n paddingLeft: () => 5,\n paddingRight: () => 5,\n paddingTop: () => 5,\n paddingBottom: () => 5,\n vLineColor: () => GRAY,\n vLineWidth: () => 1,\n },\n margin: [0, margin, 0, margin],\n },\n ]\n })\n\n return tables\n}\n\nexport async function summaryFieldsTable({ fields, settings, timezone }) {\n const tableHeader = map(fields, ({ label }) =>\n text(label, { bold: true, fontSize: 7 })\n )\n const defaultHeaders = fill(Array(DEFAULT_SUMMARY_FIELDS_COLUMN_LENGTH), {\n text: '',\n })\n const defaultRow = fill(Array(DEFAULT_SUMMARY_FIELDS_COLUMN_LENGTH), {\n text: '',\n })\n const tableRow = await Promise.map(fields, field =>\n buildSummaryField({ field, settings, timezone })\n )\n\n // NOTE: a user can only select three summary fields on the template however\n // if the form group is repeatable we could have more than the default\n // summary field column length so cap otherwise pdf will fail to generate\n const headers = take(\n concat(tableHeader, slice(defaultHeaders, tableHeader.length)),\n DEFAULT_SUMMARY_FIELDS_COLUMN_LENGTH\n )\n const row = take(\n concat(tableRow, slice(defaultRow, tableRow.length)),\n DEFAULT_SUMMARY_FIELDS_COLUMN_LENGTH\n )\n\n const summaryFieldTable = table({\n body: [headers, row],\n colSpan: 5,\n dontBreakRows: true,\n headerRows: 0,\n layout: {\n hLineWidth: () => 0,\n paddingLeft: () => 0,\n paddingRight: () => 5,\n paddingTop: () => 2,\n paddingBottom: () => 2,\n vLineWidth: () => 0,\n },\n // NOTE: pdfmake applies margin/padding to nested tables\n margin: [0, -5, 0, 0],\n widths: ['*', '*', '*'],\n })\n\n return summaryFieldTable\n}\n\nexport function summaryStatTable(options) {\n const tableOptions = defaults({}, options, {\n layout: {\n fillColor: LIGHT_BLUE,\n hLineWidth: () => 0,\n paddingLeft: () => 10,\n paddingRight: () => 10,\n paddingTop: () => 2,\n paddingBottom: () => 2,\n vLineWidth: () => 0,\n },\n widths: ['*'],\n })\n\n return table(tableOptions)\n}\n\nexport function summaryWrapperTable(options) {\n const tableOptions = defaults({}, options, {\n layout: {\n fillColor: WHITE,\n hLineWidth: () => 0,\n paddingLeft: () => 0,\n paddingRight: () => 10,\n paddingTop: () => 0,\n paddingBottom: () => 0,\n vLineWidth: () => 0,\n },\n style: 'summaryWrapperTable',\n })\n\n return table(tableOptions)\n}\n\nexport function table(options) {\n const {\n body,\n colSpan,\n dontBreakRows = false,\n headerRows = 1,\n layout = defaultLayout,\n style = 'table',\n margin,\n widths,\n } = options\n\n const definition = {\n colSpan,\n layout,\n style,\n table: {\n body,\n // NOTE: be wary of this feature, if a row spans multiple pages it won't\n // be drawn on to the pdf, only pass true here when row will be less than\n // a page\n dontBreakRows,\n headerRows,\n },\n margin,\n }\n\n // NOTE: only adds widths if passed\n // as otherwise pdfmake will error!\n // if none defined it auto calculates\n if (widths) {\n definition.table.widths = widths\n }\n\n return definition\n}\n\nexport function twoColumnTable(options) {\n const tableOptions = defaults({}, options, {\n widths: ['50%', '50%'],\n })\n return table(tableOptions)\n}\n\nexport function threeColumnTable(options) {\n const tableOptions = defaults({}, options, {\n widths: ['33%', '33%', '*'],\n })\n return table(tableOptions)\n}\n\nexport function fourColumnTable(options) {\n const tableOptions = defaults({}, options, {\n widths: ['25%', '25%', '25%', '25%'],\n })\n\n return table(tableOptions)\n}\n\nexport function sixColumnTable(options) {\n const tableOptions = defaults({}, options, {\n widths: ['16.7%', '16.66%', '16.66%', '16.66%', '16.66%', '16.66%'],\n })\n\n return table(tableOptions)\n}\n\nexport function zebraFillColor(index) {\n return index % 2 === 0 ? WHITE : LIGHT_BLUE\n}\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/pdf/helpers/table/index.js"],"names":["chunk","concat","defaults","fill","map","slice","take","Promise","DEFAULT_IMAGE_COLUMN_LENGTH","DEFAULT_SUMMARY_FIELDS_COLUMN_LENGTH","buildSummaryField","text","defaultLayout","fillColor","zebraFillColor","hLineWidth","paddingLeft","paddingRight","paddingTop","paddingBottom","vLineWidth","GRAY","LIGHT_BLUE","WHITE","imageTables","images","imageRows","tables","imageRow","index","defaultRow","Array","row","length","isMiddleRow","margin","headerRows","table","body","widths","layout","hLineColor","vLineColor","summaryFieldsTable","fields","settings","timezone","tableHeader","label","bold","fontSize","defaultHeaders","field","tableRow","headers","summaryFieldTable","colSpan","dontBreakRows","summaryStatTable","options","tableOptions","summaryWrapperTable","style","definition","twoColumnTable","threeColumnTable","fourColumnTable"],"mappings":";;;AAAA,SAASA,KAAT,EAAgBC,MAAhB,EAAwBC,QAAxB,EAAkCC,IAAlC,EAAwCC,GAAxC,EAA6CC,KAA7C,EAAoDC,IAApD,QAAgE,QAAhE;AACA,OAAOC,OAAP,MAAoB,UAApB;AAEA,SACEC,2BADF,EAEEC,oCAFF,QAGO,oBAHP;AAIA,SAASC,iBAAT,EAA4BC,IAA5B,QAAwC,KAAxC;AAEA,IAAMC,aAAa,GAAG;AACpBC,EAAAA,SAAS,EAAEC,cADS;AAEpBC,EAAAA,UAAU,EAAE;AAAA,WAAM,CAAN;AAAA,GAFQ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1B;AACD;;AAED,SAAOwB,UAAP;AACD;AAED,OAAO,SAASC,cAAT,CAAwBL,OAAxB,EAAiC;AACtC,MAAMC,YAAY,GAAG1D,QAAQ,CAAC,EAAD,EAAKyD,OAAL,EAAc;AACzCpB,IAAAA,MAAM,EAAE,CAAC,KAAD,EAAQ,KAAR;AADiC,GAAd,CAA7B;AAGA,SAAOF,KAAK,CAACuB,YAAD,CAAZ;AACD;AAED,OAAO,SAASK,gBAAT,CAA0BN,OAA1B,EAAmC;AACxC,MAAMC,YAAY,GAAG1D,QAAQ,CAAC,EAAD,EAAKyD,OAAL,EAAc;AACzCpB,IAAAA,MAAM,EAAE,CAAC,KAAD,EAAQ,KAAR,EAAe,GAAf;AADiC,GAAd,CAA7B;AAGA,SAAOF,KAAK,CAACuB,YAAD,CAAZ;AACD;AAED,OAAO,SAASM,eAAT,CAAyBP,OAAzB,EAAkC;AACvC,MAAMC,YAAY,GAAG1D,QAAQ,CAAC,EAAD,EAAKyD,OAAL,EAAc;AACzCpB,IAAAA,MAAM,EAAE,CAAC,KAAD,EAAQ,KAAR,EAAe,KAAf,EAAsB,KAAtB;AADiC,GAAd,CAA7B;AAIA,SAAOF,KAAK,CAACuB,YAAD,CAAZ;AACD;AAED,OAAO,SAAS9C,cAAT,CAAwBe,KAAxB,EAA+B;AACpC,SAAOA,KAAK,GAAG,CAAR,KAAc,CAAd,GAAkBN,KAAlB,GAA0BD,UAAjC;AACD","sourcesContent":["import { chunk, concat, defaults, fill, map, slice, take } from 'lodash'\nimport Promise from 'bluebird'\n\nimport {\n DEFAULT_IMAGE_COLUMN_LENGTH,\n DEFAULT_SUMMARY_FIELDS_COLUMN_LENGTH,\n} from '../../../constants'\nimport { buildSummaryField, text } from '../'\n\nconst defaultLayout = {\n fillColor: zebraFillColor,\n hLineWidth: () => 0,\n paddingLeft: () => 5,\n paddingRight: () => 5,\n paddingTop: () => 5,\n paddingBottom: () => 5,\n vLineWidth: () => 0,\n}\n\nexport const GRAY = '#DDDDDD'\nexport const LIGHT_BLUE = '#F0FBFF'\nexport const WHITE = '#FFFFFF'\n\nexport function imageTables(images) {\n const imageRows = chunk(images, DEFAULT_IMAGE_COLUMN_LENGTH)\n const tables = map(imageRows, (imageRow, index) => {\n const defaultRow = fill(Array(DEFAULT_IMAGE_COLUMN_LENGTH), { text: '' })\n const row = concat(imageRow, slice(defaultRow, imageRow.length))\n\n const isMiddleRow = index !== 1 && index !== imageRows.length\n const margin = isMiddleRow ? 5 : 0\n\n return [\n {\n headerRows: 0,\n table: {\n body: [[...row]],\n widths: ['*', '*'],\n },\n layout: {\n hLineColor: () => GRAY,\n hLineWidth: () => 1,\n paddingLeft: () => 5,\n paddingRight: () => 5,\n paddingTop: () => 5,\n paddingBottom: () => 5,\n vLineColor: () => GRAY,\n vLineWidth: () => 1,\n },\n margin: [0, margin, 0, margin],\n },\n ]\n })\n\n return tables\n}\n\nexport async function summaryFieldsTable({ fields, settings, timezone }) {\n const tableHeader = map(fields, ({ label }) =>\n text(label, { bold: true, fontSize: 7 })\n )\n const defaultHeaders = fill(Array(DEFAULT_SUMMARY_FIELDS_COLUMN_LENGTH), {\n text: '',\n })\n const defaultRow = fill(Array(DEFAULT_SUMMARY_FIELDS_COLUMN_LENGTH), {\n text: '',\n })\n const tableRow = await Promise.map(fields, field =>\n buildSummaryField({ field, settings, timezone })\n )\n\n // NOTE: a user can only select three summary fields on the template however\n // if the form group is repeatable we could have more than the default\n // summary field column length so cap otherwise pdf will fail to generate\n const headers = take(\n concat(tableHeader, slice(defaultHeaders, tableHeader.length)),\n DEFAULT_SUMMARY_FIELDS_COLUMN_LENGTH\n )\n const row = take(\n concat(tableRow, slice(defaultRow, tableRow.length)),\n DEFAULT_SUMMARY_FIELDS_COLUMN_LENGTH\n )\n\n const summaryFieldTable = table({\n body: [headers, row],\n colSpan: 5,\n dontBreakRows: true,\n headerRows: 0,\n layout: {\n hLineWidth: () => 0,\n paddingLeft: () => 0,\n paddingRight: () => 5,\n paddingTop: () => 2,\n paddingBottom: () => 2,\n vLineWidth: () => 0,\n },\n // NOTE: pdfmake applies margin/padding to nested tables\n margin: [0, -5, 0, 0],\n widths: ['*', '*', '*'],\n })\n\n return summaryFieldTable\n}\n\nexport function summaryStatTable(options) {\n const tableOptions = defaults({}, options, {\n layout: {\n fillColor: LIGHT_BLUE,\n hLineWidth: () => 0,\n paddingLeft: () => 10,\n paddingRight: () => 10,\n paddingTop: () => 2,\n paddingBottom: () => 2,\n vLineWidth: () => 0,\n },\n widths: ['*'],\n })\n\n return table(tableOptions)\n}\n\nexport function summaryWrapperTable(options) {\n const tableOptions = defaults({}, options, {\n layout: {\n fillColor: WHITE,\n hLineWidth: () => 0,\n paddingLeft: () => 0,\n paddingRight: () => 10,\n paddingTop: () => 0,\n paddingBottom: () => 0,\n vLineWidth: () => 0,\n },\n style: 'summaryWrapperTable',\n })\n\n return table(tableOptions)\n}\n\nexport function table(options) {\n const {\n body,\n colSpan,\n dontBreakRows = false,\n headerRows = 1,\n layout = defaultLayout,\n style = 'table',\n margin,\n widths,\n } = options\n\n const definition = {\n colSpan,\n layout,\n style,\n table: {\n body,\n // NOTE: be wary of this feature, if a row spans multiple pages it won't\n // be drawn on to the pdf, only pass true here when row will be less than\n // a page\n dontBreakRows,\n headerRows,\n },\n margin,\n }\n\n // NOTE: only adds widths if passed\n // as otherwise pdfmake will error!\n // if none defined it auto calculates\n if (widths) {\n definition.table.widths = widths\n }\n\n return definition\n}\n\nexport function twoColumnTable(options) {\n const tableOptions = defaults({}, options, {\n widths: ['50%', '50%'],\n })\n return table(tableOptions)\n}\n\nexport function threeColumnTable(options) {\n const tableOptions = defaults({}, options, {\n widths: ['33%', '33%', '*'],\n })\n return table(tableOptions)\n}\n\nexport function fourColumnTable(options) {\n const tableOptions = defaults({}, options, {\n widths: ['25%', '25%', '25%', '25%'],\n })\n\n return table(tableOptions)\n}\n\nexport function zebraFillColor(index) {\n return index % 2 === 0 ? WHITE : LIGHT_BLUE\n}\n"],"file":"index.js"}
|
|
@@ -13,9 +13,10 @@ export function generateScheduleEnd(_ref) {
|
|
|
13
13
|
frequencyValue = frequency.value;
|
|
14
14
|
var isFrequencyLessThanWeek = includes(frequencyUnit, [Unit.Millisecond, Unit.Second, Unit.Minute, Unit.Hour, Unit.Day]);
|
|
15
15
|
var mStart = moment.tz(start, timezone); // NOTE: if frequency unit less than a week we must set end to jump a week
|
|
16
|
+
// plus the interval length of the schedule frequency
|
|
16
17
|
// so that we can ensure that we are within a service interval
|
|
17
18
|
|
|
18
|
-
var end = isFrequencyLessThanWeek ? mStart.add(
|
|
19
|
+
var end = isFrequencyLessThanWeek ? mStart.add(2, Unit.Week).valueOf() : mStart.add(frequencyValue * 2, frequencyUnit).valueOf();
|
|
19
20
|
return end;
|
|
20
21
|
}
|
|
21
22
|
//# sourceMappingURL=generateScheduleEnd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/scheduling/helpers/generateScheduleEnd.ts"],"names":["includes","moment","Unit","generateScheduleEnd","frequency","start","timezone","frequencyUnit","unit","frequencyValue","value","isFrequencyLessThanWeek","Millisecond","Second","Minute","Hour","Day","mStart","tz","end","add","Week","valueOf"],"mappings":"AAAA,SAASA,QAAT,QAAyB,WAAzB;AACA,OAAOC,MAAP,MAAmB,iBAAnB;AAEA,SAAiBC,IAAjB,QAA6B,qBAA7B;;AAQA;;;AAGA,OAAO,SAASC,mBAAT,OAIyB;AAAA,MAH9BC,SAG8B,QAH9BA,SAG8B;AAAA,MAF9BC,KAE8B,QAF9BA,KAE8B;AAAA,MAD9BC,QAC8B,QAD9BA,QAC8B;AAAA,MAChBC,aADgB,GACyBH,SADzB,CACtBI,IADsB;AAAA,MACMC,cADN,GACyBL,SADzB,CACDM,KADC;AAG9B,MAAMC,uBAAuB,GAAGX,QAAQ,CAACO,aAAD,EAAgB,CACtDL,IAAI,CAACU,WADiD,EAEtDV,IAAI,CAACW,MAFiD,EAGtDX,IAAI,CAACY,MAHiD,EAItDZ,IAAI,CAACa,IAJiD,EAKtDb,IAAI,CAACc,GALiD,CAAhB,CAAxC;AAQA,MAAMC,MAAM,GAAGhB,MAAM,CAACiB,EAAP,CAAUb,KAAV,EAAiBC,QAAjB,CAAf,CAX8B,CAa9B;AACA;;AACA,MAAMa,GAAG,GAAGR,uBAAuB,GAC/BM,MAAM,CAACG,GAAP,CAAW,CAAX,EAAclB,IAAI,CAACmB,IAAnB,EAAyBC,OAAzB,EAD+B,GAE/BL,MAAM,CAACG,GAAP,CAAWX,cAAc,GAAG,CAA5B,EAA+BF,aAA/B,EAA8Ce,OAA9C,EAFJ;AAIA,SAAOH,GAAP;AACD","sourcesContent":["import { includes } from 'lodash/fp'\nimport moment from 'moment-timezone'\n\nimport { Period, Unit } from '../scheduling.types'\n\ninterface GenerateScheduleEnd {\n readonly frequency: Period\n readonly start: number\n readonly timezone: string\n}\n\n/**\n * Generates a schedule end datetime based on the start and frequency\n */\nexport function generateScheduleEnd({\n frequency,\n start,\n timezone,\n}: GenerateScheduleEnd): number {\n const { unit: frequencyUnit, value: frequencyValue } = frequency\n\n const isFrequencyLessThanWeek = includes(frequencyUnit, [\n Unit.Millisecond,\n Unit.Second,\n Unit.Minute,\n Unit.Hour,\n Unit.Day,\n ])\n\n const mStart = moment.tz(start, timezone)\n\n // NOTE: if frequency unit less than a week we must set end to jump a week\n // so that we can ensure that we are within a service interval\n const end = isFrequencyLessThanWeek\n ? mStart.add(
|
|
1
|
+
{"version":3,"sources":["../../../src/scheduling/helpers/generateScheduleEnd.ts"],"names":["includes","moment","Unit","generateScheduleEnd","frequency","start","timezone","frequencyUnit","unit","frequencyValue","value","isFrequencyLessThanWeek","Millisecond","Second","Minute","Hour","Day","mStart","tz","end","add","Week","valueOf"],"mappings":"AAAA,SAASA,QAAT,QAAyB,WAAzB;AACA,OAAOC,MAAP,MAAmB,iBAAnB;AAEA,SAAiBC,IAAjB,QAA6B,qBAA7B;;AAQA;;;AAGA,OAAO,SAASC,mBAAT,OAIyB;AAAA,MAH9BC,SAG8B,QAH9BA,SAG8B;AAAA,MAF9BC,KAE8B,QAF9BA,KAE8B;AAAA,MAD9BC,QAC8B,QAD9BA,QAC8B;AAAA,MAChBC,aADgB,GACyBH,SADzB,CACtBI,IADsB;AAAA,MACMC,cADN,GACyBL,SADzB,CACDM,KADC;AAG9B,MAAMC,uBAAuB,GAAGX,QAAQ,CAACO,aAAD,EAAgB,CACtDL,IAAI,CAACU,WADiD,EAEtDV,IAAI,CAACW,MAFiD,EAGtDX,IAAI,CAACY,MAHiD,EAItDZ,IAAI,CAACa,IAJiD,EAKtDb,IAAI,CAACc,GALiD,CAAhB,CAAxC;AAQA,MAAMC,MAAM,GAAGhB,MAAM,CAACiB,EAAP,CAAUb,KAAV,EAAiBC,QAAjB,CAAf,CAX8B,CAa9B;AACA;AACA;;AACA,MAAMa,GAAG,GAAGR,uBAAuB,GAC/BM,MAAM,CAACG,GAAP,CAAW,CAAX,EAAclB,IAAI,CAACmB,IAAnB,EAAyBC,OAAzB,EAD+B,GAE/BL,MAAM,CAACG,GAAP,CAAWX,cAAc,GAAG,CAA5B,EAA+BF,aAA/B,EAA8Ce,OAA9C,EAFJ;AAIA,SAAOH,GAAP;AACD","sourcesContent":["import { includes } from 'lodash/fp'\nimport moment from 'moment-timezone'\n\nimport { Period, Unit } from '../scheduling.types'\n\ninterface GenerateScheduleEnd {\n readonly frequency: Period\n readonly start: number\n readonly timezone: string\n}\n\n/**\n * Generates a schedule end datetime based on the start and frequency\n */\nexport function generateScheduleEnd({\n frequency,\n start,\n timezone,\n}: GenerateScheduleEnd): number {\n const { unit: frequencyUnit, value: frequencyValue } = frequency\n\n const isFrequencyLessThanWeek = includes(frequencyUnit, [\n Unit.Millisecond,\n Unit.Second,\n Unit.Minute,\n Unit.Hour,\n Unit.Day,\n ])\n\n const mStart = moment.tz(start, timezone)\n\n // NOTE: if frequency unit less than a week we must set end to jump a week\n // plus the interval length of the schedule frequency\n // so that we can ensure that we are within a service interval\n const end = isFrequencyLessThanWeek\n ? mStart.add(2, Unit.Week).valueOf()\n : mStart.add(frequencyValue * 2, frequencyUnit).valueOf()\n\n return end\n}\n"],"file":"generateScheduleEnd.js"}
|
package/package.json
CHANGED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.buildAuditFollowUps = buildAuditFollowUps;
|
|
9
|
-
|
|
10
|
-
var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
|
|
11
|
-
|
|
12
|
-
var _helpers = require("../../../helpers");
|
|
13
|
-
|
|
14
|
-
var _ = require("../");
|
|
15
|
-
|
|
16
|
-
var _images = require("../../../images");
|
|
17
|
-
|
|
18
|
-
// Still to do:
|
|
19
|
-
// *. Setup the page breaks, either on the last item here or the first in the next section
|
|
20
|
-
// - I want to do this in a way that avoids orphans, or at least only add a page break if the result looks balanced
|
|
21
|
-
// - If we can work out the page position of the last follow up item then we can determine whether to use a page break or not
|
|
22
|
-
// *. If you're not using the flag then you should make sure that all of the variables necessary have been passed in
|
|
23
|
-
// - If the required data isn't present then you should probably just not process follow up issues for the document
|
|
24
|
-
// - If you establish this at the start you can build it into the `hasFollowUps` flag
|
|
25
|
-
// *. Is there some way that you can setup an override for the pdfmake version used by storybook?
|
|
26
|
-
const LIGHTHOUSE_BASE_URL = 'https://app.lighthouse.io';
|
|
27
|
-
|
|
28
|
-
function buildAuditFollowUps(rawFollowUpIssues = [], options = {}) {
|
|
29
|
-
console.log('buildAuditFollowUps', {
|
|
30
|
-
rawFollowUpIssues,
|
|
31
|
-
options
|
|
32
|
-
});
|
|
33
|
-
const sectionTitle = [{
|
|
34
|
-
text: 'Follow-up Issues',
|
|
35
|
-
style: {
|
|
36
|
-
font: 'Gotham',
|
|
37
|
-
lineHeight: 1.1,
|
|
38
|
-
margin: [0, 0, 0, 50]
|
|
39
|
-
}
|
|
40
|
-
}];
|
|
41
|
-
const sectionDivider = (0, _.horizontalLine)({
|
|
42
|
-
margin: [0, 0, 0, 0]
|
|
43
|
-
});
|
|
44
|
-
const followUpIssues = rawFollowUpIssues.filter(item => !item.errorMessage);
|
|
45
|
-
|
|
46
|
-
if (!followUpIssues.length) {
|
|
47
|
-
// Show a `no follow up issues` message if there are no follow up issues
|
|
48
|
-
return [sectionTitle, sectionDivider, {
|
|
49
|
-
text: 'No follow up issues exist for this Audit',
|
|
50
|
-
style: _.defaultStyles.subTitle,
|
|
51
|
-
margin: [0, 5, 0, 50]
|
|
52
|
-
}];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const {
|
|
56
|
-
timezone = 'America/New_York'
|
|
57
|
-
} = options;
|
|
58
|
-
const tableBody = [];
|
|
59
|
-
followUpIssues.forEach(item => {
|
|
60
|
-
const mappedStatus = (0, _helpers.getStatusDetails)(item.status);
|
|
61
|
-
const status = {
|
|
62
|
-
text: mappedStatus.text.toUpperCase(),
|
|
63
|
-
style: { ..._.defaultStyles.small,
|
|
64
|
-
color: mappedStatus.style.color,
|
|
65
|
-
alignment: 'center'
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
let updatedAt = '';
|
|
69
|
-
|
|
70
|
-
if (item.updatedAt) {
|
|
71
|
-
const format = 'MMM D h:mma'; // e.g. Jan 21 12:59am in the Audit timezone
|
|
72
|
-
|
|
73
|
-
updatedAt = _momentTimezone.default.tz(item.updatedAt, timezone).format(format);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const link = `${LIGHTHOUSE_BASE_URL}/reports/issues/${item.issueId}`;
|
|
77
|
-
const iconLinkCell = _images.launchIcon ? {
|
|
78
|
-
alignment: 'center',
|
|
79
|
-
fit: [8, 8],
|
|
80
|
-
image: _images.launchIcon,
|
|
81
|
-
link
|
|
82
|
-
} : {
|
|
83
|
-
text: ''
|
|
84
|
-
}; // TODO Should we use the same icon for an external link as we do for a jump link?
|
|
85
|
-
|
|
86
|
-
const linkToDestination = item.questionId;
|
|
87
|
-
const iconJumpCell = _images.launchIcon ? {
|
|
88
|
-
alignment: 'center',
|
|
89
|
-
fit: [8, 8],
|
|
90
|
-
image: _images.launchIcon,
|
|
91
|
-
linkToDestination
|
|
92
|
-
} : {
|
|
93
|
-
text: ''
|
|
94
|
-
};
|
|
95
|
-
let assigneeUsername = 'Unassigned';
|
|
96
|
-
const assignees = item.assignees || [];
|
|
97
|
-
|
|
98
|
-
if (assignees.length === 1) {
|
|
99
|
-
const assigneeUser = assignees[0];
|
|
100
|
-
const {
|
|
101
|
-
firstName,
|
|
102
|
-
lastName,
|
|
103
|
-
username = 'Unknown User'
|
|
104
|
-
} = assigneeUser || {};
|
|
105
|
-
assigneeUsername = firstName && lastName ? `${firstName} ${lastName}` : username;
|
|
106
|
-
} else if (assignees.length > 1) {
|
|
107
|
-
assigneeUsername = `${assignees.length} users`;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
tableBody.push([iconLinkCell, {
|
|
111
|
-
text: item.issueTitle || '',
|
|
112
|
-
link,
|
|
113
|
-
style: 'small',
|
|
114
|
-
image: _images.launchIcon
|
|
115
|
-
}, status, {
|
|
116
|
-
text: assigneeUsername,
|
|
117
|
-
style: 'small'
|
|
118
|
-
}, iconJumpCell, {
|
|
119
|
-
text: item.questionLabel || '',
|
|
120
|
-
style: 'small',
|
|
121
|
-
linkToDestination
|
|
122
|
-
}, {
|
|
123
|
-
text: updatedAt || '',
|
|
124
|
-
style: 'small',
|
|
125
|
-
alignment: 'right'
|
|
126
|
-
}]);
|
|
127
|
-
});
|
|
128
|
-
const headerText = ['', 'Issue Title', 'Status', 'Assignees', '', 'Audit Question', 'Last Updated'];
|
|
129
|
-
const headerRow = headerText.map(text => ({
|
|
130
|
-
text,
|
|
131
|
-
style: {
|
|
132
|
-
bold: true,
|
|
133
|
-
font: 'Gotham',
|
|
134
|
-
fontSize: 8,
|
|
135
|
-
alignment: 'left'
|
|
136
|
-
}
|
|
137
|
-
}));
|
|
138
|
-
headerRow[2].alignment = 'center';
|
|
139
|
-
headerRow[6].alignment = 'right';
|
|
140
|
-
const followUpsTable = (0, _.sixColumnTable)({
|
|
141
|
-
body: [headerRow, ...tableBody],
|
|
142
|
-
style: 'titleTable',
|
|
143
|
-
widths: [6, '*', 55, 55, 6, '*', '18%'],
|
|
144
|
-
margin: [0, 0, 0, 30]
|
|
145
|
-
});
|
|
146
|
-
console.log('buildAuditFollowUps', {
|
|
147
|
-
followUpsTable
|
|
148
|
-
});
|
|
149
|
-
return [sectionTitle, sectionDivider, followUpsTable];
|
|
150
|
-
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
6
|
-
|
|
7
|
-
import moment from 'moment-timezone';
|
|
8
|
-
import { getStatusDetails } from '../../../helpers';
|
|
9
|
-
import { defaultStyles, horizontalLine, sixColumnTable } from '../';
|
|
10
|
-
import { launchIcon } from '../../../images'; // Still to do:
|
|
11
|
-
// *. Setup the page breaks, either on the last item here or the first in the next section
|
|
12
|
-
// - I want to do this in a way that avoids orphans, or at least only add a page break if the result looks balanced
|
|
13
|
-
// - If we can work out the page position of the last follow up item then we can determine whether to use a page break or not
|
|
14
|
-
// *. If you're not using the flag then you should make sure that all of the variables necessary have been passed in
|
|
15
|
-
// - If the required data isn't present then you should probably just not process follow up issues for the document
|
|
16
|
-
// - If you establish this at the start you can build it into the `hasFollowUps` flag
|
|
17
|
-
// *. Is there some way that you can setup an override for the pdfmake version used by storybook?
|
|
18
|
-
|
|
19
|
-
var LIGHTHOUSE_BASE_URL = 'https://app.lighthouse.io';
|
|
20
|
-
export function buildAuditFollowUps() {
|
|
21
|
-
var rawFollowUpIssues = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
22
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
23
|
-
console.log('buildAuditFollowUps', {
|
|
24
|
-
rawFollowUpIssues: rawFollowUpIssues,
|
|
25
|
-
options: options
|
|
26
|
-
});
|
|
27
|
-
var sectionTitle = [{
|
|
28
|
-
text: 'Follow-up Issues',
|
|
29
|
-
style: {
|
|
30
|
-
font: 'Gotham',
|
|
31
|
-
lineHeight: 1.1,
|
|
32
|
-
margin: [0, 0, 0, 50]
|
|
33
|
-
}
|
|
34
|
-
}];
|
|
35
|
-
var sectionDivider = horizontalLine({
|
|
36
|
-
margin: [0, 0, 0, 0]
|
|
37
|
-
});
|
|
38
|
-
var followUpIssues = rawFollowUpIssues.filter(function (item) {
|
|
39
|
-
return !item.errorMessage;
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
if (!followUpIssues.length) {
|
|
43
|
-
// Show a `no follow up issues` message if there are no follow up issues
|
|
44
|
-
return [sectionTitle, sectionDivider, {
|
|
45
|
-
text: 'No follow up issues exist for this Audit',
|
|
46
|
-
style: defaultStyles.subTitle,
|
|
47
|
-
margin: [0, 5, 0, 50]
|
|
48
|
-
}];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
var _options$timezone = options.timezone,
|
|
52
|
-
timezone = _options$timezone === void 0 ? 'America/New_York' : _options$timezone;
|
|
53
|
-
var tableBody = [];
|
|
54
|
-
followUpIssues.forEach(function (item) {
|
|
55
|
-
var mappedStatus = getStatusDetails(item.status);
|
|
56
|
-
var status = {
|
|
57
|
-
text: mappedStatus.text.toUpperCase(),
|
|
58
|
-
style: _objectSpread(_objectSpread({}, defaultStyles.small), {}, {
|
|
59
|
-
color: mappedStatus.style.color,
|
|
60
|
-
alignment: 'center'
|
|
61
|
-
})
|
|
62
|
-
};
|
|
63
|
-
var updatedAt = '';
|
|
64
|
-
|
|
65
|
-
if (item.updatedAt) {
|
|
66
|
-
var format = 'MMM D h:mma'; // e.g. Jan 21 12:59am in the Audit timezone
|
|
67
|
-
|
|
68
|
-
updatedAt = moment.tz(item.updatedAt, timezone).format(format);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
var link = "".concat(LIGHTHOUSE_BASE_URL, "/reports/issues/").concat(item.issueId);
|
|
72
|
-
var iconLinkCell = launchIcon ? {
|
|
73
|
-
alignment: 'center',
|
|
74
|
-
fit: [8, 8],
|
|
75
|
-
image: launchIcon,
|
|
76
|
-
link: link
|
|
77
|
-
} : {
|
|
78
|
-
text: ''
|
|
79
|
-
}; // TODO Should we use the same icon for an external link as we do for a jump link?
|
|
80
|
-
|
|
81
|
-
var linkToDestination = item.questionId;
|
|
82
|
-
var iconJumpCell = launchIcon ? {
|
|
83
|
-
alignment: 'center',
|
|
84
|
-
fit: [8, 8],
|
|
85
|
-
image: launchIcon,
|
|
86
|
-
linkToDestination: linkToDestination
|
|
87
|
-
} : {
|
|
88
|
-
text: ''
|
|
89
|
-
};
|
|
90
|
-
var assigneeUsername = 'Unassigned';
|
|
91
|
-
var assignees = item.assignees || [];
|
|
92
|
-
|
|
93
|
-
if (assignees.length === 1) {
|
|
94
|
-
var assigneeUser = assignees[0];
|
|
95
|
-
|
|
96
|
-
var _ref = assigneeUser || {},
|
|
97
|
-
firstName = _ref.firstName,
|
|
98
|
-
lastName = _ref.lastName,
|
|
99
|
-
_ref$username = _ref.username,
|
|
100
|
-
username = _ref$username === void 0 ? 'Unknown User' : _ref$username;
|
|
101
|
-
|
|
102
|
-
assigneeUsername = firstName && lastName ? "".concat(firstName, " ").concat(lastName) : username;
|
|
103
|
-
} else if (assignees.length > 1) {
|
|
104
|
-
assigneeUsername = "".concat(assignees.length, " users");
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
tableBody.push([iconLinkCell, {
|
|
108
|
-
text: item.issueTitle || '',
|
|
109
|
-
link: link,
|
|
110
|
-
style: 'small',
|
|
111
|
-
image: launchIcon
|
|
112
|
-
}, status, {
|
|
113
|
-
text: assigneeUsername,
|
|
114
|
-
style: 'small'
|
|
115
|
-
}, iconJumpCell, {
|
|
116
|
-
text: item.questionLabel || '',
|
|
117
|
-
style: 'small',
|
|
118
|
-
linkToDestination: linkToDestination
|
|
119
|
-
}, {
|
|
120
|
-
text: updatedAt || '',
|
|
121
|
-
style: 'small',
|
|
122
|
-
alignment: 'right'
|
|
123
|
-
}]);
|
|
124
|
-
});
|
|
125
|
-
var headerText = ['', 'Issue Title', 'Status', 'Assignees', '', 'Audit Question', 'Last Updated'];
|
|
126
|
-
var headerRow = headerText.map(function (text) {
|
|
127
|
-
return {
|
|
128
|
-
text: text,
|
|
129
|
-
style: {
|
|
130
|
-
bold: true,
|
|
131
|
-
font: 'Gotham',
|
|
132
|
-
fontSize: 8,
|
|
133
|
-
alignment: 'left'
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
});
|
|
137
|
-
headerRow[2].alignment = 'center';
|
|
138
|
-
headerRow[6].alignment = 'right';
|
|
139
|
-
var followUpsTable = sixColumnTable({
|
|
140
|
-
body: [headerRow].concat(tableBody),
|
|
141
|
-
style: 'titleTable',
|
|
142
|
-
widths: [6, '*', 55, 55, 6, '*', '18%'],
|
|
143
|
-
margin: [0, 0, 0, 30]
|
|
144
|
-
});
|
|
145
|
-
console.log('buildAuditFollowUps', {
|
|
146
|
-
followUpsTable: followUpsTable
|
|
147
|
-
});
|
|
148
|
-
return [sectionTitle, sectionDivider, followUpsTable];
|
|
149
|
-
}
|
|
150
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/pdf/helpers/build-audit-follow-ups/index.js"],"names":["moment","getStatusDetails","defaultStyles","horizontalLine","sixColumnTable","launchIcon","LIGHTHOUSE_BASE_URL","buildAuditFollowUps","rawFollowUpIssues","options","console","log","sectionTitle","text","style","font","lineHeight","margin","sectionDivider","followUpIssues","filter","item","errorMessage","length","subTitle","timezone","tableBody","forEach","mappedStatus","status","toUpperCase","small","color","alignment","updatedAt","format","tz","link","issueId","iconLinkCell","fit","image","linkToDestination","questionId","iconJumpCell","assigneeUsername","assignees","assigneeUser","firstName","lastName","username","push","issueTitle","questionLabel","headerText","headerRow","map","bold","fontSize","followUpsTable","body","widths"],"mappings":";;;;;;AAAA,OAAOA,MAAP,MAAmB,iBAAnB;AACA,SAASC,gBAAT,QAAiC,kBAAjC;AACA,SAASC,aAAT,EAAwBC,cAAxB,EAAwCC,cAAxC,QAA8D,KAA9D;AACA,SAASC,UAAT,QAA2B,iBAA3B,C,CACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAMC,mBAAmB,GAAG,2BAA5B;AAEA,OAAO,SAASC,mBAAT,GAAmE;AAAA,MAAtCC,iBAAsC,uEAAlB,EAAkB;AAAA,MAAdC,OAAc,uEAAJ,EAAI;AACxEC,EAAAA,OAAO,CAACC,GAAR,CAAY,qBAAZ,EAAmC;AACjCH,IAAAA,iBAAiB,EAAjBA,iBADiC;AAEjCC,IAAAA,OAAO,EAAPA;AAFiC,GAAnC;AAKA,MAAMG,YAAY,GAAG,CACnB;AACEC,IAAAA,IAAI,EAAE,kBADR;AAEEC,IAAAA,KAAK,EAAE;AACLC,MAAAA,IAAI,EAAE,QADD;AAELC,MAAAA,UAAU,EAAE,GAFP;AAGLC,MAAAA,MAAM,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,EAAAA,SAAS,CAAC,CAAD,CAAT,CAAatB,SAAb,GAAyB,QAAzB;AACAsB,EAAAA,SAAS,CAAC,CAAD,CAAT,CAAatB,SAAb,GAAyB,OAAzB;AAEA,MAAM0B,cAAc,GAAGvD,cAAc,CAAC;AACpCwD,IAAAA,IAAI,GAAGL,SAAH,SAAiB7B,SAAjB,CADgC;AAEpCZ,IAAAA,KAAK,EAAE,YAF6B;AAGpC+C,IAAAA,MAAM,EAAE,CAAC,CAAD,EAAI,GAAJ,EAAS,EAAT,EAAa,EAAb,EAAiB,CAAjB,EAAoB,GAApB,EAAyB,KAAzB,CAH4B;AAIpC5C,IAAAA,MAAM,EAAE,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,EAAV;AAJ4B,GAAD,CAArC;AAOAP,EAAAA,OAAO,CAACC,GAAR,CAAY,qBAAZ,EAAmC;AACjCgD,IAAAA,cAAc,EAAdA;AADiC,GAAnC;AAIA,SAAO,CAAC/C,YAAD,EAAeM,cAAf,EAA+ByC,cAA/B,CAAP;AACD","sourcesContent":["import moment from 'moment-timezone'\nimport { getStatusDetails } from '../../../helpers'\nimport { defaultStyles, horizontalLine, sixColumnTable } from '../'\nimport { launchIcon } from '../../../images'\n// Still to do:\n// *. Setup the page breaks, either on the last item here or the first in the next section\n// - I want to do this in a way that avoids orphans, or at least only add a page break if the result looks balanced\n// - If we can work out the page position of the last follow up item then we can determine whether to use a page break or not\n// *. If you're not using the flag then you should make sure that all of the variables necessary have been passed in\n// - If the required data isn't present then you should probably just not process follow up issues for the document\n// - If you establish this at the start you can build it into the `hasFollowUps` flag\n// *. Is there some way that you can setup an override for the pdfmake version used by storybook?\n\nconst LIGHTHOUSE_BASE_URL = 'https://app.lighthouse.io'\n\nexport function buildAuditFollowUps(rawFollowUpIssues = [], options = {}) {\n console.log('buildAuditFollowUps', {\n rawFollowUpIssues,\n options,\n })\n\n const sectionTitle = [\n {\n text: 'Follow-up Issues',\n style: {\n font: 'Gotham',\n lineHeight: 1.1,\n margin: [0, 0, 0, 50],\n },\n },\n ]\n const sectionDivider = horizontalLine({ margin: [0, 0, 0, 0] })\n\n const followUpIssues = rawFollowUpIssues.filter(item => !item.errorMessage)\n if (!followUpIssues.length) {\n // Show a `no follow up issues` message if there are no follow up issues\n return [\n sectionTitle,\n sectionDivider,\n {\n text: 'No follow up issues exist for this Audit',\n style: defaultStyles.subTitle,\n margin: [0, 5, 0, 50],\n },\n ]\n }\n\n const { timezone = 'America/New_York' } = options\n const tableBody = []\n followUpIssues.forEach(item => {\n const mappedStatus = getStatusDetails(item.status)\n const status = {\n text: mappedStatus.text.toUpperCase(),\n style: {\n ...defaultStyles.small,\n color: mappedStatus.style.color,\n alignment: 'center',\n },\n }\n\n let updatedAt = ''\n if (item.updatedAt) {\n const format = 'MMM D h:mma' // e.g. Jan 21 12:59am in the Audit timezone\n updatedAt = moment.tz(item.updatedAt, timezone).format(format)\n }\n\n const link = `${LIGHTHOUSE_BASE_URL}/reports/issues/${item.issueId}`\n const iconLinkCell = launchIcon\n ? { alignment: 'center', fit: [8, 8], image: launchIcon, link }\n : { text: '' }\n\n // TODO Should we use the same icon for an external link as we do for a jump link?\n const linkToDestination = item.questionId\n const iconJumpCell = launchIcon\n ? {\n alignment: 'center',\n fit: [8, 8],\n image: launchIcon,\n linkToDestination,\n }\n : { text: '' }\n\n let assigneeUsername = 'Unassigned'\n const assignees = item.assignees || []\n if (assignees.length === 1) {\n const assigneeUser = assignees[0]\n const { firstName, lastName, username = 'Unknown User' } =\n assigneeUser || {}\n\n assigneeUsername =\n firstName && lastName ? `${firstName} ${lastName}` : username\n } else if (assignees.length > 1) {\n assigneeUsername = `${assignees.length} users`\n }\n\n tableBody.push([\n iconLinkCell,\n { text: item.issueTitle || '', link, style: 'small', image: launchIcon },\n status,\n { text: assigneeUsername, style: 'small' },\n iconJumpCell,\n { text: item.questionLabel || '', style: 'small', linkToDestination },\n { text: updatedAt || '', style: 'small', alignment: 'right' },\n ])\n })\n\n const headerText = [\n '',\n 'Issue Title',\n 'Status',\n 'Assignees',\n '',\n 'Audit Question',\n 'Last Updated',\n ]\n const headerRow = headerText.map(text => ({\n text,\n style: {\n bold: true,\n font: 'Gotham',\n fontSize: 8,\n alignment: 'left',\n },\n }))\n headerRow[2].alignment = 'center'\n headerRow[6].alignment = 'right'\n\n const followUpsTable = sixColumnTable({\n body: [headerRow, ...tableBody],\n style: 'titleTable',\n widths: [6, '*', 55, 55, 6, '*', '18%'],\n margin: [0, 0, 0, 30],\n })\n\n console.log('buildAuditFollowUps', {\n followUpsTable,\n })\n\n return [sectionTitle, sectionDivider, followUpsTable]\n}\n"],"file":"index.js"}
|
package/mise.toml
DELETED