@page "/tools" @inject ProjectService ProjectService @using CutList.Core.Formatting Cutting Tools

Cutting Tools

@if (loading) {

Loading...

} else { @if (showForm) {
@(editingTool == null ? "Add Cutting Tool" : "Edit Cutting Tool")
Common: 1/16" = 0.0625, 1/8" = 0.125
@if (!string.IsNullOrEmpty(errorMessage)) {
@errorMessage
}
} @if (tools.Count == 0) {
No cutting tools found. Add your first cutting tool to get started.
} else { @foreach (var tool in tools) { }
Name Kerf Width Default Actions
@tool.Name @FormatKerf(tool.KerfInches) @if (tool.IsDefault) { Default }
} } @code { private List tools = new(); private bool loading = true; private bool showForm; private bool saving; private string? errorMessage; private CuttingTool formTool = new(); private CuttingTool? editingTool; private ConfirmDialog deleteDialog = null!; private CuttingTool? toolToDelete; private string deleteMessage = ""; protected override async Task OnInitializedAsync() { tools = await ProjectService.GetCuttingToolsAsync(); loading = false; } private void ShowAddForm() { editingTool = null; formTool = new CuttingTool { KerfInches = 0.125m }; showForm = true; errorMessage = null; } private void Edit(CuttingTool tool) { editingTool = tool; formTool = new CuttingTool { Id = tool.Id, Name = tool.Name, KerfInches = tool.KerfInches, IsDefault = tool.IsDefault, IsActive = tool.IsActive }; showForm = true; errorMessage = null; } private void CancelForm() { showForm = false; editingTool = null; errorMessage = null; } private async Task SaveAsync() { errorMessage = null; saving = true; try { if (string.IsNullOrWhiteSpace(formTool.Name)) { errorMessage = "Name is required"; return; } if (formTool.KerfInches < 0) { errorMessage = "Kerf width cannot be negative"; return; } if (editingTool == null) { await ProjectService.CreateCuttingToolAsync(formTool); } else { await ProjectService.UpdateCuttingToolAsync(formTool); } tools = await ProjectService.GetCuttingToolsAsync(); showForm = false; editingTool = null; } finally { saving = false; } } private void ConfirmDelete(CuttingTool tool) { toolToDelete = tool; deleteMessage = $"Are you sure you want to delete \"{tool.Name}\"?"; deleteDialog.Show(); } private async Task DeleteConfirmed() { if (toolToDelete != null) { await ProjectService.DeleteCuttingToolAsync(toolToDelete.Id); tools = await ProjectService.GetCuttingToolsAsync(); } } private string FormatKerf(decimal kerf) { // Show as fraction if it's a common value var inches = (double)kerf; var formatted = FormatHelper.ConvertToMixedFraction(inches); return $"{formatted}\" ({kerf:0.####}\")"; } }