This commit is contained in:
2020-09-09 22:33:24 +00:00
parent 1bc2c29619
commit 4007f2fe8a
3 changed files with 37 additions and 83 deletions

View File

@@ -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;
}

View File

@@ -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;
}
<html>
<body>
<div>
<h4>ayServerMetaData</h4>
{{ ayJSON ayServerMetaData }}
</div>
<div>
<h4>ayClientMetaData</h4>
{{ ayJSON ayClientMetaData }}
</div>
<div>
<h4>ayReportMetaData</h4>
{{ ayJSON ayReportMetaData }}
</div>
<div>
<h4>myData</h4>
<h5>(Fetched dynamically from API route <strong>enum-list/list/AyaType</strong>)</h5>
{{ ayJSON myData }}
</div>
<div>
<h4>ayReportData</h4>
{{#each ayReportData}}
<h2>{{ Name }}</h2>
<div>Notes: <span class="example">{{ Notes }}</span></div>
{{/each}}
</div>
</body>
</html>
*/

View File

@@ -1 +1 @@
{"Name":"EXAMPLE Translation helper","Active":true,"Notes":"","Roles":124927,"ObjectType":2,"Template":"<html>\n\n<body>\n\n\t<h2>Example: Translation helper </h2>\n\t<p>See help documentation for details</p>\n\t\n\t<div>\n\t\t<h4>ayReportData</h4>\n\t\t{{#each ayReportData}}\n\t\t<h2>{{ayT 'WidgetName' }}: {{ Name }}</h2>\n\t\t<div>{{ayT 'WidgetNotes' }}: <span class=\"example\">{{ Notes }}</span></div>\n\t\t{{/each}}\n\t</div>\n</body>\n\n</html>","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}
{"Name":"EXAMPLE Translation helper","Active":true,"Notes":"","Roles":124927,"ObjectType":2,"Template":"<html>\n\n<body>\n\n\t<h2>Example: Translation helper </h2>\n\t<p>See Report editor help documentation for details</p>\n\n\t<div>\n\t\t<h4>ayReportData</h4>\n\t\t{{#each ayReportData}}\n\t\t<h2>{{ayT 'WidgetName' }}: {{ Name }}</h2>\n\t\t<div>{{ayT 'WidgetSerial' }}:{{ Serial }}</div>\n\t\t<div>{{ayT 'WidgetDollarAmount' }}:{{ DollarAmount }}</div>\n\t\t<div>{{ayT 'WidgetStartDate' }}:{{ StartDate }}</div>\n\t\t<div>{{ayT 'WidgetNotes' }}:{{ Notes }}</div>\n\t\t{{/each}}\n\t</div>\n</body>\n\n</html>","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}