Refactor Audit service and view: implement GetCount and LoadPage methods, update OnReadData for improved data handling
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
|
||||
<DataGrid TItem="Audit"
|
||||
Data="@Audits"
|
||||
ReadData="@OnReadData"
|
||||
TotalItems="@TotalAudits"
|
||||
VirtualizeOptions="@(new() { DataGridHeight = "100%", DataGridMaxHeight = "100%"})"
|
||||
Virtualize="true"
|
||||
Responsive>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Blazorise.DataGrid;
|
||||
using FoodsharingSiegen.Contracts.Entity;
|
||||
using FoodsharingSiegen.Server.Data.Service;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
@@ -26,16 +27,44 @@ namespace FoodsharingSiegen.Server.Pages
|
||||
/// </summary>
|
||||
private List<Audit>? Audits { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the total audits (ab)
|
||||
/// </summary>
|
||||
private int TotalAudits { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Override InitializeDataAsync
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task InitializeDataAsync()
|
||||
protected override Task InitializeDataAsync()
|
||||
{
|
||||
var loadR = await AuditService?.Load(100)!;
|
||||
if (loadR.Success)
|
||||
Audits = loadR.Data;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Method OnReadData
|
||||
|
||||
/// <summary>
|
||||
/// Called when data is read (ab)
|
||||
/// </summary>
|
||||
/// <param name="e">The params</param>
|
||||
private async Task OnReadData(DataGridReadDataEventArgs<Audit> e)
|
||||
{
|
||||
var countLoad = await AuditService?.GetCount()!;
|
||||
if (countLoad.Success)
|
||||
TotalAudits = countLoad.Data;
|
||||
|
||||
// Default fallback if VirtualizeCount is not set, though Blazor shouldn't do this usually
|
||||
var limit = e.VirtualizeCount > 0 ? e.VirtualizeCount : 50;
|
||||
var offset = e.VirtualizeOffset;
|
||||
|
||||
var itemsLoad = await AuditService?.LoadPage(offset, limit)!;
|
||||
if (itemsLoad.Success)
|
||||
Audits = itemsLoad.Data;
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user