diff --git a/docs/8.0/ayanova/docs/form-ay-report-edit.md b/docs/8.0/ayanova/docs/form-ay-report-edit.md index 5529e7d4..12193593 100644 --- a/docs/8.0/ayanova/docs/form-ay-report-edit.md +++ b/docs/8.0/ayanova/docs/form-ay-report-edit.md @@ -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. -### 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: ``` -function reportPreRender(reportData) { - return reportData; +async function ayPrepareData(ayAllData) { + 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 diff --git a/server/AyaNova/Controllers/ReportController.cs b/server/AyaNova/Controllers/ReportController.cs index 3d8d0191..e01c1509 100644 --- a/server/AyaNova/Controllers/ReportController.cs +++ b/server/AyaNova/Controllers/ReportController.cs @@ -234,7 +234,7 @@ namespace AyaNova.Api.Controllers catch (System.Exception ex) { //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 (: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 (: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; int positionOfNewLine = v.IndexOf("\n at"); if (positionOfNewLine >= 0) diff --git a/server/AyaNova/biz/ReportBiz.cs b/server/AyaNova/biz/ReportBiz.cs index 4a9c819a..5c00f821 100644 --- a/server/AyaNova/biz/ReportBiz.cs +++ b/server/AyaNova/biz/ReportBiz.cs @@ -400,7 +400,10 @@ namespace AyaNova.Biz var clientMeta = "{}"; if (reportParam.ClientMeta != null) 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 #if (DEBUG) @@ -408,8 +411,8 @@ namespace AyaNova.Biz #endif //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(compileScript); //render report as HTML diff --git a/server/AyaNova/resource/rpt/ay-report.js b/server/AyaNova/resource/rpt/ay-report.js index 426d9daa..ed46eb3b 100644 --- a/server/AyaNova/resource/rpt/ay-report.js +++ b/server/AyaNova/resource/rpt/ay-report.js @@ -19,16 +19,17 @@ function ayRegisterHelpers() { }); 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(""); }); +} //eof -}//eof - -function ayPreRender(theReportData) { - if (typeof reportPreRender === "function") { - return reportPreRender(theReportData); +async function ayPreRender(ayAllData) { + if (typeof ayPrepareData === "function") { + return await ayPrepareData(ayAllData); } else { - return theReportData; + return ayAllData; } }