Added offset to report server call IO-729
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { gql } from "@apollo/client";
|
||||
import { notification } from "antd";
|
||||
import axios from "axios";
|
||||
import { gql } from "@apollo/client";
|
||||
import jsreport from "jsreport-browser-client-dist";
|
||||
import { auth } from "../firebase/firebase.utils";
|
||||
import { setEmailOptions } from "../redux/email/email.actions";
|
||||
import { store } from "../redux/store";
|
||||
import client from "../utils/GraphQLClient";
|
||||
import { TemplateList } from "./TemplateConstants";
|
||||
import moment from "moment";
|
||||
|
||||
const server = process.env.REACT_APP_REPORTS_SERVER_URL;
|
||||
jsreport.serverUrl = server;
|
||||
@@ -36,6 +37,7 @@ export default async function RenderTemplate(
|
||||
...templateObject.context,
|
||||
headerpath: `/${bodyshop.imexshopid}/header.html`,
|
||||
bodyshop: bodyshop,
|
||||
offset: moment().utcOffset(),
|
||||
},
|
||||
};
|
||||
try {
|
||||
@@ -59,23 +61,46 @@ export async function RenderTemplates(
|
||||
) {
|
||||
//Query assets that match the template name. Must be in format <<templateName>>.query
|
||||
let templateAndData = [];
|
||||
let proms = [];
|
||||
templateObjects.forEach((template) => {
|
||||
proms.push(
|
||||
(async () => {
|
||||
let { contextData, useShopSpecificTemplate } = await fetchContextData(
|
||||
template
|
||||
);
|
||||
templateAndData.push({
|
||||
templateObject: template,
|
||||
contextData,
|
||||
useShopSpecificTemplate,
|
||||
});
|
||||
})()
|
||||
);
|
||||
});
|
||||
await Promise.all(proms);
|
||||
let rootTemplate = templateAndData.shift();
|
||||
|
||||
console.log("About to await all promises.");
|
||||
await Promise.all(
|
||||
templateObjects.map(async (template) => {
|
||||
console.log("executing for", template);
|
||||
let { contextData, useShopSpecificTemplate } = await fetchContextData(
|
||||
template
|
||||
);
|
||||
templateAndData.push({
|
||||
templateObject: template,
|
||||
contextData,
|
||||
useShopSpecificTemplate,
|
||||
});
|
||||
})
|
||||
);
|
||||
console.log("All promises awaited.", templateAndData);
|
||||
let rootTemplate = templateAndData[0];
|
||||
const pdfOps = [];
|
||||
|
||||
for (var i = 1; i < templateAndData.length; i++) {
|
||||
pdfOps.push({
|
||||
template: {
|
||||
name: templateAndData[i].useShopSpecificTemplate
|
||||
? `/${bodyshop.imexshopid}/${templateAndData[i].templateObject.name}`
|
||||
: `/${templateAndData[i].templateObject.name}`,
|
||||
...(renderAsHtml ? {} : { recipe: "chrome-pdf" }),
|
||||
},
|
||||
data: {
|
||||
...templateAndData[i].contextData,
|
||||
...templateAndData[i].templateObject.variables,
|
||||
...templateAndData[i].templateObject.context,
|
||||
headerpath: `/${bodyshop.imexshopid}/header.html`,
|
||||
bodyshop: bodyshop,
|
||||
offset: moment().utcOffset(),
|
||||
},
|
||||
type: "append",
|
||||
mergeWholeDocument: true,
|
||||
renderForEveryPage: true,
|
||||
});
|
||||
}
|
||||
|
||||
let reportRequest = {
|
||||
template: {
|
||||
@@ -83,26 +108,7 @@ export async function RenderTemplates(
|
||||
? `/${bodyshop.imexshopid}/${rootTemplate.templateObject.name}`
|
||||
: `/${rootTemplate.templateObject.name}`,
|
||||
...(renderAsHtml ? {} : { recipe: "chrome-pdf" }),
|
||||
pdfOperations: templateAndData.map((template) => {
|
||||
return {
|
||||
template: {
|
||||
name: template.useShopSpecificTemplate
|
||||
? `/${bodyshop.imexshopid}/${template.templateObject.name}`
|
||||
: `/${template.templateObject.name}`,
|
||||
...(renderAsHtml ? {} : { recipe: "chrome-pdf" }),
|
||||
},
|
||||
data: {
|
||||
...template.contextData,
|
||||
...template.templateObject.variables,
|
||||
...template.templateObject.context,
|
||||
headerpath: `/${bodyshop.imexshopid}/header.html`,
|
||||
bodyshop: bodyshop,
|
||||
},
|
||||
type: "append",
|
||||
mergeWholeDocument: true,
|
||||
renderForEveryPage: true,
|
||||
};
|
||||
}),
|
||||
pdfOperations: pdfOps,
|
||||
},
|
||||
data: {
|
||||
...rootTemplate.contextData,
|
||||
@@ -110,6 +116,7 @@ export async function RenderTemplates(
|
||||
...rootTemplate.templateObject.context,
|
||||
headerpath: `/${bodyshop.imexshopid}/header.html`,
|
||||
bodyshop: bodyshop,
|
||||
offset: moment().utcOffset(),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -149,6 +156,7 @@ export const GenerateDocuments = async (templates) => {
|
||||
};
|
||||
|
||||
const fetchContextData = async (templateObject) => {
|
||||
console.log("Fetching context data", templateObject);
|
||||
jsreport.headers["Authorization"] =
|
||||
"Bearer " + (await auth.currentUser.getIdToken());
|
||||
|
||||
|
||||
@@ -54,12 +54,15 @@
|
||||
},
|
||||
"enabled": true
|
||||
},
|
||||
"child-templates": {
|
||||
"parallelLimit": 10
|
||||
},
|
||||
"sample-template": {
|
||||
"createSamples": true
|
||||
},
|
||||
"scripts": {
|
||||
"allowedModules": "*",
|
||||
"strategy": "http-server"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user