This commit is contained in:
parent
4334907d91
commit
3a2fc984dd
|
@ -23,39 +23,43 @@ class Report extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
async toPdfStream() {
|
async toPdfStream() {
|
||||||
const template = await this.render();
|
try {
|
||||||
const defaultOptions = Object.assign({}, config.pdf);
|
const template = await this.render();
|
||||||
|
const defaultOptions = Object.assign({}, config.pdf);
|
||||||
|
|
||||||
const optionsPath = `${this.path}/options.json`;
|
const optionsPath = `${this.path}/options.json`;
|
||||||
const fullPath = path.resolve(__dirname, optionsPath);
|
const fullPath = path.resolve(__dirname, optionsPath);
|
||||||
let options = defaultOptions;
|
let options = defaultOptions;
|
||||||
if (fs.existsSync(fullPath))
|
if (fs.existsSync(fullPath))
|
||||||
options = require(optionsPath);
|
options = require(optionsPath);
|
||||||
|
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
Cluster.pool.queue({}, async({page}) => {
|
Cluster.pool.queue({}, async({page}) => {
|
||||||
await page.emulateMediaType('screen');
|
await page.emulateMediaType('screen');
|
||||||
await page.setContent(template);
|
await page.setContent(template);
|
||||||
|
|
||||||
const element = await page.$('#pageFooter');
|
const element = await page.$('#pageFooter');
|
||||||
|
|
||||||
let footer = '\n';
|
let footer = '\n';
|
||||||
if (element) {
|
if (element) {
|
||||||
footer = await page.evaluate(el => {
|
footer = await page.evaluate(el => {
|
||||||
const html = el.innerHTML;
|
const html = el.innerHTML;
|
||||||
el.remove();
|
el.remove();
|
||||||
return html;
|
return html;
|
||||||
}, element);
|
}, element);
|
||||||
}
|
}
|
||||||
|
|
||||||
options.headerTemplate = '\n';
|
options.headerTemplate = '\n';
|
||||||
options.footerTemplate = footer;
|
options.footerTemplate = footer;
|
||||||
|
|
||||||
const stream = await page.pdf(options);
|
const stream = await page.pdf(options);
|
||||||
|
|
||||||
resolve(stream);
|
resolve(stream);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
} catch (e) {
|
||||||
|
console.log('ERROR CATCHED:', e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,6 +5,8 @@ const reportFooter = new Component('report-footer');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'claim-pickup-order',
|
name: 'claim-pickup-order',
|
||||||
async serverPrefetch() {
|
async serverPrefetch() {
|
||||||
|
// FORCE FAIL FOR TEST
|
||||||
|
throw new Error('Something went wrong');
|
||||||
this.client = await this.fetchClient(this.id);
|
this.client = await this.fetchClient(this.id);
|
||||||
this.sales = await this.fetchSales(this.id);
|
this.sales = await this.fetchSales(this.id);
|
||||||
this.claimConfig = await this.fetchClaimConfig();
|
this.claimConfig = await this.fetchClaimConfig();
|
||||||
|
|
Loading…
Reference in New Issue