From 0402c8d566c24c0c33722cec5cfdf2ca692cdc3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Sat, 4 Jun 2022 07:19:47 +0200 Subject: [PATCH] #383 - User property for summary sorting. --- src/Money.Api/appsettings.json | 2 +- src/Money.Blazor.Host/Pages/Summary.razor.cs | 3 ++- .../Pages/Users/Settings.razor | 22 +++++++++++++++++++ .../Pages/Users/Settings.razor.cs | 20 +++++++++++++++++ .../Queries/GetSummarySortProperty.cs | 18 +++++++++++++++ .../Services/UserPropertyQueryHandler.cs | 18 +++++++++++++++ 6 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 src/Money.Blazor.Host/Queries/GetSummarySortProperty.cs diff --git a/src/Money.Api/appsettings.json b/src/Money.Api/appsettings.json index d97baad2..69353b66 100644 --- a/src/Money.Api/appsettings.json +++ b/src/Money.Api/appsettings.json @@ -14,5 +14,5 @@ "RequireUppercase": false } }, - "UserProperties": [ "PriceDecimalDigits", "DateFormat", "MobileMenu" ] + "UserProperties": [ "PriceDecimalDigits", "DateFormat", "MobileMenu", "SummarySort" ] } diff --git a/src/Money.Blazor.Host/Pages/Summary.razor.cs b/src/Money.Blazor.Host/Pages/Summary.razor.cs index 5957a7a5..97071815 100644 --- a/src/Money.Blazor.Host/Pages/Summary.razor.cs +++ b/src/Money.Blazor.Host/Pages/Summary.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; @@ -75,10 +76,10 @@ protected override async Task OnInitializedAsync() { Log.Debug("Summary.OnInitializedAsync"); BindEvents(); - SortDescriptor = new SortDescriptor(SummarySortType.ByCategory, SortDirection.Ascending); await base.OnInitializedAsync(); + SortDescriptor = await Queries.QueryAsync(new GetSummarySortProperty()); formatter = await CurrencyFormatterFactory.CreateAsync(); } diff --git a/src/Money.Blazor.Host/Pages/Users/Settings.razor b/src/Money.Blazor.Host/Pages/Users/Settings.razor index c236eeff..9d7b8dd0 100644 --- a/src/Money.Blazor.Host/Pages/Users/Settings.razor +++ b/src/Money.Blazor.Host/Pages/Users/Settings.razor @@ -63,4 +63,26 @@ + + + + +
+ + +
+
+ + +
+
+ + +
\ 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 85f7a786..3862faa9 100644 --- a/src/Money.Blazor.Host/Pages/Users/Settings.razor.cs +++ b/src/Money.Blazor.Host/Pages/Users/Settings.razor.cs @@ -42,6 +42,11 @@ public partial class Settings : System.IDisposable, protected List MobileMenuAvailableModels { get; set; } protected List MobileSelectedIdentifiers { get; set; } + protected PropertyViewModel SummarySort { get; set; } + protected Modal SummarySortEditor { get; set; } + protected string SummarySortProperty { get; set; } + protected string SummarySortDirection { get; set; } + protected List Models { get; set; } protected List ViewModels { get; } = new List(); @@ -54,6 +59,7 @@ protected async override Task OnInitializedAsync() PriceDecimals = AddProperty("PriceDecimalDigits", "Price decimal digits", () => PriceDecimalsEditor.Show(), icon: "pound-sign", defaultValue: "2"); 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"); MobileMenuAvailableModels = await Queries.QueryAsync(new ListAvailableMenuItem()); @@ -62,6 +68,13 @@ protected async override Task OnInitializedAsync() MobileSelectedIdentifiers = MobileMenu.CurrentValue != null ? MobileMenu.CurrentValue.Split(',').ToList() : new List(0); + + if (SummarySort.CurrentValue != null) + { + string[] parts = SummarySort.CurrentValue.Split('-'); + SummarySortProperty = parts[0]; + SummarySortDirection = parts[1]; + } } public void Dispose() @@ -91,6 +104,13 @@ protected async Task SetMobileMenuAsync() MobileMenuEditor.Hide(); } + protected async Task SetSummarySortAsync() + { + SummarySort.CurrentValue = $"{SummarySortProperty}-{SummarySortDirection}"; + await SummarySort.SetAsync(); + SummarySortEditor.Hide(); + } + Task IEventHandler.HandleAsync(UserPropertyChanged payload) { var viewModel = ViewModels.FirstOrDefault(vm => vm.Key == payload.PropertyKey); diff --git a/src/Money.Blazor.Host/Queries/GetSummarySortProperty.cs b/src/Money.Blazor.Host/Queries/GetSummarySortProperty.cs new file mode 100644 index 00000000..73e55ce4 --- /dev/null +++ b/src/Money.Blazor.Host/Queries/GetSummarySortProperty.cs @@ -0,0 +1,18 @@ +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 user defined number of decimal digits or default value. + /// + public class GetSummarySortProperty : IQuery> + { } +} diff --git a/src/Money.Blazor.Host/Services/UserPropertyQueryHandler.cs b/src/Money.Blazor.Host/Services/UserPropertyQueryHandler.cs index 0d99ffde..053d7fc6 100644 --- a/src/Money.Blazor.Host/Services/UserPropertyQueryHandler.cs +++ b/src/Money.Blazor.Host/Services/UserPropertyQueryHandler.cs @@ -1,8 +1,11 @@ using Money.Models.Queries; +using Money.Models.Sorting; using Money.Queries; +using Money.Pages; using Neptuo.Queries; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Globalization; using System.IO; using System.Linq; @@ -25,6 +28,21 @@ public async Task ExecuteAsync(object query, HttpQueryDispatcher dispatc var value = IntPropertyValue(await dispatcher.QueryAsync(new FindUserProperty("PriceDecimalDigits")), 2); return value; } + else if (query is GetSummarySortProperty) + { + var value = await dispatcher.QueryAsync(new FindUserProperty("SummarySort")); + if (String.IsNullOrEmpty(value)) + value = "ByCategory-Ascending"; + + string[] parts = value.Split('-'); + + var result = new SortDescriptor( + Enum.Parse(parts[0], true), + Enum.Parse(parts[1], true) + ); + + return result; + } return await next(query); }