Skip to content

Commit

Permalink
added update date to downloadable addons
Browse files Browse the repository at this point in the history
  • Loading branch information
fgsfds committed May 29, 2024
1 parent b8bbdbd commit 0514ca4
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions Web.Server/Database/DatabaseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ private bool FillDb()
IsDisabled = false,
FileSize = addon.FileSize,
Author = addon.Author,
UpdateDate = DateTime.Now.ToUniversalTime()
});

this.SaveChanges();
Expand Down
3 changes: 3 additions & 0 deletions Web.Server/DbEntities/VersionsDbEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
Expand Down
4 changes: 3 additions & 1 deletion Web.Server/Providers/AddonsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ internal List<DownloadableAddonEntity> 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);
Expand Down Expand Up @@ -213,6 +214,7 @@ internal bool AddAddonToDatabase(AddonsJsonEntity addon)
IsDisabled = false,
FileSize = addon.FileSize,
Author = addon.Author,
UpdateDate = DateTime.Now.ToUniversalTime()
});

dbContext.SaveChanges();
Expand Down
2 changes: 2 additions & 0 deletions src/Avalonia/Core/Controls/DownloadsControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
Padding="2"
ItemsSource="{Binding DownloadableList}"
SelectedItem="{Binding SelectedDownloadable}"
SelectionMode="Single"
GridLinesVisibility="Horizontal"
IsReadOnly="True"
CornerRadius="4"
Expand All @@ -59,6 +60,7 @@
<DataGridTextColumn Header="Score" Binding="{Binding Score}" />
<DataGridTextColumn Header="Downloads" Binding="{Binding Installs}" />
<DataGridTextColumn Header="Status" Binding="{Binding Status}" FontWeight="Bold" />
<DataGridTextColumn Header="Updated" Binding="{Binding UpdateDateString}" SortMemberPath="UpdateDate" />
</DataGrid.Columns>
</DataGrid>

Expand Down
1 change: 1 addition & 0 deletions src/Avalonia/Core/Controls/DownloadsControl.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using BuildLauncher.ViewModels;
using Common.Helpers;
using CommunityToolkit.Mvvm.Input;
using System.ComponentModel;

namespace BuildLauncher.Controls
{
Expand Down
26 changes: 26 additions & 0 deletions src/Common/Entities/DownloadableAddonEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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()
{
Expand Down
4 changes: 3 additions & 1 deletion src/Common/Interfaces/IDownloadableAddon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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();
}
Expand Down

0 comments on commit 0514ca4

Please sign in to comment.