Integrate MaterialFilter component for filtering by shape, type, grade, and free-text search. Pagination now reflects filtered results. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
173 lines
5.9 KiB
Plaintext
173 lines
5.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
|
|
{
|
|
<MaterialFilter AvailableGrades="availableGrades" Value="filterState" ValueChanged="OnFilterChanged" />
|
|
|
|
@if (filteredItems.Count == 0)
|
|
{
|
|
<div class="alert alert-warning">
|
|
No stock items match your filters.
|
|
</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: 100px;">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" title="Edit"><i class="bi bi-pencil"></i></a>
|
|
<button class="btn btn-sm btn-outline-danger" @onclick="() => ConfirmDelete(item)" title="Delete"><i class="bi bi-trash"></i></button>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
|
|
<Pager TotalCount="filteredItems.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 MaterialFilterState filterState = new();
|
|
|
|
private List<StockItem> filteredItems => stockItems.Where(s =>
|
|
{
|
|
var m = s.Material;
|
|
if (filterState.Shape.HasValue && m.Shape != filterState.Shape.Value)
|
|
return false;
|
|
if (filterState.Type.HasValue && m.Type != filterState.Type.Value)
|
|
return false;
|
|
if (!string.IsNullOrEmpty(filterState.Grade) && m.Grade != filterState.Grade)
|
|
return false;
|
|
if (!string.IsNullOrWhiteSpace(filterState.SearchText))
|
|
{
|
|
var search = filterState.SearchText.Trim();
|
|
if (!Contains(m.Size, search)
|
|
&& !Contains(m.Grade, search)
|
|
&& !Contains(m.Description, search)
|
|
&& !Contains(m.Shape.GetDisplayName(), search)
|
|
&& !Contains(s.Name, search)
|
|
&& !Contains(s.Notes, search))
|
|
return false;
|
|
}
|
|
return true;
|
|
}).ToList();
|
|
|
|
private IEnumerable<string> availableGrades => stockItems
|
|
.Select(s => s.Material.Grade)
|
|
.Where(g => !string.IsNullOrEmpty(g))
|
|
.Distinct()
|
|
.OrderBy(g => g)!;
|
|
|
|
private IEnumerable<StockItem> pagedItems => filteredItems
|
|
.Skip((currentPage - 1) * pageSize)
|
|
.Take(pageSize);
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
stockItems = await StockItemService.GetAllAsync();
|
|
loading = false;
|
|
}
|
|
|
|
private void OnFilterChanged(MaterialFilterState state)
|
|
{
|
|
filterState = state;
|
|
currentPage = 1;
|
|
}
|
|
|
|
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)filteredItems.Count / pageSize);
|
|
if (currentPage > totalPages && totalPages > 0)
|
|
currentPage = totalPages;
|
|
}
|
|
}
|
|
|
|
private void OnPageChanged(int page) => currentPage = page;
|
|
|
|
private static bool Contains(string? value, string search) =>
|
|
value != null && value.Contains(search, StringComparison.OrdinalIgnoreCase);
|
|
}
|