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.5 KiB
Plaintext
173 lines
5.5 KiB
Plaintext
@page "/materials"
|
|
@inject MaterialService MaterialService
|
|
@inject NavigationManager Navigation
|
|
|
|
<PageTitle>Materials</PageTitle>
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
<h1>Materials</h1>
|
|
<a href="materials/new" class="btn btn-primary">Add Material</a>
|
|
</div>
|
|
|
|
<p class="text-muted mb-4">
|
|
Manage your material catalog here. Materials define the types of stock you work with — shape, size, type, and
|
|
grade. Once added, materials can be assigned to jobs and used to generate optimized cut lists.
|
|
</p>
|
|
|
|
@if (loading)
|
|
{
|
|
<p><em>Loading...</em></p>
|
|
}
|
|
else if (!string.IsNullOrEmpty(errorMessage))
|
|
{
|
|
<div class="alert alert-danger">
|
|
<strong>Error loading materials:</strong>
|
|
<pre style="white-space: pre-wrap;">@errorMessage</pre>
|
|
</div>
|
|
}
|
|
else if (materials.Count == 0)
|
|
{
|
|
<div class="alert alert-info">
|
|
No materials found. <a href="materials/new">Add your first material</a>.
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<MaterialFilter AvailableGrades="availableGrades" Value="filterState" ValueChanged="OnFilterChanged" />
|
|
|
|
@if (filteredMaterials.Count == 0)
|
|
{
|
|
<div class="alert alert-warning">
|
|
No materials 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 style="width: 100px;">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (var material in pagedMaterials)
|
|
{
|
|
<tr>
|
|
<td>@material.Shape.GetDisplayName()</td>
|
|
<td>@material.Type</td>
|
|
<td>@material.Grade</td>
|
|
<td>@material.Size</td>
|
|
<td>
|
|
<div class="d-flex gap-1">
|
|
<a href="materials/@material.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(material)" title="Delete"><i class="bi bi-trash"></i></button>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
|
|
<Pager TotalCount="filteredMaterials.Count" PageSize="pageSize" CurrentPage="currentPage" CurrentPageChanged="OnPageChanged" />
|
|
}
|
|
}
|
|
|
|
<ConfirmDialog @ref="deleteDialog"
|
|
Title="Delete Material"
|
|
Message="@deleteMessage"
|
|
ConfirmText="Delete"
|
|
OnConfirm="DeleteConfirmed" />
|
|
|
|
@code {
|
|
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 MaterialFilterState filterState = new();
|
|
|
|
private List<Material> filteredMaterials => materials.Where(m =>
|
|
{
|
|
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))
|
|
return false;
|
|
}
|
|
return true;
|
|
}).ToList();
|
|
|
|
private IEnumerable<string> availableGrades => materials
|
|
.Select(m => m.Grade)
|
|
.Where(g => !string.IsNullOrEmpty(g))
|
|
.Distinct()
|
|
.OrderBy(g => g)!;
|
|
|
|
private IEnumerable<Material> pagedMaterials => filteredMaterials
|
|
.Skip((currentPage - 1) * pageSize)
|
|
.Take(pageSize);
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
materials = await MaterialService.GetAllAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errorMessage = ex.ToString();
|
|
}
|
|
finally
|
|
{
|
|
loading = false;
|
|
}
|
|
}
|
|
|
|
private void OnFilterChanged(MaterialFilterState state)
|
|
{
|
|
filterState = state;
|
|
currentPage = 1;
|
|
}
|
|
|
|
private void ConfirmDelete(Material material)
|
|
{
|
|
materialToDelete = material;
|
|
deleteMessage = $"Are you sure you want to delete \"{material.Shape} - {material.Size}\"?";
|
|
deleteDialog.Show();
|
|
}
|
|
|
|
private async Task DeleteConfirmed()
|
|
{
|
|
if (materialToDelete != null)
|
|
{
|
|
await MaterialService.DeleteAsync(materialToDelete.Id);
|
|
materials = await MaterialService.GetAllAsync();
|
|
|
|
var totalPages = (int)Math.Ceiling((double)filteredMaterials.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);
|
|
}
|