feat(client): migrate ComponentLotFilterPanel to API clients
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
@* Component lot filter panel with upload/download/clear functionality *@
|
@* Component lot filter panel with upload/download/clear functionality *@
|
||||||
@inject IFileService FileService
|
@using JdeScoping.Core.ApiContracts
|
||||||
|
@using JdeScoping.Core.ViewModels
|
||||||
|
@inject IFileApiClient FileApi
|
||||||
@inject DialogService DialogService
|
@inject DialogService DialogService
|
||||||
@inject NotificationService NotificationService
|
@inject NotificationService NotificationService
|
||||||
|
|
||||||
@@ -47,8 +49,16 @@
|
|||||||
|
|
||||||
private async Task DownloadTemplateAsync()
|
private async Task DownloadTemplateAsync()
|
||||||
{
|
{
|
||||||
var lotData = ComponentLots.Select(cl => new { cl.LotNumber, cl.ItemNumber }).ToList();
|
var lotData = ComponentLots.Select(cl => new LotViewModel { LotNumber = cl.LotNumber, ItemNumber = cl.ItemNumber }).ToList().AsReadOnly();
|
||||||
await FileService.DownloadTemplateAsync("componentlots", lotData);
|
var result = await FileApi.DownloadComponentLotsTemplateAsync(lotData);
|
||||||
|
result.Switch(
|
||||||
|
bytes => { _ = JSRuntime.InvokeVoidAsync("downloadFile", "componentlots_template.xlsx", bytes); },
|
||||||
|
_ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Template not found."); },
|
||||||
|
validation => { NotificationService.Notify(NotificationSeverity.Error, "Error", string.Join("; ", validation.FieldErrors.SelectMany(e => e.Value))); },
|
||||||
|
_ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Session expired."); },
|
||||||
|
_ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Access denied."); },
|
||||||
|
error => { NotificationService.Notify(NotificationSeverity.Error, "Error", error.Message); }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task TriggerFileInput()
|
private async Task TriggerFileInput()
|
||||||
@@ -64,19 +74,22 @@
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var stream = e.File.OpenReadStream(maxAllowedSize: 10 * 1024 * 1024); // 10MB max
|
using var stream = e.File.OpenReadStream(maxAllowedSize: 10 * 1024 * 1024); // 10MB max
|
||||||
var result = await FileService.UploadAsync<ComponentLotViewModel>("componentlots", stream, e.File.Name);
|
var result = await FileApi.UploadComponentLotsAsync(stream, e.File.Name);
|
||||||
|
|
||||||
if (result.WasSuccessful)
|
result.Switch(
|
||||||
{
|
lots =>
|
||||||
ComponentLots.Clear();
|
{
|
||||||
ComponentLots.AddRange(result.Data);
|
ComponentLots.Clear();
|
||||||
await ComponentLotsChanged.InvokeAsync(ComponentLots);
|
ComponentLots.AddRange(lots.Select(l => new ComponentLotViewModel { LotNumber = l.LotNumber, ItemNumber = l.ItemNumber }));
|
||||||
NotificationService.Notify(NotificationSeverity.Success, "Upload Complete", $"Loaded {result.Data.Count} component lots.");
|
_ = ComponentLotsChanged.InvokeAsync(ComponentLots);
|
||||||
}
|
NotificationService.Notify(NotificationSeverity.Success, "Upload Complete", $"Loaded {lots.Count} component lots.");
|
||||||
else
|
},
|
||||||
{
|
_ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Upload endpoint not found."); },
|
||||||
NotificationService.Notify(NotificationSeverity.Error, "Upload Failed", result.ErrorMessage);
|
validation => { NotificationService.Notify(NotificationSeverity.Error, "Upload Failed", string.Join("; ", validation.FieldErrors.SelectMany(e => e.Value))); },
|
||||||
}
|
_ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Session expired."); },
|
||||||
|
_ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Access denied."); },
|
||||||
|
error => { NotificationService.Notify(NotificationSeverity.Error, "Upload Failed", error.Message); }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user