Compare commits
2 Commits
ee967cd046
...
701388ee34
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
701388ee34 | ||
|
|
3e099988bc |
10
FoodsharingSiegen.Contracts/Enums/ProspectSortOption.cs
Normal file
10
FoodsharingSiegen.Contracts/Enums/ProspectSortOption.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace FoodsharingSiegen.Contracts.Enums
|
||||||
|
{
|
||||||
|
public enum ProspectSortOption
|
||||||
|
{
|
||||||
|
NameAscending,
|
||||||
|
NameDescending,
|
||||||
|
ModifiedAscending,
|
||||||
|
ModifiedDescending
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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>
|
||||||
39
FoodsharingSiegen.Server/Dialogs/ProspectSortDialog.razor.cs
Normal file
39
FoodsharingSiegen.Server/Dialogs/ProspectSortDialog.razor.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,17 +25,35 @@
|
|||||||
><i class="fa-solid fa-plus"></i>
|
><i class="fa-solid fa-plus"></i>
|
||||||
</Button>
|
</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 filterList = ProspectList.ApplyFilter(Filter);
|
||||||
|
var sortList = SortProspects(filterList);
|
||||||
}
|
}
|
||||||
|
|
||||||
<hr/>
|
<hr/>
|
||||||
<ProspectFilterControl Filter="Filter" FilterChanged="FilterChangedAsync" StateFilter="ProspectStateFilter.OnBoarding"></ProspectFilterControl>
|
<ProspectFilterControl Filter="Filter" FilterChanged="FilterChangedAsync" StateFilter="ProspectStateFilter.OnBoarding"></ProspectFilterControl>
|
||||||
<hr />
|
<hr />
|
||||||
<ProspectGrid
|
<ProspectGrid
|
||||||
Prospects="filterList"
|
Prospects="sortList"
|
||||||
OnDataChanged="@LoadProspects"
|
OnDataChanged="@LoadProspects"
|
||||||
StateFilter="ProspectStateFilter.OnBoarding">
|
StateFilter="ProspectStateFilter.OnBoarding">
|
||||||
</ProspectGrid>
|
</ProspectGrid>
|
||||||
@@ -36,6 +36,8 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private List<Prospect>? ProspectList { get; set; }
|
private List<Prospect>? ProspectList { get; set; }
|
||||||
|
|
||||||
|
private ProspectSortOption CurrentSort { get; set; } = ProspectSortOption.NameAscending;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Override InitializeDataAsync
|
#region Override InitializeDataAsync
|
||||||
@@ -63,6 +65,32 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
await EditProspectDialog.ShowAsync(ModalService, LoadProspects);
|
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
|
#endregion
|
||||||
|
|
||||||
#region Private Method FilterChangedAsync
|
#region Private Method FilterChangedAsync
|
||||||
@@ -78,6 +106,18 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
await LocalStorageService.SetItem(StorageKeys.ProspectFilter, Filter);
|
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
|
#endregion
|
||||||
|
|
||||||
#region Private Method LoadProspects
|
#region Private Method LoadProspects
|
||||||
|
|||||||
Reference in New Issue
Block a user