diff --git a/server/AyaNova/biz/ReportBiz.cs b/server/AyaNova/biz/ReportBiz.cs index b263a757..fd167c80 100644 --- a/server/AyaNova/biz/ReportBiz.cs +++ b/server/AyaNova/biz/ReportBiz.cs @@ -381,6 +381,13 @@ namespace AyaNova.Biz //add Marked for markdown processing await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "ay-md.js") }); + + //Wait, might not need luxon, it appears I only use that for relative date calculations + //Luxon https://moment.github.io/luxon/ + // await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "ay-lux.js") }); + + + //VueCurrencyInput - base currency handling lib whatever that is //add stock helpers await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "ay-report.js") }); diff --git a/server/AyaNova/resource/rpt/ay-report.js b/server/AyaNova/resource/rpt/ay-report.js index 7adcc42c..ff58252b 100644 --- a/server/AyaNova/resource/rpt/ay-report.js +++ b/server/AyaNova/resource/rpt/ay-report.js @@ -1,8 +1,46 @@ +////////////////////////////////// +// Pre render function +// +async function ayPreRender(ayAllData) { + if (typeof ayPrepareData === "function") { + return await ayPrepareData(ayAllData); + } else { + return ayAllData; + } +} + +/* + "AYMETA": { + "ayReportMetaData": { "Id": 1, "Name": "report translation test", "Notes": "", "ObjectType": "Widget", "DataListKey": "", "ListView":"", "SelectedRowIds": "90" }, + "ayClientMetaData": { + "UserName": "AyaNova SuperUser", + "Authorization": "BearereyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIxNjAwMjYzOTEzIiwiaXNzIjoiYXlhbm92YS5jb20iLCJpZCI6IjEifQ.NGpDgg8mf54oTU8fyExBf1yXnsaIaHedGFmKLKlNCZ4", + "TimeZoneName": "America/Los_Angeles", "LanguageName": "en-US", "Hour12": true, "CurrencyName": "USD", "DefaultLocale": "en" } + */ + +/////////////////////////////////////// +// Set our stock handlebars helpers +// function ayRegisterHelpers() { Handlebars.registerHelper("ayCaps", function (aString) { return aString.toUpperCase(); }); + Handlebars.registerHelper("ayDateTime", function (timestamp) { + return utcDateToShortDateAndTimeLocalized(timestamp); + }); + + Handlebars.registerHelper("ayDate", function (timestamp) { + return utcDateToShortDateLocalized(timestamp); + }); + + Handlebars.registerHelper("ayTime", function (timestamp) { + return utcDateToShortTimeLocalized(timestamp); + }); + + //ayDecimal + //ayCurrency + Handlebars.registerHelper("ayMarkdown", function (astring) { return marked(astring, { breaks: true }); }); @@ -33,12 +71,75 @@ function ayRegisterHelpers() { }); } //eof -async function ayPreRender(ayAllData) { - if (typeof ayPrepareData === "function") { - return await ayPrepareData(ayAllData); - } else { - return ayAllData; +/////////////////////////////////////////// +// Turn a utc date into a displayable +// short date and time +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString +// +function utcDateToShortDateAndTimeLocalized(value) { + if (!value) { + return ""; } + + //parse the date which is identified as utc ("2020-02-06T18:18:49.148011Z") + let parsedDate = new Date(value); + + //is it a valid date? + if (!(parsedDate instanceof Date && !isNaN(parsedDate))) { + return "not valid"; + } + + return parsedDate.toLocaleString(AYMETA.ayClientMetaData.LanguageName, { + timeZone: AYMETA.ayClientMetaData.TimeZoneName, + dateStyle: "short", + timeStyle: "short", + hour12: AYMETA.ayClientMetaData.Hour12 + }); +} +/////////////////////////////////////////// +// Turn a utc date into a displayable +// short date +// +function utcDateToShortDateLocalized(value) { + if (!value) { + return ""; + } + + //parse the date which is identified as utc ("2020-02-06T18:18:49.148011Z") + let parsedDate = new Date(value); + + //is it a valid date? + if (!(parsedDate instanceof Date && !isNaN(parsedDate))) { + return "not valid"; + } + + return parsedDate.toLocaleDateString(AYMETA.ayClientMetaData.LanguageName, { + timeZone: AYMETA.ayClientMetaData.TimeZoneName, + dateStyle: "short" + }); +} +/////////////////////////////////////////// +// Turn a utc date into a displayable +// short time +// +function utcDateToShortTimeLocalized(value) { + if (!value) { + return ""; + } + + //parse the date which is identified as utc ("2020-02-06T18:18:49.148011Z") + let parsedDate = new Date(value); + + //is it a valid date? + if (!(parsedDate instanceof Date && !isNaN(parsedDate))) { + return "not valid"; + } + + return parsedDate.toLocaleTimeString(AYMETA.ayClientMetaData.LanguageName, { + timeZone: AYMETA.ayClientMetaData.TimeZoneName, + timeStyle: "short", + hour12: AYMETA.ayClientMetaData.Hour12 + }); } //////////////////////////////////