feat: Add pagination to all list pages
Integrate Pager component into Jobs, Materials, Stock, Suppliers, and Tools index pages with a page size of 25. Handles page adjustment on delete when the last page becomes empty. Also removes the Description column from the Materials table. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -47,7 +47,7 @@ else
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var job in jobs)
|
||||
@foreach (var job in pagedJobs)
|
||||
{
|
||||
<tr>
|
||||
<td><a href="jobs/@job.Id">@job.JobNumber</a></td>
|
||||
@@ -65,6 +65,8 @@ else
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<Pager TotalCount="jobs.Count" PageSize="pageSize" CurrentPage="currentPage" CurrentPageChanged="OnPageChanged" />
|
||||
}
|
||||
|
||||
<ConfirmDialog @ref="deleteDialog"
|
||||
@@ -77,10 +79,14 @@ else
|
||||
private List<Job> jobs = new();
|
||||
private bool loading = true;
|
||||
private bool creating = false;
|
||||
private int currentPage = 1;
|
||||
private int pageSize = 25;
|
||||
private ConfirmDialog deleteDialog = null!;
|
||||
private Job? jobToDelete;
|
||||
private string deleteMessage = "";
|
||||
|
||||
private IEnumerable<Job> pagedJobs => jobs.Skip((currentPage - 1) * pageSize).Take(pageSize);
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
jobs = await JobService.GetAllAsync();
|
||||
@@ -114,9 +120,15 @@ else
|
||||
{
|
||||
await JobService.DeleteAsync(jobToDelete.Id);
|
||||
jobs = await JobService.GetAllAsync();
|
||||
|
||||
var totalPages = (int)Math.Ceiling((double)jobs.Count / pageSize);
|
||||
if (currentPage > totalPages && totalPages > 0)
|
||||
currentPage = totalPages;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPageChanged(int page) => currentPage = page;
|
||||
|
||||
private async Task DuplicateJob(Job job)
|
||||
{
|
||||
var duplicate = await JobService.DuplicateAsync(job.Id);
|
||||
|
||||
@@ -40,19 +40,17 @@ else
|
||||
<th>Type</th>
|
||||
<th>Grade</th>
|
||||
<th>Size</th>
|
||||
<th>Description</th>
|
||||
<th style="width: 160px;">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var material in materials)
|
||||
@foreach (var material in pagedMaterials)
|
||||
{
|
||||
<tr>
|
||||
<td>@material.Shape.GetDisplayName()</td>
|
||||
<td>@material.Type</td>
|
||||
<td>@material.Grade</td>
|
||||
<td>@material.Size</td>
|
||||
<td>@material.Description</td>
|
||||
<td>
|
||||
<div class="d-flex gap-1">
|
||||
<a href="materials/@material.Id" class="btn btn-sm btn-outline-primary">Edit</a>
|
||||
@@ -63,6 +61,8 @@ else
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<Pager TotalCount="materials.Count" PageSize="pageSize" CurrentPage="currentPage" CurrentPageChanged="OnPageChanged" />
|
||||
}
|
||||
|
||||
<ConfirmDialog @ref="deleteDialog"
|
||||
@@ -75,10 +75,14 @@ else
|
||||
private List<Material> materials = new();
|
||||
private bool loading = true;
|
||||
private string? errorMessage;
|
||||
private int currentPage = 1;
|
||||
private int pageSize = 25;
|
||||
private ConfirmDialog deleteDialog = null!;
|
||||
private Material? materialToDelete;
|
||||
private string deleteMessage = "";
|
||||
|
||||
private IEnumerable<Material> pagedMaterials => materials.Skip((currentPage - 1) * pageSize).Take(pageSize);
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
try
|
||||
@@ -108,6 +112,12 @@ else
|
||||
{
|
||||
await MaterialService.DeleteAsync(materialToDelete.Id);
|
||||
materials = await MaterialService.GetAllAsync();
|
||||
|
||||
var totalPages = (int)Math.Ceiling((double)materials.Count / pageSize);
|
||||
if (currentPage > totalPages && totalPages > 0)
|
||||
currentPage = totalPages;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPageChanged(int page) => currentPage = page;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ else
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in stockItems)
|
||||
@foreach (var item in pagedItems)
|
||||
{
|
||||
<tr>
|
||||
<td>@item.Material.Shape.GetDisplayName()</td>
|
||||
@@ -69,6 +69,8 @@ else
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<Pager TotalCount="stockItems.Count" PageSize="pageSize" CurrentPage="currentPage" CurrentPageChanged="OnPageChanged" />
|
||||
}
|
||||
|
||||
<ConfirmDialog @ref="deleteDialog"
|
||||
@@ -80,10 +82,14 @@ else
|
||||
@code {
|
||||
private List<StockItem> stockItems = new();
|
||||
private bool loading = true;
|
||||
private int currentPage = 1;
|
||||
private int pageSize = 25;
|
||||
private ConfirmDialog deleteDialog = null!;
|
||||
private StockItem? itemToDelete;
|
||||
private string deleteMessage = "";
|
||||
|
||||
private IEnumerable<StockItem> pagedItems => stockItems.Skip((currentPage - 1) * pageSize).Take(pageSize);
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
stockItems = await StockItemService.GetAllAsync();
|
||||
@@ -103,6 +109,12 @@ else
|
||||
{
|
||||
await StockItemService.DeleteAsync(itemToDelete.Id);
|
||||
stockItems = await StockItemService.GetAllAsync();
|
||||
|
||||
var totalPages = (int)Math.Ceiling((double)stockItems.Count / pageSize);
|
||||
if (currentPage > totalPages && totalPages > 0)
|
||||
currentPage = totalPages;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPageChanged(int page) => currentPage = page;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ else
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var supplier in suppliers)
|
||||
@foreach (var supplier in pagedSuppliers)
|
||||
{
|
||||
<tr>
|
||||
<td><a href="suppliers/@supplier.Id">@supplier.Name</a></td>
|
||||
@@ -47,6 +47,8 @@ else
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<Pager TotalCount="suppliers.Count" PageSize="pageSize" CurrentPage="currentPage" CurrentPageChanged="OnPageChanged" />
|
||||
}
|
||||
|
||||
<ConfirmDialog @ref="deleteDialog"
|
||||
@@ -58,10 +60,14 @@ else
|
||||
@code {
|
||||
private List<Supplier> suppliers = new();
|
||||
private bool loading = true;
|
||||
private int currentPage = 1;
|
||||
private int pageSize = 25;
|
||||
private ConfirmDialog deleteDialog = null!;
|
||||
private Supplier? supplierToDelete;
|
||||
private string deleteMessage = "";
|
||||
|
||||
private IEnumerable<Supplier> pagedSuppliers => suppliers.Skip((currentPage - 1) * pageSize).Take(pageSize);
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
suppliers = await SupplierService.GetAllAsync();
|
||||
@@ -81,9 +87,15 @@ else
|
||||
{
|
||||
await SupplierService.DeleteAsync(supplierToDelete.Id);
|
||||
suppliers = await SupplierService.GetAllAsync();
|
||||
|
||||
var totalPages = (int)Math.Ceiling((double)suppliers.Count / pageSize);
|
||||
if (currentPage > totalPages && totalPages > 0)
|
||||
currentPage = totalPages;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPageChanged(int page) => currentPage = page;
|
||||
|
||||
private string? TruncateText(string? text, int maxLength)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text) || text.Length <= maxLength)
|
||||
|
||||
@@ -78,7 +78,7 @@ else
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var tool in tools)
|
||||
@foreach (var tool in pagedTools)
|
||||
{
|
||||
<tr>
|
||||
<td>@tool.Name</td>
|
||||
@@ -97,6 +97,8 @@ else
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<Pager TotalCount="tools.Count" PageSize="pageSize" CurrentPage="currentPage" CurrentPageChanged="OnPageChanged" />
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +114,10 @@ else
|
||||
private bool showForm;
|
||||
private bool saving;
|
||||
private string? errorMessage;
|
||||
private int currentPage = 1;
|
||||
private int pageSize = 25;
|
||||
|
||||
private IEnumerable<CuttingTool> pagedTools => tools.Skip((currentPage - 1) * pageSize).Take(pageSize);
|
||||
|
||||
private CuttingTool formTool = new();
|
||||
private CuttingTool? editingTool;
|
||||
@@ -207,9 +213,15 @@ else
|
||||
{
|
||||
await JobService.DeleteCuttingToolAsync(toolToDelete.Id);
|
||||
tools = await JobService.GetCuttingToolsAsync();
|
||||
|
||||
var totalPages = (int)Math.Ceiling((double)tools.Count / pageSize);
|
||||
if (currentPage > totalPages && totalPages > 0)
|
||||
currentPage = totalPages;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPageChanged(int page) => currentPage = page;
|
||||
|
||||
private string FormatKerf(decimal kerf)
|
||||
{
|
||||
// Show as fraction if it's a common value
|
||||
|
||||
Reference in New Issue
Block a user