This commit is contained in:
@@ -41,21 +41,27 @@ In order to get up to speed quickly with report design we recommend looking over
|
|||||||
This section is provided to define the HTML Cascading Style Sheet for the report document. This section is optional.
|
This section is provided to define the HTML Cascading Style Sheet for the report document. This section is optional.
|
||||||
|
|
||||||
|
|
||||||
### JSPreRender
|
### Prepare
|
||||||
|
|
||||||
This section is provided as a way to change the data provided to the report *before* it is rendered. You can use this section to alter data that is fed to the report template. Use of the reportPreRender function is optional but it *must* be present in it's default format even if not used as it is *always* called by the rendering process and will result in an error if missing.
|
This section is provided as a way to change the data provided to the report *before* it is rendered.
|
||||||
|
|
||||||
|
Typically this function is used to retrieve and / or alter data that is fed to the report template.
|
||||||
|
|
||||||
|
Use of the `ayPrepareData` function is optional but the function *must* be present in it's default format even if not used as it is *always* called by the rendering process and will result in an error if missing.
|
||||||
|
|
||||||
This is the minimum required default definition:
|
This is the minimum required default definition:
|
||||||
|
|
||||||
```
|
```
|
||||||
function reportPreRender(reportData) {
|
async function ayPrepareData(ayAllData) {
|
||||||
return reportData;
|
return ayAllData;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that the SAMPLE DATA section of the user interface in the report designer shows the raw data *before* it is passed to this function, not how it would look *after* this function is run. If you need to see how the data is shaped after a reportPreRender you can make use of the `ayJSON` helper documented below to view the raw data on the rendered report itself.
|
`ayAllData` parameter is an object containing all data provided for the report and is detailed below in the Report Data Objects section.
|
||||||
|
|
||||||
A common use for the reportPreRender function would be to insert or re-shape data based on calculations or data fetched from external API's or the AyaNova API itself (see the section regarding API usage below for details).
|
Note that the SAMPLE DATA section of the user interface in the report designer shows the raw data *before* it is passed to this function, not how it would look *after* this function is run. If you need to see how the data is shaped after a ayPrepareData you can make use of the `ayJSON` helper documented below to view the raw data on the rendered report itself.
|
||||||
|
|
||||||
|
A common use for the ayPrepareData function would be to insert or re-shape data based on calculations or data fetched from external API's or the AyaNova API itself (see the section regarding API usage below for details).
|
||||||
|
|
||||||
### Helpers
|
### Helpers
|
||||||
|
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
catch (System.Exception ex)
|
catch (System.Exception ex)
|
||||||
{
|
{
|
||||||
//Don't send the full stack trace, just the initial error message from the javascript eval
|
//Don't send the full stack trace, just the initial error message from the javascript eval
|
||||||
// "Evaluation failed: ReferenceError: reportdata is not defined\n at reportPreRender (<anonymous>:5:17)\n at ayPreRender (C:\\data\\code\\raven\\server\\AyaNova\\resource\\rpt\\ay-report.js:13:12)\n at __puppeteer_evaluation_script__:10:25"
|
// "Evaluation failed: ReferenceError: reportdata is not defined\n at ayPrepareData (<anonymous>:5:17)\n at ayPreRender (C:\\data\\code\\raven\\server\\AyaNova\\resource\\rpt\\ay-report.js:13:12)\n at __puppeteer_evaluation_script__:10:25"
|
||||||
var v = ex.Message;
|
var v = ex.Message;
|
||||||
int positionOfNewLine = v.IndexOf("\n at");
|
int positionOfNewLine = v.IndexOf("\n at");
|
||||||
if (positionOfNewLine >= 0)
|
if (positionOfNewLine >= 0)
|
||||||
|
|||||||
@@ -400,7 +400,10 @@ namespace AyaNova.Biz
|
|||||||
var clientMeta = "{}";
|
var clientMeta = "{}";
|
||||||
if (reportParam.ClientMeta != null)
|
if (reportParam.ClientMeta != null)
|
||||||
clientMeta = reportParam.ClientMeta.ToString();
|
clientMeta = reportParam.ClientMeta.ToString();
|
||||||
// await page.AddScriptTagAsync(new AddTagOptions() { Content = $"var ayClientMetaData = {clientMeta}" });
|
|
||||||
|
//add Server meta data
|
||||||
|
var serverMeta=$"{{ayApiUrl:`{apiUrl}`}}";
|
||||||
|
|
||||||
|
|
||||||
//this is how you view the contents of the page
|
//this is how you view the contents of the page
|
||||||
#if (DEBUG)
|
#if (DEBUG)
|
||||||
@@ -408,8 +411,8 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
//compile and run handlebars template
|
//compile and run handlebars template
|
||||||
|
//var compileScript = $"Handlebars.compile(`{report.Template}`)({{ ayReportData:ayPreRender({ReportData}), ayClientMetaData:{clientMeta}, ayServerMetaData:{{ayApiUrl:`{apiUrl}`}} }});";
|
||||||
var compileScript = $"Handlebars.compile(`{report.Template}`)({{ ayReportData:ayPreRender({ReportData}), ayClientMetaData:{clientMeta}, ayServerMetaData:{{ayApiUrl:`{apiUrl}`}} }});";
|
var compileScript = $"Handlebars.compile(`{report.Template}`)(ayPreRender({{ ayReportData:{ReportData}, ayClientMetaData:{clientMeta}, ayServerMetaData:{serverMeta} }}));";
|
||||||
var resultHTML = await page.EvaluateExpressionAsync<string>(compileScript);
|
var resultHTML = await page.EvaluateExpressionAsync<string>(compileScript);
|
||||||
|
|
||||||
//render report as HTML
|
//render report as HTML
|
||||||
|
|||||||
@@ -19,16 +19,17 @@ function ayRegisterHelpers() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Handlebars.registerHelper("ayLogo", function (size) {
|
Handlebars.registerHelper("ayLogo", function (size) {
|
||||||
var url = `${Handlebars.escapeExpression(this.ayServerMetaData.ayApiUrl)}logo/${size}`;
|
var url = `${Handlebars.escapeExpression(
|
||||||
|
this.ayServerMetaData.ayApiUrl
|
||||||
|
)}logo/${size}`;
|
||||||
return new Handlebars.SafeString("<img src='" + url + "'/>");
|
return new Handlebars.SafeString("<img src='" + url + "'/>");
|
||||||
});
|
});
|
||||||
|
} //eof
|
||||||
|
|
||||||
}//eof
|
async function ayPreRender(ayAllData) {
|
||||||
|
if (typeof ayPrepareData === "function") {
|
||||||
function ayPreRender(theReportData) {
|
return await ayPrepareData(ayAllData);
|
||||||
if (typeof reportPreRender === "function") {
|
|
||||||
return reportPreRender(theReportData);
|
|
||||||
} else {
|
} else {
|
||||||
return theReportData;
|
return ayAllData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user