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>
121 lines
3.9 KiB
Plaintext
121 lines
3.9 KiB
Plaintext
@page "/stock"
|
|
@inject StockItemService StockItemService
|
|
@inject NavigationManager Navigation
|
|
@using CutList.Core.Formatting
|
|
@using CutList.Web.Data.Entities
|
|
|
|
<PageTitle>Stock Items</PageTitle>
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
<h1>Stock Items</h1>
|
|
<a href="stock/new" class="btn btn-primary">Add Stock Item</a>
|
|
</div>
|
|
|
|
<p class="text-muted mb-4">
|
|
Stock items represent the specific lengths of material you have available for cutting. Each stock item links
|
|
a material to a length and tracks how many pieces you have on hand.
|
|
</p>
|
|
|
|
@if (loading)
|
|
{
|
|
<p><em>Loading...</em></p>
|
|
}
|
|
else if (stockItems.Count == 0)
|
|
{
|
|
<div class="alert alert-info">
|
|
No stock items found. <a href="stock/new">Add your first stock item</a>.
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<table class="table table-striped table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>Shape</th>
|
|
<th>Type</th>
|
|
<th>Grade</th>
|
|
<th>Size</th>
|
|
<th>Length</th>
|
|
<th>On Hand</th>
|
|
<th style="width: 160px;">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (var item in pagedItems)
|
|
{
|
|
<tr>
|
|
<td>@item.Material.Shape.GetDisplayName()</td>
|
|
<td>@item.Material.Type</td>
|
|
<td>@item.Material.Grade</td>
|
|
<td>@item.Material.Size</td>
|
|
<td>@ArchUnits.FormatFromInches((double)item.LengthInches)</td>
|
|
<td>
|
|
@if (item.QuantityOnHand > 0)
|
|
{
|
|
<span class="badge bg-success">@item.QuantityOnHand</span>
|
|
}
|
|
else
|
|
{
|
|
<span class="badge bg-secondary">0</span>
|
|
}
|
|
</td>
|
|
<td>
|
|
<div class="d-flex gap-1">
|
|
<a href="stock/@item.Id" class="btn btn-sm btn-outline-primary">Edit</a>
|
|
<button class="btn btn-sm btn-outline-danger" @onclick="() => ConfirmDelete(item)">Delete</button>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
|
|
<Pager TotalCount="stockItems.Count" PageSize="pageSize" CurrentPage="currentPage" CurrentPageChanged="OnPageChanged" />
|
|
}
|
|
|
|
<ConfirmDialog @ref="deleteDialog"
|
|
Title="Delete Stock Item"
|
|
Message="@deleteMessage"
|
|
ConfirmText="Delete"
|
|
OnConfirm="DeleteConfirmed" />
|
|
|
|
@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();
|
|
loading = false;
|
|
}
|
|
|
|
private void ConfirmDelete(StockItem item)
|
|
{
|
|
itemToDelete = item;
|
|
deleteMessage = $"Are you sure you want to delete \"{item.Material.DisplayName} - {ArchUnits.FormatFromInches((double)item.LengthInches)}\"?";
|
|
deleteDialog.Show();
|
|
}
|
|
|
|
private async Task DeleteConfirmed()
|
|
{
|
|
if (itemToDelete != null)
|
|
{
|
|
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;
|
|
}
|