diff --git a/server/AyaNova/biz/SearchTranslationWordBreakDataCache.cs b/server/AyaNova/biz/SearchTranslationWordBreakDataCache.cs index fa1203c9..cee17c73 100644 --- a/server/AyaNova/biz/SearchTranslationWordBreakDataCache.cs +++ b/server/AyaNova/biz/SearchTranslationWordBreakDataCache.cs @@ -17,7 +17,7 @@ namespace AyaNova.Biz await semaphoreSlim.WaitAsync(); try { - if (!theCache.ContainsKey(1)) + if (!theCache.ContainsKey(id)) theCache.Add(id, await GetTranslationSearchDataAsync(id)); return theCache.First(z=>z.Key==id).Value; } diff --git a/server/AyaNova/resource/rpt/ay-report.js b/server/AyaNova/resource/rpt/ay-report.js index e64d6133..0e20be09 100644 --- a/server/AyaNova/resource/rpt/ay-report.js +++ b/server/AyaNova/resource/rpt/ay-report.js @@ -70,7 +70,8 @@ function ayRegisterHelpers() { Handlebars.registerHelper("ayT", function (translationKey) { if (ayTranslationKeyCache[translationKey] == undefined) { - return translationKey; + throw `ayT reporting helper error: the key "${translationKey}" is not present in the translation cache, did you forget to include it in your call to "await ayGetTranslations([KeyList]);" in ayPrepareData()\nTranslationKeyCache contains: ${JSON.stringify(ayTranslationKeyCache, null, 3)}?`; + // return translationKey; } return ayTranslationKeyCache[translationKey]; }); @@ -94,12 +95,15 @@ function utcDateToShortDateAndTimeLocalized(value) { return "not valid"; } - return parsedDate.toLocaleString(AYMETA.ayClientMetaData.LanguageName || "en-US", { - timeZone: AYMETA.ayClientMetaData.TimeZoneName || "America/Winnipeg", - dateStyle: "short", - timeStyle: "short", - hour12: AYMETA.ayClientMetaData.Hour12 - }); + return parsedDate.toLocaleString( + AYMETA.ayClientMetaData.LanguageName || "en-US", + { + timeZone: AYMETA.ayClientMetaData.TimeZoneName || "America/Winnipeg", + dateStyle: "short", + timeStyle: "short", + hour12: AYMETA.ayClientMetaData.Hour12 + } + ); } /////////////////////////////////////////// // Turn a utc date into a displayable @@ -118,10 +122,13 @@ function utcDateToShortDateLocalized(value) { return "not valid"; } - return parsedDate.toLocaleDateString(AYMETA.ayClientMetaData.LanguageName || "en-US", { - timeZone: AYMETA.ayClientMetaData.TimeZoneName || "America/Winnipeg", - dateStyle: "short" - }); + return parsedDate.toLocaleDateString( + AYMETA.ayClientMetaData.LanguageName || "en-US", + { + timeZone: AYMETA.ayClientMetaData.TimeZoneName || "America/Winnipeg", + dateStyle: "short" + } + ); } /////////////////////////////////////////// // Turn a utc date into a displayable @@ -140,30 +147,36 @@ function utcDateToShortTimeLocalized(value) { return "not valid"; } - return parsedDate.toLocaleTimeString(AYMETA.ayClientMetaData.LanguageName || "en-US", { - timeZone: AYMETA.ayClientMetaData.TimeZoneName || "America/Winnipeg", - timeStyle: "short", - hour12: AYMETA.ayClientMetaData.Hour12 - }); + return parsedDate.toLocaleTimeString( + AYMETA.ayClientMetaData.LanguageName || "en-US", + { + timeZone: AYMETA.ayClientMetaData.TimeZoneName || "America/Winnipeg", + timeStyle: "short", + hour12: AYMETA.ayClientMetaData.Hour12 + } + ); } /////////////////////////////////////////// // CURRENCY LOCALIZATION -// +// // function currencyLocalized(value) { if (!value) { return ""; } return new Intl.NumberFormat( - AYMETA.ayClientMetaData.LanguageName || "en-US", - { style: 'currency', currency: AYMETA.ayClientMetaData.CurrencyName || "USD" } - ).format(value) + AYMETA.ayClientMetaData.LanguageName || "en-US", + { + style: "currency", + currency: AYMETA.ayClientMetaData.CurrencyName || "USD" + } + ).format(value); } /////////////////////////////////////////// // DECIMAL LOCALIZATION -// +// // function decimalLocalized(value) { if (!value) { @@ -171,7 +184,7 @@ function decimalLocalized(value) { } return new Intl.NumberFormat( AYMETA.ayClientMetaData.LanguageName || "en-US" - ).format(value) + ).format(value); } ////////////////////////////////// @@ -252,62 +265,3 @@ async function ayPostToAPI(route, data, token) { 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 GET method to fetch data from API server and make it available to the report template - let route=`${reportData.ayServerMetaData.ayApiUrl}server-info`; - - //Put the data into the main report data object so it's available to the template - reportData.myData={ServerInfo:await ayGetFromAPI(route, reportData.ayClientMetaData.Authorization)}; - - //Example API POST method to fetch data from api server - route=`${reportData.ayServerMetaData.ayApiUrl}search`; - let searchPostData={phrase: "Fish"}; - reportData.myData.SearchResults=await ayPostToAPI(route, reportData.ayClientMetaData.Authorization,searchPostData); - - return reportData; -} - - - - - -
-

ayServerMetaData

- {{ ayJSON ayServerMetaData }} -
- -
-

ayClientMetaData

- {{ ayJSON ayClientMetaData }} -
- -
-

ayReportMetaData

- {{ ayJSON ayReportMetaData }} -
- - -
-

myData

-
(Fetched dynamically from API route enum-list/list/AyaType)
- {{ ayJSON myData }} -
- -
-

ayReportData

- {{#each ayReportData}} -

{{ Name }}

-
Notes: {{ Notes }}
- {{/each}} -
- - - - -*/ diff --git a/server/AyaNova/resource/rpt/stock-report-templates/EXAMPLE Translation helper.ayrt b/server/AyaNova/resource/rpt/stock-report-templates/EXAMPLE Translation helper.ayrt index 6477acae..02a38e8c 100644 --- a/server/AyaNova/resource/rpt/stock-report-templates/EXAMPLE Translation helper.ayrt +++ b/server/AyaNova/resource/rpt/stock-report-templates/EXAMPLE Translation helper.ayrt @@ -1 +1 @@ -{"Name":"EXAMPLE Translation helper","Active":true,"Notes":"","Roles":124927,"ObjectType":2,"Template":"\n\n\n\n\t

Example: Translation helper

\n\t

See help documentation for details

\n\t\n\t
\n\t\t

ayReportData

\n\t\t{{#each ayReportData}}\n\t\t

{{ayT 'WidgetName' }}: {{ Name }}

\n\t\t
{{ayT 'WidgetNotes' }}: {{ Notes }}
\n\t\t{{/each}}\n\t
\n\n\n","Style":".example {\n color: blue;\n}","JsPrerender":"async function ayPrepareData(reportData){ \n //Fetch translation keys required for report\n //Server will get the translations that match the current logged in user's language \n //Only translation keys pre-fetched here will be available for use with the ayT translation helper\n ayGetTranslations([\n \"Widget\",\n \"WidgetName\",\n \"WidgetSerial\",\n \"WidgetDollarAmount\",\n \"WidgetCount\",\n \"WidgetStartDate\",\n \"WidgetEndDate\",\n \"WidgetNotes\",\n \"WidgetCustom1\",\n \"WidgetCustom2\",\n \"WidgetCustom3\",\n \"WidgetCustom4\",\n \"WidgetCustom5\",\n \"WidgetCustom6\",\n \"WidgetCustom7\",\n \"WidgetCustom8\",\n \"WidgetCustom9\",\n \"WidgetCustom10\",\n \"WidgetCustom11\",\n \"WidgetCustom12\",\n \"WidgetCustom13\",\n \"WidgetCustom14\",\n \"WidgetCustom15\",\n \"WidgetCustom16\",\n ]);\n \n return reportData;\n}","JsHelpers":"//Register custom Handlebars helpers here to use in your report script\n//https://handlebarsjs.com/guide/#custom-helpers\nHandlebars.registerHelper('loud', function (aString) {\n return aString.toUpperCase()\n})","RenderType":0} \ No newline at end of file +{"Name":"EXAMPLE Translation helper","Active":true,"Notes":"","Roles":124927,"ObjectType":2,"Template":"\n\n\n\n\t

Example: Translation helper

\n\t

See Report editor help documentation for details

\n\n\t
\n\t\t

ayReportData

\n\t\t{{#each ayReportData}}\n\t\t

{{ayT 'WidgetName' }}: {{ Name }}

\n\t\t
{{ayT 'WidgetSerial' }}:{{ Serial }}
\n\t\t
{{ayT 'WidgetDollarAmount' }}:{{ DollarAmount }}
\n\t\t
{{ayT 'WidgetStartDate' }}:{{ StartDate }}
\n\t\t
{{ayT 'WidgetNotes' }}:{{ Notes }}
\n\t\t{{/each}}\n\t
\n\n\n","Style":".example {\n color: blue;\n}","JsPrerender":"async function ayPrepareData(reportData) {\n //Fetch translation keys required for report \n //Server will get the translations that match the current logged in user's language\n //Only translation keys pre-fetched here will be available for use with the ayT translation helper\n\n //NOTE: you *must* await the call to ayGetTranslations or they will not be present for the report template use\n\n await ayGetTranslations([\n \"Widget\",\n \"WidgetName\",\n \"WidgetSerial\",\n \"WidgetDollarAmount\",\n \"WidgetCount\",\n \"WidgetStartDate\",\n \"WidgetEndDate\",\n \"WidgetNotes\",\n \"WidgetCustom1\",\n \"WidgetCustom2\",\n \"WidgetCustom3\",\n \"WidgetCustom4\",\n \"WidgetCustom5\",\n \"WidgetCustom6\",\n \"WidgetCustom7\",\n \"WidgetCustom8\",\n \"WidgetCustom9\",\n \"WidgetCustom10\",\n \"WidgetCustom11\",\n \"WidgetCustom12\",\n \"WidgetCustom13\",\n \"WidgetCustom14\",\n \"WidgetCustom15\",\n \"WidgetCustom16\",\n ]);\n\n return reportData;\n}","JsHelpers":"//Register custom Handlebars helpers here to use in your report script\n//https://handlebarsjs.com/guide/#custom-helpers\nHandlebars.registerHelper('loud', function (aString) {\n return aString.toUpperCase()\n})","RenderType":0} \ No newline at end of file