@lighthouse/common 6.0.0-canary-2 → 6.0.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.
package/.mise.toml ADDED
@@ -0,0 +1,6 @@
1
+ [tools]
2
+ node = "22.12.0"
3
+ yarn = "1.22.22"
4
+
5
+ [env]
6
+ _.file = '.envrc'
@@ -3,7 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.buildCloudfrontFetchUrl = buildCloudfrontFetchUrl;
7
6
  exports.buildFetchUrl = buildFetchUrl;
8
7
  function buildFetchUrl(url, options) {
9
8
  const {
@@ -14,17 +13,24 @@ function buildFetchUrl(url, options) {
14
13
  height,
15
14
  width,
16
15
  quality,
17
- shouldUseCloudfront
16
+ shouldUseCloudfront,
17
+ Policy,
18
+ KeyPairId,
19
+ Signature
18
20
  } = options;
19
21
  if (shouldUseCloudfront) {
20
- const transformations = [];
21
- if (width) transformations.push(`width=${width.toString()}`);
22
- if (height) transformations.push(`height=${height.toString()}`);
23
- if (quality) transformations.push(`quality=${quality.toString()}`);
24
- transformations.push(`fit=contain`);
25
- const transformationsString = transformations.join('&');
26
- const fetchUrl = `${cloudfrontBaseUrl}/${url}?${transformationsString}`;
27
- return fetchUrl;
22
+ const paramMap = {
23
+ width,
24
+ height,
25
+ quality,
26
+ fit: 'contain',
27
+ Policy,
28
+ 'Key-Pair-Id': KeyPairId,
29
+ Signature
30
+ };
31
+ const params = Object.entries(paramMap).filter(([, value]) => value != null).map(([key, value]) => `${key}=${value.toString()}`);
32
+ const paramsString = params.join('&');
33
+ return `${cloudfrontBaseUrl}/${url}?${paramsString}`;
28
34
  }
29
35
  const transformations = [];
30
36
  let transformationsString = '';
@@ -35,26 +41,4 @@ function buildFetchUrl(url, options) {
35
41
  transformationsString = `${transformations.join(',')}/`;
36
42
  const fetchUrl = `${cloudinaryBaseUrl}/${transformationsString}${awsS3BaseUrl}/${url}`;
37
43
  return fetchUrl;
38
- }
39
- function buildCloudfrontFetchUrl(path, options) {
40
- const {
41
- cloudfrontBaseUrl = '',
42
- height,
43
- width,
44
- quality,
45
- imagesPolicy,
46
- imagesKeyPairId,
47
- imagesSignature
48
- } = options;
49
- const params = [];
50
- if (width) params.push(`width=${width.toString()}`);
51
- if (height) params.push(`height=${height.toString()}`);
52
- if (quality) params.push(`quality=${quality.toString()}`);
53
- if (imagesPolicy) params.push(`Policy=${imagesPolicy}`);
54
- if (imagesKeyPairId) params.push(`Key-Pair-Id=${imagesKeyPairId}`);
55
- if (imagesSignature) params.push(`Signature=${imagesSignature}`);
56
- params.push(`fit=contain`);
57
- const paramsString = params.join('&');
58
- const fetchUrl = new URL(`${cloudfrontBaseUrl}/${path}?${paramsString}`).toString();
59
- return fetchUrl;
60
44
  }
@@ -12,15 +12,15 @@ function getAuditItemsData(items, data) {
12
12
  awsS3BaseUrl,
13
13
  cloudinaryBaseUrl,
14
14
  cloudfrontBaseUrl,
15
- imagesPolicy,
16
- imagesKeyPairId,
17
- imagesSignature
15
+ Policy,
16
+ KeyPairId,
17
+ Signature
18
18
  } = {},
19
19
  entity: {
20
20
  groupScores
21
21
  } = {}
22
22
  } = data;
23
- const shouldUseCloudfront = !!cloudfrontBaseUrl && !!imagesPolicy && !!imagesKeyPairId && !!imagesSignature;
23
+ const shouldUseCloudfront = !!cloudfrontBaseUrl && !!Policy && !!KeyPairId && !!Signature;
24
24
  const groupedItems = (0, _lodash.groupBy)(items, 'group.id');
25
25
  const auditData = {
26
26
  overallActualScore: 0,
@@ -54,37 +54,31 @@ function getAuditItemsData(items, data) {
54
54
  const rawAssets = item.assets || [];
55
55
  const assetCount = rawAssets.length;
56
56
  const assets = rawAssets.map((asset, assetIndex) => {
57
- const assetUrl = shouldUseCloudfront ? (0, _.buildCloudfrontFetchUrl)(asset, {
58
- cloudfrontBaseUrl,
59
- height: 400,
60
- width: 600,
61
- quality: 50,
62
- imagesPolicy,
63
- imagesKeyPairId,
64
- imagesSignature
65
- }) : (0, _.buildFetchUrl)(asset, {
57
+ const assetUrl = (0, _.buildFetchUrl)(asset, {
66
58
  awsS3BaseUrl,
67
59
  cloudfrontBaseUrl,
68
60
  cloudinaryBaseUrl,
69
- fit: true,
70
61
  height: 400,
71
62
  width: 600,
72
- quality: 50
63
+ quality: 50,
64
+ fit: true,
65
+ shouldUseCloudfront,
66
+ Policy,
67
+ KeyPairId,
68
+ Signature
73
69
  });
74
70
  const link = shouldUseCloudfront ? `${cloudfrontBaseUrl}/${item.signedAssets[assetIndex]}` : `${awsS3BaseUrl}/${asset}`;
75
- const thumbnailUrl = shouldUseCloudfront ? (0, _.buildCloudfrontFetchUrl)(asset, {
76
- cloudfrontBaseUrl,
77
- height: 400,
78
- width: 600,
79
- quality: 50,
80
- imagesPolicy,
81
- imagesKeyPairId,
82
- imagesSignature
83
- }) : (0, _.buildFetchUrl)(asset, {
71
+ const thumbnailUrl = (0, _.buildFetchUrl)(asset, {
84
72
  awsS3BaseUrl,
73
+ cloudfrontBaseUrl,
85
74
  cloudinaryBaseUrl,
86
75
  width: 100,
87
- quality: 50
76
+ quality: 50,
77
+ fit: true,
78
+ shouldUseCloudfront,
79
+ Policy,
80
+ KeyPairId,
81
+ Signature
88
82
  });
89
83
  const key = `${groupIndex}-item-asset-${assetIndex}`;
90
84
  return {
@@ -3,12 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "buildCloudfrontFetchUrl", {
7
- enumerable: true,
8
- get: function () {
9
- return _buildFetchUrl.buildCloudfrontFetchUrl;
10
- }
11
- });
12
6
  Object.defineProperty(exports, "buildFetchUrl", {
13
7
  enumerable: true,
14
8
  get: function () {
@@ -144,29 +144,38 @@ function generateContent(data) {
144
144
  style: 'totalScore'
145
145
  });
146
146
  const body = renderThirdRow ? [firstRow, secondRow, thirdRow] : [firstRow, secondRow];
147
- const startedAtInTimezone = entity.startedAt ? (0, _momentTimezone.default)(entity.startedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
148
- const startedAt = (0, _helpers.text)(`Started: ${startedAtInTimezone}`, {
149
- colSpan: 2,
150
- style: 'small'
151
- });
152
147
  const submittedAtInTimezone = entity.submittedAt ? (0, _momentTimezone.default)(entity.submittedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
153
148
  const submittedAt = (0, _helpers.text)(`Submitted: ${submittedAtInTimezone}`, {
154
149
  colSpan: 2,
155
150
  style: 'small'
156
151
  });
157
- const momentDuration = _momentTimezone.default.duration(Math.abs(entity.formDuration));
158
- const days = Math.floor(momentDuration.asDays()).toString().padStart(2, '0');
159
- const hours = Math.floor(momentDuration.hours()).toString().padStart(2, '0');
160
- const minutes = momentDuration.minutes().toString().padStart(2, '0');
161
- const seconds = momentDuration.seconds().toString().padStart(2, '0');
162
- const formattedFormDuration = entity.formDuration ? `${entity.formDuration < 0 ? '-' : ''}${days}:${hours}:${minutes}:${seconds}` : 'Not recorded';
163
- const formDuration = (0, _helpers.text)(`Form Duration (DD:HH:MM:SS): ${formattedFormDuration}`, {
164
- colSpan: 2,
165
- style: 'small'
166
- });
167
- body.push([startedAt, dummyColumn]);
168
- body.push([submittedAt, dummyColumn]);
169
- body.push([formDuration, dummyColumn]);
152
+ if (entity.showSimplifiedDuration) {
153
+ body.push([submittedAt, dummyColumn]);
154
+ } else {
155
+ const startedAtInTimezone = entity.startedAt ? (0, _momentTimezone.default)(entity.startedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
156
+ const startedAt = (0, _helpers.text)(`Started: ${startedAtInTimezone}`, {
157
+ colSpan: 2,
158
+ style: 'small'
159
+ });
160
+ const submittedAtInTimezone = entity.submittedAt ? (0, _momentTimezone.default)(entity.submittedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
161
+ const submittedAt = (0, _helpers.text)(`Submitted: ${submittedAtInTimezone}`, {
162
+ colSpan: 2,
163
+ style: 'small'
164
+ });
165
+ const momentDuration = _momentTimezone.default.duration(Math.abs(entity.formDuration));
166
+ const days = Math.floor(momentDuration.asDays()).toString().padStart(2, '0');
167
+ const hours = Math.floor(momentDuration.hours()).toString().padStart(2, '0');
168
+ const minutes = momentDuration.minutes().toString().padStart(2, '0');
169
+ const seconds = momentDuration.seconds().toString().padStart(2, '0');
170
+ const formattedFormDuration = entity.formDuration ? `${entity.formDuration < 0 ? '-' : ''}${days}:${hours}:${minutes}:${seconds}` : 'Not recorded';
171
+ const formDuration = (0, _helpers.text)(`Form Duration (DD:HH:MM:SS): ${formattedFormDuration}`, {
172
+ colSpan: 2,
173
+ style: 'small'
174
+ });
175
+ body.push([startedAt, dummyColumn]);
176
+ body.push([submittedAt, dummyColumn]);
177
+ body.push([formDuration, dummyColumn]);
178
+ }
170
179
  const titleTable = (0, _helpers.twoColumnTable)({
171
180
  body,
172
181
  layout: 'noBorders',
@@ -85,26 +85,30 @@ function generateContent(data) {
85
85
  style: 'small'
86
86
  });
87
87
  const body = !(0, _lodash.isEmpty)(reverseGeocoded) ? [[headerTitle], [headerSubTitle], [headerAddress]] : [[headerTitle], [headerSubTitle]];
88
- const startedAtInTimezone = entity.startedAt ? (0, _momentTimezone.default)(entity.startedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
89
- const startedAt = (0, _helpers.text)(`Started: ${startedAtInTimezone}`, {
90
- style: 'small'
91
- });
92
88
  const submittedAtInTimezone = entity.submittedAt ? (0, _momentTimezone.default)(entity.submittedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
93
89
  const submittedAt = (0, _helpers.text)(`Submitted: ${submittedAtInTimezone}`, {
94
90
  style: 'small'
95
91
  });
96
- const momentDuration = _momentTimezone.default.duration(Math.abs(entity.formDuration));
97
- const days = Math.floor(momentDuration.asDays()).toString().padStart(2, '0');
98
- const hours = Math.floor(momentDuration.hours()).toString().padStart(2, '0');
99
- const minutes = momentDuration.minutes().toString().padStart(2, '0');
100
- const seconds = momentDuration.seconds().toString().padStart(2, '0');
101
- const formattedFormDuration = entity.formDuration ? `${entity.formDuration < 0 ? '-' : ''}${days}:${hours}:${minutes}:${seconds}` : 'Not recorded';
102
- const formDuration = (0, _helpers.text)(`Form Duration (DD:HH:MM:SS): ${formattedFormDuration}`, {
103
- style: 'small'
104
- });
105
- body.push([startedAt]);
106
- body.push([submittedAt]);
107
- body.push([formDuration]);
92
+ if (entity.showSimplifiedDuration) {
93
+ body.push([submittedAt]);
94
+ } else {
95
+ const startedAtInTimezone = entity.startedAt ? (0, _momentTimezone.default)(entity.startedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
96
+ const startedAt = (0, _helpers.text)(`Started: ${startedAtInTimezone}`, {
97
+ style: 'small'
98
+ });
99
+ const momentDuration = _momentTimezone.default.duration(Math.abs(entity.formDuration));
100
+ const days = Math.floor(momentDuration.asDays()).toString().padStart(2, '0');
101
+ const hours = Math.floor(momentDuration.hours()).toString().padStart(2, '0');
102
+ const minutes = momentDuration.minutes().toString().padStart(2, '0');
103
+ const seconds = momentDuration.seconds().toString().padStart(2, '0');
104
+ const formattedFormDuration = entity.formDuration ? `${entity.formDuration < 0 ? '-' : ''}${days}:${hours}:${minutes}:${seconds}` : 'Not recorded';
105
+ const formDuration = (0, _helpers.text)(`Form Duration (DD:HH:MM:SS): ${formattedFormDuration}`, {
106
+ style: 'small'
107
+ });
108
+ body.push([startedAt]);
109
+ body.push([submittedAt]);
110
+ body.push([formDuration]);
111
+ }
108
112
  const titleTable = (0, _helpers.table)({
109
113
  body,
110
114
  layout: 'noBorders',
@@ -85,26 +85,30 @@ function generateContent(data) {
85
85
  if (!(0, _lodash.isEmpty)(reverseGeocoded)) {
86
86
  body.push([headerAddress]);
87
87
  }
88
- const startedAtInTimezone = entity.startedAt ? (0, _momentTimezone.default)(entity.startedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
89
- const startedAt = (0, _helpers.text)(`Started: ${startedAtInTimezone}`, {
90
- style: 'small'
91
- });
92
88
  const submittedAtInTimezone = entity.submittedAt ? (0, _momentTimezone.default)(entity.submittedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
93
89
  const submittedAt = (0, _helpers.text)(`Submitted: ${submittedAtInTimezone}`, {
94
90
  style: 'small'
95
91
  });
96
- const momentDuration = _momentTimezone.default.duration(Math.abs(entity.formDuration));
97
- const days = Math.floor(momentDuration.asDays()).toString().padStart(2, '0');
98
- const hours = Math.floor(momentDuration.hours()).toString().padStart(2, '0');
99
- const minutes = momentDuration.minutes().toString().padStart(2, '0');
100
- const seconds = momentDuration.seconds().toString().padStart(2, '0');
101
- const formattedFormDuration = entity.formDuration ? `${entity.formDuration < 0 ? '-' : ''}${days}:${hours}:${minutes}:${seconds}` : 'Not recorded';
102
- const formDuration = (0, _helpers.text)(`Form Duration (DD:HH:MM:SS): ${formattedFormDuration}`, {
103
- style: 'small'
104
- });
105
- body.push([startedAt]);
106
- body.push([submittedAt]);
107
- body.push([formDuration]);
92
+ if (entity.showSimplifiedDuration) {
93
+ body.push([submittedAt]);
94
+ } else {
95
+ const startedAtInTimezone = entity.startedAt ? (0, _momentTimezone.default)(entity.startedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
96
+ const startedAt = (0, _helpers.text)(`Started: ${startedAtInTimezone}`, {
97
+ style: 'small'
98
+ });
99
+ const momentDuration = _momentTimezone.default.duration(Math.abs(entity.formDuration));
100
+ const days = Math.floor(momentDuration.asDays()).toString().padStart(2, '0');
101
+ const hours = Math.floor(momentDuration.hours()).toString().padStart(2, '0');
102
+ const minutes = momentDuration.minutes().toString().padStart(2, '0');
103
+ const seconds = momentDuration.seconds().toString().padStart(2, '0');
104
+ const formattedFormDuration = entity.formDuration ? `${entity.formDuration < 0 ? '-' : ''}${days}:${hours}:${minutes}:${seconds}` : 'Not recorded';
105
+ const formDuration = (0, _helpers.text)(`Form Duration (DD:HH:MM:SS): ${formattedFormDuration}`, {
106
+ style: 'small'
107
+ });
108
+ body.push([startedAt]);
109
+ body.push([submittedAt]);
110
+ body.push([formDuration]);
111
+ }
108
112
  const titleTable = (0, _helpers.table)({
109
113
  body,
110
114
  layout: 'noBorders',
@@ -1,3 +1,4 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
1
2
  export function buildFetchUrl(url, options) {
2
3
  var awsS3BaseUrl = options.awsS3BaseUrl,
3
4
  _options$cloudfrontBa = options.cloudfrontBaseUrl,
@@ -7,16 +8,32 @@ export function buildFetchUrl(url, options) {
7
8
  height = options.height,
8
9
  width = options.width,
9
10
  quality = options.quality,
10
- shouldUseCloudfront = options.shouldUseCloudfront;
11
+ shouldUseCloudfront = options.shouldUseCloudfront,
12
+ Policy = options.Policy,
13
+ KeyPairId = options.KeyPairId,
14
+ Signature = options.Signature;
11
15
  if (shouldUseCloudfront) {
12
- var _transformations = [];
13
- if (width) _transformations.push("width=".concat(width.toString()));
14
- if (height) _transformations.push("height=".concat(height.toString()));
15
- if (quality) _transformations.push("quality=".concat(quality.toString()));
16
- _transformations.push("fit=contain");
17
- var _transformationsString = _transformations.join('&');
18
- var _fetchUrl = "".concat(cloudfrontBaseUrl, "/").concat(url, "?").concat(_transformationsString);
19
- return _fetchUrl;
16
+ var paramMap = {
17
+ width: width,
18
+ height: height,
19
+ quality: quality,
20
+ fit: 'contain',
21
+ Policy: Policy,
22
+ 'Key-Pair-Id': KeyPairId,
23
+ Signature: Signature
24
+ };
25
+ var params = Object.entries(paramMap).filter(function (_ref) {
26
+ var _ref2 = _slicedToArray(_ref, 2),
27
+ value = _ref2[1];
28
+ return value != null;
29
+ }).map(function (_ref3) {
30
+ var _ref4 = _slicedToArray(_ref3, 2),
31
+ key = _ref4[0],
32
+ value = _ref4[1];
33
+ return "".concat(key, "=").concat(value.toString());
34
+ });
35
+ var paramsString = params.join('&');
36
+ return "".concat(cloudfrontBaseUrl, "/").concat(url, "?").concat(paramsString);
20
37
  }
21
38
  var transformations = [];
22
39
  var transformationsString = '';
@@ -28,25 +45,4 @@ export function buildFetchUrl(url, options) {
28
45
  var fetchUrl = "".concat(cloudinaryBaseUrl, "/").concat(transformationsString).concat(awsS3BaseUrl, "/").concat(url);
29
46
  return fetchUrl;
30
47
  }
31
- export function buildCloudfrontFetchUrl(path, options) {
32
- var _options$cloudfrontBa2 = options.cloudfrontBaseUrl,
33
- cloudfrontBaseUrl = _options$cloudfrontBa2 === void 0 ? '' : _options$cloudfrontBa2,
34
- height = options.height,
35
- width = options.width,
36
- quality = options.quality,
37
- imagesPolicy = options.imagesPolicy,
38
- imagesKeyPairId = options.imagesKeyPairId,
39
- imagesSignature = options.imagesSignature;
40
- var params = [];
41
- if (width) params.push("width=".concat(width.toString()));
42
- if (height) params.push("height=".concat(height.toString()));
43
- if (quality) params.push("quality=".concat(quality.toString()));
44
- if (imagesPolicy) params.push("Policy=".concat(imagesPolicy));
45
- if (imagesKeyPairId) params.push("Key-Pair-Id=".concat(imagesKeyPairId));
46
- if (imagesSignature) params.push("Signature=".concat(imagesSignature));
47
- params.push("fit=contain");
48
- var paramsString = params.join('&');
49
- var fetchUrl = new URL("".concat(cloudfrontBaseUrl, "/").concat(path, "?").concat(paramsString)).toString();
50
- return fetchUrl;
51
- }
52
48
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["buildFetchUrl","url","options","awsS3BaseUrl","_options$cloudfrontBa","cloudfrontBaseUrl","cloudinaryBaseUrl","fit","height","width","quality","shouldUseCloudfront","transformations","push","concat","toString","transformationsString","join","fetchUrl","buildCloudfrontFetchUrl","path","_options$cloudfrontBa2","imagesPolicy","imagesKeyPairId","imagesSignature","params","paramsString","URL"],"sources":["../../../src/helpers/build-fetch-url/index.js"],"sourcesContent":["export function buildFetchUrl(url, options) {\n const {\n awsS3BaseUrl,\n cloudfrontBaseUrl = '',\n cloudinaryBaseUrl,\n fit,\n height,\n width,\n quality,\n shouldUseCloudfront,\n } = options\n\n if (shouldUseCloudfront) {\n const transformations = []\n\n if (width) transformations.push(`width=${width.toString()}`)\n if (height) transformations.push(`height=${height.toString()}`)\n if (quality) transformations.push(`quality=${quality.toString()}`)\n transformations.push(`fit=contain`)\n\n const transformationsString = transformations.join('&')\n\n const fetchUrl = `${cloudfrontBaseUrl}/${url}?${transformationsString}`\n return fetchUrl\n }\n\n const transformations = []\n let transformationsString = ''\n\n if (width) transformations.push(`w_${width.toString()}`)\n if (height) transformations.push(`h_${height.toString()}`)\n if (quality) transformations.push(`q_${quality.toString()}`)\n if (fit) transformations.push('c_fit')\n\n transformationsString = `${transformations.join(',')}/`\n\n const fetchUrl = `${cloudinaryBaseUrl}/${transformationsString}${awsS3BaseUrl}/${url}`\n\n return fetchUrl\n}\n\nexport function buildCloudfrontFetchUrl(path, options) {\n const {\n cloudfrontBaseUrl = '',\n height,\n width,\n quality,\n imagesPolicy,\n imagesKeyPairId,\n imagesSignature,\n } = options\n\n const params = []\n\n if (width) params.push(`width=${width.toString()}`)\n if (height) params.push(`height=${height.toString()}`)\n if (quality) params.push(`quality=${quality.toString()}`)\n if (imagesPolicy) params.push(`Policy=${imagesPolicy}`)\n if (imagesKeyPairId) params.push(`Key-Pair-Id=${imagesKeyPairId}`)\n if (imagesSignature) params.push(`Signature=${imagesSignature}`)\n params.push(`fit=contain`)\n const paramsString = params.join('&')\n\n const fetchUrl = new URL(\n `${cloudfrontBaseUrl}/${path}?${paramsString}`\n ).toString()\n\n return fetchUrl\n}\n"],"mappings":"AAAA,OAAO,SAASA,aAAaA,CAACC,GAAG,EAAEC,OAAO,EAAE;EAC1C,IACEC,YAAY,GAQVD,OAAO,CARTC,YAAY;IAAAC,qBAAA,GAQVF,OAAO,CAPTG,iBAAiB;IAAjBA,iBAAiB,GAAAD,qBAAA,cAAG,EAAE,GAAAA,qBAAA;IACtBE,iBAAiB,GAMfJ,OAAO,CANTI,iBAAiB;IACjBC,GAAG,GAKDL,OAAO,C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AIC,eAAe,EAAEC,MAAM,CAACZ,IAAI,cAAAC,MAAA,CAAcU,eAAe,CAAE,CAAC;EAChEC,MAAM,CAACZ,IAAI,cAAc,CAAC;EAC1B,IAAMa,YAAY,GAAGD,MAAM,CAACR,IAAI,CAAC,GAAG,CAAC;EAErC,IAAMC,QAAQ,GAAG,IAAIS,GAAG,IAAAb,MAAA,CACnBT,iBAAiB,OAAAS,MAAA,CAAIM,IAAI,OAAAN,MAAA,CAAIY,YAAY,CAC9C,CAAC,CAACX,QAAQ,CAAC,CAAC;EAEZ,OAAOG,QAAQ;AACjB","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["buildFetchUrl","url","options","awsS3BaseUrl","_options$cloudfrontBa","cloudfrontBaseUrl","cloudinaryBaseUrl","fit","height","width","quality","shouldUseCloudfront","Policy","KeyPairId","Signature","paramMap","params","Object","entries","filter","_ref","_ref2","_slicedToArray","value","map","_ref3","_ref4","key","concat","toString","paramsString","join","transformations","transformationsString","push","fetchUrl"],"sources":["../../../src/helpers/build-fetch-url/index.js"],"sourcesContent":["export function buildFetchUrl(url, options) {\n const {\n awsS3BaseUrl,\n cloudfrontBaseUrl = '',\n cloudinaryBaseUrl,\n fit,\n height,\n width,\n quality,\n shouldUseCloudfront,\n Policy,\n KeyPairId,\n Signature,\n } = options\n\n if (shouldUseCloudfront) {\n const paramMap = {\n width,\n height,\n quality,\n fit: 'contain',\n Policy,\n 'Key-Pair-Id': KeyPairId,\n Signature,\n }\n\n const params = Object.entries(paramMap)\n .filter(([, value]) => value != null)\n .map(([key, value]) => `${key}=${value.toString()}`)\n\n const paramsString = params.join('&')\n return `${cloudfrontBaseUrl}/${url}?${paramsString}`\n }\n\n const transformations = []\n let transformationsString = ''\n\n if (width) transformations.push(`w_${width.toString()}`)\n if (height) transformations.push(`h_${height.toString()}`)\n if (quality) transformations.push(`q_${quality.toString()}`)\n if (fit) transformations.push('c_fit')\n\n transformationsString = `${transformations.join(',')}/`\n\n const fetchUrl = `${cloudin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AAAC,MAAA,CAAIL,KAAK,CAACM,QAAQ,CAAC,CAAC;IAAA,CAAE,CAAC;IAEtD,IAAMC,YAAY,GAAGd,MAAM,CAACe,IAAI,CAAC,GAAG,CAAC;IACrC,UAAAH,MAAA,CAAUvB,iBAAiB,OAAAuB,MAAA,CAAI3B,GAAG,OAAA2B,MAAA,CAAIE,YAAY;EACpD;EAEA,IAAME,eAAe,GAAG,EAAE;EAC1B,IAAIC,qBAAqB,GAAG,EAAE;EAE9B,IAAIxB,KAAK,EAAEuB,eAAe,CAACE,IAAI,MAAAN,MAAA,CAAMnB,KAAK,CAACoB,QAAQ,CAAC,CAAC,CAAE,CAAC;EACxD,IAAIrB,MAAM,EAAEwB,eAAe,CAACE,IAAI,MAAAN,MAAA,CAAMpB,MAAM,CAACqB,QAAQ,CAAC,CAAC,CAAE,CAAC;EAC1D,IAAInB,OAAO,EAAEsB,eAAe,CAACE,IAAI,MAAAN,MAAA,CAAMlB,OAAO,CAACmB,QAAQ,CAAC,CAAC,CAAE,CAAC;EAC5D,IAAItB,GAAG,EAAEyB,eAAe,CAACE,IAAI,CAAC,OAAO,CAAC;EAEtCD,qBAAqB,MAAAL,MAAA,CAAMI,eAAe,CAACD,IAAI,CAAC,GAAG,CAAC,MAAG;EAEvD,IAAMI,QAAQ,MAAAP,MAAA,CAAMtB,iBAAiB,OAAAsB,MAAA,CAAIK,qBAAqB,EAAAL,MAAA,CAAGzB,YAAY,OAAAyB,MAAA,CAAI3B,GAAG,CAAE;EAEtF,OAAOkC,QAAQ;AACjB","ignoreList":[]}
@@ -1,18 +1,18 @@
1
1
  import { find, groupBy, map, get, round } from 'lodash';
2
- import { buildFetchUrl, buildCloudfrontFetchUrl } from '../';
2
+ import { buildFetchUrl } from '../';
3
3
  export function getAuditItemsData(items, data) {
4
4
  var _data$settings = data.settings,
5
5
  _data$settings2 = _data$settings === void 0 ? {} : _data$settings,
6
6
  awsS3BaseUrl = _data$settings2.awsS3BaseUrl,
7
7
  cloudinaryBaseUrl = _data$settings2.cloudinaryBaseUrl,
8
8
  cloudfrontBaseUrl = _data$settings2.cloudfrontBaseUrl,
9
- imagesPolicy = _data$settings2.imagesPolicy,
10
- imagesKeyPairId = _data$settings2.imagesKeyPairId,
11
- imagesSignature = _data$settings2.imagesSignature,
9
+ Policy = _data$settings2.Policy,
10
+ KeyPairId = _data$settings2.KeyPairId,
11
+ Signature = _data$settings2.Signature,
12
12
  _data$entity = data.entity,
13
13
  _data$entity2 = _data$entity === void 0 ? {} : _data$entity,
14
14
  groupScores = _data$entity2.groupScores;
15
- var shouldUseCloudfront = !!cloudfrontBaseUrl && !!imagesPolicy && !!imagesKeyPairId && !!imagesSignature;
15
+ var shouldUseCloudfront = !!cloudfrontBaseUrl && !!Policy && !!KeyPairId && !!Signature;
16
16
  var groupedItems = groupBy(items, 'group.id');
17
17
  var auditData = {
18
18
  overallActualScore: 0,
@@ -46,37 +46,31 @@ export function getAuditItemsData(items, data) {
46
46
  var rawAssets = item.assets || [];
47
47
  var assetCount = rawAssets.length;
48
48
  var assets = rawAssets.map(function (asset, assetIndex) {
49
- var assetUrl = shouldUseCloudfront ? buildCloudfrontFetchUrl(asset, {
50
- cloudfrontBaseUrl: cloudfrontBaseUrl,
51
- height: 400,
52
- width: 600,
53
- quality: 50,
54
- imagesPolicy: imagesPolicy,
55
- imagesKeyPairId: imagesKeyPairId,
56
- imagesSignature: imagesSignature
57
- }) : buildFetchUrl(asset, {
49
+ var assetUrl = buildFetchUrl(asset, {
58
50
  awsS3BaseUrl: awsS3BaseUrl,
59
51
  cloudfrontBaseUrl: cloudfrontBaseUrl,
60
52
  cloudinaryBaseUrl: cloudinaryBaseUrl,
61
- fit: true,
62
53
  height: 400,
63
54
  width: 600,
64
- quality: 50
55
+ quality: 50,
56
+ fit: true,
57
+ shouldUseCloudfront: shouldUseCloudfront,
58
+ Policy: Policy,
59
+ KeyPairId: KeyPairId,
60
+ Signature: Signature
65
61
  });
66
62
  var link = shouldUseCloudfront ? "".concat(cloudfrontBaseUrl, "/").concat(item.signedAssets[assetIndex]) : "".concat(awsS3BaseUrl, "/").concat(asset);
67
- var thumbnailUrl = shouldUseCloudfront ? buildCloudfrontFetchUrl(asset, {
68
- cloudfrontBaseUrl: cloudfrontBaseUrl,
69
- height: 400,
70
- width: 600,
71
- quality: 50,
72
- imagesPolicy: imagesPolicy,
73
- imagesKeyPairId: imagesKeyPairId,
74
- imagesSignature: imagesSignature
75
- }) : buildFetchUrl(asset, {
63
+ var thumbnailUrl = buildFetchUrl(asset, {
76
64
  awsS3BaseUrl: awsS3BaseUrl,
65
+ cloudfrontBaseUrl: cloudfrontBaseUrl,
77
66
  cloudinaryBaseUrl: cloudinaryBaseUrl,
78
67
  width: 100,
79
- quality: 50
68
+ quality: 50,
69
+ fit: true,
70
+ shouldUseCloudfront: shouldUseCloudfront,
71
+ Policy: Policy,
72
+ KeyPairId: KeyPairId,
73
+ Signature: Signature
80
74
  });
81
75
  var key = "".concat(groupIndex, "-item-asset-").concat(assetIndex);
82
76
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["find","groupBy","map","get","round","buildFetchUrl","buildCloudfrontFetchUrl","getAuditItemsData","items","data","_data$settings","settings","_data$settings2","awsS3BaseUrl","cloudinaryBaseUrl","cloudfrontBaseUrl","imagesPolicy","imagesKeyPairId","imagesSignature","_data$entity","entity","_data$entity2","groupScores","shouldUseCloudfront","groupedItems","auditData","overallActualScore","overallMaximumScore","groupIndex","key","skipped","group","title","label","groupData","groupMaximumScore","groupActualScore","groupResultScore","groupPercentageResultScore","currentGroupScores","max","actual","result","percentageResult","item","itemIndex","hasScore","score","rawAssets","assets","assetCount","length","asset","assetIndex","assetUrl","height","width","quality","fit","link","concat","signedAssets","thumbnailUrl","comments","matchingScore","scores","value","scoreLabel","scoreWeight","weight","questionId","_id"],"sources":["../../../src/helpers/get-audit-items-data/index.js"],"sourcesContent":["import { find, groupBy, map, get, round } from 'lodash'\n\nimport { buildFetchUrl, buildCloudfrontFetchUrl } from '../'\n\nexport function getAuditItemsData(items, data) {\n const {\n settings: {\n awsS3BaseUrl,\n cloudinaryBaseUrl,\n cloudfrontBaseUrl,\n imagesPolicy,\n imagesKeyPairId,\n imagesSignature,\n } = {},\n entity: { groupScores } = {},\n } = data\n\n const shouldUseCloudfront =\n !!cloudfrontBaseUrl &&\n !!imagesPolicy &&\n !!imagesKeyPairId &&\n !!imagesSignature\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 rawAssets = item.assets || []\n const assetCount = rawAssets.length\n\n const assets = rawAssets.map((asset, assetIndex) => {\n const assetUrl = shouldUseCloudfront\n ? buildCloudfrontFetchUrl(asset, {\n cloudfrontBaseUrl,\n height: 400,\n width: 600,\n quality: 50,\n imagesPolicy,\n imagesKeyPairId,\n imagesSignature,\n })\n : buildFetchUrl(asset, {\n awsS3BaseUrl,\n cloudfrontBaseUrl,\n cloudinaryBaseUrl,\n fit: true,\n height: 400,\n width: 600,\n quality: 50,\n })\n\n const link = shouldUseCloudfront\n ? `${cloudfrontBaseUrl}/${item.signedAssets[assetIndex]}`\n : `${awsS3BaseUrl}/${asset}`\n\n const thumbnailUrl = shouldUseCloudfront\n ? buildCloudfrontFetchUrl(asset, {\n cloudfrontBaseUrl,\n height: 400,\n width: 600,\n quality: 50,\n imagesPolicy,\n imagesKeyPairId,\n imagesSignature,\n })\n : 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"],"mappings":"AAAA,SAASA,IAAI,EAAEC,OAAO,EAAEC,GAAG,EAAEC,GAAG,EAAEC,KAAK,QAAQ,QAAQ;AAEvD,SAASC,aAAa,EAAEC,uBAAuB,QAAQ,KAAK;AAE5D,OAAO,SAASC,iBAAiBA,CAACC,KAAK,EAAEC,IAAI,EAAE;EAC7C,IAAAC,cAAA,GAUID,IAAI,CATNE,QAAQ;IAAAC,eAAA,GAAAF,cAAA,cAOJ,CAAC,CAAC,GAAAA,cAAA;IANJG,YAAY,GAAAD,eAAA,CAAZC,YAAY;IACZC,iBAAiB,GAAAF,eAAA,CAAjBE,iBAAiB;IACjBC,iBAAiB,GAAAH,eAAA,CAAjBG,iBAAiB;IACjBC,YAAY,GAAAJ,eAAA,CAAZI,YAAY;IACZC,eAAe,GAAAL,eAAA,CAAfK,eAAe;IACfC,eAAe,GAAAN,eAAA,CAAfM,eAAe;IAAAC,YAAA,GAGfV,IAAI,CADNW,MAAM;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c,QAAQ,EAARA,QAAQ;QACRlC,GAAG,EAAHA,GAAG;QACHI,KAAK,EAALA,KAAK;QACLqC,UAAU,EAAE1B,IAAI,CAAC2B,GAAG;QACpBxB,KAAK,EAALA,KAAK;QACLoB,UAAU,EAAVA,UAAU;QACVC,WAAW,EAAXA,WAAW;QACXC,MAAM,EAANA;MACF,CAAC;IACH,CAAC,CAAC;IAEF,OAAOnC,SAAS;EAClB,CAAC,CAAC;EAEF,OAAOT,SAAS;AAClB","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["find","groupBy","map","get","round","buildFetchUrl","getAuditItemsData","items","data","_data$settings","settings","_data$settings2","awsS3BaseUrl","cloudinaryBaseUrl","cloudfrontBaseUrl","Policy","KeyPairId","Signature","_data$entity","entity","_data$entity2","groupScores","shouldUseCloudfront","groupedItems","auditData","overallActualScore","overallMaximumScore","groupIndex","key","skipped","group","title","label","groupData","groupMaximumScore","groupActualScore","groupResultScore","groupPercentageResultScore","currentGroupScores","max","actual","result","percentageResult","item","itemIndex","hasScore","score","rawAssets","assets","assetCount","length","asset","assetIndex","assetUrl","height","width","quality","fit","link","concat","signedAssets","thumbnailUrl","comments","matchingScore","scores","value","scoreLabel","scoreWeight","weight","questionId","_id"],"sources":["../../../src/helpers/get-audit-items-data/index.js"],"sourcesContent":["import { find, groupBy, map, get, round } from 'lodash'\n\nimport { buildFetchUrl } from '../'\n\nexport function getAuditItemsData(items, data) {\n const {\n settings: {\n awsS3BaseUrl,\n cloudinaryBaseUrl,\n cloudfrontBaseUrl,\n Policy,\n KeyPairId,\n Signature,\n } = {},\n entity: { groupScores } = {},\n } = data\n\n const shouldUseCloudfront =\n !!cloudfrontBaseUrl && !!Policy && !!KeyPairId && !!Signature\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 rawAssets = item.assets || []\n const assetCount = rawAssets.length\n\n const assets = rawAssets.map((asset, assetIndex) => {\n const assetUrl = buildFetchUrl(asset, {\n awsS3BaseUrl,\n cloudfrontBaseUrl,\n cloudinaryBaseUrl,\n height: 400,\n width: 600,\n quality: 50,\n fit: true,\n shouldUseCloudfront,\n Policy,\n KeyPairId,\n Signature,\n })\n\n const link = shouldUseCloudfront\n ? `${cloudfrontBaseUrl}/${item.signedAssets[assetIndex]}`\n : `${awsS3BaseUrl}/${asset}`\n\n const thumbnailUrl = buildFetchUrl(asset, {\n awsS3BaseUrl,\n cloudfrontBaseUrl,\n cloudinaryBaseUrl,\n width: 100,\n quality: 50,\n fit: true,\n shouldUseCloudfront,\n Policy,\n KeyPairId,\n Signature,\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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IAAI,CAACqB,MAAM,EAAE;QAAEC,KAAK,EAAEnB;MAAM,CAAC,CAAC;;MAEzD;MACA,IAAMoB,UAAU,GACdrB,QAAQ,IAAIkB,aAAa,IAAI,CAAClC,OAAO,GAAGkC,aAAa,CAAC/B,KAAK,GAAG,GAAG;MACnE,IAAMmC,WAAW,GAAGtB,QAAQ,IAAI,CAAChB,OAAO,GAAGc,IAAI,CAACwB,WAAW,GAAG,GAAG;MACjE,IAAMC,MAAM,GAAGvB,QAAQ,GAAGF,IAAI,CAACyB,MAAM,GAAG,GAAG;MAE3C,OAAO;QACLnB,UAAU,EAAVA,UAAU;QACVD,MAAM,EAANA,MAAM;QACNc,QAAQ,EAARA,QAAQ;QACRlC,GAAG,EAAHA,GAAG;QACHI,KAAK,EAALA,KAAK;QACLqC,UAAU,EAAE1B,IAAI,CAAC2B,GAAG;QACpBxB,KAAK,EAALA,KAAK;QACLoB,UAAU,EAAVA,UAAU;QACVC,WAAW,EAAXA,WAAW;QACXC,MAAM,EAANA;MACF,CAAC;IACH,CAAC,CAAC;IAEF,OAAOnC,SAAS;EAClB,CAAC,CAAC;EAEF,OAAOT,SAAS;AAClB","ignoreList":[]}
@@ -1,7 +1,7 @@
1
1
  // NOTE these are global helpers which may used on multiple projects
2
2
  export { getAuditEntryDetails } from './get-audit-entry-details';
3
3
  export { getAuditItemsData } from './get-audit-items-data';
4
- export { buildFetchUrl, buildCloudfrontFetchUrl } from './build-fetch-url';
4
+ export { buildFetchUrl } from './build-fetch-url';
5
5
  export { fetchImage, validateBase64Image } from './fetch-image';
6
6
  export { getAssigneesFullNames } from './get-assignees-full-names';
7
7
  export { getGeometryGeocodedString } from './get-geometry-geocoded-string';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["getAuditEntryDetails","getAuditItemsData","buildFetchUrl","buildCloudfrontFetchUrl","fetchImage","validateBase64Image","getAssigneesFullNames","getGeometryGeocodedString","getIssueDetails","getJobDetails","getLocationReference","getPrettyDuration","getReferenceDetails","getStatusDetails","getTaskEntryDetails","getTimezoneAbbr","getTimezoneDatetime","getUserFullName","getValueAsPercentage"],"sources":["../../src/helpers/index.js"],"sourcesContent":["// NOTE these are global helpers which may used on multiple projects\nexport { getAuditEntryDetails } from './get-audit-entry-details'\nexport { getAuditItemsData } from './get-audit-items-data'\nexport { buildFetchUrl, buildCloudfrontFetchUrl } from './build-fetch-url'\nexport { fetchImage, validateBase64Image } from './fetch-image'\nexport { getAssigneesFullNames } from './get-assignees-full-names'\nexport { getGeometryGeocodedString } from './get-geometry-geocoded-string'\nexport { getIssueDetails } from './get-issue-details'\nexport { getJobDetails } from './get-job-details'\nexport { getLocationReference } from './get-location-reference'\nexport { getPrettyDuration } from './get-pretty-duration'\nexport { getReferenceDetails } from './get-reference-details'\nexport { getStatusDetails } from './get-status-details'\nexport { getTaskEntryDetails } from './get-task-entry-details'\nexport { getTimezoneAbbr } from './get-timezone-abbr'\nexport { getTimezoneDatetime } from './get-timezone-datetime'\nexport { getUserFullName } from './get-user-full-name'\nexport { getValueAsPercentage } from './get-value-as-percentage'\n"],"mappings":"AAAA;AACA,SAASA,oBAAoB,QAAQ,2BAA2B;AAChE,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,aAAa,EAAEC,uBAAuB,QAAQ,mBAAmB;AAC1E,SAASC,UAAU,EAAEC,mBAAmB,QAAQ,eAAe;AAC/D,SAASC,qBAAqB,QAAQ,4BAA4B;AAClE,SAASC,yBAAyB,QAAQ,gCAAgC;AAC1E,SAASC,eAAe,QAAQ,qBAAqB;AACrD,SAASC,aAAa,QAAQ,mBAAmB;AACjD,SAASC,oBAAoB,QAAQ,0BAA0B;AAC/D,SAASC,iBAAiB,QAAQ,uBAAuB;AACzD,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,gBAAgB,QAAQ,sBAAsB;AACvD,SAASC,mBAAmB,QAAQ,0BAA0B;AAC9D,SAASC,eAAe,QAAQ,qBAAqB;AACrD,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,oBAAoB,QAAQ,2BAA2B","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["getAuditEntryDetails","getAuditItemsData","buildFetchUrl","fetchImage","validateBase64Image","getAssigneesFullNames","getGeometryGeocodedString","getIssueDetails","getJobDetails","getLocationReference","getPrettyDuration","getReferenceDetails","getStatusDetails","getTaskEntryDetails","getTimezoneAbbr","getTimezoneDatetime","getUserFullName","getValueAsPercentage"],"sources":["../../src/helpers/index.js"],"sourcesContent":["// NOTE these are global helpers which may used on multiple projects\nexport { getAuditEntryDetails } from './get-audit-entry-details'\nexport { getAuditItemsData } from './get-audit-items-data'\nexport { buildFetchUrl } from './build-fetch-url'\nexport { fetchImage, validateBase64Image } from './fetch-image'\nexport { getAssigneesFullNames } from './get-assignees-full-names'\nexport { getGeometryGeocodedString } from './get-geometry-geocoded-string'\nexport { getIssueDetails } from './get-issue-details'\nexport { getJobDetails } from './get-job-details'\nexport { getLocationReference } from './get-location-reference'\nexport { getPrettyDuration } from './get-pretty-duration'\nexport { getReferenceDetails } from './get-reference-details'\nexport { getStatusDetails } from './get-status-details'\nexport { getTaskEntryDetails } from './get-task-entry-details'\nexport { getTimezoneAbbr } from './get-timezone-abbr'\nexport { getTimezoneDatetime } from './get-timezone-datetime'\nexport { getUserFullName } from './get-user-full-name'\nexport { getValueAsPercentage } from './get-value-as-percentage'\n"],"mappings":"AAAA;AACA,SAASA,oBAAoB,QAAQ,2BAA2B;AAChE,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,aAAa,QAAQ,mBAAmB;AACjD,SAASC,UAAU,EAAEC,mBAAmB,QAAQ,eAAe;AAC/D,SAASC,qBAAqB,QAAQ,4BAA4B;AAClE,SAASC,yBAAyB,QAAQ,gCAAgC;AAC1E,SAASC,eAAe,QAAQ,qBAAqB;AACrD,SAASC,aAAa,QAAQ,mBAAmB;AACjD,SAASC,oBAAoB,QAAQ,0BAA0B;AAC/D,SAASC,iBAAiB,QAAQ,uBAAuB;AACzD,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,gBAAgB,QAAQ,sBAAsB;AACvD,SAASC,mBAAmB,QAAQ,0BAA0B;AAC9D,SAASC,eAAe,QAAQ,qBAAqB;AACrD,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,oBAAoB,QAAQ,2BAA2B","ignoreList":[]}
@@ -140,29 +140,38 @@ function generateContent(data) {
140
140
  style: 'totalScore'
141
141
  });
142
142
  var body = renderThirdRow ? [firstRow, secondRow, thirdRow] : [firstRow, secondRow];
143
- var startedAtInTimezone = entity.startedAt ? moment(entity.startedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
144
- var startedAt = text("Started: ".concat(startedAtInTimezone), {
145
- colSpan: 2,
146
- style: 'small'
147
- });
148
143
  var submittedAtInTimezone = entity.submittedAt ? moment(entity.submittedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
149
144
  var submittedAt = text("Submitted: ".concat(submittedAtInTimezone), {
150
145
  colSpan: 2,
151
146
  style: 'small'
152
147
  });
153
- var momentDuration = moment.duration(Math.abs(entity.formDuration));
154
- var days = Math.floor(momentDuration.asDays()).toString().padStart(2, '0');
155
- var hours = Math.floor(momentDuration.hours()).toString().padStart(2, '0');
156
- var minutes = momentDuration.minutes().toString().padStart(2, '0');
157
- var seconds = momentDuration.seconds().toString().padStart(2, '0');
158
- var formattedFormDuration = entity.formDuration ? "".concat(entity.formDuration < 0 ? '-' : '').concat(days, ":").concat(hours, ":").concat(minutes, ":").concat(seconds) : 'Not recorded';
159
- var formDuration = text("Form Duration (DD:HH:MM:SS): ".concat(formattedFormDuration), {
160
- colSpan: 2,
161
- style: 'small'
162
- });
163
- body.push([startedAt, dummyColumn]);
164
- body.push([submittedAt, dummyColumn]);
165
- body.push([formDuration, dummyColumn]);
148
+ if (entity.showSimplifiedDuration) {
149
+ body.push([submittedAt, dummyColumn]);
150
+ } else {
151
+ var startedAtInTimezone = entity.startedAt ? moment(entity.startedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
152
+ var startedAt = text("Started: ".concat(startedAtInTimezone), {
153
+ colSpan: 2,
154
+ style: 'small'
155
+ });
156
+ var _submittedAtInTimezone = entity.submittedAt ? moment(entity.submittedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
157
+ var _submittedAt = text("Submitted: ".concat(_submittedAtInTimezone), {
158
+ colSpan: 2,
159
+ style: 'small'
160
+ });
161
+ var momentDuration = moment.duration(Math.abs(entity.formDuration));
162
+ var days = Math.floor(momentDuration.asDays()).toString().padStart(2, '0');
163
+ var hours = Math.floor(momentDuration.hours()).toString().padStart(2, '0');
164
+ var minutes = momentDuration.minutes().toString().padStart(2, '0');
165
+ var seconds = momentDuration.seconds().toString().padStart(2, '0');
166
+ var formattedFormDuration = entity.formDuration ? "".concat(entity.formDuration < 0 ? '-' : '').concat(days, ":").concat(hours, ":").concat(minutes, ":").concat(seconds) : 'Not recorded';
167
+ var formDuration = text("Form Duration (DD:HH:MM:SS): ".concat(formattedFormDuration), {
168
+ colSpan: 2,
169
+ style: 'small'
170
+ });
171
+ body.push([startedAt, dummyColumn]);
172
+ body.push([_submittedAt, dummyColumn]);
173
+ body.push([formDuration, dummyColumn]);
174
+ }
166
175
  var titleTable = twoColumnTable({
167
176
  body: body,
168
177
  layout: 'noBorders',
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["Promise","isEmpty","round","moment","buildAuditContent","buildAuditFollowUps","buildTemplateContent","generateDefinition","getFormattedAddress","horizontalLine","text","twoColumnTable","getAuditEntryDetails","buildAuditPdf","pdfOptions","data","entity","timezone","_pdfOptions$flags","flags","sequenceId","timestamp","createdAt","title","fileTitle","concat","generateContent","then","content","_objectSpread","type","catch","err","Error","message","_entity$followUps","followUps","_entity$footerFields","footerFields","_entity$gps","gps","_entity$headerFields","headerFields","_entity$score","score","_entity$title","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","startedAtInTimezone","startedAt","tz","format","submittedAtInTimezone","submittedAt","momentDuration","duration","Math","abs","formDuration","days","floor","asDays","toString","padStart","hours","minutes","seconds","formattedFormDuration","push","titleTable","layout","widths","margin","totalScoreTable","hLineTop","hLineBottom","followUpItems","promises","entry","items","footerTemplate","formGroups","headerTemplate","auditItemsTitle","font","lineHeight","props","_ref","_toConsumableArray"],"sources":["../../../src/pdf/audit/index.js"],"sourcesContent":["import Promise from 'bluebird'\nimport { isEmpty, round } from 'lodash'\nimport moment from 'moment-timezone'\n\nimport {\n buildAuditContent,\n buildAuditFollowUps,\n buildTemplateContent,\n generateDefinition,\n getFormattedAddress,\n horizontalLine,\n text,\n twoColumnTable,\n} from '../helpers'\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 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) {\n const { entity } = data\n\n const {\n followUps = [],\n footerFields = {},\n gps = {},\n headerFields = {},\n score = {},\n title = 'Unknown',\n } = entity\n\n const timezone = entity?.timezone || data?.timezone || 'UTC'\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 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 startedAtInTimezone = entity.startedAt\n ? moment(entity.startedAt)\n .tz(timezone)\n .format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const startedAt = text(`Started: ${startedAtInTimezone}`, {\n colSpan: 2,\n style: 'small',\n })\n\n const submittedAtInTimezone = entity.submittedAt\n ? moment(entity.submittedAt)\n .tz(timezone)\n .format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const submittedAt = text(`Submitted: ${submittedAtInTimezone}`, {\n colSpan: 2,\n style: 'small',\n })\n\n const momentDuration = moment.duration(Math.abs(entity.formDuration))\n const days = Math.floor(momentDuration.asDays())\n .toString()\n .padStart(2, '0')\n const hours = Math.floor(momentDuration.hours())\n .toString()\n .padStart(2, '0')\n const minutes = momentDuration\n .minutes()\n .toString()\n .padStart(2, '0')\n const seconds = momentDuration\n .seconds()\n .toString()\n .padStart(2, '0')\n const formattedFormDuration = entity.formDuration\n ? `${\n entity.formDuration < 0 ? '-' : ''\n }${days}:${hours}:${minutes}:${seconds}`\n : 'Not recorded'\n const formDuration = text(\n `Form Duration (DD:HH:MM:SS): ${formattedFormDuration}`,\n {\n colSpan: 2,\n style: 'small',\n }\n )\n\n body.push([startedAt, dummyColumn])\n body.push([submittedAt, dummyColumn])\n body.push([formDuration, dummyColumn])\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 = buildAuditFollowUps(followUps, { timezone })\n\n const promises = {\n entry: buildAuditContent(groupedData.items),\n footerTemplate: buildTemplateContent(footerFields.formGroups, data),\n headerTemplate: buildTemplateContent(headerFields.formGroups, data),\n }\n\n const auditItemsTitle = [\n {\n text: 'Audit Items',\n style: {\n font: 'Gotham',\n lineHeight: 1.1,\n },\n },\n hLineTop,\n ]\n\n return Promise.props(promises)\n .then(({ entry, footerTemplate, headerTemplate }) => [\n titleTable,\n followUpItems,\n ...auditItemsTitle,\n ...headerTemplate,\n ...entry,\n hLineTop,\n totalScoreTable,\n hLineBottom,\n ...footerTemplate,\n ])\n .catch(err => {\n throw new Error(`GenerateContentError: ${err.message}`)\n })\n}\n"],"mappings":";;;;AAAA,OAAOA,OAAO,MAAM,UAAU;AAC9B,SAASC,OAAO,EAAEC,KAAK,QAAQ,QAAQ;AACvC,OAAOC,MAAM,MAAM,iBAAiB;AAEpC,SACE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C,GAAG,EAAI;IACZ,MAAM,IAAIC,KAAK,0BAAAR,MAAA,CAA0BO,GAAG,CAACE,OAAO,CAAE,CAAC;EACzD,CAAC,CAAC;AACN","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["Promise","isEmpty","round","moment","buildAuditContent","buildAuditFollowUps","buildTemplateContent","generateDefinition","getFormattedAddress","horizontalLine","text","twoColumnTable","getAuditEntryDetails","buildAuditPdf","pdfOptions","data","entity","timezone","_pdfOptions$flags","flags","sequenceId","timestamp","createdAt","title","fileTitle","concat","generateContent","then","content","_objectSpread","type","catch","err","Error","message","_entity$followUps","followUps","_entity$footerFields","footerFields","_entity$gps","gps","_entity$headerFields","headerFields","_entity$score","score","_entity$title","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","submittedAtInTimezone","submittedAt","tz","format","showSimplifiedDuration","push","startedAtInTimezone","startedAt","momentDuration","duration","Math","abs","formDuration","days","floor","asDays","toString","padStart","hours","minutes","seconds","formattedFormDuration","titleTable","layout","widths","margin","totalScoreTable","hLineTop","hLineBottom","followUpItems","promises","entry","items","footerTemplate","formGroups","headerTemplate","auditItemsTitle","font","lineHeight","props","_ref","_toConsumableArray"],"sources":["../../../src/pdf/audit/index.js"],"sourcesContent":["import Promise from 'bluebird'\nimport { isEmpty, round } from 'lodash'\nimport moment from 'moment-timezone'\n\nimport {\n buildAuditContent,\n buildAuditFollowUps,\n buildTemplateContent,\n generateDefinition,\n getFormattedAddress,\n horizontalLine,\n text,\n twoColumnTable,\n} from '../helpers'\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 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) {\n const { entity } = data\n\n const {\n followUps = [],\n footerFields = {},\n gps = {},\n headerFields = {},\n score = {},\n title = 'Unknown',\n } = entity\n\n const timezone = entity?.timezone || data?.timezone || 'UTC'\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 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 submittedAtInTimezone = entity.submittedAt\n ? moment(entity.submittedAt)\n .tz(timezone)\n .format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const submittedAt = text(`Submitted: ${submittedAtInTimezone}`, {\n colSpan: 2,\n style: 'small',\n })\n\n if (entity.showSimplifiedDuration) {\n body.push([submittedAt, dummyColumn])\n } else {\n const startedAtInTimezone = entity.startedAt\n ? moment(entity.startedAt)\n .tz(timezone)\n .format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const startedAt = text(`Started: ${startedAtInTimezone}`, {\n colSpan: 2,\n style: 'small',\n })\n\n const submittedAtInTimezone = entity.submittedAt\n ? moment(entity.submittedAt)\n .tz(timezone)\n .format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const submittedAt = text(`Submitted: ${submittedAtInTimezone}`, {\n colSpan: 2,\n style: 'small',\n })\n\n const momentDuration = moment.duration(Math.abs(entity.formDuration))\n const days = Math.floor(momentDuration.asDays())\n .toString()\n .padStart(2, '0')\n const hours = Math.floor(momentDuration.hours())\n .toString()\n .padStart(2, '0')\n const minutes = momentDuration\n .minutes()\n .toString()\n .padStart(2, '0')\n const seconds = momentDuration\n .seconds()\n .toString()\n .padStart(2, '0')\n const formattedFormDuration = entity.formDuration\n ? `${\n entity.formDuration < 0 ? '-' : ''\n }${days}:${hours}:${minutes}:${seconds}`\n : 'Not recorded'\n const formDuration = text(\n `Form Duration (DD:HH:MM:SS): ${formattedFormDuration}`,\n {\n colSpan: 2,\n style: 'small',\n }\n )\n\n body.push([startedAt, dummyColumn])\n body.push([submittedAt, dummyColumn])\n body.push([formDuration, dummyColumn])\n }\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 = buildAuditFollowUps(followUps, { timezone })\n\n const promises = {\n entry: buildAuditContent(groupedData.items),\n footerTemplate: buildTemplateContent(footerFields.formGroups, data),\n headerTemplate: buildTemplateContent(headerFields.formGroups, data),\n }\n\n const auditItemsTitle = [\n {\n text: 'Audit Items',\n style: {\n font: 'Gotham',\n lineHeight: 1.1,\n },\n },\n hLineTop,\n ]\n\n return Promise.props(promises)\n .then(({ entry, footerTemplate, headerTemplate }) => [\n titleTable,\n followUpItems,\n ...auditItemsTitle,\n ...headerTemplate,\n ...entry,\n hLineTop,\n totalScoreTable,\n hLineBottom,\n ...footerTemplate,\n ])\n .catch(err => {\n throw new Error(`GenerateContentError: ${err.message}`)\n })\n}\n"],"mappings":";;;;AAAA,OAAOA,OAAO,MAAM,UAAU;AAC9B,SAASC,OAAO,EAAEC,KAAK,QAAQ,QAAQ;AACvC,OAAOC,MAAM,MAAM,iBAAiB;AAEpC,SACEC,iBAAiB,EACjBC,mBAAmB,EACnBC,oBAAoB,EACpBC,kBAAkB,EAClBC,mBAAmB,EACnBC,cAAc,EACdC,IAAI,EACJC,cAAc,QACT,YAAY;AACnB,SAASC,oBAAoB,QAAQ,eAAe;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAACC,UAAU,EAAEC,IAAI,EAAE;EAC9C,IAAQC,MAAM,GAAeD,IAAI,CAAzBC,MAAM;IAAEC,QAAQ,GAAKF,IAAI,CAAjBE,QAAQ;EACxB,IAAAC,iBAAA,GAAuBJ,UAAU,CAAzBK,KAAK;IAALA,KAAK,GAAAD,iBAAA,cAAG,CAAC,CAAC,GAAAA,iBAAA;EAElB,IAAME,UAAU,GAAGJ,MAAM,CAACI,UAAU;EACpC,IAAMC,SAAS,GAA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ent(data) {
78
78
  style: 'small'
79
79
  });
80
80
  var body = !isEmpty(reverseGeocoded) ? [[headerTitle], [headerSubTitle], [headerAddress]] : [[headerTitle], [headerSubTitle]];
81
- var startedAtInTimezone = entity.startedAt ? moment(entity.startedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
82
- var startedAt = text("Started: ".concat(startedAtInTimezone), {
83
- style: 'small'
84
- });
85
81
  var submittedAtInTimezone = entity.submittedAt ? moment(entity.submittedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
86
82
  var submittedAt = text("Submitted: ".concat(submittedAtInTimezone), {
87
83
  style: 'small'
88
84
  });
89
- var momentDuration = moment.duration(Math.abs(entity.formDuration));
90
- var days = Math.floor(momentDuration.asDays()).toString().padStart(2, '0');
91
- var hours = Math.floor(momentDuration.hours()).toString().padStart(2, '0');
92
- var minutes = momentDuration.minutes().toString().padStart(2, '0');
93
- var seconds = momentDuration.seconds().toString().padStart(2, '0');
94
- var formattedFormDuration = entity.formDuration ? "".concat(entity.formDuration < 0 ? '-' : '').concat(days, ":").concat(hours, ":").concat(minutes, ":").concat(seconds) : 'Not recorded';
95
- var formDuration = text("Form Duration (DD:HH:MM:SS): ".concat(formattedFormDuration), {
96
- style: 'small'
97
- });
98
- body.push([startedAt]);
99
- body.push([submittedAt]);
100
- body.push([formDuration]);
85
+ if (entity.showSimplifiedDuration) {
86
+ body.push([submittedAt]);
87
+ } else {
88
+ var startedAtInTimezone = entity.startedAt ? moment(entity.startedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
89
+ var startedAt = text("Started: ".concat(startedAtInTimezone), {
90
+ style: 'small'
91
+ });
92
+ var momentDuration = moment.duration(Math.abs(entity.formDuration));
93
+ var days = Math.floor(momentDuration.asDays()).toString().padStart(2, '0');
94
+ var hours = Math.floor(momentDuration.hours()).toString().padStart(2, '0');
95
+ var minutes = momentDuration.minutes().toString().padStart(2, '0');
96
+ var seconds = momentDuration.seconds().toString().padStart(2, '0');
97
+ var formattedFormDuration = entity.formDuration ? "".concat(entity.formDuration < 0 ? '-' : '').concat(days, ":").concat(hours, ":").concat(minutes, ":").concat(seconds) : 'Not recorded';
98
+ var formDuration = text("Form Duration (DD:HH:MM:SS): ".concat(formattedFormDuration), {
99
+ style: 'small'
100
+ });
101
+ body.push([startedAt]);
102
+ body.push([submittedAt]);
103
+ body.push([formDuration]);
104
+ }
101
105
  var titleTable = table({
102
106
  body: body,
103
107
  layout: 'noBorders',
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["get","filter","isEmpty","map","moment","buildTemplateContent","generateDefinition","getFormattedAddress","horizontalLine","table","text","threeColumnTable","getIssueDetails","getStatusDetails","getTimezoneAbbr","getTimezoneDatetime","buildIssuePdf","pdfOptions","data","entity","timezone","sequenceId","timestamp","createdAt","title","fileTitle","concat","generateContent","then","content","_objectSpread","type","entry","_entity$gps","gps","_entity$timeline","timeline","entityDetails","assigneeNames","durationText","gpsText","locationText","statusColor","statusText","reverseGeocoded","subTitle","headerTitle","style","headerSubTitle","address","headerAddress","body","startedAtInTimezone","startedAt","tz","format","submittedAtInTimezone","submittedAt","momentDuration","duration","Math","abs","formDuration","days","floor","asDays","toString","padStart","hours","minutes","seconds","formattedFormDuration","push","titleTable","layout","statusLabelText","bold","statusValueText","color","metaTable","durationLabelText","durationValueText","assigneeLabelText","assigneeValueText","timelineTitle","timelineHorizontalLine","timelineTable","createTimelineTable","formGroups","_toConsumableArray","timezoneAbbr","timelineHeaderRow","alignment","statusUpdates","timelineBodyRows","colSpan","item","_item$meta","meta","source","next","firstName","lastName","fullName","isNew","isUpdate","isOpen","statusDetails","nextStatusText","activity","datetime","showTzAbbr"],"sources":["../../../src/pdf/issue/index.js"],"sourcesContent":["import { get, filter, isEmpty, map } from 'lodash'\nimport moment from 'moment-timezone'\n\nimport {\n buildTemplateContent,\n generateDefinition,\n getFormattedAddress,\n horizontalLine,\n table,\n text,\n threeColumnTable,\n} from '../helpers'\n\nimport {\n getIssueDetails,\n getStatusDetails,\n getTimezoneAbbr,\n getTimezoneDatetime,\n} from '../../helpers'\n\n/**\n * buildIssuePdf\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} data - pdf data\n * @param {object} data.entity - issue 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 * @param {object} data.zones - zone documents\n * @returns {Promise} returns pdfmake definition object\n */\nexport function buildIssuePdf(pdfOptions, data) {\n const { entity, timezone } = data\n\n const sequenceId = entity.sequenceId\n const timestamp = entity.createdAt\n const title = entity.title || 'Unknown'\n\n const fileTitle = `Issue Report - ${title}`\n\n return generateContent(data).then(content =>\n generateDefinition({\n content,\n fileTitle,\n sequenceId,\n timestamp,\n timezone,\n type: 'Issue',\n ...pdfOptions,\n })\n )\n}\n\nfunction generateContent(data) {\n const { entity, timezone } = data\n const { entry, gps = {}, timeline = [], title } = entity\n\n const entityDetails = getIssueDetails(data)\n\n const {\n assigneeNames,\n durationText,\n gpsText,\n locationText,\n statusColor,\n statusText,\n } = entityDetails\n\n const reverseGeocoded = gps.reverseGeocoded\n\n const subTitle = `${locationText || gpsText}`\n const headerTitle = text(title, { style: 'title' })\n const headerSubTitle = text(subTitle, { style: 'subTitle' })\n const address = !isEmpty(reverseGeocoded)\n ? getFormattedAddress(reverseGeocoded)\n : ''\n const headerAddress = text(address, { style: 'small' })\n\n const body = !isEmpty(reverseGeocoded)\n ? [[headerTitle], [headerSubTitle], [headerAddress]]\n : [[headerTitle], [headerSubTitle]]\n\n const startedAtInTimezone = entity.startedAt\n ? moment(entity.startedAt)\n .tz(timezone)\n .format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const startedAt = text(`Started: ${startedAtInTimezone}`, {\n style: 'small',\n })\n\n const submittedAtInTimezone = entity.submittedAt\n ? moment(entity.submittedAt)\n .tz(timezone)\n .format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const submittedAt = text(`Submitted: ${submittedAtInTimezone}`, {\n style: 'small',\n })\n\n const momentDuration = moment.duration(Math.abs(entity.formDuration))\n const days = Math.floor(momentDuration.asDays())\n .toString()\n .padStart(2, '0')\n const hours = Math.floor(momentDuration.hours())\n .toString()\n .padStart(2, '0')\n const minutes = momentDuration\n .minutes()\n .toString()\n .padStart(2, '0')\n const seconds = momentDuration\n .seconds()\n .toString()\n .padStart(2, '0')\n const formattedFormDuration = entity.formDuration\n ? `${\n entity.formDuration < 0 ? '-' : ''\n }${days}:${hours}:${minutes}:${seconds}`\n : 'Not recorded'\n const formDuration = text(\n `Form Duration (DD:HH:MM:SS): ${formattedFormDuration}`,\n {\n style: 'small',\n }\n )\n\n body.push([startedAt])\n body.push([submittedAt])\n body.push([formDuration])\n\n const titleTable = table({\n body,\n layout: 'noBorders',\n style: 'titleTable',\n })\n\n const statusLabelText = text('Status', { bold: true })\n const statusValueText = text(statusText, { color: statusColor })\n\n const metaTable = table({\n body: [[statusLabelText, statusValueText]],\n layout: 'noBorders',\n style: 'metaTable',\n })\n\n if (statusText === 'CLOSED') {\n const durationLabelText = text('Duration', { bold: true })\n const durationValueText = text(durationText)\n metaTable.table.body.push([durationLabelText, durationValueText])\n }\n\n const assigneeLabelText = text('Assignees', { bold: true })\n const assigneeValueText = text(assigneeNames)\n metaTable.table.body.push([assigneeLabelText, assigneeValueText])\n\n const timelineTitle = text('Timeline', { style: 'timelineTitle' })\n const timelineHorizontalLine = horizontalLine()\n const timelineTable = createTimelineTable(timeline, timezone)\n\n return buildTemplateContent(entry.formGroups, data).then(entry => [\n titleTable,\n metaTable,\n timelineTitle,\n timelineHorizontalLine,\n timelineTable,\n ...entry,\n ])\n}\n\nfunction createTimelineTable(timeline, timezone) {\n const timezoneAbbr = getTimezoneAbbr(timezone)\n\n const timelineHeaderRow = [\n text('Activity', { bold: true }),\n text('User', { bold: true }),\n text(`Date & Timestamp (${timezoneAbbr})`, {\n alignment: 'right',\n bold: true,\n }),\n ]\n\n const statusUpdates = filter(timeline, ['meta.field', 'status'])\n\n const timelineBodyRows = isEmpty(statusUpdates)\n ? [text('No Timeline activity', { colSpan: 3 })]\n : map(statusUpdates, item => {\n const { meta = {}, source, timestamp, type } = item\n\n const next = get(meta, 'next')\n const firstName = get(source, 'meta.firstName')\n const lastName = get(source, 'meta.lastName')\n\n const fullName =\n firstName && lastName ? `${firstName} ${lastName}` : 'Unknown User'\n\n const isNew = type === 'issue-new'\n const isUpdate = type === 'issue-update'\n const isOpen = next === 'open'\n\n const statusDetails = getStatusDetails(next)\n const nextStatusText = statusDetails.text\n\n const activity =\n isNew && isOpen\n ? 'Issue opened'\n : isNew && !isOpen\n ? `Issue opened with status ${nextStatusText}`\n : isUpdate\n ? `Issue updated to ${nextStatusText}`\n : 'Unknown status timeline change'\n\n const datetime = getTimezoneDatetime({\n format: 'ddd, MMM D h:mm:ssa z',\n showTzAbbr: false,\n timestamp,\n timezone,\n })\n\n return [\n text(activity),\n text(fullName),\n text(datetime, { alignment: 'right' }),\n ]\n })\n\n const timelineTable = threeColumnTable({\n body: [timelineHeaderRow, ...timelineBodyRows],\n })\n\n return timelineTable\n}\n"],"mappings":";;;;AAAA,SAASA,GAAG,EAAEC,MAAM,EAAEC,OAAO,EAAEC,GAAG,QAAQ,QAAQ;AAClD,OAAOC,MAAM,MAAM,iBAAiB;AAEpC,SACEC,oBAAoB,EACpBC,kBAAkB,EACl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AS,EAATA,SAAS;MACTF,QAAQ,EAARA;IACF,CAAC,CAAC;IAEF,OAAO,CACLV,IAAI,CAACmG,QAAQ,CAAC,EACdnG,IAAI,CAAC6F,QAAQ,CAAC,EACd7F,IAAI,CAACoG,QAAQ,EAAE;MAAElB,SAAS,EAAE;IAAQ,CAAC,CAAC,CACvC;EACH,CAAC,CAAC;EAEN,IAAMN,aAAa,GAAG3E,gBAAgB,CAAC;IACrCwC,IAAI,GAAGwC,iBAAiB,EAAAjE,MAAA,CAAA+D,kBAAA,CAAKK,gBAAgB;EAC/C,CAAC,CAAC;EAEF,OAAOR,aAAa;AACtB","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["get","filter","isEmpty","map","moment","buildTemplateContent","generateDefinition","getFormattedAddress","horizontalLine","table","text","threeColumnTable","getIssueDetails","getStatusDetails","getTimezoneAbbr","getTimezoneDatetime","buildIssuePdf","pdfOptions","data","entity","timezone","sequenceId","timestamp","createdAt","title","fileTitle","concat","generateContent","then","content","_objectSpread","type","entry","_entity$gps","gps","_entity$timeline","timeline","entityDetails","assigneeNames","durationText","gpsText","locationText","statusColor","statusText","reverseGeocoded","subTitle","headerTitle","style","headerSubTitle","address","headerAddress","body","submittedAtInTimezone","submittedAt","tz","format","showSimplifiedDuration","push","startedAtInTimezone","startedAt","momentDuration","duration","Math","abs","formDuration","days","floor","asDays","toString","padStart","hours","minutes","seconds","formattedFormDuration","titleTable","layout","statusLabelText","bold","statusValueText","color","metaTable","durationLabelText","durationValueText","assigneeLabelText","assigneeValueText","timelineTitle","timelineHorizontalLine","timelineTable","createTimelineTable","formGroups","_toConsumableArray","timezoneAbbr","timelineHeaderRow","alignment","statusUpdates","timelineBodyRows","colSpan","item","_item$meta","meta","source","next","firstName","lastName","fullName","isNew","isUpdate","isOpen","statusDetails","nextStatusText","activity","datetime","showTzAbbr"],"sources":["../../../src/pdf/issue/index.js"],"sourcesContent":["import { get, filter, isEmpty, map } from 'lodash'\nimport moment from 'moment-timezone'\n\nimport {\n buildTemplateContent,\n generateDefinition,\n getFormattedAddress,\n horizontalLine,\n table,\n text,\n threeColumnTable,\n} from '../helpers'\n\nimport {\n getIssueDetails,\n getStatusDetails,\n getTimezoneAbbr,\n getTimezoneDatetime,\n} from '../../helpers'\n\n/**\n * buildIssuePdf\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} data - pdf data\n * @param {object} data.entity - issue 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 * @param {object} data.zones - zone documents\n * @returns {Promise} returns pdfmake definition object\n */\nexport function buildIssuePdf(pdfOptions, data) {\n const { entity, timezone } = data\n\n const sequenceId = entity.sequenceId\n const timestamp = entity.createdAt\n const title = entity.title || 'Unknown'\n\n const fileTitle = `Issue Report - ${title}`\n\n return generateContent(data).then(content =>\n generateDefinition({\n content,\n fileTitle,\n sequenceId,\n timestamp,\n timezone,\n type: 'Issue',\n ...pdfOptions,\n })\n )\n}\n\nfunction generateContent(data) {\n const { entity, timezone } = data\n const { entry, gps = {}, timeline = [], title } = entity\n\n const entityDetails = getIssueDetails(data)\n\n const {\n assigneeNames,\n durationText,\n gpsText,\n locationText,\n statusColor,\n statusText,\n } = entityDetails\n\n const reverseGeocoded = gps.reverseGeocoded\n\n const subTitle = `${locationText || gpsText}`\n const headerTitle = text(title, { style: 'title' })\n const headerSubTitle = text(subTitle, { style: 'subTitle' })\n const address = !isEmpty(reverseGeocoded)\n ? getFormattedAddress(reverseGeocoded)\n : ''\n const headerAddress = text(address, { style: 'small' })\n\n const body = !isEmpty(reverseGeocoded)\n ? [[headerTitle], [headerSubTitle], [headerAddress]]\n : [[headerTitle], [headerSubTitle]]\n\n const submittedAtInTimezone = entity.submittedAt\n ? moment(entity.submittedAt)\n .tz(timezone)\n .format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const submittedAt = text(`Submitted: ${submittedAtInTimezone}`, {\n style: 'small',\n })\n\n if (entity.showSimplifiedDuration) {\n body.push([submittedAt])\n } else {\n const startedAtInTimezone = entity.startedAt\n ? moment(entity.startedAt)\n .tz(timezone)\n .format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const startedAt = text(`Started: ${startedAtInTimezone}`, {\n style: 'small',\n })\n\n const momentDuration = moment.duration(Math.abs(entity.formDuration))\n const days = Math.floor(momentDuration.asDays())\n .toString()\n .padStart(2, '0')\n const hours = Math.floor(momentDuration.hours())\n .toString()\n .padStart(2, '0')\n const minutes = momentDuration\n .minutes()\n .toString()\n .padStart(2, '0')\n const seconds = momentDuration\n .seconds()\n .toString()\n .padStart(2, '0')\n const formattedFormDuration = entity.formDuration\n ? `${\n entity.formDuration < 0 ? '-' : ''\n }${days}:${hours}:${minutes}:${seconds}`\n : 'Not recorded'\n const formDuration = text(\n `Form Duration (DD:HH:MM:SS): ${formattedFormDuration}`,\n {\n style: 'small',\n }\n )\n\n body.push([startedAt])\n body.push([submittedAt])\n body.push([formDuration])\n }\n\n const titleTable = table({\n body,\n layout: 'noBorders',\n style: 'titleTable',\n })\n\n const statusLabelText = text('Status', { bold: true })\n const statusValueText = text(statusText, { color: statusColor })\n\n const metaTable = table({\n body: [[statusLabelText, statusValueText]],\n layout: 'noBorders',\n style: 'metaTable',\n })\n\n if (statusText === 'CLOSED') {\n const durationLabelText = text('Duration', { bold: true })\n const durationValueText = text(durationText)\n metaTable.table.body.push([durationLabelText, durationValueText])\n }\n\n const assigneeLabelText = text('Assignees', { bold: true })\n const assigneeValueText = text(assigneeNames)\n metaTable.table.body.push([assigneeLabelText, assigneeValueText])\n\n const timelineTitle = text('Timeline', { style: 'timelineTitle' })\n const timelineHorizontalLine = horizontalLine()\n const timelineTable = createTimelineTable(timeline, timezone)\n\n return buildTemplateContent(entry.formGroups, data).then(entry => [\n titleTable,\n metaTable,\n timelineTitle,\n timelineHorizontalLine,\n timelineTable,\n ...entry,\n ])\n}\n\nfunction createTimelineTable(timeline, timezone) {\n const timezoneAbbr = getTimezoneAbbr(timezone)\n\n const timelineHeaderRow = [\n text('Activity', { bold: true }),\n text('User', { bold: true }),\n text(`Date & Timestamp (${timezoneAbbr})`, {\n alignment: 'right',\n bold: true,\n }),\n ]\n\n const statusUpdates = filter(timeline, ['meta.field', 'status'])\n\n const timelineBodyRows = isEmpty(statusUpdates)\n ? [text('No Timeline activity', { colSpan: 3 })]\n : map(statusUpdates, item => {\n const { meta = {}, source, timestamp, type } = item\n\n const next = get(meta, 'next')\n const firstName = get(source, 'meta.firstName')\n const lastName = get(source, 'meta.lastName')\n\n const fullName =\n firstName && lastName ? `${firstName} ${lastName}` : 'Unknown User'\n\n const isNew = type === 'issue-new'\n const isUpdate = type === 'issue-update'\n const isOpen = next === 'open'\n\n const statusDetails = getStatusDetails(next)\n const nextStatusText = statusDetails.text\n\n const activity =\n isNew && isOpen\n ? 'Issue opened'\n : isNew && !isOpen\n ? `Issue opened with status ${nextStatusText}`\n : isUpdate\n ? `Issue updated to ${nextStatusText}`\n : 'Unknown status timeline change'\n\n const datetime = getTimezoneDatetime({\n format: 'ddd, MMM D h:mm:ssa z',\n showTzAbbr: false,\n timestamp,\n timezone,\n })\n\n return [\n text(activity),\n text(fullName),\n text(datetime, { alignment: 'right' }),\n ]\n })\n\n const timelineTable = threeColumnTable({\n body: [timelineHeaderRow, ...timelineBodyRows],\n })\n\n return timelineTable\n}\n"],"mappings":";;;;AAAA,SAASA,GAAG,EA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IE,MAAM,GACX,cAAc,GACdF,KAAK,IAAI,CAACE,MAAM,+BAAAjF,MAAA,CACYmF,cAAc,IAC1CH,QAAQ,uBAAAhF,MAAA,CACYmF,cAAc,IAClC,gCAAgC;IAEtC,IAAME,QAAQ,GAAGhG,mBAAmB,CAAC;MACnCwC,MAAM,EAAE,uBAAuB;MAC/ByD,UAAU,EAAE,KAAK;MACjB1F,SAAS,EAATA,SAAS;MACTF,QAAQ,EAARA;IACF,CAAC,CAAC;IAEF,OAAO,CACLV,IAAI,CAACoG,QAAQ,CAAC,EACdpG,IAAI,CAAC8F,QAAQ,CAAC,EACd9F,IAAI,CAACqG,QAAQ,EAAE;MAAElB,SAAS,EAAE;IAAQ,CAAC,CAAC,CACvC;EACH,CAAC,CAAC;EAEN,IAAMN,aAAa,GAAG5E,gBAAgB,CAAC;IACrCwC,IAAI,GAAGyC,iBAAiB,EAAAlE,MAAA,CAAAgE,kBAAA,CAAKK,gBAAgB;EAC/C,CAAC,CAAC;EAEF,OAAOR,aAAa;AACtB","ignoreList":[]}
@@ -77,26 +77,30 @@ function generateContent(data) {
77
77
  if (!isEmpty(reverseGeocoded)) {
78
78
  body.push([headerAddress]);
79
79
  }
80
- var startedAtInTimezone = entity.startedAt ? moment(entity.startedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
81
- var startedAt = text("Started: ".concat(startedAtInTimezone), {
82
- style: 'small'
83
- });
84
80
  var submittedAtInTimezone = entity.submittedAt ? moment(entity.submittedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
85
81
  var submittedAt = text("Submitted: ".concat(submittedAtInTimezone), {
86
82
  style: 'small'
87
83
  });
88
- var momentDuration = moment.duration(Math.abs(entity.formDuration));
89
- var days = Math.floor(momentDuration.asDays()).toString().padStart(2, '0');
90
- var hours = Math.floor(momentDuration.hours()).toString().padStart(2, '0');
91
- var minutes = momentDuration.minutes().toString().padStart(2, '0');
92
- var seconds = momentDuration.seconds().toString().padStart(2, '0');
93
- var formattedFormDuration = entity.formDuration ? "".concat(entity.formDuration < 0 ? '-' : '').concat(days, ":").concat(hours, ":").concat(minutes, ":").concat(seconds) : 'Not recorded';
94
- var formDuration = text("Form Duration (DD:HH:MM:SS): ".concat(formattedFormDuration), {
95
- style: 'small'
96
- });
97
- body.push([startedAt]);
98
- body.push([submittedAt]);
99
- body.push([formDuration]);
84
+ if (entity.showSimplifiedDuration) {
85
+ body.push([submittedAt]);
86
+ } else {
87
+ var startedAtInTimezone = entity.startedAt ? moment(entity.startedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z') : 'Not recorded';
88
+ var startedAt = text("Started: ".concat(startedAtInTimezone), {
89
+ style: 'small'
90
+ });
91
+ var momentDuration = moment.duration(Math.abs(entity.formDuration));
92
+ var days = Math.floor(momentDuration.asDays()).toString().padStart(2, '0');
93
+ var hours = Math.floor(momentDuration.hours()).toString().padStart(2, '0');
94
+ var minutes = momentDuration.minutes().toString().padStart(2, '0');
95
+ var seconds = momentDuration.seconds().toString().padStart(2, '0');
96
+ var formattedFormDuration = entity.formDuration ? "".concat(entity.formDuration < 0 ? '-' : '').concat(days, ":").concat(hours, ":").concat(minutes, ":").concat(seconds) : 'Not recorded';
97
+ var formDuration = text("Form Duration (DD:HH:MM:SS): ".concat(formattedFormDuration), {
98
+ style: 'small'
99
+ });
100
+ body.push([startedAt]);
101
+ body.push([submittedAt]);
102
+ body.push([formDuration]);
103
+ }
100
104
  var titleTable = table({
101
105
  body: body,
102
106
  layout: 'noBorders',
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["isEmpty","moment","buildTemplateContent","generateDefinition","getFormattedAddress","text","table","getTaskEntryDetails","buildTaskPdf","pdfOptions","data","entity","timezone","sequenceId","timestamp","createdAt","title","fileTitle","concat","generateContent","then","content","_objectSpread","type","entry","_entity$gps","gps","entityDetails","gpsText","locationText","referenceValue","timezoneHourTime","reverseGeocoded","subTitle","headerSubTitle","style","headerTitle","address","headerAddress","body","push","startedAtInTimezone","startedAt","tz","format","submittedAtInTimezone","submittedAt","momentDuration","duration","Math","abs","formDuration","days","floor","asDays","toString","padStart","hours","minutes","seconds","formattedFormDuration","titleTable","layout","formGroups","_toConsumableArray"],"sources":["../../../src/pdf/task/index.js"],"sourcesContent":["import { isEmpty } from 'lodash'\nimport moment from 'moment-timezone'\n\nimport {\n buildTemplateContent,\n generateDefinition,\n getFormattedAddress,\n text,\n table,\n} from '../helpers'\nimport { getTaskEntryDetails } from '../../helpers'\n\n/**\n * buildTaskPdf\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} data - pdf data\n * @param {object} data.entity - task 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 * @param {object} data.zones - zone documents\n * @returns {Promise} returns pdfmake definition object\n */\nexport function buildTaskPdf(pdfOptions, data) {\n const { entity, timezone } = data\n\n const sequenceId = entity.sequenceId\n const timestamp = entity.createdAt\n const title = entity.title || 'Unknown'\n\n const fileTitle = `Task Report - ${title}`\n\n return generateContent(data).then(content =>\n generateDefinition({\n content,\n fileTitle,\n sequenceId,\n timestamp,\n timezone,\n type: 'Task',\n ...pdfOptions,\n })\n )\n}\n\nfunction generateContent(data) {\n const { entity, timezone } = data\n\n const { entry, gps = {}, title } = entity\n\n const entityDetails = getTaskEntryDetails(data)\n\n const {\n gpsText,\n locationText,\n referenceValue,\n timezoneHourTime,\n } = entityDetails\n\n const reverseGeocoded = gps.reverseGeocoded\n\n const subTitle = `${locationText ||\n gpsText} - ${timezoneHourTime} by ${referenceValue}`\n const headerSubTitle = text(subTitle, { style: 'subTitle' })\n const headerTitle = text(title, { style: 'title' })\n const address = !isEmpty(reverseGeocoded)\n ? getFormattedAddress(reverseGeocoded)\n : ''\n const headerAddress = text(address, { style: 'small' })\n\n const body = [[headerTitle], [headerSubTitle]]\n\n if (!isEmpty(reverseGeocoded)) {\n body.push([headerAddress])\n }\n\n const startedAtInTimezone = entity.startedAt\n ? moment(entity.startedAt)\n .tz(timezone)\n .format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const startedAt = text(`Started: ${startedAtInTimezone}`, {\n style: 'small',\n })\n\n const submittedAtInTimezone = entity.submittedAt\n ? moment(entity.submittedAt)\n .tz(timezone)\n .format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const submittedAt = text(`Submitted: ${submittedAtInTimezone}`, {\n style: 'small',\n })\n\n const momentDuration = moment.duration(Math.abs(entity.formDuration))\n const days = Math.floor(momentDuration.asDays())\n .toString()\n .padStart(2, '0')\n const hours = Math.floor(momentDuration.hours())\n .toString()\n .padStart(2, '0')\n const minutes = momentDuration\n .minutes()\n .toString()\n .padStart(2, '0')\n const seconds = momentDuration\n .seconds()\n .toString()\n .padStart(2, '0')\n const formattedFormDuration = entity.formDuration\n ? `${\n entity.formDuration < 0 ? '-' : ''\n }${days}:${hours}:${minutes}:${seconds}`\n : 'Not recorded'\n const formDuration = text(\n `Form Duration (DD:HH:MM:SS): ${formattedFormDuration}`,\n {\n style: 'small',\n }\n )\n\n body.push([startedAt])\n body.push([submittedAt])\n body.push([formDuration])\n\n const titleTable = table({\n body,\n layout: 'noBorders',\n style: 'titleTable',\n })\n\n return buildTemplateContent(entry.formGroups, data).then(entry => [\n titleTable,\n ...entry,\n ])\n}\n"],"mappings":";;;;AAAA,SAASA,OAAO,QAAQ,QAAQ;AA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AAO,IACtC,cAAc;EAClB,IAAMR,YAAY,GAAG9C,IAAI,iCAAAa,MAAA,CACS0C,qBAAqB,GACrD;IACEzB,KAAK,EAAE;EACT,CACF,CAAC;EAEDI,IAAI,CAACC,IAAI,CAAC,CAACE,SAAS,CAAC,CAAC;EACtBH,IAAI,CAACC,IAAI,CAAC,CAACM,WAAW,CAAC,CAAC;EACxBP,IAAI,CAACC,IAAI,CAAC,CAACW,YAAY,CAAC,CAAC;EAEzB,IAAMU,UAAU,GAAGvD,KAAK,CAAC;IACvBiC,IAAI,EAAJA,IAAI;IACJuB,MAAM,EAAE,WAAW;IACnB3B,KAAK,EAAE;EACT,CAAC,CAAC;EAEF,OAAOjC,oBAAoB,CAACsB,KAAK,CAACuC,UAAU,EAAErD,IAAI,CAAC,CAACU,IAAI,CAAC,UAAAI,KAAK;IAAA,QAC5DqC,UAAU,EAAA3C,MAAA,CAAA8C,kBAAA,CACPxC,KAAK;EAAA,CACT,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["isEmpty","moment","buildTemplateContent","generateDefinition","getFormattedAddress","text","table","getTaskEntryDetails","buildTaskPdf","pdfOptions","data","entity","timezone","sequenceId","timestamp","createdAt","title","fileTitle","concat","generateContent","then","content","_objectSpread","type","entry","_entity$gps","gps","entityDetails","gpsText","locationText","referenceValue","timezoneHourTime","reverseGeocoded","subTitle","headerSubTitle","style","headerTitle","address","headerAddress","body","push","submittedAtInTimezone","submittedAt","tz","format","showSimplifiedDuration","startedAtInTimezone","startedAt","momentDuration","duration","Math","abs","formDuration","days","floor","asDays","toString","padStart","hours","minutes","seconds","formattedFormDuration","titleTable","layout","formGroups","_toConsumableArray"],"sources":["../../../src/pdf/task/index.js"],"sourcesContent":["import { isEmpty } from 'lodash'\nimport moment from 'moment-timezone'\n\nimport {\n buildTemplateContent,\n generateDefinition,\n getFormattedAddress,\n text,\n table,\n} from '../helpers'\nimport { getTaskEntryDetails } from '../../helpers'\n\n/**\n * buildTaskPdf\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} data - pdf data\n * @param {object} data.entity - task 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 * @param {object} data.zones - zone documents\n * @returns {Promise} returns pdfmake definition object\n */\nexport function buildTaskPdf(pdfOptions, data) {\n const { entity, timezone } = data\n\n const sequenceId = entity.sequenceId\n const timestamp = entity.createdAt\n const title = entity.title || 'Unknown'\n\n const fileTitle = `Task Report - ${title}`\n\n return generateContent(data).then(content =>\n generateDefinition({\n content,\n fileTitle,\n sequenceId,\n timestamp,\n timezone,\n type: 'Task',\n ...pdfOptions,\n })\n )\n}\n\nfunction generateContent(data) {\n const { entity, timezone } = data\n\n const { entry, gps = {}, title } = entity\n\n const entityDetails = getTaskEntryDetails(data)\n\n const {\n gpsText,\n locationText,\n referenceValue,\n timezoneHourTime,\n } = entityDetails\n\n const reverseGeocoded = gps.reverseGeocoded\n\n const subTitle = `${locationText ||\n gpsText} - ${timezoneHourTime} by ${referenceValue}`\n const headerSubTitle = text(subTitle, { style: 'subTitle' })\n const headerTitle = text(title, { style: 'title' })\n const address = !isEmpty(reverseGeocoded)\n ? getFormattedAddress(reverseGeocoded)\n : ''\n const headerAddress = text(address, { style: 'small' })\n\n const body = [[headerTitle], [headerSubTitle]]\n\n if (!isEmpty(reverseGeocoded)) {\n body.push([headerAddress])\n }\n\n const submittedAtInTimezone = entity.submittedAt\n ? moment(entity.submittedAt)\n .tz(timezone)\n .format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const submittedAt = text(`Submitted: ${submittedAtInTimezone}`, {\n style: 'small',\n })\n\n if (entity.showSimplifiedDuration) {\n body.push([submittedAt])\n } else {\n const startedAtInTimezone = entity.startedAt\n ? moment(entity.startedAt)\n .tz(timezone)\n .format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const startedAt = text(`Started: ${startedAtInTimezone}`, {\n style: 'small',\n })\n\n const momentDuration = moment.duration(Math.abs(entity.formDuration))\n const days = Math.floor(momentDuration.asDays())\n .toString()\n .padStart(2, '0')\n const hours = Math.floor(momentDuration.hours())\n .toString()\n .padStart(2, '0')\n const minutes = momentDuration\n .minutes()\n .toString()\n .padStart(2, '0')\n const seconds = momentDuration\n .seconds()\n .toString()\n .padStart(2, '0')\n const formattedFormDuration = entity.formDuration\n ? `${\n entity.formDuration < 0 ? '-' : ''\n }${days}:${hours}:${minutes}:${seconds}`\n : 'Not recorded'\n const formDuration = text(\n `Form Duration (DD:HH:MM:SS): ${formattedFormDuration}`,\n {\n style: 'small',\n }\n )\n\n body.push([startedAt])\n body.push([submittedAt])\n body.push([formDuration])\n }\n\n const titleTable = table({\n body,\n layout: 'noBorders',\n style: 'titleTable',\n })\n\n return buildTemplateContent(entry.formGroups, data).then(entry => [\n titleTable,\n ...entry,\n ])\n}\n"],"mappings":";;;;AAAA,SAASA,OAAO,QAAQ,QAAQ;AAChC,OAAOC,MAAM,MAAM,iBAAiB;AAEpC,SACEC,oBAAoB,EACpBC,kBAAkB,EAClBC,mBAAmB,EACnBC,IAAI,EACJC,KAAK,QACA,YAAY;AACnB,SAASC,mBAAmB,QAAQ,eAAe;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,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AAC,CAAC;IACtBR,IAAI,CAACC,IAAI,CAAC,CAACE,WAAW,CAAC,CAAC;IACxBH,IAAI,CAACC,IAAI,CAAC,CAACY,YAAY,CAAC,CAAC;EAC3B;EAEA,IAAMU,UAAU,GAAGxD,KAAK,CAAC;IACvBiC,IAAI,EAAJA,IAAI;IACJwB,MAAM,EAAE,WAAW;IACnB5B,KAAK,EAAE;EACT,CAAC,CAAC;EAEF,OAAOjC,oBAAoB,CAACsB,KAAK,CAACwC,UAAU,EAAEtD,IAAI,CAAC,CAACU,IAAI,CAAC,UAAAI,KAAK;IAAA,QAC5DsC,UAAU,EAAA5C,MAAA,CAAA+C,kBAAA,CACPzC,KAAK;EAAA,CACT,CAAC;AACJ","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lighthouse/common",
3
- "version": "6.0.0-canary-2",
3
+ "version": "6.0.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "lib/index.js",