From 0514ca4bc43f5c3088972433f1c05d243d337af0 Mon Sep 17 00:00:00 2001 From: fgsfds <4870330+fgsfds@users.noreply.github.com> Date: Wed, 29 May 2024 12:13:22 +0500 Subject: [PATCH] added update date to downloadable addons --- Web.Server/Database/DatabaseContext.cs | 1 + Web.Server/DbEntities/VersionsDbEntity.cs | 3 +++ Web.Server/Providers/AddonsProvider.cs | 4 ++- .../Core/Controls/DownloadsControl.axaml | 2 ++ .../Core/Controls/DownloadsControl.axaml.cs | 1 + .../Entities/DownloadableAddonEntity.cs | 26 +++++++++++++++++++ src/Common/Interfaces/IDownloadableAddon.cs | 4 ++- 7 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Web.Server/Database/DatabaseContext.cs b/Web.Server/Database/DatabaseContext.cs index b5e3f731..cedd1e32 100644 --- a/Web.Server/Database/DatabaseContext.cs +++ b/Web.Server/Database/DatabaseContext.cs @@ -125,6 +125,7 @@ private bool FillDb() IsDisabled = false, FileSize = addon.FileSize, Author = addon.Author, + UpdateDate = DateTime.Now.ToUniversalTime() }); this.SaveChanges(); diff --git a/Web.Server/DbEntities/VersionsDbEntity.cs b/Web.Server/DbEntities/VersionsDbEntity.cs index 5eff2f53..4a6a9e43 100644 --- a/Web.Server/DbEntities/VersionsDbEntity.cs +++ b/Web.Server/DbEntities/VersionsDbEntity.cs @@ -36,6 +36,9 @@ public sealed class VersionsDbEntity [Column("is_disabled")] public required bool IsDisabled { get; set; } + [Column("updated")] + public required DateTime UpdateDate { get; set; } + public AddonsDbEntity AddonsTable { get; set; } } diff --git a/Web.Server/Providers/AddonsProvider.cs b/Web.Server/Providers/AddonsProvider.cs index fe4247ea..cc747fd7 100644 --- a/Web.Server/Providers/AddonsProvider.cs +++ b/Web.Server/Providers/AddonsProvider.cs @@ -85,7 +85,8 @@ internal List GetAddons(GameEnum gameEnum) Author = version.Value.Author, Dependencies = depsResult, Installs = hasInstalls ? installsNumber : 0, - Score = hasScore ? scoreNumber : 0 + Score = hasScore ? scoreNumber : 0, + UpdateDate = version.Value.UpdateDate }; result.Add(newDownloadable); @@ -213,6 +214,7 @@ internal bool AddAddonToDatabase(AddonsJsonEntity addon) IsDisabled = false, FileSize = addon.FileSize, Author = addon.Author, + UpdateDate = DateTime.Now.ToUniversalTime() }); dbContext.SaveChanges(); diff --git a/src/Avalonia/Core/Controls/DownloadsControl.axaml b/src/Avalonia/Core/Controls/DownloadsControl.axaml index 88afeb40..a1230ad9 100644 --- a/src/Avalonia/Core/Controls/DownloadsControl.axaml +++ b/src/Avalonia/Core/Controls/DownloadsControl.axaml @@ -47,6 +47,7 @@ Padding="2" ItemsSource="{Binding DownloadableList}" SelectedItem="{Binding SelectedDownloadable}" + SelectionMode="Single" GridLinesVisibility="Horizontal" IsReadOnly="True" CornerRadius="4" @@ -59,6 +60,7 @@ + diff --git a/src/Avalonia/Core/Controls/DownloadsControl.axaml.cs b/src/Avalonia/Core/Controls/DownloadsControl.axaml.cs index 45e7d67b..ddd6858d 100644 --- a/src/Avalonia/Core/Controls/DownloadsControl.axaml.cs +++ b/src/Avalonia/Core/Controls/DownloadsControl.axaml.cs @@ -2,6 +2,7 @@ using BuildLauncher.ViewModels; using Common.Helpers; using CommunityToolkit.Mvvm.Input; +using System.ComponentModel; namespace BuildLauncher.Controls { diff --git a/src/Common/Entities/DownloadableAddonEntity.cs b/src/Common/Entities/DownloadableAddonEntity.cs index 916024cc..45402ff7 100644 --- a/src/Common/Entities/DownloadableAddonEntity.cs +++ b/src/Common/Entities/DownloadableAddonEntity.cs @@ -47,6 +47,9 @@ public sealed class DownloadableAddonEntity : IDownloadableAddon [JsonPropertyName("Author")] public string? Author { get; set; } + [JsonPropertyName("UpdateDate")] + public DateTime UpdateDate { get; set; } + [JsonIgnore] public bool IsInstalled { get; set; } @@ -75,6 +78,29 @@ public string Status [JsonIgnore] public string FileSizeString => FileSize.ToSizeString(); + [JsonIgnore] + public string UpdateDateString + { + get + { + var now = DateTime.UtcNow; + var span = now - UpdateDate; + + if (span.TotalDays < 1) + { + return "Today"; + } + else if (span.TotalDays < 2) + { + return "Yesterday"; + } + else + { + return $"{(int)span.TotalDays} days ago"; + } + } + } + public string ToMarkdownString() { diff --git a/src/Common/Interfaces/IDownloadableAddon.cs b/src/Common/Interfaces/IDownloadableAddon.cs index e581c233..55152c23 100644 --- a/src/Common/Interfaces/IDownloadableAddon.cs +++ b/src/Common/Interfaces/IDownloadableAddon.cs @@ -10,7 +10,6 @@ public interface IDownloadableAddon string Title { get; set; } Uri DownloadUrl { get; set; } long FileSize { get; set; } - string FileSizeString { get; } string Version { get; set; } bool HasNewerVersion { get; set; } bool IsInstalled { get; set; } @@ -19,6 +18,9 @@ public interface IDownloadableAddon string? Description { get; set; } int Installs { get; set; } int Score { get; set; } + DateTime UpdateDate { get; set; } + string FileSizeString { get; } + string UpdateDateString { get; } string ToMarkdownString(); }