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:
2026-02-07 13:46:12 -05:00
parent 8ed10939d4
commit 5468b2748d
5 changed files with 65 additions and 7 deletions

View File

@@ -47,7 +47,7 @@ else
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach (var job in jobs) @foreach (var job in pagedJobs)
{ {
<tr> <tr>
<td><a href="jobs/@job.Id">@job.JobNumber</a></td> <td><a href="jobs/@job.Id">@job.JobNumber</a></td>
@@ -65,6 +65,8 @@ else
} }
</tbody> </tbody>
</table> </table>
<Pager TotalCount="jobs.Count" PageSize="pageSize" CurrentPage="currentPage" CurrentPageChanged="OnPageChanged" />
} }
<ConfirmDialog @ref="deleteDialog" <ConfirmDialog @ref="deleteDialog"
@@ -77,10 +79,14 @@ else
private List<Job> jobs = new(); private List<Job> jobs = new();
private bool loading = true; private bool loading = true;
private bool creating = false; private bool creating = false;
private int currentPage = 1;
private int pageSize = 25;
private ConfirmDialog deleteDialog = null!; private ConfirmDialog deleteDialog = null!;
private Job? jobToDelete; private Job? jobToDelete;
private string deleteMessage = ""; private string deleteMessage = "";
private IEnumerable<Job> pagedJobs => jobs.Skip((currentPage - 1) * pageSize).Take(pageSize);
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
jobs = await JobService.GetAllAsync(); jobs = await JobService.GetAllAsync();
@@ -114,9 +120,15 @@ else
{ {
await JobService.DeleteAsync(jobToDelete.Id); await JobService.DeleteAsync(jobToDelete.Id);
jobs = await JobService.GetAllAsync(); 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) private async Task DuplicateJob(Job job)
{ {
var duplicate = await JobService.DuplicateAsync(job.Id); var duplicate = await JobService.DuplicateAsync(job.Id);

View File

@@ -40,19 +40,17 @@ else
<th>Type</th> <th>Type</th>
<th>Grade</th> <th>Grade</th>
<th>Size</th> <th>Size</th>
<th>Description</th>
<th style="width: 160px;">Actions</th> <th style="width: 160px;">Actions</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach (var material in materials) @foreach (var material in pagedMaterials)
{ {
<tr> <tr>
<td>@material.Shape.GetDisplayName()</td> <td>@material.Shape.GetDisplayName()</td>
<td>@material.Type</td> <td>@material.Type</td>
<td>@material.Grade</td> <td>@material.Grade</td>
<td>@material.Size</td> <td>@material.Size</td>
<td>@material.Description</td>
<td> <td>
<div class="d-flex gap-1"> <div class="d-flex gap-1">
<a href="materials/@material.Id" class="btn btn-sm btn-outline-primary">Edit</a> <a href="materials/@material.Id" class="btn btn-sm btn-outline-primary">Edit</a>
@@ -63,6 +61,8 @@ else
} }
</tbody> </tbody>
</table> </table>
<Pager TotalCount="materials.Count" PageSize="pageSize" CurrentPage="currentPage" CurrentPageChanged="OnPageChanged" />
} }
<ConfirmDialog @ref="deleteDialog" <ConfirmDialog @ref="deleteDialog"
@@ -75,10 +75,14 @@ else
private List<Material> materials = new(); private List<Material> materials = new();
private bool loading = true; private bool loading = true;
private string? errorMessage; private string? errorMessage;
private int currentPage = 1;
private int pageSize = 25;
private ConfirmDialog deleteDialog = null!; private ConfirmDialog deleteDialog = null!;
private Material? materialToDelete; private Material? materialToDelete;
private string deleteMessage = ""; private string deleteMessage = "";
private IEnumerable<Material> pagedMaterials => materials.Skip((currentPage - 1) * pageSize).Take(pageSize);
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
try try
@@ -108,6 +112,12 @@ else
{ {
await MaterialService.DeleteAsync(materialToDelete.Id); await MaterialService.DeleteAsync(materialToDelete.Id);
materials = await MaterialService.GetAllAsync(); 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;
} }

View File

@@ -41,7 +41,7 @@ else
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach (var item in stockItems) @foreach (var item in pagedItems)
{ {
<tr> <tr>
<td>@item.Material.Shape.GetDisplayName()</td> <td>@item.Material.Shape.GetDisplayName()</td>
@@ -69,6 +69,8 @@ else
} }
</tbody> </tbody>
</table> </table>
<Pager TotalCount="stockItems.Count" PageSize="pageSize" CurrentPage="currentPage" CurrentPageChanged="OnPageChanged" />
} }
<ConfirmDialog @ref="deleteDialog" <ConfirmDialog @ref="deleteDialog"
@@ -80,10 +82,14 @@ else
@code { @code {
private List<StockItem> stockItems = new(); private List<StockItem> stockItems = new();
private bool loading = true; private bool loading = true;
private int currentPage = 1;
private int pageSize = 25;
private ConfirmDialog deleteDialog = null!; private ConfirmDialog deleteDialog = null!;
private StockItem? itemToDelete; private StockItem? itemToDelete;
private string deleteMessage = ""; private string deleteMessage = "";
private IEnumerable<StockItem> pagedItems => stockItems.Skip((currentPage - 1) * pageSize).Take(pageSize);
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
stockItems = await StockItemService.GetAllAsync(); stockItems = await StockItemService.GetAllAsync();
@@ -103,6 +109,12 @@ else
{ {
await StockItemService.DeleteAsync(itemToDelete.Id); await StockItemService.DeleteAsync(itemToDelete.Id);
stockItems = await StockItemService.GetAllAsync(); 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;
} }

View File

@@ -31,7 +31,7 @@ else
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach (var supplier in suppliers) @foreach (var supplier in pagedSuppliers)
{ {
<tr> <tr>
<td><a href="suppliers/@supplier.Id">@supplier.Name</a></td> <td><a href="suppliers/@supplier.Id">@supplier.Name</a></td>
@@ -47,6 +47,8 @@ else
} }
</tbody> </tbody>
</table> </table>
<Pager TotalCount="suppliers.Count" PageSize="pageSize" CurrentPage="currentPage" CurrentPageChanged="OnPageChanged" />
} }
<ConfirmDialog @ref="deleteDialog" <ConfirmDialog @ref="deleteDialog"
@@ -58,10 +60,14 @@ else
@code { @code {
private List<Supplier> suppliers = new(); private List<Supplier> suppliers = new();
private bool loading = true; private bool loading = true;
private int currentPage = 1;
private int pageSize = 25;
private ConfirmDialog deleteDialog = null!; private ConfirmDialog deleteDialog = null!;
private Supplier? supplierToDelete; private Supplier? supplierToDelete;
private string deleteMessage = ""; private string deleteMessage = "";
private IEnumerable<Supplier> pagedSuppliers => suppliers.Skip((currentPage - 1) * pageSize).Take(pageSize);
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
suppliers = await SupplierService.GetAllAsync(); suppliers = await SupplierService.GetAllAsync();
@@ -81,9 +87,15 @@ else
{ {
await SupplierService.DeleteAsync(supplierToDelete.Id); await SupplierService.DeleteAsync(supplierToDelete.Id);
suppliers = await SupplierService.GetAllAsync(); 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) private string? TruncateText(string? text, int maxLength)
{ {
if (string.IsNullOrEmpty(text) || text.Length <= maxLength) if (string.IsNullOrEmpty(text) || text.Length <= maxLength)

View File

@@ -78,7 +78,7 @@ else
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach (var tool in tools) @foreach (var tool in pagedTools)
{ {
<tr> <tr>
<td>@tool.Name</td> <td>@tool.Name</td>
@@ -97,6 +97,8 @@ else
} }
</tbody> </tbody>
</table> </table>
<Pager TotalCount="tools.Count" PageSize="pageSize" CurrentPage="currentPage" CurrentPageChanged="OnPageChanged" />
} }
} }
@@ -112,6 +114,10 @@ else
private bool showForm; private bool showForm;
private bool saving; private bool saving;
private string? errorMessage; 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 formTool = new();
private CuttingTool? editingTool; private CuttingTool? editingTool;
@@ -207,9 +213,15 @@ else
{ {
await JobService.DeleteCuttingToolAsync(toolToDelete.Id); await JobService.DeleteCuttingToolAsync(toolToDelete.Id);
tools = await JobService.GetCuttingToolsAsync(); 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) private string FormatKerf(decimal kerf)
{ {
// Show as fraction if it's a common value // Show as fraction if it's a common value