Files
CutList/CutList.Web/Components/Pages/Jobs/Index.razor
AJ Isaacs 59f86c8e79 refactor: Merge Results page into Job Edit as a tab
Move optimization results UI from separate Results.razor page into
the Edit.razor tabbed editor. Results are now loaded from saved JSON
on page load instead of re-running on every visit. Remove the
standalone optimize button from Jobs index.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 22:12:57 -05:00

143 lines
4.5 KiB
Plaintext

@page "/jobs"
@inject JobService JobService
@inject NavigationManager Navigation
<PageTitle>Jobs</PageTitle>
<div class="d-flex justify-content-between align-items-center mb-3">
<h1>Jobs</h1>
<div class="d-flex gap-2">
<button class="btn btn-success" @onclick="QuickCreateJob" disabled="@creating">
@if (creating)
{
<span class="spinner-border spinner-border-sm me-1"></span>
}
Quick Create
</button>
<a href="jobs/new" class="btn btn-primary">New Job</a>
</div>
</div>
<p class="text-muted mb-4">
Jobs organize the parts you need to cut for a project. Add parts with their required lengths and quantities,
assign stock materials, then run the optimizer to generate an efficient cut list that minimizes waste.
</p>
@if (loading)
{
<p><em>Loading...</em></p>
}
else if (jobs.Count == 0)
{
<div class="alert alert-info">
No jobs found. <a href="jobs/new">Create your first job</a>.
</div>
}
else
{
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Job #</th>
<th>Name</th>
<th>Customer</th>
<th>Cutting Tool</th>
<th>Last Modified</th>
<th style="width: 150px;">Actions</th>
</tr>
</thead>
<tbody>
@foreach (var job in pagedJobs)
{
<tr>
<td>
<a href="jobs/@job.Id">@job.JobNumber</a>
@if (job.IsLocked)
{
<i class="bi bi-lock-fill text-warning ms-1" title="Locked — materials ordered"></i>
}
</td>
<td>@(job.Name ?? "-")</td>
<td>@(job.Customer ?? "-")</td>
<td>@(job.CuttingTool?.Name ?? "-")</td>
<td>@((job.UpdatedAt ?? job.CreatedAt).ToLocalTime().ToString("g"))</td>
<td>
<a href="jobs/@job.Id" class="btn btn-sm btn-outline-primary" title="Edit"><i class="bi bi-pencil"></i></a>
<button class="btn btn-sm btn-outline-secondary" @onclick="() => DuplicateJob(job)" title="Copy"><i class="bi bi-copy"></i></button>
<button class="btn btn-sm btn-outline-danger" @onclick="() => ConfirmDelete(job)" title="Delete"><i class="bi bi-trash"></i></button>
</td>
</tr>
}
</tbody>
</table>
<Pager TotalCount="jobs.Count" PageSize="pageSize" CurrentPage="currentPage" CurrentPageChanged="OnPageChanged" />
}
<ConfirmDialog @ref="deleteDialog"
Title="Delete Job"
Message="@deleteMessage"
ConfirmText="Delete"
OnConfirm="DeleteConfirmed" />
@code {
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();
loading = false;
}
private async Task QuickCreateJob()
{
creating = true;
try
{
var job = await JobService.QuickCreateAsync();
Navigation.NavigateTo($"jobs/{job.Id}");
}
finally
{
creating = false;
}
}
private void ConfirmDelete(Job job)
{
jobToDelete = job;
deleteMessage = $"Are you sure you want to delete \"{job.DisplayName}\"? This will also delete all parts.";
deleteDialog.Show();
}
private async Task DeleteConfirmed()
{
if (jobToDelete != null)
{
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);
Navigation.NavigateTo($"jobs/{duplicate.Id}");
}
}