@lighthouse/common 4.30.1-canary.0 → 4.30.1-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pdf/audit/index.js +6 -0
- package/dist/pdf/helpers/build-audit-follow-ups/index.js +11 -0
- package/lib/pdf/audit/index.js +6 -0
- package/lib/pdf/audit/index.js.map +1 -1
- package/lib/pdf/helpers/build-audit-content/index.js.map +1 -1
- package/lib/pdf/helpers/build-audit-follow-ups/index.js +11 -0
- package/lib/pdf/helpers/build-audit-follow-ups/index.js.map +1 -1
- package/package.json +1 -1
package/dist/pdf/audit/index.js
CHANGED
|
@@ -44,6 +44,9 @@ function buildAuditPdf(pdfOptions, data) {
|
|
|
44
44
|
entity,
|
|
45
45
|
timezone
|
|
46
46
|
} = data;
|
|
47
|
+
console.log('buildAuditPdf', {
|
|
48
|
+
version: '4.30.1-canary.2'
|
|
49
|
+
});
|
|
47
50
|
const sequenceId = entity.sequenceId;
|
|
48
51
|
const timestamp = entity.createdAt;
|
|
49
52
|
const title = entity.title || 'Unknown';
|
|
@@ -76,6 +79,9 @@ function generateContent(data) {
|
|
|
76
79
|
} = entity;
|
|
77
80
|
const entityDetails = (0, _helpers2.getAuditEntryDetails)(data);
|
|
78
81
|
const hasFollowUps = !!entity.followUps;
|
|
82
|
+
console.log('buildAuditPdf', {
|
|
83
|
+
hasFollowUps
|
|
84
|
+
});
|
|
79
85
|
const {
|
|
80
86
|
gpsText,
|
|
81
87
|
groupedData,
|
|
@@ -19,9 +19,17 @@ var _images = require("../../../images");
|
|
|
19
19
|
// *. Setup the page breaks, either on the last item here or the first in the next section
|
|
20
20
|
// - I want to do this in a way that avoids orphans, or at least only add a page break if the result looks balanced
|
|
21
21
|
// - If we can work out the page position of the last follow up item then we can determine whether to use a page break or not
|
|
22
|
+
// *. If you're not using the flag then you should make sure that all of the variables necessary have been passed in
|
|
23
|
+
// - If the required data isn't present then you should probably just not process follow up issues for the document
|
|
24
|
+
// - If you establish this at the start you can build it into the `hasFollowUps` flag
|
|
25
|
+
// *. Is there some way that you can setup an override for the pdfmake version used by storybook?
|
|
22
26
|
const LIGHTHOUSE_BASE_URL = 'https://app.lighthouse.io';
|
|
23
27
|
|
|
24
28
|
function buildAuditFollowUps(rawFollowUpIssues = [], options = {}) {
|
|
29
|
+
console.log('buildAuditFollowUps', {
|
|
30
|
+
rawFollowUpIssues,
|
|
31
|
+
options
|
|
32
|
+
});
|
|
25
33
|
const sectionTitle = [{
|
|
26
34
|
text: 'Follow-up Issues',
|
|
27
35
|
style: {
|
|
@@ -135,5 +143,8 @@ function buildAuditFollowUps(rawFollowUpIssues = [], options = {}) {
|
|
|
135
143
|
widths: [6, '*', 55, 55, 6, '*', '18%'],
|
|
136
144
|
margin: [0, 0, 0, 30]
|
|
137
145
|
});
|
|
146
|
+
console.log('buildAuditFollowUps', {
|
|
147
|
+
followUpsTable
|
|
148
|
+
});
|
|
138
149
|
return [sectionTitle, sectionDivider, followUpsTable];
|
|
139
150
|
}
|
package/lib/pdf/audit/index.js
CHANGED
|
@@ -37,6 +37,9 @@ import { getAuditEntryDetails } from '../../helpers';
|
|
|
37
37
|
export function buildAuditPdf(pdfOptions, data) {
|
|
38
38
|
var entity = data.entity,
|
|
39
39
|
timezone = data.timezone;
|
|
40
|
+
console.log('buildAuditPdf', {
|
|
41
|
+
version: '4.30.1-canary.2'
|
|
42
|
+
});
|
|
40
43
|
var sequenceId = entity.sequenceId;
|
|
41
44
|
var timestamp = entity.createdAt;
|
|
42
45
|
var title = entity.title || 'Unknown';
|
|
@@ -72,6 +75,9 @@ function generateContent(data) {
|
|
|
72
75
|
title = _entity$title === void 0 ? 'Unknown' : _entity$title;
|
|
73
76
|
var entityDetails = getAuditEntryDetails(data);
|
|
74
77
|
var hasFollowUps = !!entity.followUps;
|
|
78
|
+
console.log('buildAuditPdf', {
|
|
79
|
+
hasFollowUps: hasFollowUps
|
|
80
|
+
});
|
|
75
81
|
var gpsText = entityDetails.gpsText,
|
|
76
82
|
groupedData = entityDetails.groupedData,
|
|
77
83
|
locationText = entityDetails.locationText,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/pdf/audit/index.js"],"names":["Promise","isEmpty","round","buildAuditContent","buildAuditFollowUps","buildTemplateContent","generateDefinition","getFormattedAddress","horizontalLine","text","twoColumnTable","getAuditEntryDetails","buildAuditPdf","pdfOptions","data","entity","timezone","sequenceId","timestamp","createdAt","title","fileTitle","generateContent","then","content","type","catch","err","Error","message","followUps","footerFields","gps","headerFields","score","entityDetails","hasFollowUps","gpsText","groupedData","locationText","referenceValue","timezoneHourTime","scoreText","target","targetServiceLevel","renderTargetFields","headerTitle","style","headerScore","alignment","firstRow","subTitle","headerSubTitle","colSpan","secondRow","reverseGeocoded","address","renderHeaderAddress","dummyColumn","headerAddress","renderThirdRow","thirdRow","serviceLevelBelow","serviceLevelText","scoreServiceLevelSubTitle","truncatedTargetPercent","scoreTargetText","scoreTargetSubTitle","scoreBreakdown","actual","max","scorePercentage","scoreTitle","body","titleTable","layout","widths","margin","totalScoreTable","hLineTop","hLineBottom","followUpItems","promises","entry","items","footerTemplate","formGroups","headerTemplate","auditItemsTitle","font","lineHeight","props"],"mappings":";;;;;;;AAAA,OAAOA,OAAP,MAAoB,UAApB;AACA,SAASC,OAAT,EAAkBC,KAAlB,QAA+B,QAA/B;AAEA,SACEC,iBADF,EAEEC,mBAFF,EAGEC,oBAHF,EAIEC,kBAJF,EAKEC,mBALF,EAMEC,cANF,EAOEC,IAPF,EAQEC,cARF,QASO,YATP;AAWA,SAASC,oBAAT,QAAqC,eAArC;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,OAAO,SAASC,aAAT,CAAuBC,UAAvB,EAAmCC,IAAnC,EAAyC;AAAA,MACtCC,MADsC,GACjBD,IADiB,CACtCC,MADsC;AAAA,MAC9BC,QAD8B,GACjBF,IADiB,CAC9BE,QAD8B;AAG9C,MAAMC,UAAU,GAAG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,QAAUA,cAAV;AAAA,QAA0BE,cAA1B,QAA0BA,cAA1B;AAAA,YACJb,UADI,4BAEDa,cAFC,IAGJN,aAHI,GAIDO,eAJC,qBAKDL,KALC,IAMJJ,QANI,EAOJD,eAPI,EAQJE,WARI,sBASDK,cATC;AAAA,GADD,EAYJ3D,KAZI,CAYE,UAAAC,GAAG,EAAI;AACZ,UAAM,IAAIC,KAAJ,iCAAmCD,GAAG,CAACE,OAAvC,EAAN;AACD,GAdI,CAAP;AAeD","sourcesContent":["import Promise from 'bluebird'\nimport { isEmpty, round } from 'lodash'\n\nimport {\n buildAuditContent,\n buildAuditFollowUps,\n buildTemplateContent,\n generateDefinition,\n getFormattedAddress,\n horizontalLine,\n text,\n twoColumnTable,\n} from '../helpers'\n\nimport { getAuditEntryDetails } from '../../helpers'\n\n/**\n * buildAuditPdf\n *\n * @param {object} pdfOptions - the pdf options\n * @param {string} pdfOptions.fileTitle - pdf file title\n * @param {function} pdfOptions.footer - function executed to generate footer\n * @param {function} pdfOptions.header - function executed to generate header\n * @param {string} pdfOptions.logoUrl - pdf logo url\n * @param {array} pdfOptions.pageMargins - pdf page margins\n * @param {string} pdfOptions.pageOrientation - pdf page orientation\n * @param {string} pdfOptions.pageSize - pdf page size\n * @param {object} pdfOptions.styles - pdf styles\n * @param {object} pdfOptions.title - pdf title\n * @param {object} pdfOptions.flags - flags to conditionally render parts of the pdf\n * @param {object} data - pdf data\n * @param {object} data.entity - audit document\n * @param {object} data.locations - locations documents\n * @param {object} data.settings - settings properties\n * @param {string} data.settings.awsS3BaseUrl - aws S3 base url\n * @param {string} data.settings.cloudinaryBaseUrl - cloudinary base url\n * @param {string} data.timezone - timezone string\n * @param {object} data.users - application user documents\n * @returns {Promise} returns pdfmake definition object\n */\nexport function buildAuditPdf(pdfOptions, data) {\n const { entity, timezone } = data\n\n const sequenceId = entity.sequenceId\n const timestamp = entity.createdAt\n const title = entity.title || 'Unknown'\n const fileTitle = `Audit Report - ${title}`\n\n return generateContent(data)\n .then(content =>\n generateDefinition({\n content,\n fileTitle,\n sequenceId,\n timestamp,\n timezone,\n type: 'Audit',\n ...pdfOptions,\n })\n )\n .catch(err => {\n throw new Error(`BuildAuditPdfError: ${err.message}`)\n })\n}\n\nfunction generateContent(data) {\n const { entity } = data\n\n const {\n followUps = [],\n footerFields = {},\n gps = {},\n headerFields = {},\n score = {},\n timezone,\n title = 'Unknown',\n } = entity\n\n const entityDetails = getAuditEntryDetails(data)\n const hasFollowUps = !!entity.followUps\n\n const {\n gpsText,\n groupedData,\n locationText,\n referenceValue,\n timezoneHourTime,\n scoreText,\n target,\n targetServiceLevel,\n } = entityDetails\n\n const renderTargetFields = !!targetServiceLevel\n const headerTitle = text(title, { style: 'title' })\n const headerScore = text(scoreText, { alignment: 'right', style: 'title' })\n const firstRow = [headerTitle, headerScore]\n const subTitle = `${locationText ||\n gpsText} - ${timezoneHourTime} by ${referenceValue}`\n\n let headerSubTitle = text(subTitle, { colSpan: 2, style: 'subTitle' })\n let secondRow = [headerSubTitle]\n\n const reverseGeocoded = gps.reverseGeocoded\n const address = !isEmpty(reverseGeocoded)\n ? getFormattedAddress(reverseGeocoded)\n : ''\n const renderHeaderAddress = !isEmpty(reverseGeocoded)\n const dummyColumn = text(' ', { style: 'small' })\n\n let headerAddress = text(address, { colSpan: 2, style: 'small' })\n const renderThirdRow = renderHeaderAddress || renderTargetFields\n let thirdRow = renderHeaderAddress ? [headerAddress] : []\n\n if (renderTargetFields) {\n headerSubTitle = text(subTitle, { style: 'subTitle' })\n\n const serviceLevelBelow = targetServiceLevel === 'below'\n const serviceLevelText =\n targetServiceLevel === 'above'\n ? 'Above Target'\n : targetServiceLevel === 'on'\n ? 'On Target'\n : targetServiceLevel === 'below'\n ? 'Below Target'\n : ''\n\n const scoreServiceLevelSubTitle = text(serviceLevelText, {\n alignment: 'right',\n style: serviceLevelBelow ? 'serviceLevelBelow' : 'serviceLevelAboveOrOn',\n })\n\n secondRow = [headerSubTitle, scoreServiceLevelSubTitle]\n headerAddress = text(address, { style: 'small' })\n\n const truncatedTargetPercent = round(target, 2)\n const scoreTargetText = `(Target - ${truncatedTargetPercent}%)`\n const scoreTargetSubTitle = text(scoreTargetText, {\n alignment: 'right',\n style: 'subTitle',\n })\n\n thirdRow = renderHeaderAddress\n ? [headerAddress, scoreTargetSubTitle]\n : [dummyColumn, scoreTargetSubTitle]\n }\n\n const scoreBreakdown = text(\n `${round(score.actual, 2)} / ${round(score.max, 2)}`,\n {\n alignment: 'right',\n style: 'totalScore',\n }\n )\n const scorePercentage = text(scoreText, {\n alignment: 'right',\n colSpan: 2,\n style: 'totalAuditScore',\n })\n const scoreTitle = text('Total Score', { style: 'totalScore' })\n\n const body = renderThirdRow\n ? [firstRow, secondRow, thirdRow]\n : [firstRow, secondRow]\n\n const titleTable = twoColumnTable({\n body,\n layout: 'noBorders',\n style: 'titleTable',\n widths: ['*', 100],\n margin: [0, 0, 0, 30],\n })\n\n const totalScoreTable = twoColumnTable({\n body: [[scoreTitle, scoreBreakdown], [scorePercentage]],\n layout: 'noBorders',\n widths: ['*', 100],\n })\n\n const hLineTop = horizontalLine({ margin: [0, 10, 0, 0] })\n const hLineBottom = horizontalLine()\n\n const followUpItems = hasFollowUps\n ? buildAuditFollowUps(followUps, { timezone })\n : []\n\n const promises = {\n entry: buildAuditContent(groupedData.items, { hasFollowUps }),\n footerTemplate: buildTemplateContent(footerFields.formGroups, data),\n headerTemplate: buildTemplateContent(headerFields.formGroups, data),\n }\n\n const auditItemsTitle = hasFollowUps\n ? [\n {\n text: 'Audit Items',\n style: {\n font: 'Gotham',\n lineHeight: 1.1,\n },\n },\n hLineTop,\n ]\n : []\n\n return Promise.props(promises)\n .then(({ entry, footerTemplate, headerTemplate }) => [\n titleTable,\n ...headerTemplate,\n followUpItems,\n ...auditItemsTitle,\n ...entry,\n hLineTop,\n totalScoreTable,\n hLineBottom,\n ...footerTemplate,\n ])\n .catch(err => {\n throw new Error(`GenerateContentError: ${err.message}`)\n })\n}\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/pdf/audit/index.js"],"names":["Promise","isEmpty","round","buildAuditContent","buildAuditFollowUps","buildTemplateContent","generateDefinition","getFormattedAddress","horizontalLine","text","twoColumnTable","getAuditEntryDetails","buildAuditPdf","pdfOptions","data","entity","timezone","console","log","version","sequenceId","timestamp","createdAt","title","fileTitle","generateContent","then","content","type","catch","err","Error","message","followUps","footerFields","gps","headerFields","score","entityDetails","hasFollowUps","gpsText","groupedData","locationText","referenceValue","timezoneHourTime","scoreText","target","targetServiceLevel","renderTargetFields","headerTitle","style","headerScore","alignment","firstRow","subTitle","headerSubTitle","colSpan","secondRow","reverseGeocoded","address","renderHeaderAddress","dummyColumn","headerAddress","renderThirdRow","thirdRow","serviceLevelBelow","serviceLevelText","scoreServiceLevelSubTitle","truncatedTargetPercent","scoreTargetText","scoreTargetSubTitle","scoreBreakdown","actual","max","scorePercentage","scoreTitle","body","titleTable","layout","widths","margin","totalScoreTable","hLineTop","hLineBottom","followUpItems","promises","entry","items","footerTemplate","formGroups","headerTemplate","auditItemsTitle","font","lineHeight","props"],"mappings":";;;;;;;AAAA,OAAOA,OAAP,MAAoB,UAApB;AACA,SAASC,OAAT,EAAkBC,KAAlB,QAA+B,QAA/B;AAEA,SACEC,iBADF,EAEEC,mBAFF,EAGEC,oBAHF,EAIEC,kBAJF,EAKEC,mBALF,EAMEC,cANF,EAOEC,IAPF,EAQEC,cARF,QASO,YATP;AAWA,SAASC,oBAAT,QAAqC,eAArC;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,OAAO,SAASC,aAAT,CAAuBC,UAAvB,EAAmCC,IAAnC,EAAyC;AAAA,MACtCC,MADsC,GACjBD,IADiB,CACtCC,MADsC;AAAA,MAC9BC,QAD8B,GACjBF,IADiB,CAC9BE,QAD8B;AAG9CC,EAAAA,OAAO,CAACC,GAAR,CAAY,eAAZ,EAA6B;AAC3BC,IAAAA,OAAO,EAAE;AADkB,GAA7B;AAI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ARF,CADgC,GAWhC,EAXJ;AAaA,SAAOlF,OAAO,CAAC8F,KAAR,CAAcT,QAAd,EACJ3D,IADI,CACC;AAAA,QAAG4D,KAAH,QAAGA,KAAH;AAAA,QAAUE,cAAV,QAAUA,cAAV;AAAA,QAA0BE,cAA1B,QAA0BA,cAA1B;AAAA,YACJb,UADI,4BAEDa,cAFC,IAGJN,aAHI,GAIDO,eAJC,qBAKDL,KALC,IAMJJ,QANI,EAOJD,eAPI,EAQJE,WARI,sBASDK,cATC;AAAA,GADD,EAYJ3D,KAZI,CAYE,UAAAC,GAAG,EAAI;AACZ,UAAM,IAAIC,KAAJ,iCAAmCD,GAAG,CAACE,OAAvC,EAAN;AACD,GAdI,CAAP;AAeD","sourcesContent":["import Promise from 'bluebird'\nimport { isEmpty, round } from 'lodash'\n\nimport {\n buildAuditContent,\n buildAuditFollowUps,\n buildTemplateContent,\n generateDefinition,\n getFormattedAddress,\n horizontalLine,\n text,\n twoColumnTable,\n} from '../helpers'\n\nimport { getAuditEntryDetails } from '../../helpers'\n\n/**\n * buildAuditPdf\n *\n * @param {object} pdfOptions - the pdf options\n * @param {string} pdfOptions.fileTitle - pdf file title\n * @param {function} pdfOptions.footer - function executed to generate footer\n * @param {function} pdfOptions.header - function executed to generate header\n * @param {string} pdfOptions.logoUrl - pdf logo url\n * @param {array} pdfOptions.pageMargins - pdf page margins\n * @param {string} pdfOptions.pageOrientation - pdf page orientation\n * @param {string} pdfOptions.pageSize - pdf page size\n * @param {object} pdfOptions.styles - pdf styles\n * @param {object} pdfOptions.title - pdf title\n * @param {object} pdfOptions.flags - flags to conditionally render parts of the pdf\n * @param {object} data - pdf data\n * @param {object} data.entity - audit document\n * @param {object} data.locations - locations documents\n * @param {object} data.settings - settings properties\n * @param {string} data.settings.awsS3BaseUrl - aws S3 base url\n * @param {string} data.settings.cloudinaryBaseUrl - cloudinary base url\n * @param {string} data.timezone - timezone string\n * @param {object} data.users - application user documents\n * @returns {Promise} returns pdfmake definition object\n */\nexport function buildAuditPdf(pdfOptions, data) {\n const { entity, timezone } = data\n\n console.log('buildAuditPdf', {\n version: '4.30.1-canary.2',\n })\n \n const sequenceId = entity.sequenceId\n const timestamp = entity.createdAt\n const title = entity.title || 'Unknown'\n const fileTitle = `Audit Report - ${title}`\n\n return generateContent(data)\n .then(content =>\n generateDefinition({\n content,\n fileTitle,\n sequenceId,\n timestamp,\n timezone,\n type: 'Audit',\n ...pdfOptions,\n })\n )\n .catch(err => {\n throw new Error(`BuildAuditPdfError: ${err.message}`)\n })\n}\n\nfunction generateContent(data) {\n const { entity } = data\n\n const {\n followUps = [],\n footerFields = {},\n gps = {},\n headerFields = {},\n score = {},\n timezone,\n title = 'Unknown',\n } = entity\n\n const entityDetails = getAuditEntryDetails(data)\n const hasFollowUps = !!entity.followUps\n \n console.log('buildAuditPdf', {\n hasFollowUps,\n })\n\n const {\n gpsText,\n groupedData,\n locationText,\n referenceValue,\n timezoneHourTime,\n scoreText,\n target,\n targetServiceLevel,\n } = entityDetails\n\n const renderTargetFields = !!targetServiceLevel\n const headerTitle = text(title, { style: 'title' })\n const headerScore = text(scoreText, { alignment: 'right', style: 'title' })\n const firstRow = [headerTitle, headerScore]\n const subTitle = `${locationText ||\n gpsText} - ${timezoneHourTime} by ${referenceValue}`\n\n let headerSubTitle = text(subTitle, { colSpan: 2, style: 'subTitle' })\n let secondRow = [headerSubTitle]\n\n const reverseGeocoded = gps.reverseGeocoded\n const address = !isEmpty(reverseGeocoded)\n ? getFormattedAddress(reverseGeocoded)\n : ''\n const renderHeaderAddress = !isEmpty(reverseGeocoded)\n const dummyColumn = text(' ', { style: 'small' })\n\n let headerAddress = text(address, { colSpan: 2, style: 'small' })\n const renderThirdRow = renderHeaderAddress || renderTargetFields\n let thirdRow = renderHeaderAddress ? [headerAddress] : []\n\n if (renderTargetFields) {\n headerSubTitle = text(subTitle, { style: 'subTitle' })\n\n const serviceLevelBelow = targetServiceLevel === 'below'\n const serviceLevelText =\n targetServiceLevel === 'above'\n ? 'Above Target'\n : targetServiceLevel === 'on'\n ? 'On Target'\n : targetServiceLevel === 'below'\n ? 'Below Target'\n : ''\n\n const scoreServiceLevelSubTitle = text(serviceLevelText, {\n alignment: 'right',\n style: serviceLevelBelow ? 'serviceLevelBelow' : 'serviceLevelAboveOrOn',\n })\n\n secondRow = [headerSubTitle, scoreServiceLevelSubTitle]\n headerAddress = text(address, { style: 'small' })\n\n const truncatedTargetPercent = round(target, 2)\n const scoreTargetText = `(Target - ${truncatedTargetPercent}%)`\n const scoreTargetSubTitle = text(scoreTargetText, {\n alignment: 'right',\n style: 'subTitle',\n })\n\n thirdRow = renderHeaderAddress\n ? [headerAddress, scoreTargetSubTitle]\n : [dummyColumn, scoreTargetSubTitle]\n }\n\n const scoreBreakdown = text(\n `${round(score.actual, 2)} / ${round(score.max, 2)}`,\n {\n alignment: 'right',\n style: 'totalScore',\n }\n )\n const scorePercentage = text(scoreText, {\n alignment: 'right',\n colSpan: 2,\n style: 'totalAuditScore',\n })\n const scoreTitle = text('Total Score', { style: 'totalScore' })\n\n const body = renderThirdRow\n ? [firstRow, secondRow, thirdRow]\n : [firstRow, secondRow]\n\n const titleTable = twoColumnTable({\n body,\n layout: 'noBorders',\n style: 'titleTable',\n widths: ['*', 100],\n margin: [0, 0, 0, 30],\n })\n\n const totalScoreTable = twoColumnTable({\n body: [[scoreTitle, scoreBreakdown], [scorePercentage]],\n layout: 'noBorders',\n widths: ['*', 100],\n })\n\n const hLineTop = horizontalLine({ margin: [0, 10, 0, 0] })\n const hLineBottom = horizontalLine()\n\n const followUpItems = hasFollowUps\n ? buildAuditFollowUps(followUps, { timezone })\n : []\n\n const promises = {\n entry: buildAuditContent(groupedData.items, { hasFollowUps }),\n footerTemplate: buildTemplateContent(footerFields.formGroups, data),\n headerTemplate: buildTemplateContent(headerFields.formGroups, data),\n }\n\n const auditItemsTitle = hasFollowUps\n ? [\n {\n text: 'Audit Items',\n style: {\n font: 'Gotham',\n lineHeight: 1.1,\n },\n },\n hLineTop,\n ]\n : []\n\n return Promise.props(promises)\n .then(({ entry, footerTemplate, headerTemplate }) => [\n titleTable,\n ...headerTemplate,\n followUpItems,\n ...auditItemsTitle,\n ...entry,\n hLineTop,\n totalScoreTable,\n hLineBottom,\n ...footerTemplate,\n ])\n .catch(err => {\n throw new Error(`GenerateContentError: ${err.message}`)\n })\n}\n"],"file":"index.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/pdf/helpers/build-audit-content/index.js"],"names":["flatten","isEmpty","round","Promise","fetchImage","fourColumnTable","horizontalLine","imageTables","table","text","LIGHT_BLUE","WHITE","buildAuditContent","method","items","options","hasFollowUps","map","group","item","index","assets","assetUrl","link","then","base64String","alignment","fit","image","rowImages","rows","fillColor","hasImages","hasComments","comments","label","id","questionId","push","scoreLabel","weight","scoreWeight","imageRow","colSpan","stack","commentsRow","margin","style","groupTableRows","actual","groupActualScore","max","groupMaximumScore","resultText","groupPercentageResultScore","skipped","groupScoreText","bold","headerText","title","groupHeaderTable","body","layout","widths","groupTableHeader","groupTable","headerRows","hLine"],"mappings":";AAAA,SAASA,OAAT,EAAkBC,OAAlB,EAA2BC,KAA3B,QAAwC,QAAxC;AACA,OAAOC,OAAP,MAAoB,UAApB;AAEA,SAASC,UAAT,QAA2B,kBAA3B;
|
|
1
|
+
{"version":3,"sources":["../../../../src/pdf/helpers/build-audit-content/index.js"],"names":["flatten","isEmpty","round","Promise","fetchImage","fourColumnTable","horizontalLine","imageTables","table","text","LIGHT_BLUE","WHITE","buildAuditContent","method","items","options","hasFollowUps","map","group","item","index","assets","assetUrl","link","then","base64String","alignment","fit","image","rowImages","rows","fillColor","hasImages","hasComments","comments","label","id","questionId","push","scoreLabel","weight","scoreWeight","imageRow","colSpan","stack","commentsRow","margin","style","groupTableRows","actual","groupActualScore","max","groupMaximumScore","resultText","groupPercentageResultScore","skipped","groupScoreText","bold","headerText","title","groupHeaderTable","body","layout","widths","groupTableHeader","groupTable","headerRows","hL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CADmB,EAEvBhD,IAAI,CAAC,QAAD,EAAW;AAAEgD,QAAAA,IAAI,EAAE;AAAR,OAAX,CAFmB,EAGvBhD,IAAI,CAAC,QAAD,EAAW;AAAEiB,QAAAA,SAAS,EAAE,QAAb;AAAuB+B,QAAAA,IAAI,EAAE;AAA7B,OAAX,CAHmB,EAIvBhD,IAAI,CAAC,OAAD,EAAU;AAAEiB,QAAAA,SAAS,EAAE,OAAb;AAAsB+B,QAAAA,IAAI,EAAE;AAA5B,OAAV,CAJmB,CAAzB;AAOA,UAAMQ,UAAU,GAAG5D,eAAe,CAAC;AACjC6D,QAAAA,UAAU,EAAE,CADqB;AAEjC;AACAL,QAAAA,IAAI,GAAGG,gBAAH,4BAAwBhE,OAAO,CAACgD,cAAD,CAA/B,EAH6B;AAIjCe,QAAAA,MAAM,EAAE,CAAC,KAAD,EAAQ,KAAR,EAAe,IAAf,EAAqB,IAArB;AAJyB,OAAD,CAAlC;AAOA,UAAMI,KAAK,GAAG7D,cAAc,EAA5B;AAEA,aAAO,CAACsD,gBAAD,EAAmBO,KAAnB,EAA0BF,UAA1B,CAAP;AACD,KAhGM,CAAP;AAiGD,GAlGM,CAAP;AAmGD,CAtGgC,CAA1B","sourcesContent":["import { flatten, isEmpty, round } from 'lodash'\nimport Promise from 'bluebird'\n\nimport { fetchImage } from '../../../helpers'\nimport { fourColumnTable, horizontalLine, imageTables, table, text } from '../'\nimport { LIGHT_BLUE, WHITE } from '../table'\n\nexport const buildAuditContent = Promise.method((items, options) => {\n const { hasFollowUps } = options\n\n return Promise.map(items, group => {\n return Promise.map(group.items, (item, index) => {\n return Promise.map(item.assets, ({ assetUrl, link }) => {\n return fetchImage(assetUrl).then(base64String => ({\n alignment: 'center',\n fit: [210, 210],\n image: base64String,\n link,\n }))\n }).then(rowImages => {\n const rows = []\n\n const fillColor = index % 2 === 0 ? WHITE : LIGHT_BLUE\n const hasImages = !isEmpty(rowImages)\n const hasComments = !isEmpty(item.comments)\n\n // Some audits use questionId to link a follow up issue and its question\n const label = hasFollowUps\n ? { text: item.label, fillColor, id: item.questionId }\n : { text: item.label, fillColor }\n\n rows.push([\n label,\n { text: item.scoreLabel, fillColor },\n { alignment: 'center', text: item.weight, fillColor },\n { alignment: 'right', text: item.scoreWeight, fillColor },\n ])\n\n if (hasImages) {\n const imageRow = [\n {\n colSpan: 4,\n fillColor,\n stack: imageTables(rowImages),\n },\n ]\n\n rows.push(imageRow)\n }\n\n if (hasComments) {\n const commentsRow = [\n {\n colSpan: 4,\n fillColor,\n margin: [0, -10, 0, 0],\n stack: [\n { text: 'Comments:', style: 'commentsHeader' },\n { text: item.comments },\n ],\n },\n ]\n\n rows.push(commentsRow)\n }\n\n return rows\n })\n }).then(groupTableRows => {\n const actual = round(group.groupActualScore, 2)\n const max = round(group.groupMaximumScore, 2)\n const resultText = `${group.groupPercentageResultScore}%`\n\n const { skipped } = group\n\n const groupScoreText = skipped\n ? null\n : text(`${actual} / ${max} (${resultText})`, {\n alignment: 'right',\n bold: true,\n })\n const headerText = text(group.title)\n\n const groupHeaderTable = table({\n body: [[headerText, groupScoreText]],\n layout: 'noBorders',\n style: 'groupHeaderTable',\n widths: ['*', '*'],\n })\n\n const groupTableHeader = [\n text('Question', { bold: true }),\n text('Answer', { bold: true }),\n text('Weight', { alignment: 'center', bold: true }),\n text('Score', { alignment: 'right', bold: true }),\n ]\n\n const groupTable = fourColumnTable({\n headerRows: 0,\n // NOTE: must flatten here as we have arrays of rows\n body: [groupTableHeader, ...flatten(groupTableRows)],\n widths: ['60%', '24%', '8%', '8%'],\n })\n\n const hLine = horizontalLine()\n\n return [groupHeaderTable, hLine, groupTable]\n })\n })\n})\n"],"file":"index.js"}
|
|
@@ -11,11 +11,19 @@ import { launchIcon } from '../../../images'; // Still to do:
|
|
|
11
11
|
// *. Setup the page breaks, either on the last item here or the first in the next section
|
|
12
12
|
// - I want to do this in a way that avoids orphans, or at least only add a page break if the result looks balanced
|
|
13
13
|
// - If we can work out the page position of the last follow up item then we can determine whether to use a page break or not
|
|
14
|
+
// *. If you're not using the flag then you should make sure that all of the variables necessary have been passed in
|
|
15
|
+
// - If the required data isn't present then you should probably just not process follow up issues for the document
|
|
16
|
+
// - If you establish this at the start you can build it into the `hasFollowUps` flag
|
|
17
|
+
// *. Is there some way that you can setup an override for the pdfmake version used by storybook?
|
|
14
18
|
|
|
15
19
|
var LIGHTHOUSE_BASE_URL = 'https://app.lighthouse.io';
|
|
16
20
|
export function buildAuditFollowUps() {
|
|
17
21
|
var rawFollowUpIssues = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
18
22
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
23
|
+
console.log('buildAuditFollowUps', {
|
|
24
|
+
rawFollowUpIssues: rawFollowUpIssues,
|
|
25
|
+
options: options
|
|
26
|
+
});
|
|
19
27
|
var sectionTitle = [{
|
|
20
28
|
text: 'Follow-up Issues',
|
|
21
29
|
style: {
|
|
@@ -134,6 +142,9 @@ export function buildAuditFollowUps() {
|
|
|
134
142
|
widths: [6, '*', 55, 55, 6, '*', '18%'],
|
|
135
143
|
margin: [0, 0, 0, 30]
|
|
136
144
|
});
|
|
145
|
+
console.log('buildAuditFollowUps', {
|
|
146
|
+
followUpsTable: followUpsTable
|
|
147
|
+
});
|
|
137
148
|
return [sectionTitle, sectionDivider, followUpsTable];
|
|
138
149
|
}
|
|
139
150
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/pdf/helpers/build-audit-follow-ups/index.js"],"names":["moment","getStatusDetails","defaultStyles","horizontalLine","sixColumnTable","launchIcon","LIGHTHOUSE_BASE_URL","buildAuditFollowUps","rawFollowUpIssues","options","sectionTitle","text","style","font","lineHeight","margin","sectionDivider","followUpIssues","filter","item","errorMessage","length","subTitle","timezone","tableBody","forEach","mappedStatus","status","toUpperCase","small","color","alignment","updatedAt","format","tz","link","issueId","iconLinkCell","fit","image","linkToDestination","questionId","iconJumpCell","assigneeUsername","assignees","assigneeUser","firstName","lastName","username","push","groupName","questionLabel","headerText","headerRow","map","bold","fontSize","followUpsTable","body","widths"],"mappings":";;;;;;AAAA,OAAOA,MAAP,MAAmB,iBAAnB;AACA,SAASC,gBAAT,QAAiC,kBAAjC;AACA,SAASC,aAAT,EAAwBC,cAAxB,EAAwCC,cAAxC,QAA8D,KAA9D;AACA,SAASC,UAAT,QAA2B,iBAA3B,C,CACA;AACA;AACA;AACA;;AAEA,IAAMC,mBAAmB,GAAG,2BAA5B;AAEA,OAAO,SAASC,mBAAT,GAAmE;AAAA,MAAtCC,iBAAsC,uEAAlB,EAAkB;AAAA,MAAdC,OAAc,uEAAJ,EAAI;
|
|
1
|
+
{"version":3,"sources":["../../../../src/pdf/helpers/build-audit-follow-ups/index.js"],"names":["moment","getStatusDetails","defaultStyles","horizontalLine","sixColumnTable","launchIcon","LIGHTHOUSE_BASE_URL","buildAuditFollowUps","rawFollowUpIssues","options","console","log","sectionTitle","text","style","font","lineHeight","margin","sectionDivider","followUpIssues","filter","item","errorMessage","length","subTitle","timezone","tableBody","forEach","mappedStatus","status","toUpperCase","small","color","alignment","updatedAt","format","tz","link","issueId","iconLinkCell","fit","image","linkToDestination","questionId","iconJumpCell","assigneeUsername","assignees","assigneeUser","firstName","lastName","username","push","groupName","questionLabel","headerText","headerRow","map","bold","fontSize","followUpsTable","body","widths"],"mappings":";;;;;;AAAA,OAAOA,MAAP,MAAmB,iBAAnB;AACA,SAASC,gBAAT,QAAiC,kBAAjC;AACA,SAASC,aAAT,EAAwBC,cAAxB,EAAwCC,cAAxC,QAA8D,KAA9D;AACA,SAASC,UAAT,QAA2B,iBAA3B,C,CACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAMC,mBAAmB,GAAG,2BAA5B;AAEA,OAAO,SAASC,mBAAT,GAAmE;AAAA,MAAtCC,iBAAsC,uEAAlB,EAAkB;AAAA,MAAdC,OAAc,uEAAJ,EAAI;AACx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MAAMC,SAAS,GAAGD,UAAU,CAACE,GAAX,CAAe,UAAA3C,IAAI;AAAA,WAAK;AACxCA,MAAAA,IAAI,EAAJA,IADwC;AAExCC,MAAAA,KAAK,EAAE;AACL2C,QAAAA,IAAI,EAAE,IADD;AAEL1C,QAAAA,IAAI,EAAE,QAFD;AAGL2C,QAAAA,QAAQ,EAAE,CAHL;AAILzB,QAAAA,SAAS,EAAE;AAJN;AAFiC,KAAL;AAAA,GAAnB,CAAlB;AASAsB,EAAAA,SAAS,CAAC,CAAD,CAAT,CAAatB,SAAb,GAAyB,QAAzB;AACAsB,EAAAA,SAAS,CAAC,CAAD,CAAT,CAAatB,SAAb,GAAyB,OAAzB;AAEA,MAAM0B,cAAc,GAAGvD,cAAc,CAAC;AACpCwD,IAAAA,IAAI,GAAGL,SAAH,SAAiB7B,SAAjB,CADgC;AAEpCZ,IAAAA,KAAK,EAAE,YAF6B;AAGpC+C,IAAAA,MAAM,EAAE,CAAC,CAAD,EAAI,GAAJ,EAAS,EAAT,EAAa,EAAb,EAAiB,CAAjB,EAAoB,GAApB,EAAyB,KAAzB,CAH4B;AAIpC5C,IAAAA,MAAM,EAAE,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,EAAV;AAJ4B,GAAD,CAArC;AAOAP,EAAAA,OAAO,CAACC,GAAR,CAAY,qBAAZ,EAAmC;AACjCgD,IAAAA,cAAc,EAAdA;AADiC,GAAnC;AAIA,SAAO,CAAC/C,YAAD,EAAeM,cAAf,EAA+ByC,cAA/B,CAAP;AACD","sourcesContent":["import moment from 'moment-timezone'\nimport { getStatusDetails } from '../../../helpers'\nimport { defaultStyles, horizontalLine, sixColumnTable } from '../'\nimport { launchIcon } from '../../../images'\n// Still to do:\n// *. Setup the page breaks, either on the last item here or the first in the next section\n// - I want to do this in a way that avoids orphans, or at least only add a page break if the result looks balanced\n// - If we can work out the page position of the last follow up item then we can determine whether to use a page break or not\n// *. If you're not using the flag then you should make sure that all of the variables necessary have been passed in\n// - If the required data isn't present then you should probably just not process follow up issues for the document\n// - If you establish this at the start you can build it into the `hasFollowUps` flag\n// *. Is there some way that you can setup an override for the pdfmake version used by storybook?\n\nconst LIGHTHOUSE_BASE_URL = 'https://app.lighthouse.io'\n\nexport function buildAuditFollowUps(rawFollowUpIssues = [], options = {}) {\n console.log('buildAuditFollowUps', {\n rawFollowUpIssues,\n options,\n })\n \n const sectionTitle = [\n {\n text: 'Follow-up Issues',\n style: {\n font: 'Gotham',\n lineHeight: 1.1,\n margin: [0, 0, 0, 50],\n },\n },\n ]\n const sectionDivider = horizontalLine({ margin: [0, 0, 0, 0] })\n\n const followUpIssues = rawFollowUpIssues.filter(item => !item.errorMessage)\n if (!followUpIssues.length) {\n // Show a `no follow up issues` message if there are no follow up issues\n return [\n sectionTitle,\n sectionDivider,\n {\n text: 'No follow up issues exist for this Audit',\n style: defaultStyles.subTitle,\n margin: [0, 5, 0, 50],\n },\n ]\n }\n\n const { timezone = 'America/New_York' } = options\n const tableBody = []\n followUpIssues.forEach(item => {\n const mappedStatus = getStatusDetails(item.status)\n const status = {\n text: mappedStatus.text.toUpperCase(),\n style: {\n ...defaultStyles.small,\n color: mappedStatus.style.color,\n alignment: 'center',\n },\n }\n\n let updatedAt = ''\n if (item.updatedAt) {\n const format = 'MMM D h:mma' // e.g. Jan 21 12:59am in the Audit timezone\n updatedAt = moment.tz(item.updatedAt, timezone).format(format)\n }\n\n const link = `${LIGHTHOUSE_BASE_URL}/reports/issues/${item.issueId}`\n const iconLinkCell = launchIcon\n ? { alignment: 'center', fit: [8, 8], image: launchIcon, link }\n : { text: '' }\n\n // TODO Should we use the same icon for an external link as we do for a jump link?\n const linkToDestination = item.questionId\n const iconJumpCell = launchIcon\n ? {\n alignment: 'center',\n fit: [8, 8],\n image: launchIcon,\n linkToDestination,\n }\n : { text: '' }\n\n let assigneeUsername = 'Unassigned'\n const assignees = item.assignees || []\n if (assignees.length === 1) {\n const assigneeUser = assignees[0]\n const { firstName, lastName, username = 'Unknown User' } =\n assigneeUser || {}\n\n assigneeUsername =\n firstName && lastName ? `${firstName} ${lastName}` : username\n } else if (assignees.length > 1) {\n assigneeUsername = `${assignees.length} users`\n }\n\n tableBody.push([\n iconLinkCell,\n { text: item.groupName || '', link, style: 'small', image: launchIcon },\n status,\n { text: assigneeUsername, style: 'small' },\n iconJumpCell,\n { text: item.questionLabel || '', style: 'small', linkToDestination },\n { text: updatedAt || '', style: 'small', alignment: 'right' },\n ])\n })\n\n const headerText = [\n '',\n 'Issue Title',\n 'Status',\n 'Assignees',\n '',\n 'Audit Question',\n 'Last Updated',\n ]\n const headerRow = headerText.map(text => ({\n text,\n style: {\n bold: true,\n font: 'Gotham',\n fontSize: 8,\n alignment: 'left',\n },\n }))\n headerRow[2].alignment = 'center'\n headerRow[6].alignment = 'right'\n\n const followUpsTable = sixColumnTable({\n body: [headerRow, ...tableBody],\n style: 'titleTable',\n widths: [6, '*', 55, 55, 6, '*', '18%'],\n margin: [0, 0, 0, 30],\n })\n \n console.log('buildAuditFollowUps', {\n followUpsTable,\n })\n\n return [sectionTitle, sectionDivider, followUpsTable]\n}\n"],"file":"index.js"}
|