@lighthouse/common 4.34.0-canary-4 → 4.34.0-canary-6
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/dist/pdf/task/index.js +22 -17
- package/lib/pdf/task/index.js +19 -17
- package/lib/pdf/task/index.js.map +1 -1
- package/package.json +1 -1
package/dist/pdf/task/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
@@ -11,6 +13,8 @@ var _helpers = require("../helpers");
|
|
|
11
13
|
|
|
12
14
|
var _helpers2 = require("../../helpers");
|
|
13
15
|
|
|
16
|
+
var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
|
|
17
|
+
|
|
14
18
|
/**
|
|
15
19
|
* buildTaskPdf
|
|
16
20
|
*
|
|
@@ -57,7 +61,8 @@ function buildTaskPdf(pdfOptions, data) {
|
|
|
57
61
|
|
|
58
62
|
function generateContent(data) {
|
|
59
63
|
const {
|
|
60
|
-
entity
|
|
64
|
+
entity,
|
|
65
|
+
timezone
|
|
61
66
|
} = data;
|
|
62
67
|
const {
|
|
63
68
|
entry,
|
|
@@ -89,30 +94,30 @@ function generateContent(data) {
|
|
|
89
94
|
body.push([headerAddress]);
|
|
90
95
|
}
|
|
91
96
|
|
|
92
|
-
|
|
93
|
-
console.
|
|
94
|
-
|
|
95
|
-
});
|
|
97
|
+
const entityFields = Object.keys(entity);
|
|
98
|
+
console.log('entityFields', entityFields);
|
|
99
|
+
const formDurationFieldsPresent = ['formDuration', 'startedAt', 'submittedAt'].some(field => entityFields.includes(field));
|
|
96
100
|
|
|
97
|
-
if (
|
|
98
|
-
const
|
|
101
|
+
if (formDurationFieldsPresent) {
|
|
102
|
+
const startedAtInTimezone = (0, _momentTimezone.default)(startedAt).tz(timezone).format('yyyy-MM-DD HH:mm:ss z');
|
|
103
|
+
const startedAt = (0, _helpers.text)(`Started At: ${entityDetails.startedAt ? startedAtInTimezone : 'Not recorded'}`, {
|
|
99
104
|
style: 'small'
|
|
100
105
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (entityDetails.submittedAt) {
|
|
105
|
-
const submittedAt = (0, _helpers.text)(`Submitted: ${entityDetails.submittedAt}`, {
|
|
106
|
+
const submittedAtInTimezone = (0, _momentTimezone.default)(submittedAt).tz(timezone).format('yyyy-MM-DD HH:mm:ss z');
|
|
107
|
+
const submittedAt = (0, _helpers.text)(`Submitted At: ${entityDetails.submittedAt ? submittedAtInTimezone : 'Not recorded'}`, {
|
|
106
108
|
style: 'small'
|
|
107
109
|
});
|
|
108
|
-
body.push([submittedAt]);
|
|
109
|
-
}
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
const momentDuration = _momentTimezone.default.duration(Math.abs(formDuration));
|
|
112
|
+
|
|
113
|
+
const hours = Math.floor(momentDuration.asHours()).toString().padStart(2, '0');
|
|
114
|
+
const minutes = momentDuration.minutes().toString().padStart(2, '0');
|
|
115
|
+
const seconds = momentDuration.seconds().toString().padStart(2, '0');
|
|
116
|
+
const formattedFormDuration = `${formDuration < 0 ? '-' : ''}${hours}:${minutes}:${seconds}`;
|
|
117
|
+
const formDuration = (0, _helpers.text)(`Form Duration (HH:MM:SS): ${entity.formDuration ? formattedFormDuration : 'Not recorded'}`, {
|
|
113
118
|
style: 'small'
|
|
114
119
|
});
|
|
115
|
-
body.push([formDuration]);
|
|
120
|
+
body.push([startedAt, submittedAt, formDuration]);
|
|
116
121
|
}
|
|
117
122
|
|
|
118
123
|
const titleTable = (0, _helpers.table)({
|
package/lib/pdf/task/index.js
CHANGED
|
@@ -8,6 +8,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
8
8
|
import { isEmpty } from 'lodash';
|
|
9
9
|
import { buildTemplateContent, generateDefinition, getFormattedAddress, text, table } from '../helpers';
|
|
10
10
|
import { getTaskEntryDetails } from '../../helpers';
|
|
11
|
+
import moment from 'moment-timezone';
|
|
11
12
|
/**
|
|
12
13
|
* buildTaskPdf
|
|
13
14
|
*
|
|
@@ -53,7 +54,8 @@ export function buildTaskPdf(pdfOptions, data) {
|
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
function generateContent(data) {
|
|
56
|
-
var entity = data.entity
|
|
57
|
+
var entity = data.entity,
|
|
58
|
+
timezone = data.timezone;
|
|
57
59
|
var entry = entity.entry,
|
|
58
60
|
_entity$gps = entity.gps,
|
|
59
61
|
gps = _entity$gps === void 0 ? {} : _entity$gps,
|
|
@@ -81,30 +83,30 @@ function generateContent(data) {
|
|
|
81
83
|
body.push([headerAddress]);
|
|
82
84
|
}
|
|
83
85
|
|
|
84
|
-
|
|
85
|
-
console.
|
|
86
|
-
|
|
86
|
+
var entityFields = Object.keys(entity);
|
|
87
|
+
console.log('entityFields', entityFields);
|
|
88
|
+
var formDurationFieldsPresent = ['formDuration', 'startedAt', 'submittedAt'].some(function (field) {
|
|
89
|
+
return entityFields.includes(field);
|
|
87
90
|
});
|
|
88
91
|
|
|
89
|
-
if (
|
|
90
|
-
var
|
|
92
|
+
if (formDurationFieldsPresent) {
|
|
93
|
+
var startedAtInTimezone = moment(startedAt).tz(timezone).format('yyyy-MM-DD HH:mm:ss z');
|
|
94
|
+
var startedAt = text("Started At: ".concat(entityDetails.startedAt ? startedAtInTimezone : 'Not recorded'), {
|
|
91
95
|
style: 'small'
|
|
92
96
|
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (entityDetails.submittedAt) {
|
|
97
|
-
var submittedAt = text("Submitted: ".concat(entityDetails.submittedAt), {
|
|
97
|
+
var submittedAtInTimezone = moment(submittedAt).tz(timezone).format('yyyy-MM-DD HH:mm:ss z');
|
|
98
|
+
var submittedAt = text("Submitted At: ".concat(entityDetails.submittedAt ? submittedAtInTimezone : 'Not recorded'), {
|
|
98
99
|
style: 'small'
|
|
99
100
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
var
|
|
101
|
+
var momentDuration = moment.duration(Math.abs(formDuration));
|
|
102
|
+
var hours = Math.floor(momentDuration.asHours()).toString().padStart(2, '0');
|
|
103
|
+
var minutes = momentDuration.minutes().toString().padStart(2, '0');
|
|
104
|
+
var seconds = momentDuration.seconds().toString().padStart(2, '0');
|
|
105
|
+
var formattedFormDuration = "".concat(formDuration < 0 ? '-' : '').concat(hours, ":").concat(minutes, ":").concat(seconds);
|
|
106
|
+
var formDuration = text("Form Duration (HH:MM:SS): ".concat(entity.formDuration ? formattedFormDuration : 'Not recorded'), {
|
|
105
107
|
style: 'small'
|
|
106
108
|
});
|
|
107
|
-
body.push([formDuration]);
|
|
109
|
+
body.push([startedAt, submittedAt, formDuration]);
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
var titleTable = table({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/pdf/task/index.js"],"names":["isEmpty","buildTemplateContent","generateDefinition","getFormattedAddress","text","table","getTaskEntryDetails","buildTaskPdf","pdfOptions","data","entity","timezone","sequenceId","timestamp","createdAt","title","fileTitle","generateContent","then","content","type","entry","gps","entityDetails","gpsText","locationText","referenceValue","timezoneHourTime","reverseGeocoded","subTitle","headerSubTitle","style","headerTitle","address","headerAddress","body","push","console","log","
|
|
1
|
+
{"version":3,"sources":["../../../src/pdf/task/index.js"],"names":["isEmpty","buildTemplateContent","generateDefinition","getFormattedAddress","text","table","getTaskEntryDetails","moment","buildTaskPdf","pdfOptions","data","entity","timezone","sequenceId","timestamp","createdAt","title","fileTitle","generateContent","then","content","type","entry","gps","entityDetails","gpsText","locationText","referenceValue","timezoneHourTime","reverseGeocoded","subTitle","headerSubTitle","style","headerTitle","address","headerAddress","body","push","entityFields","Object","keys","console","log","formDurationFieldsPresent","some","field","includes","startedAtInTimezone","startedAt","tz","format","submittedAtInTimezone","submittedAt","momentDuration","duration","Math","abs","formDuration","hours","floor","asHours","toString","padStart","minutes","seconds","formattedFormDuration","titleTable","layout","formGroups"],"mappings":";;;;;;;AAAA,SAASA,OAAT,QAAwB,QAAxB;AACA,SACEC,oBADF,EAEEC,kBAFF,EAGEC,mBAHF,EAIEC,IAJF,EAKEC,KALF,QAMO,YANP;AAQA,SAASC,mBAAT,QAAoC,eAApC;AACA,OAAOC,MAAP,MAAmB,iBAAnB;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,OAAO,SAASC,YAAT,CAAsBC,UAAtB,EAAkCC,IAAlC,EAAwC;AAAA,MACrCC,MADqC,GAChBD,IADgB,CACrCC,MADqC;AAAA,MAC7BC,QAD6B,GAChBF,IADgB,CAC7BE,QAD6B;AAG7C,MAAMC,UAAU,GAAGF,MAAM,CAACE,UAA1B;AACA,MAAMC,SAAS,GAAGH,MAAM,CAACI,SAAzB;AACA,MAAMC,KAAK,GAAGL,MAAM,CAACK,KAAP,IAAgB,SAA9B;AAEA,MAAMC,SAAS,2BAAoBD,KAApB,CAAf;AAEA,SAAOE,eAAe,CAACR,IAAD,CAAf,CAAsBS,IAAtB,CAA2B,UAAAC,OAAO;AAAA,WACvClB,kBAAkB;AAChBkB,MAAAA,OAAO,EAAPA,OADgB;AAEhBH,MAAAA,SAAS,EAATA,SAFgB;AAGhBJ,MAAAA,UAAU,EAAVA,UAHgB;AAIhBC,MAAAA,SAAS,EAATA,SAJgB;AAKhBF,MAAAA,QAAQ,EAARA,QALgB;AAMhBS,MAAAA,IAAI,EAAE;AANU,OAObZ,UAPa,EADqB;AAAA,GAAlC,CAAP;AAWD;;AAED,SAASS,eAAT,CAAyBR,IAAzB,EAA+B;AAAA,MACrBC,MADqB,GACAD,IADA,CACrBC,MADqB;AAAA,MACbC,QADa,GACAF,IADA,CACbE,QADa;AAAA,MAGrBU,KAHqB,GAGMX,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AAIA,QAAMG,qBAAqB,aACzBR,YAAY,GAAG,CAAf,GAAmB,GAAnB,GAAyB,EADA,SAExBC,KAFwB,cAEfK,OAFe,cAEJC,OAFI,CAA3B;AAGA,QAAMP,YAAY,GAAGrD,IAAI,qCAErBO,MAAM,CAAC8C,YAAP,GAAsBQ,qBAAtB,GAA8C,cAFzB,GAIvB;AACEjC,MAAAA,KAAK,EAAE;AADT,KAJuB,CAAzB;AASAI,IAAAA,IAAI,CAACC,IAAL,CAAU,CAACW,SAAD,EAAYI,WAAZ,EAAyBK,YAAzB,CAAV;AACD;;AAED,MAAMS,UAAU,GAAG7D,KAAK,CAAC;AACvB+B,IAAAA,IAAI,EAAJA,IADuB;AAEvB+B,IAAAA,MAAM,EAAE,WAFe;AAGvBnC,IAAAA,KAAK,EAAE;AAHgB,GAAD,CAAxB;AAMA,SAAO/B,oBAAoB,CAACqB,KAAK,CAAC8C,UAAP,EAAmB1D,IAAnB,CAApB,CAA6CS,IAA7C,CAAkD,UAAAG,KAAK;AAAA,YAC5D4C,UAD4D,4BAEzD5C,KAFyD;AAAA,GAAvD,CAAP;AAID","sourcesContent":["import { isEmpty } from 'lodash'\nimport {\n buildTemplateContent,\n generateDefinition,\n getFormattedAddress,\n text,\n table,\n} from '../helpers'\n\nimport { getTaskEntryDetails } from '../../helpers'\nimport moment from 'moment-timezone'\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 entityFields = Object.keys(entity)\n console.log('entityFields', entityFields)\n\n const formDurationFieldsPresent = [\n 'formDuration',\n 'startedAt',\n 'submittedAt',\n ].some(field => entityFields.includes(field))\n\n if (formDurationFieldsPresent) {\n const startedAtInTimezone = moment(startedAt)\n .tz(timezone)\n .format('yyyy-MM-DD HH:mm:ss z')\n const startedAt = text(\n `Started At: ${\n entityDetails.startedAt ? startedAtInTimezone : 'Not recorded'\n }`,\n {\n style: 'small',\n }\n )\n\n const submittedAtInTimezone = moment(submittedAt)\n .tz(timezone)\n .format('yyyy-MM-DD HH:mm:ss z')\n const submittedAt = text(\n `Submitted At: ${\n entityDetails.submittedAt ? submittedAtInTimezone : 'Not recorded'\n }`,\n {\n style: 'small',\n }\n )\n\n const momentDuration = moment.duration(Math.abs(formDuration))\n const hours = Math.floor(momentDuration.asHours())\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 = `${\n formDuration < 0 ? '-' : ''\n }${hours}:${minutes}:${seconds}`\n const formDuration = text(\n `Form Duration (HH:MM:SS): ${\n entity.formDuration ? formattedFormDuration : 'Not recorded'\n }`,\n {\n style: 'small',\n }\n )\n\n body.push([startedAt, submittedAt, 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"],"file":"index.js"}
|