AccountingNext/Schaad.Accounting.UI/Components/Pages/BookingTexts.razor.cs
Claudio Schaad 0c48539ce6 PR U-9: FluentSearch filter on grid pages
Accounts, BookingRules, BookingTexts, BankTransactions each get an
<FluentSearch> above the grid, backed by a computed Filtered
IQueryable over an in-memory source list. FluentSearch is Immediate,
so filtering happens on each keystroke; data sizes are small enough
for per-render LINQ.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-07-04 10:10:43 +02:00

84 lines
3 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.FluentUI.AspNetCore.Components;
using Schaad.Accounting.Interfaces;
using Schaad.Accounting.Models;
using Schaad.Accounting.UI.Components.Pages.Dialogs;
namespace Schaad.Accounting.UI.Components.Pages;
public partial class BookingTexts : ComponentBase
{
[Inject]
private IBookingTextRepository bookingTextRepository { get; set; } = null!;
[Inject]
private IDialogService dialogService { get; set; } = null!;
[Inject]
private IToastService toastService { get; set; } = null!;
private IReadOnlyList<BookingText> source = [];
private string filter = "";
private IQueryable<BookingText> Filtered =>
string.IsNullOrWhiteSpace(filter)
? source.AsQueryable()
: source.AsQueryable().Where(t => t.Text.Contains(filter, StringComparison.OrdinalIgnoreCase));
protected override async Task OnInitializedAsync()
{
source = await bookingTextRepository.GetBookingTextListAsync();
await base.OnInitializedAsync();
}
private async Task AddAsync()
{
var data = new BookingText();
var dialog = await dialogService.ShowDialogAsync<BookingTextDialog>(data, new DialogParameters()
{
Height = "500px",
Title = "Add Buchungstext",
PreventDismissOnOverlayClick = true,
PreventScroll = true,
});
var result = await dialog.Result;
if (!result.Cancelled && result.Data != null)
{
source = await bookingTextRepository.GetBookingTextListAsync();
toastService.ShowToast(ToastIntent.Success, "Buchungstext gespeichert", 3000);
}
}
private async Task EditAsync(string id)
{
var data = await bookingTextRepository.GetBookingTextAsync(id);
var dialog = await dialogService.ShowDialogAsync<BookingTextDialog>(data, new DialogParameters()
{
Height = "500px",
Title = "Edit Buchungstext",
PreventDismissOnOverlayClick = true,
PreventScroll = true,
});
var result = await dialog.Result;
if (!result.Cancelled && result.Data != null)
{
source = await bookingTextRepository.GetBookingTextListAsync();
toastService.ShowToast(ToastIntent.Success, "Buchungstext gespeichert", 3000);
}
}
private async Task DeleteAsync(string id)
{
var bookingText = await bookingTextRepository.GetBookingTextAsync(id);
var dialog = await dialogService.ShowConfirmationAsync($"Buchungstext '{bookingText.Text}' wirklich löschen?", "Ja", "Nein", "Buchungstext löschen");
var result = await dialog.Result;
if (!result.Cancelled)
{
await bookingTextRepository.DeleteBookingTextAsync(id);
source = await bookingTextRepository.GetBookingTextListAsync();
toastService.ShowToast(ToastIntent.Success, "Buchungstext gelöscht", 3000);
}
}
}