@lighthouse/common 4.29.0 → 4.29.1-canary.0

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.
@@ -93,6 +93,7 @@ function getAuditItemsData(items, data) {
93
93
  comments,
94
94
  key,
95
95
  label,
96
+ questionId: item._id,
96
97
  score,
97
98
  scoreLabel,
98
99
  scoreWeight,
@@ -69,10 +69,12 @@ function generateContent(data, flags) {
69
69
  entity
70
70
  } = data;
71
71
  const {
72
+ followUps = [],
72
73
  footerFields = {},
73
74
  gps = {},
74
75
  headerFields = {},
75
76
  score = {},
77
+ timezone,
76
78
  title = 'Unknown'
77
79
  } = entity;
78
80
  const entityDetails = (0, _helpers2.getAuditEntryDetails)(data);
@@ -86,6 +88,9 @@ function generateContent(data, flags) {
86
88
  target,
87
89
  targetServiceLevel
88
90
  } = entityDetails;
91
+ const {
92
+ rolloutAuditFollowUps
93
+ } = flags;
89
94
  const renderTargetFields = !!targetServiceLevel;
90
95
  const headerTitle = (0, _helpers.text)(title, {
91
96
  style: 'title'
@@ -127,7 +132,8 @@ function generateContent(data, flags) {
127
132
  secondRow = [headerSubTitle, scoreServiceLevelSubTitle];
128
133
  headerAddress = (0, _helpers.text)(address, {
129
134
  style: 'small'
130
- }); // TODO: Determine if we always want 2 decimal places or not
135
+ }); // @ChrisHurt - This TODO has been here for 3 years, what should happen with it?
136
+ // TODO: Determine if we always want 2 decimal places or not
131
137
  // If so apply `.toFixed(2)`
132
138
 
133
139
  const truncatedTargetPercent = (0, _lodash.round)(target, 2);
@@ -167,8 +173,13 @@ function generateContent(data, flags) {
167
173
  margin: [0, 10, 0, 0]
168
174
  });
169
175
  const hLineBottom = (0, _helpers.horizontalLine)();
176
+ const followUpItems = rolloutAuditFollowUps ? (0, _helpers.buildAuditFollowUps)(followUps, {
177
+ timezone
178
+ }) : [];
170
179
  const promises = {
171
- entry: (0, _helpers.buildAuditContent)(groupedData.items),
180
+ entry: (0, _helpers.buildAuditContent)(groupedData.items, {
181
+ flags
182
+ }),
172
183
  footerTemplate: (0, _helpers.buildTemplateContent)(footerFields.formGroups, data),
173
184
  headerTemplate: (0, _helpers.buildTemplateContent)(headerFields.formGroups, data)
174
185
  };
@@ -176,9 +187,7 @@ function generateContent(data, flags) {
176
187
  entry,
177
188
  footerTemplate,
178
189
  headerTemplate
179
- }) => {
180
- return [titleTable, ...headerTemplate, ...entry, hLineTop, totalScoreTable, hLineBottom, ...footerTemplate];
181
- }).catch(err => {
190
+ }) => [titleTable, ...headerTemplate, followUpItems, ...entry, hLineTop, totalScoreTable, hLineBottom, ...footerTemplate]).catch(err => {
182
191
  throw new Error(`GenerateContentError: ${err.message}`);
183
192
  });
184
193
  }
@@ -17,7 +17,10 @@ var _ = require("../");
17
17
 
18
18
  var _table = require("../table");
19
19
 
