This commit is contained in:
@@ -253,13 +253,19 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
var httpConnectionFeature = HttpContext.Features.Get<IHttpConnectionFeature>();
|
var httpConnectionFeature = HttpContext.Features.Get<IHttpConnectionFeature>();
|
||||||
var API_URL = $"http://127.0.0.1:{httpConnectionFeature.LocalPort}/api/v8/";
|
var API_URL = $"http://127.0.0.1:{httpConnectionFeature.LocalPort}/api/v8/";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await biz.RenderReport(reportParam, API_URL);
|
||||||
|
|
||||||
var result = await biz.RenderReport(reportParam, API_URL);
|
if (string.IsNullOrWhiteSpace(result))
|
||||||
if (string.IsNullOrWhiteSpace(result))
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
else
|
||||||
else
|
return Ok(ApiOkResponse.Response(result));
|
||||||
return Ok(ApiOkResponse.Response(result));
|
}
|
||||||
|
catch (System.Exception ex)
|
||||||
|
{
|
||||||
|
return BadRequest(new ApiErrorResponse(ApiErrorCode.API_SERVER_ERROR, null, ex.Message));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -347,10 +347,16 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
log.LogDebug($"Preparing page: adding this report's scripts, style and templates to page");
|
log.LogDebug($"Preparing page: adding this report's scripts, style and templates to page");
|
||||||
|
|
||||||
//TODO: CUSTOM HELPERS
|
//add report pre-render, helpers and style
|
||||||
|
//TODO: Add code to vet / evaluate these scripts and see if they are safe and contain valid methods expected
|
||||||
|
await page.AddScriptTagAsync(new AddTagOptions() { Content = report.JsPrerender });
|
||||||
|
await page.AddScriptTagAsync(new AddTagOptions() { Content = report.JsHelpers });
|
||||||
|
await page.AddStyleTagAsync(new AddTagOptions() { Content = report.Style });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//compile and run handlebars template
|
//compile and run handlebars template
|
||||||
var compileScript = $"let reportData=ayPreRender({ReportData});Handlebars.compile({report.Template})(reportData);";
|
var compileScript = $"let ayReportData=ayPreRender({ReportData});Handlebars.compile(`{report.Template}`)(ayReportData);";
|
||||||
var resultHTML = await page.EvaluateExpressionAsync<string>(compileScript);
|
var resultHTML = await page.EvaluateExpressionAsync<string>(compileScript);
|
||||||
|
|
||||||
//render report as HTML
|
//render report as HTML
|
||||||
@@ -365,8 +371,8 @@ namespace AyaNova.Biz
|
|||||||
//If need the generated page content
|
//If need the generated page content
|
||||||
//var pagecontent = await page.GetContentAsync();
|
//var pagecontent = await page.GetContentAsync();
|
||||||
|
|
||||||
string outputFileName = StringUtil.ReplaceLastOccurrence(FileUtil.NewRandomFileName,".","")+".pdf";
|
string outputFileName = StringUtil.ReplaceLastOccurrence(FileUtil.NewRandomFileName, ".", "") + ".pdf";
|
||||||
string outputFullPath= System.IO.Path.Combine(FileUtil.TemporaryFilesFolder,outputFileName);
|
string outputFullPath = System.IO.Path.Combine(FileUtil.TemporaryFilesFolder, outputFileName);
|
||||||
|
|
||||||
//render to pdf and return
|
//render to pdf and return
|
||||||
await page.PdfAsync(outputFullPath);
|
await page.PdfAsync(outputFullPath);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ function ayRegisterHelpers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ayPreRender(theReportData) {
|
function ayPreRender(theReportData) {
|
||||||
if (reportPrerender != null) {
|
if (typeof reportPreRender === "function") {
|
||||||
return reportPreRender(theReportData);
|
return reportPreRender(theReportData);
|
||||||
}else{
|
}else{
|
||||||
return theReportData;
|
return theReportData;
|
||||||
|
|||||||
Reference in New Issue
Block a user