diff --git a/src/Commons/Configuration/ServiceCollectionExtensions.cs b/src/Commons/Configuration/ServiceCollectionExtensions.cs index 83ebbee63..93eea2fb1 100644 --- a/src/Commons/Configuration/ServiceCollectionExtensions.cs +++ b/src/Commons/Configuration/ServiceCollectionExtensions.cs @@ -8,6 +8,7 @@ using JJMasterData.Commons.Security.Cryptography; using JJMasterData.Commons.Security.Cryptography.Abstractions; using JJMasterData.Commons.Tasks; +using JJMasterData.Commons.Util; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Localization; @@ -77,5 +78,7 @@ private static void AddMasterDataCommonsServices(this IServiceCollection service services.AddTransient(); services.AddSingleton(); + + services.AddTransient(); } } \ No newline at end of file diff --git a/src/Commons/Localization/MasterDataResources.pt-BR.resx b/src/Commons/Localization/MasterDataResources.pt-BR.resx index d29fba4d0..bd2487975 100644 --- a/src/Commons/Localization/MasterDataResources.pt-BR.resx +++ b/src/Commons/Localization/MasterDataResources.pt-BR.resx @@ -4117,4 +4117,37 @@ Copiar De... + + Agora mesmo + + + Há 1 minuto + + + Há {0} minutos + + + Há 1 hora + + + Há {0} horas + + + Há 1 dia + + + Há {0} dias + + + Há {0} meses e 1 dia + + + Há {0} meses e {1} dias + + + Há 1 ano + + + Há {0} anos + diff --git a/src/Commons/Util/DateService.cs b/src/Commons/Util/DateService.cs new file mode 100644 index 000000000..766d9200a --- /dev/null +++ b/src/Commons/Util/DateService.cs @@ -0,0 +1,64 @@ +using System; +using JJMasterData.Commons.Localization; +using Microsoft.Extensions.Localization; + +namespace JJMasterData.Commons.Util; + +public class DateService(IStringLocalizer localizer) +{ + public string GetPhrase(DateTime date) + { + var timeDifference = DateTime.Now - date; + + if (date == DateTime.MinValue) + { + return localizer["Never"]; + } + + if (timeDifference.TotalSeconds < 60) + { + return localizer["Just now"]; + } + + if (timeDifference.TotalMinutes < 60) + { + int minutes = (int)timeDifference.TotalMinutes; + return minutes == 1 + ? localizer["1 minute ago"] + : localizer["{0} minutes ago", minutes]; + } + if (timeDifference.TotalHours < 24) + { + int hours = (int)timeDifference.TotalHours; + return hours == 1 + ? localizer["1 hour ago"] + : localizer["{0} hours ago", hours]; + } + if (timeDifference.TotalDays < 30) + { + int days = (int)timeDifference.TotalDays; + return days == 1 + ? localizer["1 day ago"] + : localizer["{0} days ago", days]; + } + if (timeDifference.TotalDays < 365) + { + int months = (int)(timeDifference.TotalDays / 30); + int remainingDays = (int)(timeDifference.TotalDays % 30); + if (remainingDays == 1) + { + return months == 0 + ? localizer["1 day ago"] + : localizer["{0} months and 1 day ago", months]; + } + + return months == 0 + ? localizer["{0} days ago", remainingDays] + : localizer["{0} months and {1} days ago", months, remainingDays]; + } + int years = (int)(timeDifference.TotalDays / 365); + return years == 1 + ? localizer["1 year ago"] + : localizer["{0} years ago", years]; + } +} \ No newline at end of file diff --git a/src/Core/DataDictionary/Services/ElementService.cs b/src/Core/DataDictionary/Services/ElementService.cs index 54cbd0569..1a3a9a3c6 100644 --- a/src/Core/DataDictionary/Services/ElementService.cs +++ b/src/Core/DataDictionary/Services/ElementService.cs @@ -1,16 +1,20 @@ #nullable enable +using System; +using System.Globalization; using System.Threading.Tasks; using JJMasterData.Commons.Configuration.Options; using JJMasterData.Commons.Data.Entity.Repository; using JJMasterData.Commons.Data.Entity.Repository.Abstractions; using JJMasterData.Commons.Localization; +using JJMasterData.Commons.Util; using JJMasterData.Core.DataDictionary.Models; using JJMasterData.Core.DataDictionary.Repository.Abstractions; using JJMasterData.Core.DataDictionary.Structure; using JJMasterData.Core.Http.Abstractions; using JJMasterData.Core.Tasks; using JJMasterData.Core.UI.Components; +using JJMasterData.Core.UI.Html; using Microsoft.Extensions.Localization; @@ -23,6 +27,7 @@ public class ElementService( IEntityRepository entityRepository, IDataDictionaryRepository dataDictionaryRepository, DataDictionaryFormElementFactory dataDictionaryFormElementFactory, + DateService dateService, IUrlHelper urlHelper) : DataDictionaryServiceBase(validationDictionary, dataDictionaryRepository, stringLocalizer) { @@ -156,15 +161,24 @@ await DataDictionaryRepository.GetFormElementInfoListAsync(filter, args.OrderBy, { if (args.Field.Name == DataDictionaryStructure.Name) { - if (args.DataRow.TryGetValue("info", out var info) && !string.IsNullOrWhiteSpace(info?.ToString())) + var info = args.DataRow[DataDictionaryStructure.Info]?.ToString(); + if (!string.IsNullOrWhiteSpace(info)) { - args.HtmlResult?.AppendSpan(span => + args.HtmlResult!.AppendSpan(span => { span.WithCssClass("fa fa-question-circle help-description"); - span.WithToolTip(info?.ToString()); + span.WithToolTip(info); }); } } + + if (args.Field.Name == DataDictionaryStructure.LastModified) + { + var lastModified = (DateTime)args.DataRow[DataDictionaryStructure.LastModified]!; + args.HtmlResult = new HtmlBuilder(HtmlTag.Span) + .WithToolTip(lastModified.ToString(CultureInfo.CurrentCulture)) + .AppendText(dateService.GetPhrase(lastModified)); + } return ValueTaskHelper.CompletedTask; }; diff --git a/src/Core/DataDictionary/Structure/DataDictionaryStructure.cs b/src/Core/DataDictionary/Structure/DataDictionaryStructure.cs index 6c9fcf5fe..558d22d79 100644 --- a/src/Core/DataDictionary/Structure/DataDictionaryStructure.cs +++ b/src/Core/DataDictionary/Structure/DataDictionaryStructure.cs @@ -24,8 +24,8 @@ public static Element GetElement(string tableName) var element = new Element(tableName, "Data Dictionary"); element.Fields.AddPk(Type, "Type", FieldType.Varchar, 1, false, FilterMode.Equal); element.Fields[Type].EnableOnDelete = false; - element.Fields.AddPk(Name, "Element Name", FieldType.NVarchar, 64, false, FilterMode.Equal); - element.Fields.Add(TableName, "Table Name", FieldType.NVarchar, -1, false, FilterMode.MultValuesContain); + element.Fields.AddPk(Name, "Element", FieldType.NVarchar, 64, false, FilterMode.Equal); + element.Fields.Add(TableName, "Table", FieldType.NVarchar, -1, false, FilterMode.MultValuesContain); element.Fields.Add(Json, "Filter For Anything", FieldType.NVarchar, -1, false, FilterMode.Contain); element.Fields.Add(Info, "Info", FieldType.NVarchar, 150, false, FilterMode.None); element.Fields.Add(Owner, "Owner", FieldType.NVarchar, 64, false, FilterMode.None);