20
- const buildAuditContent = _bluebird.default.method(items => {
20
+ const buildAuditContent = _bluebird.default.method((items, options) => {
21
+ const {
22
+ flags = {}
23
+ } = options;
21
24
  return _bluebird.default.map(items, group => {
22
25
  return _bluebird.default.map(group.items, (item, index) => {
23
26
  return _bluebird.default.map(item.assets, ({
@@ -34,11 +37,17 @@ const buildAuditContent = _bluebird.default.method(items => {
34
37
  const rows = [];
35
38
  const fillColor = index % 2 === 0 ? _table.WHITE : _table.LIGHT_BLUE;
36
39
  const hasImages = !(0, _lodash.isEmpty)(rowImages);
37
- const hasComments = !(0, _lodash.isEmpty)(item.comments);
38
- rows.push([{
40
+ const hasComments = !(0, _lodash.isEmpty)(item.comments); // Some audits use questionId to link a follow up issue and its question
41
+
42
+ const label = flags.rolloutAuditFollowUps ? {
43
+ text: item.label,
44
+ fillColor,
45
+ id: item.questionId
46
+ } : {
39
47
  text: item.label,
40
48
  fillColor
41
- }, {
49
+ };
50
+ rows.push([label, {
42
51
  text: item.scoreLabel,
43
52
  fillColor
44
53
  }, {
@@ -78,6 +87,17 @@ const buildAuditContent = _bluebird.default.method(items => {
78
87
  return rows;
79
88
  });
80
89
  }).then(groupTableRows => {
90
+ const sectionTitle = [{
91
+ text: 'Audit Items',
92
+ style: {
93
+ font: 'Gotham',
94
+ lineHeight: 1.1,
95
+ padding: [0, 50, 0, 0]
96
+ }
97
+ }];
98
+ const sectionDivider = (0, _.horizontalLine)({
99
+ margin: [0, 10, 0, 0]
100
+ });
81
101
  const actual = (0, _lodash.round)(group.groupActualScore, 2);
82
102
  const max = (0, _lodash.round)(group.groupMaximumScore, 2);
83
103
  const resultText = `${group.groupPercentageResultScore}%`;
@@ -113,7 +133,7 @@ const buildAuditContent = _bluebird.default.method(items => {
113
133
  widths: ['60%', '24%', '8%', '8%']
114
134
  });
115
135
  const hLine = (0, _.horizontalLine)();
116
- return [groupHeaderTable, hLine, groupTable];
136
+ return flags.rolloutAuditFollowUps ? [sectionTitle, sectionDivider, groupHeaderTable, hLine, groupTable] : [groupHeaderTable, hLine, groupTable];
117
137
  });
118
138
  });
119
139
  });
@@ -0,0 +1,145 @@
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
+ // Audit follow up issues datatype
19
+ // @TODO: What does `errorMessage` contain here and can we ignore these?
20
+ // - Is this still an issue?
21
+ // followUps: [
22
+ // {
23
+ // errorMessage: String,
24
+ // issueId: ObjectId,
25
+ // issueTemplateId: ObjectId,
26
+ // questionLabel: String,
27
+ // questionScore: Number,
28
+ // questionScoreText: String,
29
+ // },
30
+ // ],
31
+ //
32
+ // Let's make the assumption that the data will come in in the correct format as follows:
33
+ // followUpIssues: [
34
+ // {
35
+ // title: 'Title', - Issue title
36
+ // question: 'Question', - Audit Question
37
+ // answer: 'Answer', - Audit Answer
38
+ // status: 'Status', - Issue status
39
+ // assignee: 'Assignee', - Issue assignee
40
+ // date: 'Date', - Issue last update
41
+ // },
42
+ // ]
43
+ //
44
+ // Still to do:
45
+ // *. Add a space above the follow up title
46
+ // *. Setup the page breaks, either on the last item here or the first in the next section
47
+ // *. Clean up the code in here as it's a little gross, if you can tidy up the styles that may help
48
+ const LIGHTHOUSE_BASE_URL = 'https://app.lighthouse.io';
49
+
50
+ function buildAuditFollowUps(followUpIssues = [], options = {}) {
51
+ if (!followUpIssues.length) {
52
+ // @TODO Do we need to make a note of not having any follow ups on the PDF?
53
+ console.log('No follow up issues found');
54
+ return [];
55
+ }
56
+
57
+ const {
58
+ timezone = 'America/New_York'
59
+ } = options;
60
+ const sectionTitle = [{
61
+ text: 'Follow-up Issues',
62
+ style: {
63
+ font: 'Gotham',
64
+ lineHeight: 1.1,
65
+ padding: [0, 50, 0, 0]
66
+ }
67
+ }];
68
+ const sectionDivider = (0, _.horizontalLine)({
69
+ margin: [0, 10, 0, 0]
70
+ });
71
+ const tableBody = [];
72
+ followUpIssues.forEach(item => {
73
+ const mappedStatus = (0, _helpers.getStatusDetails)(item.status);
74
+ const status = {
75
+ text: mappedStatus.text,
76
+ style: { ..._.defaultStyles.small,
77
+ color: mappedStatus.style.color,
78
+ alignment: 'center'
79
+ }
80
+ };
81
+ let updatedAt = '';
82
+
83
+ if (item.updatedAt) {
84
+ const format = 'MMM D h:mma'; // e.g. Jan 21 12:59am
85
+
86
+ const mUpdatedAt = item.updatedAt ? _momentTimezone.default.tz(item.updatedAt, timezone) : '';
87
+ updatedAt = mUpdatedAt.format(format);
88
+ } // TODO: The icon should come in like it does below, but what is the fit [8, 8]?
89
+
90
+
91
+ const link = `${LIGHTHOUSE_BASE_URL}/reports/issues/${item.issueId}`;
92
+ const iconLinkCell = _images.launchIcon ? {
93
+ alignment: 'center',
94
+ fit: [8, 8],
95
+ image: _images.launchIcon,
96
+ link
97
+ } : {
98
+ text: ''
99
+ };
100
+ const linkToDestination = item.questionId;
101
+ const iconJumpCell = _images.launchIcon ? {
102
+ alignment: 'center',
103
+ fit: [8, 8],
104
+ image: _images.launchIcon,
105
+ linkToDestination
106
+ } : {
107
+ text: ''
108
+ };
109
+ tableBody.push([iconLinkCell, {
110
+ text: item.groupName || '',
111
+ link,
112
+ style: 'small',
113
+ image: _images.launchIcon
114
+ }, status, {
115
+ text: item.assigneeUsername,
116
+ style: 'small'
117
+ }, iconJumpCell, {
118
+ text: item.questionLabel || '',
119
+ style: 'small'
120
+ }, {
121
+ text: updatedAt || '',
122
+ style: 'small',
123
+ alignment: 'right'
124
+ }]);
125
+ });
126
+ const headerText = ['', 'Issue Title', 'Status', 'Assignees', '', 'Audit Question', 'Last Updated'];
127
+ const headerRow = headerText.map(text => ({
128
+ text,
129
+ style: {
130
+ bold: true,
131
+ font: 'Gotham',
132
+ fontSize: 8,
133
+ alignment: 'left'
134
+ }
135
+ }));
136
+ headerRow[2].alignment = 'center';
137
+ headerRow[6].alignment = 'right'; // TODO Is there any need to translate column headers?
138
+
139
+ const followUpsTable = (0, _.sixColumnTable)({
140
+ body: [headerRow, ...tableBody],
141
+ style: 'titleTable',
142
+ widths: [6, '*', 55, 55, 6, '*', '18%']
143
+ });
144
+ return [sectionTitle, sectionDivider, followUpsTable];
145
+ }
@@ -9,6 +9,12 @@ 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
+ });
12
18
  Object.defineProperty(exports, "buildLocationScansContent", {
13
19
  enumerable: true,
14
20
  get: function () {
@@ -117,40 +123,46 @@ Object.defineProperty(exports, "imageTables", {
117
123
  return _table.imageTables;
118
124
  }
119
125
  });
120
- Object.defineProperty(exports, "table", {
126
+ Object.defineProperty(exports, "sixColumnTable", {
121
127
  enumerable: true,
122
128
  get: function () {
123
- return _table.table;
129
+ return _table.sixColumnTable;
124
130
  }
125
131
  });
126
- Object.defineProperty(exports, "twoColumnTable", {
132
+ Object.defineProperty(exports, "summaryFieldsTable", {
127
133
  enumerable: true,
128
134
  get: function () {
129
- return _table.twoColumnTable;
135
+ return _table.summaryFieldsTable;
130
136
  }
131
137
  });
132
- Object.defineProperty(exports, "threeColumnTable", {
138
+ Object.defineProperty(exports, "summaryStatTable", {
133
139
  enumerable: true,
134
140
  get: function () {
135
- return _table.threeColumnTable;
141
+ return _table.summaryStatTable;
136
142
  }
137
143
  });
138
- Object.defineProperty(exports, "summaryFieldsTable", {
144
+ Object.defineProperty(exports, "summaryWrapperTable", {
139
145
  enumerable: true,
140
146
  get: function () {
141
- return _table.summaryFieldsTable;
147
+ return _table.summaryWrapperTable;
142
148
  }
143
149
  });
144
- Object.defineProperty(exports, "summaryStatTable", {
150
+ Object.defineProperty(exports, "table", {
145
151
  enumerable: true,
146
152
  get: function () {
147
- return _table.summaryStatTable;
153
+ return _table.table;
148
154
  }
149
155
  });
150
- Object.defineProperty(exports, "summaryWrapperTable", {
156
+ Object.defineProperty(exports, "threeColumnTable", {
151
157
  enumerable: true,
152
158
  get: function () {
153
- return _table.summaryWrapperTable;
159
+ return _table.threeColumnTable;
160
+ }
161
+ });
162
+ Object.defineProperty(exports, "twoColumnTable", {
163
+ enumerable: true,
164
+ get: function () {
165
+ return _table.twoColumnTable;
154
166
  }
155
167
  });
156
168
  Object.defineProperty(exports, "zebraFillColor", {
@@ -168,6 +180,8 @@ Object.defineProperty(exports, "text", {
168
180
 
169
181
  var _buildAuditContent = require("./build-audit-content");
170
182
 
183
+ var _buildAuditFollowUps = require("./build-audit-follow-ups");
184
+
171
185
  var _buildLocationScansContent = require("./build-location-scans-content");
172
186
 
173
187
  var _buildTemplateContent = require("./build-template-content");
@@ -13,6 +13,7 @@ exports.table = table;
13
13
  exports.twoColumnTable = twoColumnTable;
14
14
  exports.threeColumnTable = threeColumnTable;
15
15
  exports.fourColumnTable = fourColumnTable;
16
+ exports.sixColumnTable = sixColumnTable;
16
17
  exports.zebraFillColor = zebraFillColor;
17
18
  exports.WHITE = exports.LIGHT_BLUE = exports.GRAY = void 0;
18
19
 
@@ -206,6 +207,13 @@ function fourColumnTable(options) {
206
207
  return table(tableOptions);
207
208
  }
208
209
 
210
+ function sixColumnTable(options) {
211
+ const tableOptions = (0, _lodash.defaults)({}, options, {
212
+ widths: ['25%', '25%', '25%', '25%']
213
+ });
214
+ return table(tableOptions);
215
+ }
216
+
209
217
  function zebraFillColor(index) {
210
218
  return index % 2 === 0 ? WHITE : LIGHT_BLUE;
211
219
  }
@@ -82,6 +82,7 @@ export function getAuditItemsData(items, data) {
82
82
  comments: comments,
83
83
  key: key,
84
84
  label: label,
85
+ questionId: item._id,
85
86
  score: score,
86
87
  scoreLabel: scoreLabel,
87
88
  scoreWeight: scoreWeight,
@@ -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"],"mappings":"AAAA,SAASA,IAAT,EAAeC,OAAf,EAAwBC,GAAxB,EAA6BC,GAA7B,EAAkCC,KAAlC,QAA+C,QAA/C;AAEA,SAASC,aAAT,QAA8B,KAA9B;AAEA,OAAO,SAASC,iBAAT,CAA2BC,KAA3B,EAAkCC,IAAlC,EAAwC;AAAA,uBAIzCA,IAJyC,CAE3CC,QAF2C;AAAA,+CAEK,EAFL;AAAA,MAE/BC,YAF+B,kBAE/BA,YAF+B;AAAA,MAEjBC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6BA,UAAMC,QAAQ,GAAGhB,IAAI,CAACgB,QAAtB;AACA,UAAM3B,KAAK,GAAGW,IAAI,CAACX,KAAnB;AACA,UAAMc,KAAK,GAAGH,IAAI,CAACG,KAAnB;AAEA,UAAMlB,GAAG,aAAMD,UAAN,mBAAyBiB,SAAzB,CAAT;AACA,UAAMgB,aAAa,GAAGnD,IAAI,CAACkC,IAAI,CAACkB,MAAN,EAAc;AAAEC,QAAAA,KAAK,EAAEhB;AAAT,OAAd,CAA1B,CA1C+C,CA4C/C;;AACA,UAAMiB,UAAU,GACdlB,QAAQ,IAAIe,aAAZ,IAA6B,CAAC/B,OAA9B,GAAwC+B,aAAa,CAAC5B,KAAtD,GAA8D,GADhE;AAEA,UAAMgC,WAAW,GAAGnB,QAAQ,IAAI,CAAChB,OAAb,GAAuBc,IAAI,CAACqB,WAA5B,GAA0C,GAA9D;AACA,UAAMC,MAAM,GAAGpB,QAAQ,GAAGF,IAAI,CAACsB,MAAR,GAAiB,GAAxC;AAEA,aAAO;AACLlB,QAAAA,UAAU,EAAVA,UADK;AAELC,QAAAA,MAAM,EAANA,MAFK;AAGLW,QAAAA,QAAQ,EAARA,QAHK;AAIL/B,QAAAA,GAAG,EAAHA,GAJK;AAKLI,QAAAA,KAAK,EAALA,KALK;AAMLc,QAAAA,KAAK,EAALA,KANK;AAOLiB,QAAAA,UAAU,EAAVA,UAPK;AAQLC,QAAAA,WAAW,EAAXA,WARK;AASLC,QAAAA,MAAM,EAANA;AATK,OAAP;AAWD,KA7DiB,CAAlB;AA+DA,WAAOhC,SAAP;AACD,GAxFoB,CAArB;AA0FA,SAAOT,SAAP;AACD","sourcesContent":["import { find, groupBy, map, get, round } from 'lodash'\n\nimport { buildFetchUrl } 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"}
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","questionId","_id"],"mappings":"AAAA,SAASA,IAAT,EAAeC,OAAf,EAAwBC,GAAxB,EAA6BC,GAA7B,EAAkCC,KAAlC,QAA+C,QAA/C;AAEA,SAASC,aAAT,QAA8B,KAA9B;AAEA,OAAO,SAASC,iBAAT,CAA2BC,KAA3B,EAAkCC,IAAlC,EAAwC;AAAA,uBAIzCA,IAJyC,CAE3CC,QAF2C;AAAA,+CAEK,EAFL;AAAA,MAE/BC,YAF+B,kBAE/BA,YAF+B;AAAA,MAEjBC,iBAFiB,kBAEjBA,iBAFiB;AAAA,qBAIzCH,IAJyC,CAG3CI,MAH2C;AAAA,2CAGjB,EAHiB;AAAA,MAGjCC,WAHiC,gBAGjCA,WAHiC;AAM7C,MAAMC,YAAY,GAAGb,OAAO,CAACM,KAAD,EAAQ,UAAR,CAA5B;AAEA,MAAMQ,SAAS,GAAG;AAChBC,IAAAA,kBAAkB,EAAE,CADJ;AAEhBC,IAAAA,mBAAmB,EAAE;AAFL,GAAlB;AAKAF,EAAAA,SAAS,CAACR,KAAV,GAAkBL,GAAG,CAACY,YAAD,EAAe,UAACP,KAAD,EAAQW,UAAR,EAAuB;AACzD,QAAMC,GAAG,GAAGD,UAAZ;AACA,QAAME,OAAO,GAAG,CAAC,CAACb,KAAK,CAAC,CAAD,CAAL,CAASc,KAAT,CAAeD,OAAjC;AACA,QAAME,KAAK,GAAGf,KAAK,CAAC,CAAD,CAAL,CAASc,KAAT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,GAAGF,IAAI,CAACsB,MAAR,GAAiB,GAAxC;AAEA,aAAO;AACLlB,QAAAA,UAAU,EAAVA,UADK;AAELC,QAAAA,MAAM,EAANA,MAFK;AAGLW,QAAAA,QAAQ,EAARA,QAHK;AAIL/B,QAAAA,GAAG,EAAHA,GAJK;AAKLI,QAAAA,KAAK,EAALA,KALK;AAMLkC,QAAAA,UAAU,EAAEvB,IAAI,CAACwB,GANZ;AAOLrB,QAAAA,KAAK,EAALA,KAPK;AAQLiB,QAAAA,UAAU,EAAVA,UARK;AASLC,QAAAA,WAAW,EAAXA,WATK;AAULC,QAAAA,MAAM,EAANA;AAVK,OAAP;AAYD,KA5DiB,CAAlB;AA8DA,WAAOhC,SAAP;AACD,GAvFoB,CAArB;AAyFA,SAAOT,SAAP;AACD","sourcesContent":["import { find, groupBy, map, get, round } from 'lodash'\n\nimport { buildFetchUrl } 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 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 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 questionId: item._id,\n score,\n scoreLabel,\n scoreWeight,\n weight,\n }\n })\n\n return groupData\n })\n\n return auditData\n}\n"],"file":"index.js"}
@@ -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, buildTemplateContent, generateDefinition, getFormattedAddress, horizontalLine, text, twoColumnTable } from '../helpers';
10
+ import { buildAuditContent, buildAuditFollowUps, buildTemplateContent, defaultStyles, generateDefinition, getFormattedAddress, horizontalLine, text, twoColumnTable } from '../helpers';
11
11
  import { getAuditEntryDetails } from '../../helpers';
12
12
  /**
13
13
  * buildAuditPdf
@@ -59,7 +59,9 @@ export function buildAuditPdf(pdfOptions, data) {
59
59
 
60
60
  function generateContent(data, flags) {
61
61
  var entity = data.entity;
62
- var _entity$footerFields = entity.footerFields,
62
+ var _entity$followUps = entity.followUps,
63
+ followUps = _entity$followUps === void 0 ? [] : _entity$followUps,
64
+ _entity$footerFields = entity.footerFields,
63
65
  footerFields = _entity$footerFields === void 0 ? {} : _entity$footerFields,
64
66
  _entity$gps = entity.gps,
65
67
  gps = _entity$gps === void 0 ? {} : _entity$gps,
@@ -67,6 +69,7 @@ function generateContent(data, flags) {
67
69
  headerFields = _entity$headerFields === void 0 ? {} : _entity$headerFields,
68
70
  _entity$score = entity.score,
69
71
  score = _entity$score === void 0 ? {} : _entity$score,
72
+ timezone = entity.timezone,
70
73
  _entity$title = entity.title,
71
74
  title = _entity$title === void 0 ? 'Unknown' : _entity$title;
72
75
  var entityDetails = getAuditEntryDetails(data);
@@ -78,6 +81,7 @@ function generateContent(data, flags) {
78
81
  scoreText = entityDetails.scoreText,
79
82
  target = entityDetails.target,
80
83
  targetServiceLevel = entityDetails.targetServiceLevel;
84
+ var rolloutAuditFollowUps = flags.rolloutAuditFollowUps;
81
85
  var renderTargetFields = !!targetServiceLevel;
82
86
  var headerTitle = text(title, {
83
87
  style: 'title'
@@ -119,7 +123,8 @@ function generateContent(data, flags) {
119
123
  secondRow = [headerSubTitle, scoreServiceLevelSubTitle];
120
124
  headerAddress = text(address, {
121
125
  style: 'small'
122
- }); // TODO: Determine if we always want 2 decimal places or not
126
+ }); // @ChrisHurt - This TODO has been here for 3 years, what should happen with it?
127
+ // TODO: Determine if we always want 2 decimal places or not
123
128
  // If so apply `.toFixed(2)`
124
129
 
125
130
  var truncatedTargetPercent = round(target, 2);
@@ -159,8 +164,13 @@ function generateContent(data, flags) {
159
164
  margin: [0, 10, 0, 0]
160
165
  });
161
166
  var hLineBottom = horizontalLine();
167
+ var followUpItems = rolloutAuditFollowUps ? buildAuditFollowUps(followUps, {
168
+ timezone: timezone
169
+ }) : [];
162
170
  var promises = {
163
- entry: buildAuditContent(groupedData.items),
171
+ entry: buildAuditContent(groupedData.items, {
172
+ flags: flags
173
+ }),
164
174
  footerTemplate: buildTemplateContent(footerFields.formGroups, data),
165
175
  headerTemplate: buildTemplateContent(headerFields.formGroups, data)
166
176
  };
@@ -168,7 +178,7 @@ function generateContent(data, flags) {
168
178
  var entry = _ref.entry,
169
179
  footerTemplate = _ref.footerTemplate,
170
180
  headerTemplate = _ref.headerTemplate;
171
- return [titleTable].concat(_toConsumableArray(headerTemplate), _toConsumableArray(entry), [hLineTop, totalScoreTable, hLineBottom], _toConsumableArray(footerTemplate));
181
+ return [titleTable].concat(_toConsumableArray(headerTemplate), [followUpItems], _toConsumableArray(entry), [hLineTop, totalScoreTable, hLineBottom], _toConsumableArray(footerTemplate));
172
182
  }).catch(function (err) {
173
183
  throw new Error("GenerateContentError: ".concat(err.message));
174
184
  });
@@ -1 +1 @@
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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\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"}
1
+ {"version":3,"sources":["../../../src/pdf/audit/index.js"],"names":["Promise","isEmpty","round","buildAuditContent","buildAuditFollowUps","buildTemplateContent","defaultStyles","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","followUps","footerFields","gps","headerFields","score","entityDetails","gpsText","groupedData","locationText","referenceValue","timezoneHourTime","scoreText","target","targetServiceLevel","rolloutAuditFollowUps","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","followUpItems","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,mBAFF,EAGEC,oBAHF,EAIEC,aAJF,EAKEC,kBALF,EAMEC,mBANF,EAOEC,cAPF,EAQEC,IARF,EASEC,cATF,QAUO,YAVP;AAYA,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,CAEtCI,KAFsC;AAAA,MAEtCA,KAFsC,kCAE9B,EAF8B;AAI9C,MAAMC,UAAU,GAAGH,MAAM,CAACG,UAA1B;AACA,MAAMC,SAAS,GAAGJ,MAAM,CAACK,SAAzB;AACA,MAAMC,KAAK,GAAGN,MAAM,CAACM,KAAP,IAAgB,SAA9B;AAEA,MAAMC,SAAS,4BAAqBD,KAArB,CAAf;AAEA,SAAOE,eAAe,CAACT,IAAD,EAAOG,KAAP,CAAf,CACJO,IADI,CACC,UAAAC,OAAO;AAAA,WACXnB,kBAAkB;AAChBmB,MAAAA,OAAO,EAAPA,OADgB;AAEhBH,MAAAA,SAAS,EAATA,SAFgB;AAGhBJ,MAAAA,UAAU,EAAVA,UAHgB;AAIhBC,MAAAA,SAAS,EAATA,SAJgB;AAKhBH,MAAAA,QAAQ,EAARA,QALgB;AAMhBU,MAAAA,IAAI,EAAE;AANU,OAObb,UAPa,EADP;AAAA,GADR,EAYJc,KAZI,CAYE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EAARA;AAAF,GAAZ,CADoB,GAEvC,EAFJ;AAIA,MAAMmE,QAAQ,GAAG;AACfC,IAAAA,KAAK,EAAElF,iBAAiB,CAACoC,WAAW,CAAC+C,KAAb,EAAoB;AAAEpE,MAAAA,KAAK,EAALA;AAAF,KAApB,CADT;AAEfqE,IAAAA,cAAc,EAAElF,oBAAoB,CAAC4B,YAAY,CAACuD,UAAd,EAA0BzE,IAA1B,CAFrB;AAGf0E,IAAAA,cAAc,EAAEpF,oBAAoB,CAAC8B,YAAY,CAACqD,UAAd,EAA0BzE,IAA1B;AAHrB,GAAjB;AAMA,SAAOf,OAAO,CAAC0F,KAAR,CAAcN,QAAd,EACJ3D,IADI,CACC;AAAA,QAAG4D,KAAH,QAAGA,KAAH;AAAA,QAAUE,cAAV,QAAUA,cAAV;AAAA,QAA0BE,cAA1B,QAA0BA,cAA1B;AAAA,YACJb,UADI,4BAEDa,cAFC,IAGJN,aAHI,sBAIDE,KAJC,IAKJL,QALI,EAMJD,eANI,EAOJG,WAPI,sBAQDK,cARC;AAAA,GADD,EAWJ3D,KAXI,CAWE,UAAAC,GAAG,EAAI;AACZ,UAAM,IAAIC,KAAJ,iCAAmCD,GAAG,CAACE,OAAvC,EAAN;AACD,GAbI,CAAP;AAcD","sourcesContent":["import Promise from 'bluebird'\nimport { isEmpty, round } from 'lodash'\n\nimport {\n buildAuditContent,\n buildAuditFollowUps,\n buildTemplateContent,\n defaultStyles,\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 followUps = [],\n footerFields = {},\n gps = {},\n headerFields = {},\n score = {},\n timezone,\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 { rolloutAuditFollowUps } = flags\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 // @ChrisHurt - This TODO has been here for 3 years, what should happen with it?\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 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 followUpItems = rolloutAuditFollowUps\n ? buildAuditFollowUps(followUps, { timezone })\n : []\n\n const promises = {\n entry: buildAuditContent(groupedData.items, { flags }),\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 titleTable,\n ...headerTemplate,\n followUpItems,\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"}
@@ -4,7 +4,9 @@ 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) {
7
+ export var buildAuditContent = Promise.method(function (items, options) {
8
+ var _options$flags = options.flags,
9
+ flags = _options$flags === void 0 ? {} : _options$flags;
8
10
  return Promise.map(items, function (group) {
9
11
  return Promise.map(group.items, function (item, index) {
10
12
  return Promise.map(item.assets, function (_ref) {
@@ -22,11 +24,17 @@ export var buildAuditContent = Promise.method(function (items) {
22
24
  var rows = [];
23
25
  var fillColor = index % 2 === 0 ? WHITE : LIGHT_BLUE;
24
26
  var hasImages = !isEmpty(rowImages);
25
- var hasComments = !isEmpty(item.comments);
26
- rows.push([{
27
+ var hasComments = !isEmpty(item.comments); // Some audits use questionId to link a follow up issue and its question
28
+
29
+ var label = flags.rolloutAuditFollowUps ? {
30
+ text: item.label,
31
+ fillColor: fillColor,
32
+ id: item.questionId
33
+ } : {
27
34
  text: item.label,
28
35
  fillColor: fillColor
29
- }, {
36
+ };
37
+ rows.push([label, {
30
38
  text: item.scoreLabel,
31
39
  fillColor: fillColor
32
40
  }, {
@@ -66,6 +74,17 @@ export var buildAuditContent = Promise.method(function (items) {
66
74
  return rows;
67
75
  });
68
76
  }).then(function (groupTableRows) {
77
+ var sectionTitle = [{
78
+ text: 'Audit Items',
79
+ style: {
80
+ font: 'Gotham',
81
+ lineHeight: 1.1,
82
+ padding: [0, 50, 0, 0]
83
+ }
84
+ }];
85
+ var sectionDivider = horizontalLine({
86
+ margin: [0, 10, 0, 0]
87
+ });
69
88
  var actual = round(group.groupActualScore, 2);
70
89
  var max = round(group.groupMaximumScore, 2);
71
90
  var resultText = "".concat(group.groupPercentageResultScore, "%");
@@ -99,7 +118,7 @@ export var buildAuditContent = Promise.method(function (items) {
99
118
  widths: ['60%', '24%', '8%', '8%']
100
119
  });
101
120
  var hLine = horizontalLine();
102
- return [groupHeaderTable, hLine, groupTable];
121
+ return flags.rolloutAuditFollowUps ? [sectionTitle, sectionDivider, groupHeaderTable, hLine, groupTable] : [groupHeaderTable, hLine, groupTable];
103
122
  });
104
123
  });
105
124
  });
@@ -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","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,KAAv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EAH6B;AAIjCe,QAAAA,MAAM,EAAE,CAAC,KAAD,EAAQ,KAAR,EAAe,IAAf,EAAqB,IAArB;AAJyB,OAAD,CAAlC;AAOA,UAAMI,KAAK,GAAGzD,cAAc,EAA5B;AAEA,aAAO,CAACkD,gBAAD,EAAmBO,KAAnB,EAA0BF,UAA1B,CAAP;AACD,KA3FM,CAAP;AA4FD,GA7FM,CAAP;AA8FD,CA/FgC,CAA1B","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"}
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","options","flags","map","group","item","index","assets","assetUrl","link","then","base64String","alignment","fit","image","rowImages","rows","fillColor","hasImages","hasComments","comments","label","rolloutAuditFollowUps","id","questionId","push","scoreLabel","weight","scoreWeight","imageRow","colSpan","stack","commentsRow","margin","style","groupTableRows","sectionTitle","font","lineHeight","padding","sectionDivider","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,OA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N;AAJqB,OAAD,CAA9B;AAOA,UAAMC,gBAAgB,GAAG,CACvB7D,IAAI,CAAC,UAAD,EAAa;AAAEsD,QAAAA,IAAI,EAAE;AAAR,OAAb,CADmB,EAEvBtD,IAAI,CAAC,QAAD,EAAW;AAAEsD,QAAAA,IAAI,EAAE;AAAR,OAAX,CAFmB,EAGvBtD,IAAI,CAAC,QAAD,EAAW;AAAEiB,QAAAA,SAAS,EAAE,QAAb;AAAuBqC,QAAAA,IAAI,EAAE;AAA7B,OAAX,CAHmB,EAIvBtD,IAAI,CAAC,OAAD,EAAU;AAAEiB,QAAAA,SAAS,EAAE,OAAb;AAAsBqC,QAAAA,IAAI,EAAE;AAA5B,OAAV,CAJmB,CAAzB;AAOA,UAAMQ,UAAU,GAAGlE,eAAe,CAAC;AACjCmE,QAAAA,UAAU,EAAE,CADqB;AAEjC;AACAL,QAAAA,IAAI,GAAGG,gBAAH,4BAAwBtE,OAAO,CAACiD,cAAD,CAA/B,EAH6B;AAIjCoB,QAAAA,MAAM,EAAE,CAAC,KAAD,EAAQ,KAAR,EAAe,IAAf,EAAqB,IAArB;AAJyB,OAAD,CAAlC;AAOA,UAAMI,KAAK,GAAGnE,cAAc,EAA5B;AAEA,aAAOU,KAAK,CAACoB,qBAAN,GACH,CAACc,YAAD,EAAeI,cAAf,EAA+BY,gBAA/B,EAAiDO,KAAjD,EAAwDF,UAAxD,CADG,GAEH,CAACL,gBAAD,EAAmBO,KAAnB,EAA0BF,UAA1B,CAFJ;AAGD,KA9GM,CAAP;AA+GD,GAhHM,CAAP;AAiHD,CApHgC,CAA1B","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, options) => {\n const { flags = {} } = options\n\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 // Some audits use questionId to link a follow up issue and its question\n const label = flags.rolloutAuditFollowUps\n ? { text: item.label, fillColor, id: item.questionId }\n : { text: item.label, fillColor }\n\n rows.push([\n label,\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 sectionTitle = [\n {\n text: 'Audit Items',\n style: {\n font: 'Gotham',\n lineHeight: 1.1,\n padding: [0, 50, 0, 0],\n },\n },\n ]\n const sectionDivider = horizontalLine({ margin: [0, 10, 0, 0] })\n\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 flags.rolloutAuditFollowUps\n ? [sectionTitle, sectionDivider, groupHeaderTable, hLine, groupTable]\n : [groupHeaderTable, hLine, groupTable]\n })\n })\n})\n"],"file":"index.js"}
@@ -0,0 +1,142 @@
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
+ // Audit follow up issues datatype
8
+ // @TODO: What does `errorMessage` contain here and can we ignore these?
9
+ // - Is this still an issue?
10
+ // followUps: [
11
+ // {
12
+ // errorMessage: String,
13
+ // issueId: ObjectId,
14
+ // issueTemplateId: ObjectId,
15
+ // questionLabel: String,
16
+ // questionScore: Number,
17
+ // questionScoreText: String,
18
+ // },
19
+ // ],
20
+ //
21
+ // Let's make the assumption that the data will come in in the correct format as follows:
22
+ // followUpIssues: [
23
+ // {
24
+ // title: 'Title', - Issue title
25
+ // question: 'Question', - Audit Question
26
+ // answer: 'Answer', - Audit Answer
27
+ // status: 'Status', - Issue status
28
+ // assignee: 'Assignee', - Issue assignee
29
+ // date: 'Date', - Issue last update
30
+ // },
31
+ // ]
32
+ //
33
+ // Still to do:
34
+ // *. Add a space above the follow up title
35
+ // *. Setup the page breaks, either on the last item here or the first in the next section
36
+ // *. Clean up the code in here as it's a little gross, if you can tidy up the styles that may help
37
+ import moment from 'moment-timezone';
38
+ import { getStatusDetails } from '../../../helpers';
39
+ import { defaultStyles, horizontalLine, sixColumnTable } from '../';
40
+ import { launchIcon } from '../../../images';
41
+ var LIGHTHOUSE_BASE_URL = 'https://app.lighthouse.io';
42
+ export function buildAuditFollowUps() {
43
+ var followUpIssues = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
44
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
45
+
46
+ if (!followUpIssues.length) {
47
+ // @TODO Do we need to make a note of not having any follow ups on the PDF?
48
+ console.log('No follow up issues found');
49
+ return [];
50
+ }
51
+
52
+ var _options$timezone = options.timezone,
53
+ timezone = _options$timezone === void 0 ? 'America/New_York' : _options$timezone;
54
+ var sectionTitle = [{
55
+ text: 'Follow-up Issues',
56
+ style: {
57
+ font: 'Gotham',
58
+ lineHeight: 1.1,
59
+ padding: [0, 50, 0, 0]
60
+ }
61
+ }];
62
+ var sectionDivider = horizontalLine({
63
+ margin: [0, 10, 0, 0]
64
+ });
65
+ var tableBody = [];
66
+ followUpIssues.forEach(function (item) {
67
+ var mappedStatus = getStatusDetails(item.status);
68
+ var status = {
69
+ text: mappedStatus.text,
70
+ style: _objectSpread(_objectSpread({}, defaultStyles.small), {}, {
71
+ color: mappedStatus.style.color,
72
+ alignment: 'center'
73
+ })
74
+ };
75
+ var updatedAt = '';
76
+
77
+ if (item.updatedAt) {
78
+ var format = 'MMM D h:mma'; // e.g. Jan 21 12:59am
79
+
80
+ var mUpdatedAt = item.updatedAt ? moment.tz(item.updatedAt, timezone) : '';
81
+ updatedAt = mUpdatedAt.format(format);
82
+ } // TODO: The icon should come in like it does below, but what is the fit [8, 8]?
83
+
84
+
85
+ var link = "".concat(LIGHTHOUSE_BASE_URL, "/reports/issues/").concat(item.issueId);
86
+ var iconLinkCell = launchIcon ? {
87
+ alignment: 'center',
88
+ fit: [8, 8],
89
+ image: launchIcon,
90
+ link: link
91
+ } : {
92
+ text: ''
93
+ };
94
+ var linkToDestination = item.questionId;
95
+ var iconJumpCell = launchIcon ? {
96
+ alignment: 'center',
97
+ fit: [8, 8],
98
+ image: launchIcon,
99
+ linkToDestination: linkToDestination
100
+ } : {
101
+ text: ''
102
+ };
103
+ tableBody.push([iconLinkCell, {
104
+ text: item.groupName || '',
105
+ link: link,
106
+ style: 'small',
107
+ image: launchIcon
108
+ }, status, {
109
+ text: item.assigneeUsername,
110
+ style: 'small'
111
+ }, iconJumpCell, {
112
+ text: item.questionLabel || '',
113
+ style: 'small'
114
+ }, {
115
+ text: updatedAt || '',
116
+ style: 'small',
117
+ alignment: 'right'
118
+ }]);
119
+ });
120
+ var headerText = ['', 'Issue Title', 'Status', 'Assignees', '', 'Audit Question', 'Last Updated'];
121
+ var headerRow = headerText.map(function (text) {
122
+ return {
123
+ text: text,
124
+ style: {
125
+ bold: true,
126
+ font: 'Gotham',
127
+ fontSize: 8,
128
+ alignment: 'left'
129
+ }
130
+ };
131
+ });
132
+ headerRow[2].alignment = 'center';
133
+ headerRow[6].alignment = 'right'; // TODO Is there any need to translate column headers?
134
+
135
+ var followUpsTable = sixColumnTable({
136
+ body: [headerRow].concat(tableBody),
137
+ style: 'titleTable',
138
+ widths: [6, '*', 55, 55, 6, '*', '18%']
139
+ });
140
+ return [sectionTitle, sectionDivider, followUpsTable];
141
+ }
142
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/pdf/helpers/build-audit-follow-ups/index.js"],"names":["moment","getStatusDetails","defaultStyles","horizontalLine","sixColumnTable","launchIcon","LIGHTHOUSE_BASE_URL","buildAuditFollowUps","followUpIssues","options","length","console","log","timezone","sectionTitle","text","style","font","lineHeight","padding","sectionDivider","margin","tableBody","forEach","item","mappedStatus","status","small","color","alignment","updatedAt","format","mUpdatedAt","tz","link","issueId","iconLinkCell","fit","image","linkToDestination","questionId","iconJumpCell","push","groupName","assigneeUsername","questionLabel","headerText","headerRow","map","bold","fontSize","followUpsTable","body","widths"],"mappings":";;;;;;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAOA,MAAP,MAAmB,iBAAnB;AACA,SAASC,gBAAT,QAAiC,kBAAjC;AACA,SAASC,aAAT,EAAwBC,cAAxB,EAAwCC,cAAxC,QAA8D,KAA9D;AACA,SAASC,UAAT,QAA2B,iBAA3B;AAEA,IAAMC,mBAAmB,GAAG,2BAA5B;AAEA,OAAO,SAASC,mBAAT,GAAgE;AAAA,MAAnCC,cAAmC,uEAAlB,EAAkB;AAAA,MAAdC,OAAc,uEAAJ,EAAI;;AACrE,MAAI,CAACD,cAAc,CAACE,MAApB,EAA4B;AAC1B;AACAC,IAAAA,OAAO,CAACC,GAAR,CAAY,2BAAZ;AACA,WAAO,EAAP;AACD;;AALoE,0BAO3BH,OAP2B,CAO7DI,QAP6D;AAAA,MAO7DA,QAP6D,kCAOlD,kBAPkD;AAQrE,MAAMC,YAAY,GAAG,CACnB;AACEC,IAAAA,IAAI,EAAE,kBADR;AAEEC,IAAAA,KAAK,EAAE;AACLC,MAAAA,IAAI,EAAE,QADD;AAELC,MAAAA,UAAU,EAAE,GAFP;AAGLC,MAAAA,OAAO,EAAE,CAAC,CAAD,EAAI,EAAJ,EAAQ,CAAR,EAAW,CAAX;AAHJ;AAFT,GADmB,CAArB;AAUA,MAAMC,cAAc,GAAGjB,cAAc,CAAC;AAAEkB,IAAAA,MAAM,EAAE,CAAC,CAAD,EAAI,EAAJ,EAAQ,CAAR,EAAW,CAAX;AAAV,GAAD,CAArC;AAEA,MAAMC,SAAS,GAAG,EAAlB;AACAd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AT,CAAalB,SAAb,GAAyB,OAAzB,CAxFqE,CA0FrE;;AACA,MAAMsB,cAAc,GAAG/C,cAAc,CAAC;AACpCgD,IAAAA,IAAI,GAAGL,SAAH,SAAiBzB,SAAjB,CADgC;AAEpCN,IAAAA,KAAK,EAAE,YAF6B;AAGpCqC,IAAAA,MAAM,EAAE,CAAC,CAAD,EAAI,GAAJ,EAAS,EAAT,EAAa,EAAb,EAAiB,CAAjB,EAAoB,GAApB,EAAyB,KAAzB;AAH4B,GAAD,CAArC;AAMA,SAAO,CAACvC,YAAD,EAAeM,cAAf,EAA+B+B,cAA/B,CAAP;AACD","sourcesContent":["// Audit follow up issues datatype\n\n// @TODO: What does `errorMessage` contain here and can we ignore these?\n// - Is this still an issue?\n// followUps: [\n// {\n// errorMessage: String,\n// issueId: ObjectId,\n// issueTemplateId: ObjectId,\n// questionLabel: String,\n// questionScore: Number,\n// questionScoreText: String,\n// },\n// ],\n//\n// Let's make the assumption that the data will come in in the correct format as follows:\n// followUpIssues: [\n// {\n// title: 'Title', - Issue title\n// question: 'Question', - Audit Question\n// answer: 'Answer', - Audit Answer\n// status: 'Status', - Issue status\n// assignee: 'Assignee', - Issue assignee\n// date: 'Date', - Issue last update\n// },\n// ]\n//\n// Still to do:\n// *. Add a space above the follow up title\n// *. Setup the page breaks, either on the last item here or the first in the next section\n// *. Clean up the code in here as it's a little gross, if you can tidy up the styles that may help\n\nimport moment from 'moment-timezone'\nimport { getStatusDetails } from '../../../helpers'\nimport { defaultStyles, horizontalLine, sixColumnTable } from '../'\nimport { launchIcon } from '../../../images'\n\nconst LIGHTHOUSE_BASE_URL = 'https://app.lighthouse.io'\n\nexport function buildAuditFollowUps(followUpIssues = [], options = {}) {\n if (!followUpIssues.length) {\n // @TODO Do we need to make a note of not having any follow ups on the PDF?\n console.log('No follow up issues found')\n return []\n }\n\n const { timezone = 'America/New_York' } = options\n const sectionTitle = [\n {\n text: 'Follow-up Issues',\n style: {\n font: 'Gotham',\n lineHeight: 1.1,\n padding: [0, 50, 0, 0],\n },\n },\n ]\n const sectionDivider = horizontalLine({ margin: [0, 10, 0, 0] })\n\n const tableBody = []\n followUpIssues.forEach(item => {\n const mappedStatus = getStatusDetails(item.status)\n const status = {\n text: mappedStatus.text,\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\n const mUpdatedAt = item.updatedAt\n ? moment.tz(item.updatedAt, timezone)\n : ''\n updatedAt = mUpdatedAt.format(format)\n }\n\n // TODO: The icon should come in like it does below, but what is the fit [8, 8]?\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 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 tableBody.push([\n iconLinkCell,\n { text: item.groupName || '', link, style: 'small', image: launchIcon },\n status,\n { text: item.assigneeUsername, style: 'small' },\n iconJumpCell,\n { text: item.questionLabel || '', style: 'small' },\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\n headerRow[2].alignment = 'center'\n headerRow[6].alignment = 'right'\n\n // TODO Is there any need to translate column headers?\n const followUpsTable = sixColumnTable({\n body: [headerRow, ...tableBody],\n style: 'titleTable',\n widths: [6, '*', 55, 55, 6, '*', '18%'],\n })\n\n return [sectionTitle, sectionDivider, followUpsTable]\n}\n"],"file":"index.js"}
@@ -1,4 +1,5 @@
1
1
  export { buildAuditContent } from './build-audit-content';
2
+ export { buildAuditFollowUps } from './build-audit-follow-ups';
2
3
  export { buildLocationScansContent, buildLocationScansBoundaries } from './build-location-scans-content';
3
4
  export { buildTemplateContent } from './build-template-content';
4
5
  export { defaultFooter } from './default-footer';
@@ -10,6 +11,6 @@ export { generateDefinition } from './generate-definition';
10
11
  export { horizontalLine } from './horizontal-line';
11
12
  export { convertToPdfMake, getStyleAttributes, parseHtml, toPdf } from './html-transformer';
12
13
  export { parseValue } from './parse-value';
13
- export { fourColumnTable, imageTables, table, twoColumnTable, threeColumnTable, summaryFieldsTable, summaryStatTable, summaryWrapperTable, zebraFillColor } from './table';
14
+ export { fourColumnTable, imageTables, sixColumnTable, summaryFieldsTable, summaryStatTable, summaryWrapperTable, table, threeColumnTable, twoColumnTable, zebraFillColor } from './table';
14
15
  export { text } from './text';
15
16
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"sources":["../../../src/pdf/helpers/index.js"],"names":["buildAuditContent","buildAuditFollowUps","buildLocationScansContent","buildLocationScansBoundaries","buildTemplateContent","defaultFooter","defaultHeader","defaultStyles","buildSummaryField","buildTemplateFieldRow","getFormattedAddress","generateDefinition","horizontalLine","convertToPdfMake","getStyleAttributes","parseHtml","toPdf","parseValue","fourColumnTable","imageTables","sixColumnTable","summaryFieldsTable","summaryStatTable","summaryWrapperTable","table","threeColumnTable","twoColumnTable","zebraFillColor","text"],"mappings":"AAAA,SAASA,iBAAT,QAAkC,uBAAlC;AACA,SAASC,mBAAT,QAAoC,0BAApC;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,cAHF,EAIEC,kBAJF,EAKEC,gBALF,EAMEC,mBANF,EAOEC,KAPF,EAQEC,gBARF,EASEC,cATF,EAUEC,cAVF,QAWO,SAXP;AAYA,SAASC,IAAT,QAAqB,QAArB","sourcesContent":["export { buildAuditContent } from './build-audit-content'\nexport { buildAuditFollowUps } from './build-audit-follow-ups'\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 sixColumnTable,\n summaryFieldsTable,\n summaryStatTable,\n summaryWrapperTable,\n table,\n threeColumnTable,\n twoColumnTable,\n zebraFillColor,\n} from './table'\nexport { text } from './text'\n"],"file":"index.js"}
@@ -265,6 +265,12 @@ 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: ['25%', '25%', '25%', '25%']
271
+ });
272
+ return table(tableOptions);
273
+ }
268
274
  export function zebraFillColor(index) {
269
275
  return index % 2 === 0 ? WHITE : LIGHT_BLUE;
270
276
  }
@@ -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"],"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,GAHO;AAIpBC,EAAAA,YAAY,EAAE;AAAA,WAAM,CAAN;AAAA,GAJM;AAKpBC,EAAAA,UAAU,EAAE;AAAA,WAAM,CAAN;AAAA,GALQ;AAMpBC,EAAAA,aAAa,EAAE;AAAA,WAAM,CA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B;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"}
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,GAHO;AAIpBC,EAAAA,YAAY,EAAE;AAAA,WAAM,CAAN;AAAA,GAJM;AAKpBC,EAAAA,UAAU,EAAE;AAAA,WAAM,CAAN;AAAA,GALQ;AAMpBC,EAAAA,aAAa,EAAE;AAAA,WAAM,CAAN;AAAA,GANK;AAOpBC,EAAAA,UAAU,EAAE;AAAA,WAAM,CAAN;AAAA;AAPQ,CAAtB;AAUA,OAAO,IAAMC,IAAI,GAAG,SAAb;AACP,OAAO,IAAMC,UAAU,GAAG,SAAnB;AACP,OAAO,IAAMC,KAAK,GAAG,SAAd;AAEP,OAAO,SAASC,WAAT,CAAqBC,MAArB,EAA6B;AAClC,MAAMC,SAAS,GAAG1B,KAAK,CAACyB,MAAD,EAASjB,2BAAT,CAAvB;AACA,MAAMmB,MAAM,GAAGvB,GAAG,CAACs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AMC,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,SAASO,cAAT,CAAwBR,OAAxB,EAAiC;AACtC,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 sixColumnTable(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"}
package/mise.toml CHANGED
@@ -1,2 +1,3 @@
1
1
  [tools]
2
2
  node = "16"
3
+ python = "3.9"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lighthouse/common",
3
- "version": "4.29.0",
3
+ "version": "4.29.1-canary.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "lib/index.js",