Skip to content

Commit

Permalink
#383 - Search sort settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Jun 5, 2022
1 parent dc8306d commit 4d6ec70
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Money.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"RequireUppercase": false
}
},
"UserProperties": [ "PriceDecimalDigits", "DateFormat", "MobileMenu", "SummarySort", "ExpenseOverviewSort" ]
"UserProperties": [ "PriceDecimalDigits", "DateFormat", "MobileMenu", "SummarySort", "ExpenseOverviewSort", "SearchSort" ]
}
2 changes: 1 addition & 1 deletion src/Money.Blazor.Host/Pages/Overview.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using Money.Models.Loading;
using Money.Models.Queries;
using Money.Models.Sorting;
using Money.Services;
using Money.Queries;
using Money.Services;
using Neptuo;
using Neptuo.Commands;
using Neptuo.Events;
Expand Down
6 changes: 4 additions & 2 deletions src/Money.Blazor.Host/Pages/Search.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Money.Models.Loading;
using Money.Models.Queries;
using Money.Models.Sorting;
using Money.Queries;
using Money.Services;
using Neptuo.Events;
using Neptuo.Events.Handlers;
Expand All @@ -25,8 +26,6 @@ public partial class Search : System.IDisposable,
IEventHandler<OutcomeWhenChanged>,
IEventHandler<PulledToRefresh>
{
public static readonly SortDescriptor<OutcomeOverviewSortType> DefaultSort = new SortDescriptor<OutcomeOverviewSortType>(OutcomeOverviewSortType.ByWhen, SortDirection.Descending);

public CurrencyFormatter CurrencyFormatter { get; private set; }

[Inject]
Expand All @@ -46,6 +45,8 @@ public partial class Search : System.IDisposable,

protected ElementReference SearchBox { get; set; }

protected SortDescriptor<OutcomeOverviewSortType> DefaultSort { get; set; }

protected LoadingContext Loading { get; } = new LoadingContext();
protected SortDescriptor<OutcomeOverviewSortType> Sort { get; set; }
protected PagingContext PagingContext { get; set; }
Expand All @@ -56,6 +57,7 @@ public partial class Search : System.IDisposable,

protected async override Task OnInitializedAsync()
{
DefaultSort = await Queries.QueryAsync(new GetSearchSortProperty());
FormSort = Sort = DefaultSort;
PagingContext = new PagingContext(LoadPageAsync, Loading);
CurrencyFormatter = await CurrencyFormatterFactory.CreateAsync();
Expand Down
4 changes: 4 additions & 0 deletions src/Money.Blazor.Host/Pages/Users/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@

<PropertyDialog @ref="ExpenseOverviewSortEditor" Model="@ExpenseOverviewSort" Title="Set expense overview sort">
<SortDescriptorEditor T="OutcomeOverviewSortType" @bind-Property="ExpenseOverviewSort.Property" @bind-Direction="ExpenseOverviewSort.Direction" />
</PropertyDialog>

<PropertyDialog @ref="SearchSortEditor" Model="@SearchSort" Title="Set search sort">
<SortDescriptorEditor T="OutcomeOverviewSortType" @bind-Property="SearchSort.Property" @bind-Direction="SearchSort.Direction" />
</PropertyDialog>
4 changes: 4 additions & 0 deletions src/Money.Blazor.Host/Pages/Users/Settings.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public partial class Settings : System.IDisposable,
protected SortPropertyViewModel<OutcomeOverviewSortType> ExpenseOverviewSort { get; set; }
protected PropertyDialog ExpenseOverviewSortEditor { get; set; }

protected SortPropertyViewModel<OutcomeOverviewSortType> SearchSort { get; set; }
protected PropertyDialog SearchSortEditor { get; set; }

protected List<UserPropertyModel> Models { get; set; }
protected List<PropertyViewModel> ViewModels { get; } = new List<PropertyViewModel>();

Expand All @@ -63,6 +66,7 @@ protected async override Task OnInitializedAsync()
MobileMenu = AddProperty<MobileMenuPropertyViewModel>("MobileMenu", "Mobile menu", () => MobileMenuEditor.Show(), icon: "mobile");
SummarySort = AddProperty<SortPropertyViewModel<SummarySortType>>("SummarySort", "Summary sort", () => SummarySortEditor.Show(), icon: "sort-alpha-down", defaultValue: "ByCategory-Ascending");
ExpenseOverviewSort = AddProperty<SortPropertyViewModel<OutcomeOverviewSortType>>("ExpenseOverviewSort", "Expense overview sort", () => ExpenseOverviewSortEditor.Show(), icon: "sort-alpha-down", defaultValue: "ByWhen-Descending");
SearchSort = AddProperty<SortPropertyViewModel<OutcomeOverviewSortType>>("SearchSort", "Search sort", () => SearchSortEditor.Show(), icon: "sort-alpha-down", defaultValue: "ByWhen-Descending");

await LoadAsync();
}
Expand Down
19 changes: 19 additions & 0 deletions src/Money.Blazor.Host/Queries/GetSearchSortProperty.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// A query for getting a sort descriptor for expense overview.
/// </summary>
public class GetSearchSortProperty : IQuery<SortDescriptor<OutcomeOverviewSortType>>
{ }
}
4 changes: 4 additions & 0 deletions src/Money.Blazor.Host/Services/UserPropertyQueryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public async Task<object> ExecuteAsync(object query, HttpQueryDispatcher dispatc
{
return await GetSortDescriptorAsync<OutcomeOverviewSortType>(dispatcher, "ExpenseOverviewSort", "ByWhen-Descending");
}
else if (query is GetSearchSortProperty)
{
return await GetSortDescriptorAsync<OutcomeOverviewSortType>(dispatcher, "SearchSort", "ByWhen-Descending");
}

return await next(query);
}
Expand Down

0 comments on commit 4d6ec70

Please sign in to comment.