This commit is contained in:
@@ -69,7 +69,7 @@ namespace AyaNova.Biz
|
||||
return null;
|
||||
}
|
||||
Report newObject = new Report();
|
||||
|
||||
|
||||
CopyObject.Copy(dbObject, newObject);
|
||||
string newUniqueName = string.Empty;
|
||||
bool NotUnique = true;
|
||||
@@ -402,21 +402,21 @@ namespace AyaNova.Biz
|
||||
clientMeta = reportParam.ClientMeta.ToString();
|
||||
|
||||
//add Server meta data
|
||||
var serverMeta=$"{{ayApiUrl:`{apiUrl}`}}";
|
||||
|
||||
var serverMeta = $"{{ayApiUrl:`{apiUrl}`}}";
|
||||
|
||||
|
||||
|
||||
|
||||
#if (DEBUG)
|
||||
//view page contents
|
||||
//view page contents
|
||||
var pagecontent = await page.GetContentAsync();
|
||||
|
||||
#endif
|
||||
//prePareData / preRender
|
||||
var ReportDataObject=$"{{ ayReportData:{ReportData}, ayClientMetaData:{clientMeta}, ayServerMetaData:{serverMeta} }}";
|
||||
var preRenderResult=await page.EvaluateExpressionAsync<dynamic>($"ayPreRender({ReportDataObject});");
|
||||
//prePareData / preRender
|
||||
var ReportDataObject = $"{{ ayReportData:{ReportData}, ayClientMetaData:{clientMeta}, ayServerMetaData:{serverMeta} }}";
|
||||
var PreParedReportDataObject = await page.EvaluateExpressionAsync<dynamic>($"ayPreRender({ReportDataObject});");//note ayPreRender is async but dont' use await to call it as the EvaluateExpressionAsync function knows how to handle that already
|
||||
|
||||
//compile the template
|
||||
var compileScript = $"Handlebars.compile(`{report.Template}`)({preRenderResult});";
|
||||
//compile the template
|
||||
var compileScript = $"Handlebars.compile(`{report.Template}`)({PreParedReportDataObject});";
|
||||
var compiledHTML = await page.EvaluateExpressionAsync<string>(compileScript);
|
||||
|
||||
//render report as HTML
|
||||
@@ -424,12 +424,7 @@ namespace AyaNova.Biz
|
||||
|
||||
//add style (after page or it won't work)
|
||||
if (!string.IsNullOrWhiteSpace(report.Style))
|
||||
{
|
||||
await page.AddStyleTagAsync(new AddTagOptions { Content = report.Style });
|
||||
}
|
||||
|
||||
//If need the generated page content
|
||||
//var pagecontent = await page.GetContentAsync();
|
||||
|
||||
string outputFileName = StringUtil.ReplaceLastOccurrence(FileUtil.NewRandomFileName, ".", "") + ".pdf";
|
||||
string outputFullPath = System.IO.Path.Combine(FileUtil.TemporaryFilesFolder, outputFileName);
|
||||
|
||||
@@ -34,15 +34,65 @@ async function ayPreRender(ayAllData) {
|
||||
}
|
||||
}
|
||||
|
||||
// function ayPreRender(ayAllData) {
|
||||
// if (typeof ayPrepareData === "function") {
|
||||
// return ayPrepareData(ayAllData);
|
||||
// } else {
|
||||
// return ayAllData;
|
||||
// }
|
||||
// }
|
||||
///////////////////////////////////
|
||||
// GET DATA FROM API SERVER
|
||||
//
|
||||
async function ayGetFromAPI(route, token) {
|
||||
try {
|
||||
let r = await fetch(route, {
|
||||
method: "get",
|
||||
mode: "cors",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
Authorization: token
|
||||
}
|
||||
});
|
||||
return await r.json();
|
||||
} catch (error) {
|
||||
//fundamental error, can't proceed with this call
|
||||
// handleError("GET", error, route);
|
||||
//todo: deal with this properly
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// function ayPreRender(ayAllData) {
|
||||
// return ayAllData;
|
||||
// // return typeof ayPrepareData;
|
||||
// }
|
||||
///////////////////////////////////
|
||||
// POST DATA TO API SERVER
|
||||
//
|
||||
async function ayPostToAPI(route, token, data) {
|
||||
try {
|
||||
fetchOptions = {
|
||||
method: "post",
|
||||
mode: "cors",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
Authorization: token
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
};
|
||||
let r = await fetch(route, fetchOptions);
|
||||
return await r.json();
|
||||
} catch (error) {
|
||||
//todo: better handle this
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
async function ayPrepareData(reportData) {
|
||||
//this function (if present) is called with the report data
|
||||
//before the report is rendered
|
||||
//modify data as required here and return it to change the data before the report renders
|
||||
|
||||
//Example of using API method to fetch data from API server and make it available to the report template
|
||||
let route=`${reportData.ayServerMetaData.ayApiUrl}enum-list/list/AyaType`;
|
||||
|
||||
//Put the data into the main report data object so it's available to the template
|
||||
reportData.myData={AyaTypeList:await ayGetFromAPI(route, reportData.ayClientMetaData.Authorization)};
|
||||
|
||||
return reportData;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user