Redesigns Project Edit with a tabbed interface and adds material selection (shape -> size) when adding parts. Updates Index to show customer instead of material. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
400 lines
14 KiB
Plaintext
400 lines
14 KiB
Plaintext
@page "/projects/new"
|
|
@page "/projects/{Id:int}"
|
|
@inject ProjectService ProjectService
|
|
@inject MaterialService MaterialService
|
|
@inject NavigationManager Navigation
|
|
@using CutList.Core.Formatting
|
|
|
|
<PageTitle>@(IsNew ? "New Project" : project.Name)</PageTitle>
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
<h1>@(IsNew ? "New Project" : project.Name)</h1>
|
|
@if (!IsNew)
|
|
{
|
|
<a href="projects/@Id/results" class="btn btn-success">Run Optimization</a>
|
|
}
|
|
</div>
|
|
|
|
@if (loading)
|
|
{
|
|
<p><em>Loading...</em></p>
|
|
}
|
|
else if (IsNew)
|
|
{
|
|
<!-- New Project: Simple form -->
|
|
<div class="row">
|
|
<div class="col-lg-6">
|
|
@RenderDetailsForm()
|
|
</div>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<!-- Existing Project: Tabbed interface -->
|
|
<ul class="nav nav-tabs mb-3" role="tablist">
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link @(activeTab == Tab.Details ? "active" : "")"
|
|
@onclick="() => SetTab(Tab.Details)" type="button">
|
|
Details
|
|
</button>
|
|
</li>
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link @(activeTab == Tab.Parts ? "active" : "")"
|
|
@onclick="() => SetTab(Tab.Parts)" type="button">
|
|
Parts
|
|
@if (project.Parts.Count > 0)
|
|
{
|
|
<span class="badge bg-secondary ms-1">@project.Parts.Sum(p => p.Quantity)</span>
|
|
}
|
|
</button>
|
|
</li>
|
|
</ul>
|
|
|
|
<div class="tab-content">
|
|
@if (activeTab == Tab.Details)
|
|
{
|
|
<div class="row">
|
|
<div class="col-lg-6">
|
|
@RenderDetailsForm()
|
|
</div>
|
|
</div>
|
|
}
|
|
else if (activeTab == Tab.Parts)
|
|
{
|
|
@RenderPartsTab()
|
|
}
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
private enum Tab { Details, Parts }
|
|
|
|
[Parameter]
|
|
public int? Id { get; set; }
|
|
|
|
private Project project = new();
|
|
private List<Material> materials = new();
|
|
private List<CuttingTool> cuttingTools = new();
|
|
|
|
private bool loading = true;
|
|
private bool savingProject;
|
|
private string? projectErrorMessage;
|
|
private Tab activeTab = Tab.Details;
|
|
|
|
private void SetTab(Tab tab) => activeTab = tab;
|
|
|
|
// Parts form
|
|
private bool showPartForm;
|
|
private ProjectPart newPart = new();
|
|
private ProjectPart? editingPart;
|
|
private string? partErrorMessage;
|
|
private string selectedShape = string.Empty;
|
|
|
|
private IEnumerable<string> DistinctShapes => materials.Select(m => m.Shape).Distinct().OrderBy(s => s);
|
|
private IEnumerable<Material> FilteredMaterials => string.IsNullOrEmpty(selectedShape)
|
|
? Enumerable.Empty<Material>()
|
|
: materials.Where(m => m.Shape == selectedShape).OrderBy(m => m.Size);
|
|
|
|
private bool IsNew => !Id.HasValue;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
materials = await MaterialService.GetAllAsync();
|
|
cuttingTools = await ProjectService.GetCuttingToolsAsync();
|
|
|
|
if (Id.HasValue)
|
|
{
|
|
var existing = await ProjectService.GetByIdAsync(Id.Value);
|
|
if (existing == null)
|
|
{
|
|
Navigation.NavigateTo("projects");
|
|
return;
|
|
}
|
|
project = existing;
|
|
}
|
|
else
|
|
{
|
|
// Set default cutting tool for new projects
|
|
var defaultTool = await ProjectService.GetDefaultCuttingToolAsync();
|
|
if (defaultTool != null)
|
|
{
|
|
project.CuttingToolId = defaultTool.Id;
|
|
}
|
|
}
|
|
|
|
loading = false;
|
|
}
|
|
|
|
private RenderFragment RenderDetailsForm() => __builder =>
|
|
{
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h5 class="mb-0">Project Details</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<EditForm Model="project" OnValidSubmit="SaveProjectAsync">
|
|
<div class="mb-3">
|
|
<label class="form-label">Project Name</label>
|
|
<InputText class="form-control" @bind-Value="project.Name" />
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Customer</label>
|
|
<InputText class="form-control" @bind-Value="project.Customer" placeholder="Customer name" />
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Cutting Tool</label>
|
|
<InputSelect class="form-select" @bind-Value="project.CuttingToolId">
|
|
<option value="">-- Select Tool --</option>
|
|
@foreach (var tool in cuttingTools)
|
|
{
|
|
<option value="@tool.Id">@tool.Name (@tool.KerfInches" kerf)</option>
|
|
}
|
|
</InputSelect>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Notes</label>
|
|
<InputTextArea class="form-control" @bind-Value="project.Notes" rows="3" />
|
|
</div>
|
|
|
|
@if (!string.IsNullOrEmpty(projectErrorMessage))
|
|
{
|
|
<div class="alert alert-danger">@projectErrorMessage</div>
|
|
}
|
|
|
|
<div class="d-flex gap-2">
|
|
<button type="submit" class="btn btn-primary" disabled="@savingProject">
|
|
@if (savingProject)
|
|
{
|
|
<span class="spinner-border spinner-border-sm me-1"></span>
|
|
}
|
|
@(IsNew ? "Create Project" : "Save")
|
|
</button>
|
|
<a href="projects" class="btn btn-outline-secondary">Back</a>
|
|
</div>
|
|
</EditForm>
|
|
</div>
|
|
</div>
|
|
};
|
|
|
|
private RenderFragment RenderPartsTab() => __builder =>
|
|
{
|
|
<div class="card">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<h5 class="mb-0">Parts to Cut</h5>
|
|
<button class="btn btn-primary" @onclick="ShowAddPartForm">Add Part</button>
|
|
</div>
|
|
<div class="card-body">
|
|
@if (showPartForm)
|
|
{
|
|
<div class="border rounded p-3 mb-3 bg-light">
|
|
<h6>@(editingPart == null ? "Add Part" : "Edit Part")</h6>
|
|
<div class="row g-3">
|
|
<div class="col-md-2">
|
|
<label class="form-label">Shape</label>
|
|
<select class="form-select" @bind="selectedShape" @bind:after="OnShapeChanged">
|
|
<option value="">-- Select --</option>
|
|
@foreach (var shape in DistinctShapes)
|
|
{
|
|
<option value="@shape">@shape</option>
|
|
}
|
|
</select>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<label class="form-label">Size</label>
|
|
<select class="form-select" @bind="newPart.MaterialId" disabled="@string.IsNullOrEmpty(selectedShape)">
|
|
<option value="0">-- Select --</option>
|
|
@foreach (var material in FilteredMaterials)
|
|
{
|
|
<option value="@material.Id">@material.Size</option>
|
|
}
|
|
</select>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label class="form-label">Length</label>
|
|
<LengthInput @bind-Value="newPart.LengthInches" />
|
|
</div>
|
|
<div class="col-md-2">
|
|
<label class="form-label">Qty</label>
|
|
<input type="number" class="form-control" @bind="newPart.Quantity" min="1" />
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label class="form-label">Name <span class="text-muted fw-normal">(optional)</span></label>
|
|
<input type="text" class="form-control" @bind="newPart.Name" placeholder="Part name" />
|
|
</div>
|
|
</div>
|
|
@if (!string.IsNullOrEmpty(partErrorMessage))
|
|
{
|
|
<div class="alert alert-danger mt-3 mb-0">@partErrorMessage</div>
|
|
}
|
|
<div class="mt-3 d-flex gap-2">
|
|
<button class="btn btn-primary" @onclick="SavePartAsync">@(editingPart == null ? "Add Part" : "Save Changes")</button>
|
|
<button class="btn btn-outline-secondary" @onclick="CancelPartForm">Cancel</button>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@if (project.Parts.Count == 0)
|
|
{
|
|
<div class="text-center py-4 text-muted">
|
|
<p class="mb-2">No parts added yet.</p>
|
|
<p class="small">Add the parts you need to cut, selecting the material for each.</p>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<div class="table-responsive">
|
|
<table class="table table-hover mb-0">
|
|
<thead>
|
|
<tr>
|
|
<th>Material</th>
|
|
<th>Length</th>
|
|
<th>Qty</th>
|
|
<th>Name</th>
|
|
<th style="width: 120px;">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (var part in project.Parts)
|
|
{
|
|
<tr>
|
|
<td>@part.Material.DisplayName</td>
|
|
<td>@ArchUnits.FormatFromInches((double)part.LengthInches)</td>
|
|
<td>@part.Quantity</td>
|
|
<td>@(string.IsNullOrWhiteSpace(part.Name) ? "-" : part.Name)</td>
|
|
<td>
|
|
<button class="btn btn-sm btn-outline-primary me-1" @onclick="() => EditPart(part)">Edit</button>
|
|
<button class="btn btn-sm btn-outline-danger" @onclick="() => DeletePart(part)">Delete</button>
|
|
</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="mt-3 text-muted">
|
|
Total: @project.Parts.Sum(p => p.Quantity) pieces
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
};
|
|
|
|
private async Task SaveProjectAsync()
|
|
{
|
|
projectErrorMessage = null;
|
|
savingProject = true;
|
|
|
|
try
|
|
{
|
|
if (string.IsNullOrWhiteSpace(project.Name))
|
|
{
|
|
projectErrorMessage = "Project name is required";
|
|
return;
|
|
}
|
|
|
|
if (IsNew)
|
|
{
|
|
var created = await ProjectService.CreateAsync(project);
|
|
Navigation.NavigateTo($"projects/{created.Id}");
|
|
}
|
|
else
|
|
{
|
|
await ProjectService.UpdateAsync(project);
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
savingProject = false;
|
|
}
|
|
}
|
|
|
|
// Parts methods
|
|
private void ShowAddPartForm()
|
|
{
|
|
editingPart = null;
|
|
newPart = new ProjectPart { ProjectId = Id!.Value, Quantity = 1 };
|
|
selectedShape = string.Empty;
|
|
showPartForm = true;
|
|
partErrorMessage = null;
|
|
}
|
|
|
|
private void OnShapeChanged()
|
|
{
|
|
newPart.MaterialId = 0;
|
|
}
|
|
|
|
private void EditPart(ProjectPart part)
|
|
{
|
|
editingPart = part;
|
|
newPart = new ProjectPart
|
|
{
|
|
Id = part.Id,
|
|
ProjectId = part.ProjectId,
|
|
MaterialId = part.MaterialId,
|
|
Name = part.Name,
|
|
LengthInches = part.LengthInches,
|
|
Quantity = part.Quantity,
|
|
SortOrder = part.SortOrder
|
|
};
|
|
selectedShape = part.Material?.Shape ?? string.Empty;
|
|
showPartForm = true;
|
|
partErrorMessage = null;
|
|
}
|
|
|
|
private void CancelPartForm()
|
|
{
|
|
showPartForm = false;
|
|
editingPart = null;
|
|
}
|
|
|
|
private async Task SavePartAsync()
|
|
{
|
|
partErrorMessage = null;
|
|
|
|
if (string.IsNullOrEmpty(selectedShape))
|
|
{
|
|
partErrorMessage = "Please select a shape";
|
|
return;
|
|
}
|
|
|
|
if (newPart.MaterialId == 0)
|
|
{
|
|
partErrorMessage = "Please select a size";
|
|
return;
|
|
}
|
|
|
|
if (newPart.LengthInches <= 0)
|
|
{
|
|
partErrorMessage = "Length must be greater than zero";
|
|
return;
|
|
}
|
|
|
|
if (newPart.Quantity < 1)
|
|
{
|
|
partErrorMessage = "Quantity must be at least 1";
|
|
return;
|
|
}
|
|
|
|
if (editingPart == null)
|
|
{
|
|
await ProjectService.AddPartAsync(newPart);
|
|
}
|
|
else
|
|
{
|
|
await ProjectService.UpdatePartAsync(newPart);
|
|
}
|
|
|
|
project = (await ProjectService.GetByIdAsync(Id!.Value))!;
|
|
showPartForm = false;
|
|
editingPart = null;
|
|
}
|
|
|
|
private async Task DeletePart(ProjectPart part)
|
|
{
|
|
await ProjectService.DeletePartAsync(part.Id);
|
|
project = (await ProjectService.GetByIdAsync(Id!.Value))!;
|
|
}
|
|
}
|