Compare commits

..

2 Commits

5 changed files with 117 additions and 1 deletions

View File

@@ -0,0 +1,10 @@
namespace FoodsharingSiegen.Contracts.Enums
{
public enum ProspectSortOption
{
NameAscending,
NameDescending,
ModifiedAscending,
ModifiedDescending
}
}

View File

@@ -0,0 +1,9 @@
@inherits FsBase
@using FoodsharingSiegen.Contracts.Enums
<div class="d-grid gap-2">
<Button Color="@GetSortButtonColor(ProspectSortOption.NameAscending)" Clicked="() => SelectAsync(ProspectSortOption.NameAscending)">Name (aufsteigend)</Button>
<Button Color="@GetSortButtonColor(ProspectSortOption.NameDescending)" Clicked="() => SelectAsync(ProspectSortOption.NameDescending)">Name (absteigend)</Button>
<Button Color="@GetSortButtonColor(ProspectSortOption.ModifiedAscending)" Clicked="() => SelectAsync(ProspectSortOption.ModifiedAscending)">Geändert (aufsteigend)</Button>
<Button Color="@GetSortButtonColor(ProspectSortOption.ModifiedDescending)" Clicked="() => SelectAsync(ProspectSortOption.ModifiedDescending)">Geändert (absteigend)</Button>
</div>

View File

@@ -0,0 +1,39 @@
using Blazorise;
using FoodsharingSiegen.Contracts.Enums;
using FoodsharingSiegen.Server.BaseClasses;
using Microsoft.AspNetCore.Components;
namespace FoodsharingSiegen.Server.Dialogs
{
public partial class ProspectSortDialog : FsBase
{
[Parameter]
public ProspectSortOption CurrentSort { get; set; } = ProspectSortOption.NameAscending;
[Parameter]
public Func<ProspectSortOption, Task>? OnSortSelected { get; set; }
public static async Task ShowAsync(IModalService modalService, ProspectSortOption currentSort, Func<ProspectSortOption, Task> onSortSelected)
{
await modalService.Show<ProspectSortDialog>("Sortieren", p =>
{
p.Add(nameof(CurrentSort), currentSort);
p.Add(nameof(OnSortSelected), onSortSelected);
}, new ModalInstanceOptions
{
Size = ModalSize.Small,
});
}
private Color GetSortButtonColor(ProspectSortOption option)
{
return CurrentSort == option ? Color.Success : Color.Secondary;
}
private async Task SelectAsync(ProspectSortOption option)
{
if (OnSortSelected != null) await OnSortSelected(option);
await ModalService.Hide();
}
}
}

View File

@@ -25,17 +25,35 @@
><i class="fa-solid fa-plus"></i>
</Button>
<Button
Color="Color.Primary"
Width="Width.Px(50)"
Height="Height.Px(50)"
title="Sortieren"
style="min-width: auto;"
Clicked="@OpenSortDialogAsync"
><i class="fa-solid fa-sort"></i>
</Button>
<div class="badge-row mt-2">
@if (HasCustomSort)
{
<Badge Color="Color.Primary" Closable="true" CloseClicked="@EventCallback.Factory.Create(this, ResetSortAsync)">@CurrentSortText</Badge>
}
</div>
@{
var filterList = ProspectList.ApplyFilter(Filter);
var sortList = SortProspects(filterList);
}
<hr/>
<ProspectFilterControl Filter="Filter" FilterChanged="FilterChangedAsync" StateFilter="ProspectStateFilter.OnBoarding"></ProspectFilterControl>
<hr />
<ProspectGrid
Prospects="filterList"
Prospects="sortList"
OnDataChanged="@LoadProspects"
StateFilter="ProspectStateFilter.OnBoarding">
</ProspectGrid>

View File

@@ -36,6 +36,8 @@ namespace FoodsharingSiegen.Server.Pages
/// </summary>
private List<Prospect>? ProspectList { get; set; }
private ProspectSortOption CurrentSort { get; set; } = ProspectSortOption.NameAscending;
#endregion
#region Override InitializeDataAsync
@@ -63,6 +65,32 @@ namespace FoodsharingSiegen.Server.Pages
await EditProspectDialog.ShowAsync(ModalService, LoadProspects);
}
private async Task OpenSortDialogAsync()
{
await ProspectSortDialog.ShowAsync(ModalService, CurrentSort, async option =>
{
CurrentSort = option;
await InvokeAsync(StateHasChanged);
});
}
private bool HasCustomSort => CurrentSort != ProspectSortOption.NameAscending;
private string CurrentSortText => CurrentSort switch
{
ProspectSortOption.NameDescending => "Sortierung: Name (absteigend)",
ProspectSortOption.ModifiedAscending => "Sortierung: Zuletzt geaendert (aufsteigend) ",
ProspectSortOption.ModifiedDescending => "Sortierung: Zuletzt geaendert (absteigend) ",
_ => string.Empty
};
private async Task ResetSortAsync()
{
CurrentSort = ProspectSortOption.NameAscending;
await InvokeAsync(StateHasChanged);
}
#endregion
#region Private Method FilterChangedAsync
@@ -78,6 +106,18 @@ namespace FoodsharingSiegen.Server.Pages
await LocalStorageService.SetItem(StorageKeys.ProspectFilter, Filter);
}
private List<Prospect> SortProspects(List<Prospect> prospects)
{
return CurrentSort switch
{
ProspectSortOption.NameAscending => prospects.OrderBy(x => x.Name, StringComparer.OrdinalIgnoreCase).ToList(),
ProspectSortOption.NameDescending => prospects.OrderByDescending(x => x.Name, StringComparer.OrdinalIgnoreCase).ToList(),
ProspectSortOption.ModifiedAscending => prospects.OrderBy(x => x.Modified ?? x.Created).ToList(),
ProspectSortOption.ModifiedDescending => prospects.OrderByDescending(x => x.Modified ?? x.Created).ToList(),
_ => prospects
};
}
#endregion
#region Private Method LoadProspects