diff --git a/CutList.Web/Components/Pages/Error.razor b/CutList.Web/Components/Pages/Error.razor new file mode 100644 index 0000000..da844c2 --- /dev/null +++ b/CutList.Web/Components/Pages/Error.razor @@ -0,0 +1,17 @@ +@page "/Error" + +Error + +
+
+
+
+
+

Something went wrong

+

An unexpected error occurred. Please try again later.

+ Return to home page +
+
+
+
+
diff --git a/CutList.Web/Components/Pages/Jobs/Edit.razor b/CutList.Web/Components/Pages/Jobs/Edit.razor index f0b6b73..4e0dcea 100644 --- a/CutList.Web/Components/Pages/Jobs/Edit.razor +++ b/CutList.Web/Components/Pages/Jobs/Edit.razor @@ -32,7 +32,14 @@ } -@if (loading) +@if (!string.IsNullOrEmpty(loadError)) +{ +
+
Error loading job
+
@loadError
+
+} +else if (loading) {

Loading...

} @@ -331,6 +338,7 @@ else private List cuttingTools = new(); private bool loading = true; + private string? loadError; private bool savingJob; private string? jobErrorMessage; private Tab activeTab = Tab.Details; @@ -388,43 +396,50 @@ else protected override async Task OnInitializedAsync() { - materials = await MaterialService.GetAllAsync(); - cuttingTools = await JobService.GetCuttingToolsAsync(); - - if (Id.HasValue) + try { - var existing = await JobService.GetByIdAsync(Id.Value); - if (existing == null) - { - Navigation.NavigateTo("jobs"); - return; - } - job = existing; + materials = await MaterialService.GetAllAsync(); + cuttingTools = await JobService.GetCuttingToolsAsync(); - // Load saved optimization results if available - if (job.OptimizationResultJson != null) + if (Id.HasValue) { - LoadSavedResults(); + var existing = await JobService.GetByIdAsync(Id.Value); + if (existing == null) + { + Navigation.NavigateTo("jobs"); + return; + } + job = existing; + + // Load saved optimization results if available + if (job.OptimizationResultJson != null) + { + await LoadSavedResultsAsync(); + } + } + else + { + // Set default cutting tool for new jobs + var defaultTool = await JobService.GetDefaultCuttingToolAsync(); + if (defaultTool != null) + { + job.CuttingToolId = defaultTool.Id; + } } } - else + catch (Exception ex) { - // Set default cutting tool for new jobs - var defaultTool = await JobService.GetDefaultCuttingToolAsync(); - if (defaultTool != null) - { - job.CuttingToolId = defaultTool.Id; - } + loadError = ex.ToString(); } loading = false; } - private void LoadSavedResults() + private async Task LoadSavedResultsAsync() { try { - packResult = PackingService.LoadSavedResult(job.OptimizationResultJson!); + packResult = await PackingService.LoadSavedResultAsync(job.OptimizationResultJson!); if (packResult != null) { summary = PackingService.GetSummary(packResult);