Skip to content

Commit

Permalink
#383 - Expense overview sort settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Jun 5, 2022
1 parent 8bb0bf4 commit dc8306d
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 15 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" ]
"UserProperties": [ "PriceDecimalDigits", "DateFormat", "MobileMenu", "SummarySort", "ExpenseOverviewSort" ]
}
5 changes: 4 additions & 1 deletion src/Money.Blazor.Host/Pages/Overview.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,7 +55,7 @@ public partial class Overview<T> :
protected List<OutcomeOverviewModel> Items { get; set; }

protected LoadingContext Loading { get; } = new LoadingContext();
protected SortDescriptor<OutcomeOverviewSortType> SortDescriptor { get; set; } = new SortDescriptor<OutcomeOverviewSortType>(OutcomeOverviewSortType.ByWhen, SortDirection.Descending);
protected SortDescriptor<OutcomeOverviewSortType> SortDescriptor { get; set; }
protected PagingContext PagingContext { get; set; }

protected override async Task OnInitializedAsync()
Expand All @@ -65,6 +66,8 @@ protected override async Task OnInitializedAsync()

CategoryKey = CreateSelectedCategoryFromParameters();
SelectedPeriod = CreateSelectedItemFromParameters();

SortDescriptor = await Queries.QueryAsync(new GetExpenseOverviewSortProperty());

if (!CategoryKey.IsEmpty)
{
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 @@ -55,4 +55,8 @@

<PropertyDialog @ref="SummarySortEditor" Model="@SummarySort" Title="Set summary sort">
<SortDescriptorEditor T="SummarySortType" @bind-Property="SummarySort.Property" @bind-Direction="SummarySort.Direction" />
</PropertyDialog>

<PropertyDialog @ref="ExpenseOverviewSortEditor" Model="@ExpenseOverviewSort" Title="Set expense overview sort">
<SortDescriptorEditor T="OutcomeOverviewSortType" @bind-Property="ExpenseOverviewSort.Property" @bind-Direction="ExpenseOverviewSort.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 @@ -46,6 +46,9 @@ public partial class Settings : System.IDisposable,
protected SortPropertyViewModel<SummarySortType> SummarySort { get; set; }
protected PropertyDialog SummarySortEditor { get; set; }

protected SortPropertyViewModel<OutcomeOverviewSortType> ExpenseOverviewSort { get; set; }
protected PropertyDialog ExpenseOverviewSortEditor { get; set; }

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

Expand All @@ -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<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");

await LoadAsync();
}
Expand Down
19 changes: 19 additions & 0 deletions src/Money.Blazor.Host/Queries/GetExpenseOverviewSortProperty.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 GetExpenseOverviewSortProperty : IQuery<SortDescriptor<OutcomeOverviewSortType>>
{ }
}
2 changes: 1 addition & 1 deletion src/Money.Blazor.Host/Queries/GetSummarySortProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Money.Queries
{
/// <summary>
/// A query for getting a user defined number of decimal digits or default value.
/// A query for getting a sort descriptor for summary.
/// </summary>
public class GetSummarySortProperty : IQuery<SortDescriptor<SummarySortType>>
{ }
Expand Down
35 changes: 23 additions & 12 deletions src/Money.Blazor.Host/Services/UserPropertyQueryHandler.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -30,21 +31,31 @@ public async Task<object> 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<SummarySortType>(dispatcher, "SummarySort", "ByCategory-Ascending");
}
else if (query is GetExpenseOverviewSortProperty)
{
return await GetSortDescriptorAsync<OutcomeOverviewSortType>(dispatcher, "ExpenseOverviewSort", "ByWhen-Descending");
}

string[] parts = value.Split('-');
return await next(query);
}

var result = new SortDescriptor<SummarySortType>(
Enum.Parse<SummarySortType>(parts[0], true),
Enum.Parse<SortDirection>(parts[1], true)
);
private async Task<SortDescriptor<T>> GetSortDescriptorAsync<T>(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<T>(
Enum.Parse<T>(parts[0], true),
Enum.Parse<SortDirection>(parts[1], true)
);

return result;
}

private int IntPropertyValue(string value, int defaultValue)
Expand Down

0 comments on commit dc8306d

Please sign in to comment.