Compare commits

..

4 Commits

7 changed files with 142 additions and 5 deletions

View File

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

View File

@@ -12,8 +12,23 @@
<div class="@divClass"> <div class="@divClass">
<h5 class="mb-2 d-flex"> <h5 class="mb-2 d-flex">
<div class="flex-grow-1"> <div class="flex-grow-1">
@Prospect?.Name @if(string.IsNullOrWhiteSpace(Prospect?.Name))
<small style="font-size: .9rem;">@Prospect?.FsId</small> {
<i class="fa-solid fa-exclamation-triangle text-warning"></i>
<doublearrows></doublearrows>
<em>»Name fehlt«</em>
}
else
{
@Prospect?.Name
}
@if (Prospect?.FsId != null && Prospect.FsId != 0)
{
<small style="font-size: .9rem; margin-left: 0.5rem;">@Prospect?.FsId</small>
}
</div> </div>
<div> <div>
@if (CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador)) @if (CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador))

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

@@ -16,20 +16,44 @@
<Button <Button
Color="Color.Primary" Color="Color.Primary"
Width="Width.Px(50)"
Height="Height.Px(50)"
title="Hinzufügen"
style="min-width: auto;"
Clicked="@CreateProspectAsync" Clicked="@CreateProspectAsync"
Visibility="@(CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador) ? Visibility.Default : Visibility.Invisible)" Visibility="@(CurrentUser.IsInGroup(UserGroup.WelcomeTeam, UserGroup.Ambassador) ? Visibility.Default : Visibility.Invisible)"
>Hinzufügen ><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>

View File

@@ -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

View File

@@ -1 +1 @@
20260410 20260416