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