Skip to content

Commit

Permalink
Merge pull request #1690 from Nexus-Mods/fix/datagrid-sorting
Browse files Browse the repository at this point in the history
Fix DataGrid sorting
  • Loading branch information
Al12rs authored Jun 26, 2024
2 parents f2bbcb4 + 567f69a commit 7550468
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 20 deletions.
15 changes: 10 additions & 5 deletions src/NexusMods.App.UI/Pages/Downloads/InProgressView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@
Width="1">
<DataGrid.Columns>
<DataGridTemplateColumn Header="{x:Static resources:Language.Helpers_GenerateHeader_MOD_NAME}"
Width="*">
Width="*"
SortMemberPath="Name">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="viewModels:IDownloadTaskViewModel">
<TextBlock Classes="BodyMDNormal"
Expand All @@ -175,7 +176,8 @@
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

<DataGridTemplateColumn Header="{x:Static resources:Language.Helpers_GenerateHeader_VERSION}">
<DataGridTemplateColumn Header="{x:Static resources:Language.Helpers_GenerateHeader_VERSION}"
SortMemberPath="Version">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="viewModels:IDownloadTaskViewModel">
<TextBlock Classes="BodyMDNormal"
Expand All @@ -185,7 +187,8 @@
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

<DataGridTemplateColumn Header="{x:Static resources:Language.Helpers_GenerateHeader_GAME}">
<DataGridTemplateColumn Header="{x:Static resources:Language.Helpers_GenerateHeader_GAME}"
SortMemberPath="Game">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="viewModels:IDownloadTaskViewModel">
<TextBlock Classes="BodyMDNormal"
Expand All @@ -195,7 +198,8 @@
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

<DataGridTemplateColumn Header="{x:Static resources:Language.Helpers_GenerateHeader_SIZE}">
<DataGridTemplateColumn Header="{x:Static resources:Language.Helpers_GenerateHeader_SIZE}"
SortMemberPath="SizeBytes">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="viewModels:IDownloadTaskViewModel">
<TextBlock Classes="BodyMDNormal"
Expand All @@ -205,7 +209,8 @@
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

<DataGridTemplateColumn Header="{x:Static resources:Language.DownloadCompleted_COMPLETED}">
<DataGridTemplateColumn Header="{x:Static resources:Language.DownloadCompleted_COMPLETED}"
SortMemberPath="CompletedTime">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="viewModels:IDownloadTaskViewModel">
<TextBlock Classes="BodyMDNormal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class DownloadTaskDesignViewModel : AViewModel<IDownloadTaskViewModel>, I
public string Version { get; set; } = "1.0.0";
public string Game { get; set; } = "Unknown Game";
public string HumanizedSize => ByteSize.FromBytes(SizeBytes).ToString();
public DateTime CompletedTime { get; }
public string HumanizedCompletedTime { get; } = "-";
public DownloadTaskStatus Status { get; set; } = DownloadTaskStatus.Idle;
public EntityId TaskId { get; set; } = EntityId.From(1024);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,21 @@ public DownloadTaskViewModel(IDownloadTask task)

_task.WhenAnyValue(t => t.PersistentState.Status)
.Where(s => s.Equals(DownloadTaskStatus.Completed))
.CombineLatest(interval)
.Select(_ =>
{
var isCompleted = _task.PersistentState.TryGetAsCompletedDownloadState(out var completed);

return _task.PersistentState.Status.Equals(DownloadTaskStatus.Completed) && isCompleted
? completed.CompletedDateTime.Humanize()
: "-";
}
)
{
var dlIsCompleted = _task.PersistentState.TryGetAsCompletedDownloadState(out var completedDl);

return _task.PersistentState.Status.Equals(DownloadTaskStatus.Completed) && dlIsCompleted
? completedDl.CompletedDateTime
: DateTime.MinValue;
})
.OnUI()
.BindTo(this, x => x.CompletedTime)
.DisposeWith(d);

this.WhenAnyValue(vm => vm.CompletedTime)
.CombineLatest(interval)
.Select(tuple => tuple.First.Equals(DateTime.MinValue) ? "-" : tuple.First.Humanize())
.OnUI()
.BindTo(this, x => x.HumanizedCompletedTime)
.DisposeWith(d);
Expand All @@ -98,6 +103,8 @@ public DownloadTaskViewModel(IDownloadTask task)

public string HumanizedSize => ByteSize.FromBytes(SizeBytes).ToString();

[Reactive] public DateTime CompletedTime { get; set; }

[Reactive] public string HumanizedCompletedTime { get; set; } = "-";

public EntityId TaskId => _task.PersistentState.Id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reactive;
using JetBrains.Annotations;
using NexusMods.App.UI.Controls.Navigation;
using NexusMods.MnemonicDB.Abstractions;
using NexusMods.Networking.Downloaders.Interfaces;
Expand Down Expand Up @@ -34,6 +35,13 @@ public interface IDownloadTaskViewModel : IViewModelInterface
/// </summary>
public string HumanizedSize { get; }

/// <summary>
/// The DateTime when the download was completed
/// Used for sorting and filtering.
/// </summary>
[UsedImplicitly]
public DateTime CompletedTime { get; }

/// <summary>
/// The DateTime when the download was completed in humanized string format.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTemplateColumn Header="{x:Static resources:Language.FileOriginsPageView_NameHeader}"
Width="*">
Width="*"
SortMemberPath="Name">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="fileOriginEntry:IFileOriginEntryViewModel">
<TextBlock Classes="BodyMDNormal"
Expand All @@ -93,7 +94,8 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="{x:Static resources:Language.FileOriginsPageView_VersionHeader}">
<DataGridTemplateColumn Header="{x:Static resources:Language.FileOriginsPageView_VersionHeader}"
SortMemberPath="Version">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="fileOriginEntry:IFileOriginEntryViewModel">
<TextBlock Classes="BodyMDNormal"
Expand All @@ -102,7 +104,8 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="{x:Static resources:Language.FileOriginsPageView_SizeHeader}">
<DataGridTemplateColumn Header="{x:Static resources:Language.FileOriginsPageView_SizeHeader}"
SortMemberPath="Size">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="fileOriginEntry:IFileOriginEntryViewModel">
<TextBlock Classes="BodyMDNormal"
Expand All @@ -111,7 +114,8 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="{x:Static resources:Language.FileOriginsPageView_DownloadedHeader}">
<DataGridTemplateColumn Header="{x:Static resources:Language.FileOriginsPageView_DownloadedHeader}"
SortMemberPath="DisplayArchiveDate">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="fileOriginEntry:IFileOriginEntryViewModel">
<TextBlock Classes="BodyMDNormal"
Expand All @@ -120,7 +124,8 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="{x:Static resources:Language.FileOriginsPageView_InstalledHeader}">
<DataGridTemplateColumn Header="{x:Static resources:Language.FileOriginsPageView_InstalledHeader}"
SortMemberPath="DisplayLastInstalledDate">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="fileOriginEntry:IFileOriginEntryViewModel">
<TextBlock Classes="BodyMDNormal"
Expand All @@ -129,7 +134,9 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="{x:Static resources:Language.FileOriginsPageView_ActionHeader}" MinWidth="102">
<DataGridTemplateColumn Header="{x:Static resources:Language.FileOriginsPageView_ActionHeader}"
MinWidth="102"
SortMemberPath="IsModAddedToLoadout">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="fileOriginEntry:IFileOriginEntryViewModel">
<Grid>
Expand Down

0 comments on commit 7550468

Please sign in to comment.