Skip to content

Commit

Permalink
Improve Data Dictionary list readability at Last Modified Date
Browse files Browse the repository at this point in the history
  • Loading branch information
gumbarros committed Jan 3, 2025
1 parent a1934c0 commit c228258
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/Commons/Configuration/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,5 +78,7 @@ private static void AddMasterDataCommonsServices(this IServiceCollection service
services.AddTransient<IEncryptionService, EncryptionService>();

services.AddSingleton<IBackgroundTaskManager, BackgroundTaskManager>();

services.AddTransient<DateService>();
}
}
33 changes: 33 additions & 0 deletions src/Commons/Localization/MasterDataResources.pt-BR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -4117,4 +4117,37 @@
<data name="Copy From..." xml:space="preserve">
<value>Copiar De...</value>
</data>
<data name="Just now" xml:space="preserve">
<value>Agora mesmo</value>
</data>
<data name="1 minute ago" xml:space="preserve">
<value>Há 1 minuto</value>
</data>
<data name="{0} minutes ago" xml:space="preserve">
<value>Há {0} minutos</value>
</data>
<data name="1 hour ago" xml:space="preserve">
<value>Há 1 hora</value>
</data>
<data name="{0} hours ago" xml:space="preserve">
<value>Há {0} horas</value>
</data>
<data name="1 day ago" xml:space="preserve">
<value>Há 1 dia</value>
</data>
<data name="{0} days ago" xml:space="preserve">
<value>Há {0} dias</value>
</data>
<data name="{0} months and 1 day ago" xml:space="preserve">
<value>Há {0} meses e 1 dia</value>
</data>
<data name="{0} months and {1} days ago" xml:space="preserve">
<value>Há {0} meses e {1} dias</value>
</data>
<data name="1 year ago" xml:space="preserve">
<value>Há 1 ano</value>
</data>
<data name="{0} years ago" xml:space="preserve">
<value>Há {0} anos</value>
</data>
</root>
64 changes: 64 additions & 0 deletions src/Commons/Util/DateService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using JJMasterData.Commons.Localization;
using Microsoft.Extensions.Localization;

namespace JJMasterData.Commons.Util;

public class DateService(IStringLocalizer<MasterDataResources> 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];
}
}
20 changes: 17 additions & 3 deletions src/Core/DataDictionary/Services/ElementService.cs
Original file line number Diff line number Diff line change
@@ -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;


Expand All @@ -23,6 +27,7 @@ public class ElementService(
IEntityRepository entityRepository,
IDataDictionaryRepository dataDictionaryRepository,
DataDictionaryFormElementFactory dataDictionaryFormElementFactory,
DateService dateService,
IUrlHelper urlHelper)
: DataDictionaryServiceBase(validationDictionary, dataDictionaryRepository, stringLocalizer)
{
Expand Down Expand Up @@ -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;
};
Expand Down
4 changes: 2 additions & 2 deletions src/Core/DataDictionary/Structure/DataDictionaryStructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c228258

Please sign in to comment.