From b60dc75c8e5aa825eb911e480a73de7f93aaaecf Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 28 Aug 2018 00:03:06 +0000 Subject: [PATCH] --- .../UserLocaleIdFromContext.cs | 20 ++++++++++++++ .../AyaNova/Controllers/EventLogController.cs | 4 +-- server/AyaNova/Startup.cs | 13 +++++----- server/AyaNova/biz/EventLogProcessor.cs | 26 ++++++++++++++++--- server/AyaNova/biz/LocaleBiz.cs | 17 +++++++++++- server/AyaNova/resource/de.json | 5 +++- server/AyaNova/resource/en.json | 5 +++- server/AyaNova/resource/es.json | 5 +++- server/AyaNova/resource/fr.json | 7 +++-- 9 files changed, 85 insertions(+), 17 deletions(-) create mode 100644 server/AyaNova/ControllerHelpers/UserLocaleIdFromContext.cs diff --git a/server/AyaNova/ControllerHelpers/UserLocaleIdFromContext.cs b/server/AyaNova/ControllerHelpers/UserLocaleIdFromContext.cs new file mode 100644 index 00000000..1ac10840 --- /dev/null +++ b/server/AyaNova/ControllerHelpers/UserLocaleIdFromContext.cs @@ -0,0 +1,20 @@ +using EnumsNET; +using System.Collections.Generic; + +namespace AyaNova.Api.ControllerHelpers +{ + + internal static class UserLocaleIdFromContext + { + internal static long LocaleId(IDictionary HttpContextItems) + { + + long? l = (long?)HttpContextItems["AY_LOCALE_ID"]; + if (l==null) + return 0L; + return (long)l; + } + } + + +}//eons \ No newline at end of file diff --git a/server/AyaNova/Controllers/EventLogController.cs b/server/AyaNova/Controllers/EventLogController.cs index 20fa34eb..8aefc594 100644 --- a/server/AyaNova/Controllers/EventLogController.cs +++ b/server/AyaNova/Controllers/EventLogController.cs @@ -67,7 +67,7 @@ namespace AyaNova.Api.Controllers return StatusCode(401, new ApiNotAuthorizedResponse()); } - var result = await EventLogProcessor.GetLogForObject(opt.AyId, ct); + var result = await EventLogProcessor.GetLogForObject(opt.AyId, UserLocaleIdFromContext.LocaleId(HttpContext.Items), ct); //Log EventLogProcessor.AddEntry(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.Metrics, AyaEvent.Retrieved), ct); @@ -107,7 +107,7 @@ namespace AyaNova.Api.Controllers return StatusCode(401, new ApiNotAuthorizedResponse()); } - var result = await EventLogProcessor.GetLogForUser(opt.AyId, ct); + var result = await EventLogProcessor.GetLogForUser(opt.AyId, UserLocaleIdFromContext.LocaleId(HttpContext.Items), ct); //Log EventLogProcessor.AddEntry(new Event(UserId, 0, AyaType.Metrics, AyaEvent.Retrieved), ct); diff --git a/server/AyaNova/Startup.cs b/server/AyaNova/Startup.cs index 3118550a..bef694a0 100644 --- a/server/AyaNova/Startup.cs +++ b/server/AyaNova/Startup.cs @@ -41,7 +41,7 @@ namespace AyaNova _hostingEnvironment = hostingEnvironment; AyaNova.Util.ApplicationLogging.LoggerFactory = logFactory; //this must be set here - ServerBootConfig.AYANOVA_CONTENT_ROOT_PATH=hostingEnvironment.ContentRootPath; + ServerBootConfig.AYANOVA_CONTENT_ROOT_PATH = hostingEnvironment.ContentRootPath; } @@ -337,10 +337,11 @@ namespace AyaNova var ct = context.RequestServices.GetService(); //get the user record - var u = ct.User.AsNoTracking().Where(a => a.Id == userId).Select(m => new { roles = m.Roles, name = m.Name, Id = m.Id }).First(); + var u = ct.User.AsNoTracking().Where(a => a.Id == userId).Select(m => new { roles = m.Roles, name = m.Name, Id = m.Id, LocaleId = m.LocaleId }).First(); context.Request.HttpContext.Items["AY_ROLES"] = u.roles; context.Request.HttpContext.Items["AY_USERNAME"] = u.name; context.Request.HttpContext.Items["AY_USER_ID"] = u.Id; + context.Request.HttpContext.Items["AY_LOCALE_ID"] = u.LocaleId; } await next.Invoke(); }); @@ -384,13 +385,13 @@ namespace AyaNova // AyaNova.Core.License.Initialize(apiServerState, dbContext, _log); // AyaNova.Core.License.Fetch(apiServerState, dbContext, _log); // Util.Seeder.SeedDatabase(dbContext, Util.Seeder.SeedLevel.SmallOneManShopTrialDataSet); - + #endif - - - + + + //Open up the server for visitors apiServerState.SetOpen(); diff --git a/server/AyaNova/biz/EventLogProcessor.cs b/server/AyaNova/biz/EventLogProcessor.cs index 2421d718..24781a12 100644 --- a/server/AyaNova/biz/EventLogProcessor.cs +++ b/server/AyaNova/biz/EventLogProcessor.cs @@ -43,12 +43,32 @@ namespace AyaNova.Biz ct.SaveChanges(); } - internal static Task GetLogForObject(long ayId, AyContext ct) + /// + /// Get the event log for a specified object + /// + /// + /// + /// + /// + internal static async Task GetLogForObject(long ayId, long userLocaleId, AyContext ct) { - throw new NotImplementedException(); + var items = await ct.Event + .Where(m => m.AyId == ayId) + .OrderBy(m => m.Created) + .ToListAsync(); + + AyaNova.Api.Controllers.LocaleController.LocaleSubsetParam param = new Api.Controllers.LocaleController.LocaleSubsetParam(); + param.LocaleId = userLocaleId; + param.Keys.AddRange(new string[] { "CommonCreated", "Delete","Modified","Retrieved" }); + var LT = LocaleBiz.GetSubsetStatic(param); + + //Have list of locales + + return null; + } - internal static Task GetLogForUser(long ayId, AyContext ct) + internal static Task GetLogForUser(long ayId, long userLocaleId, AyContext ct) { throw new NotImplementedException(); } diff --git a/server/AyaNova/biz/LocaleBiz.cs b/server/AyaNova/biz/LocaleBiz.cs index 3901efd0..71b53d5c 100644 --- a/server/AyaNova/biz/LocaleBiz.cs +++ b/server/AyaNova/biz/LocaleBiz.cs @@ -103,6 +103,16 @@ namespace AyaNova.Biz return ret.ToList(); } + //Get the keys for a list of keys provided, static format for calling from other internal classes + internal static async Task>> GetSubsetStatic(AyaNova.Api.Controllers.LocaleController.LocaleSubsetParam param) + { + AyContext ct = ServiceProviderProvider.DBContext; + if (!LocaleExistsStatic(param.LocaleId, ct)) + param.LocaleId = ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID; + var ret = await ct.LocaleItem.Where(x => x.LocaleId == param.LocaleId && param.Keys.Contains(x.Key)).ToDictionaryAsync(x => x.Key, x => x.Display); + return ret.ToList(); + } + /// /// Get the value of the key provided in the default locale chosen @@ -133,7 +143,7 @@ namespace AyaNova.Biz internal bool PutLocaleItemDisplayText(LocaleItem dbObj, NewTextIdConcurrencyTokenItem inObj, Locale dbParent) { - if (dbParent.Stock == true) + if (dbParent.Stock == true) { AddError(ValidationErrorType.InvalidOperation, "object", "LocaleItem is from a Stock locale and cannot be modified"); return false; @@ -271,6 +281,11 @@ namespace AyaNova.Biz return ct.Locale.Any(e => e.Id == id); } + public static bool LocaleExistsStatic(long id, AyContext ct) + { + return ct.Locale.Any(e => e.Id == id); + } + public bool LocaleItemExists(long id) { return ct.LocaleItem.Any(e => e.Id == id); diff --git a/server/AyaNova/resource/de.json b/server/AyaNova/resource/de.json index e9f67a20..9192442b 100644 --- a/server/AyaNova/resource/de.json +++ b/server/AyaNova/resource/de.json @@ -1411,5 +1411,8 @@ "WorkorderStatusName": "Arbeitsauftragsstatus - Name", "WorkorderStatusUnderlined": "Unterstrichen", "WorkorderSummaryTemplate": "Arbeitsauftragspostenzusammenfassung - Vorlage", - "WorkorderSummaryWorkorderItem": "Anzuzeigende Informationen über Arbeitsauftragsposten" + "WorkorderSummaryWorkorderItem": "Anzuzeigende Informationen über Arbeitsauftragsposten", + + "Modified":"Modified", + "Retrieved":"Retrieved" } \ No newline at end of file diff --git a/server/AyaNova/resource/en.json b/server/AyaNova/resource/en.json index 677f8b48..fc73f6a6 100644 --- a/server/AyaNova/resource/en.json +++ b/server/AyaNova/resource/en.json @@ -1411,5 +1411,8 @@ "WorkorderStatusName": "Workorder Status Name", "WorkorderStatusUnderlined": "Underlined", "WorkorderSummaryTemplate": "Workorder Item Summary Template", - "WorkorderSummaryWorkorderItem": "Workorder Item Info To Display" + "WorkorderSummaryWorkorderItem": "Workorder Item Info To Display", + + "Modified":"Modified", + "Retrieved":"Retrieved" } \ No newline at end of file diff --git a/server/AyaNova/resource/es.json b/server/AyaNova/resource/es.json index 092927cc..5b5de510 100644 --- a/server/AyaNova/resource/es.json +++ b/server/AyaNova/resource/es.json @@ -1411,5 +1411,8 @@ "WorkorderStatusName": "Nombre estado del pedido", "WorkorderStatusUnderlined": "Subrayado", "WorkorderSummaryTemplate": "Plantilla resumen elemento pedido", - "WorkorderSummaryWorkorderItem": "Información mostrada elemento de pedido" + "WorkorderSummaryWorkorderItem": "Información mostrada elemento de pedido", + + "Modified":"Modified", + "Retrieved":"Retrieved" } \ No newline at end of file diff --git a/server/AyaNova/resource/fr.json b/server/AyaNova/resource/fr.json index 9e916cc8..60fb1b7a 100644 --- a/server/AyaNova/resource/fr.json +++ b/server/AyaNova/resource/fr.json @@ -1411,5 +1411,8 @@ "WorkorderStatusName": "Nom d'état de bon de travail", "WorkorderStatusUnderlined": "Souligné", "WorkorderSummaryTemplate": "Modèle de résumé d'élément de bon de travail", - "WorkorderSummaryWorkorderItem": "Infos de bon de travail à afficher" -} \ No newline at end of file + "WorkorderSummaryWorkorderItem": "Infos de bon de travail à afficher", + + "Modified": "Modified", + "Retrieved":"Retrieved" +}