Implement sorting functionality for prospects with a dialog and custom sort options
This commit is contained in:
@@ -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>
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user