Skip to content

Commit

Permalink
Add sorting to Completed Downloads section, at the cost of using plai…
Browse files Browse the repository at this point in the history
…n strings to indicate property paths..
  • Loading branch information
Al12rs committed Jun 26, 2024
1 parent 218a366 commit 39e320d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 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 @@ -69,11 +69,14 @@ public DownloadTaskViewModel(IDownloadTask task)

_task.WhenAnyValue(t => t.PersistentState.Status)
.Where(s => s.Equals(DownloadTaskStatus.Completed))
.Select(_ => _task.PersistentState.Remap<CompletedDownloadState.Model>().CompletedAt)
.OnUI()
.BindTo(this, x => x.CompletedTime)
.DisposeWith(d);

this.WhenAnyValue(vm => vm.CompletedTime)
.CombineLatest(interval)
.Select(_ => _task.PersistentState.Status.Equals(DownloadTaskStatus.Completed)
? _task.PersistentState.Remap<CompletedDownloadState.Model>().CompletedAt.Humanize()
: "-"
)
.Select( value => value.First.Humanize())
.OnUI()
.BindTo(this, x => x.HumanizedCompletedTime)
.DisposeWith(d);
Expand All @@ -89,6 +92,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

0 comments on commit 39e320d

Please sign in to comment.