Skip to content

Commit 0514ca4

Browse files
committed
added update date to downloadable addons
1 parent b8bbdbd commit 0514ca4

File tree

7 files changed

+39
-2
lines changed

7 files changed

+39
-2
lines changed

Web.Server/Database/DatabaseContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ private bool FillDb()
125125
IsDisabled = false,
126126
FileSize = addon.FileSize,
127127
Author = addon.Author,
128+
UpdateDate = DateTime.Now.ToUniversalTime()
128129
});
129130

130131
this.SaveChanges();

Web.Server/DbEntities/VersionsDbEntity.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public sealed class VersionsDbEntity
3636
[Column("is_disabled")]
3737
public required bool IsDisabled { get; set; }
3838

39+
[Column("updated")]
40+
public required DateTime UpdateDate { get; set; }
41+
3942

4043
public AddonsDbEntity AddonsTable { get; set; }
4144
}

Web.Server/Providers/AddonsProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ internal List<DownloadableAddonEntity> GetAddons(GameEnum gameEnum)
8585
Author = version.Value.Author,
8686
Dependencies = depsResult,
8787
Installs = hasInstalls ? installsNumber : 0,
88-
Score = hasScore ? scoreNumber : 0
88+
Score = hasScore ? scoreNumber : 0,
89+
UpdateDate = version.Value.UpdateDate
8990
};
9091

9192
result.Add(newDownloadable);
@@ -213,6 +214,7 @@ internal bool AddAddonToDatabase(AddonsJsonEntity addon)
213214
IsDisabled = false,
214215
FileSize = addon.FileSize,
215216
Author = addon.Author,
217+
UpdateDate = DateTime.Now.ToUniversalTime()
216218
});
217219

218220
dbContext.SaveChanges();

src/Avalonia/Core/Controls/DownloadsControl.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
Padding="2"
4848
ItemsSource="{Binding DownloadableList}"
4949
SelectedItem="{Binding SelectedDownloadable}"
50+
SelectionMode="Single"
5051
GridLinesVisibility="Horizontal"
5152
IsReadOnly="True"
5253
CornerRadius="4"
@@ -59,6 +60,7 @@
5960
<DataGridTextColumn Header="Score" Binding="{Binding Score}" />
6061
<DataGridTextColumn Header="Downloads" Binding="{Binding Installs}" />
6162
<DataGridTextColumn Header="Status" Binding="{Binding Status}" FontWeight="Bold" />
63+
<DataGridTextColumn Header="Updated" Binding="{Binding UpdateDateString}" SortMemberPath="UpdateDate" />
6264
</DataGrid.Columns>
6365
</DataGrid>
6466

src/Avalonia/Core/Controls/DownloadsControl.axaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using BuildLauncher.ViewModels;
33
using Common.Helpers;
44
using CommunityToolkit.Mvvm.Input;
5+
using System.ComponentModel;
56

67
namespace BuildLauncher.Controls
78
{

src/Common/Entities/DownloadableAddonEntity.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public sealed class DownloadableAddonEntity : IDownloadableAddon
4747
[JsonPropertyName("Author")]
4848
public string? Author { get; set; }
4949

50+
[JsonPropertyName("UpdateDate")]
51+
public DateTime UpdateDate { get; set; }
52+
5053

5154
[JsonIgnore]
5255
public bool IsInstalled { get; set; }
@@ -75,6 +78,29 @@ public string Status
7578
[JsonIgnore]
7679
public string FileSizeString => FileSize.ToSizeString();
7780

81+
[JsonIgnore]
82+
public string UpdateDateString
83+
{
84+
get
85+
{
86+
var now = DateTime.UtcNow;
87+
var span = now - UpdateDate;
88+
89+
if (span.TotalDays < 1)
90+
{
91+
return "Today";
92+
}
93+
else if (span.TotalDays < 2)
94+
{
95+
return "Yesterday";
96+
}
97+
else
98+
{
99+
return $"{(int)span.TotalDays} days ago";
100+
}
101+
}
102+
}
103+
78104

79105
public string ToMarkdownString()
80106
{

src/Common/Interfaces/IDownloadableAddon.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public interface IDownloadableAddon
1010
string Title { get; set; }
1111
Uri DownloadUrl { get; set; }
1212
long FileSize { get; set; }
13-
string FileSizeString { get; }
1413
string Version { get; set; }
1514
bool HasNewerVersion { get; set; }
1615
bool IsInstalled { get; set; }
@@ -19,6 +18,9 @@ public interface IDownloadableAddon
1918
string? Description { get; set; }
2019
int Installs { get; set; }
2120
int Score { get; set; }
21+
DateTime UpdateDate { get; set; }
22+
string FileSizeString { get; }
23+
string UpdateDateString { get; }
2224

2325
string ToMarkdownString();
2426
}

0 commit comments

Comments
 (0)