diff --git a/src/Money.Api/appsettings.json b/src/Money.Api/appsettings.json index 69353b66..52f3de01 100644 --- a/src/Money.Api/appsettings.json +++ b/src/Money.Api/appsettings.json @@ -14,5 +14,5 @@ "RequireUppercase": false } }, - "UserProperties": [ "PriceDecimalDigits", "DateFormat", "MobileMenu", "SummarySort" ] + "UserProperties": [ "PriceDecimalDigits", "DateFormat", "MobileMenu", "SummarySort", "ExpenseOverviewSort" ] } diff --git a/src/Money.Blazor.Host/Pages/Overview.razor.cs b/src/Money.Blazor.Host/Pages/Overview.razor.cs index 55477c29..ced43a12 100644 --- a/src/Money.Blazor.Host/Pages/Overview.razor.cs +++ b/src/Money.Blazor.Host/Pages/Overview.razor.cs @@ -7,6 +7,7 @@ using Money.Models.Queries; using Money.Models.Sorting; using Money.Services; +using Money.Queries; using Neptuo; using Neptuo.Commands; using Neptuo.Events; @@ -54,7 +55,7 @@ public partial class Overview : protected List Items { get; set; } protected LoadingContext Loading { get; } = new LoadingContext(); - protected SortDescriptor SortDescriptor { get; set; } = new SortDescriptor(OutcomeOverviewSortType.ByWhen, SortDirection.Descending); + protected SortDescriptor SortDescriptor { get; set; } protected PagingContext PagingContext { get; set; } protected override async Task OnInitializedAsync() @@ -65,6 +66,8 @@ protected override async Task OnInitializedAsync() CategoryKey = CreateSelectedCategoryFromParameters(); SelectedPeriod = CreateSelectedItemFromParameters(); + + SortDescriptor = await Queries.QueryAsync(new GetExpenseOverviewSortProperty()); if (!CategoryKey.IsEmpty) { diff --git a/src/Money.Blazor.Host/Pages/Users/Settings.razor b/src/Money.Blazor.Host/Pages/Users/Settings.razor index 26d4c5f3..f5ba42dd 100644 --- a/src/Money.Blazor.Host/Pages/Users/Settings.razor +++ b/src/Money.Blazor.Host/Pages/Users/Settings.razor @@ -55,4 +55,8 @@ + + + + \ No newline at end of file diff --git a/src/Money.Blazor.Host/Pages/Users/Settings.razor.cs b/src/Money.Blazor.Host/Pages/Users/Settings.razor.cs index 316a7c1f..78741d37 100644 --- a/src/Money.Blazor.Host/Pages/Users/Settings.razor.cs +++ b/src/Money.Blazor.Host/Pages/Users/Settings.razor.cs @@ -46,6 +46,9 @@ public partial class Settings : System.IDisposable, protected SortPropertyViewModel SummarySort { get; set; } protected PropertyDialog SummarySortEditor { get; set; } + protected SortPropertyViewModel ExpenseOverviewSort { get; set; } + protected PropertyDialog ExpenseOverviewSortEditor { get; set; } + protected List Models { get; set; } protected List ViewModels { get; } = new List(); @@ -59,6 +62,7 @@ protected async override Task OnInitializedAsync() DateFormat = AddProperty("DateFormat", "Date format", () => DateFormatEditor.Show(), icon: "calendar-day", defaultValue: CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern); MobileMenu = AddProperty("MobileMenu", "Mobile menu", () => MobileMenuEditor.Show(), icon: "mobile"); SummarySort = AddProperty>("SummarySort", "Summary sort", () => SummarySortEditor.Show(), icon: "sort-alpha-down", defaultValue: "ByCategory-Ascending"); + ExpenseOverviewSort = AddProperty>("ExpenseOverviewSort", "Expense overview sort", () => ExpenseOverviewSortEditor.Show(), icon: "sort-alpha-down", defaultValue: "ByWhen-Descending"); await LoadAsync(); } diff --git a/src/Money.Blazor.Host/Queries/GetExpenseOverviewSortProperty.cs b/src/Money.Blazor.Host/Queries/GetExpenseOverviewSortProperty.cs new file mode 100644 index 00000000..5625e214 --- /dev/null +++ b/src/Money.Blazor.Host/Queries/GetExpenseOverviewSortProperty.cs @@ -0,0 +1,19 @@ +using Money.Models; +using Money.Models.Sorting; +using Money.Pages; +using Neptuo.Queries; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Money.Queries +{ + /// + /// A query for getting a sort descriptor for expense overview. + /// + public class GetExpenseOverviewSortProperty : IQuery> + { } +} diff --git a/src/Money.Blazor.Host/Queries/GetSummarySortProperty.cs b/src/Money.Blazor.Host/Queries/GetSummarySortProperty.cs index 73e55ce4..fe05c157 100644 --- a/src/Money.Blazor.Host/Queries/GetSummarySortProperty.cs +++ b/src/Money.Blazor.Host/Queries/GetSummarySortProperty.cs @@ -11,7 +11,7 @@ namespace Money.Queries { /// - /// A query for getting a user defined number of decimal digits or default value. + /// A query for getting a sort descriptor for summary. /// public class GetSummarySortProperty : IQuery> { } diff --git a/src/Money.Blazor.Host/Services/UserPropertyQueryHandler.cs b/src/Money.Blazor.Host/Services/UserPropertyQueryHandler.cs index 053d7fc6..df1ea92b 100644 --- a/src/Money.Blazor.Host/Services/UserPropertyQueryHandler.cs +++ b/src/Money.Blazor.Host/Services/UserPropertyQueryHandler.cs @@ -1,4 +1,5 @@ -using Money.Models.Queries; +using Money.Models; +using Money.Models.Queries; using Money.Models.Sorting; using Money.Queries; using Money.Pages; @@ -30,21 +31,31 @@ public async Task ExecuteAsync(object query, HttpQueryDispatcher dispatc } else if (query is GetSummarySortProperty) { - var value = await dispatcher.QueryAsync(new FindUserProperty("SummarySort")); - if (String.IsNullOrEmpty(value)) - value = "ByCategory-Ascending"; + return await GetSortDescriptorAsync(dispatcher, "SummarySort", "ByCategory-Ascending"); + } + else if (query is GetExpenseOverviewSortProperty) + { + return await GetSortDescriptorAsync(dispatcher, "ExpenseOverviewSort", "ByWhen-Descending"); + } - string[] parts = value.Split('-'); + return await next(query); + } - var result = new SortDescriptor( - Enum.Parse(parts[0], true), - Enum.Parse(parts[1], true) - ); + private async Task> GetSortDescriptorAsync(HttpQueryDispatcher dispatcher, string propertyName, string defaultValue) + where T : struct + { + var value = await dispatcher.QueryAsync(new FindUserProperty(propertyName)); + if (String.IsNullOrEmpty(value)) + value = defaultValue; - return result; - } + string[] parts = value.Split('-'); - return await next(query); + var result = new SortDescriptor( + Enum.Parse(parts[0], true), + Enum.Parse(parts[1], true) + ); + + return result; } private int IntPropertyValue(string value, int defaultValue)