Gestiti salvataggi rest

This commit is contained in:
2026-03-02 10:50:34 +01:00
parent e027d8e5cf
commit ab9578a45f
58 changed files with 1235 additions and 305 deletions

View File

@@ -1,13 +1,19 @@
@page "/ispezione"
@using SteUp.Shared.Components.Layout
@using SteUp.Shared.Components.Layout.Overlay
@using SteUp.Shared.Components.SingleElements.Card
@using SteUp.Shared.Core.Dto
@using SteUp.Shared.Core.Entities
@using SteUp.Shared.Core.Enum
@using SteUp.Shared.Core.Interface.IntegryApi
@using SteUp.Shared.Core.Interface.LocalDb
@using SteUp.Shared.Core.Messages.Ispezione
@using SteUp.Shared.Core.Messages.Scheda
@inject NewSchedaService NewScheda
@inject CompleteInspectionService CompleteInspection
@inject IIspezioniService IspezioniService
@inject IDialogService Dialog
@inject IIntegrySteupService IntegrySteupService
@implements IDisposable
<HeaderLayout Title="Ispezione" BackTo="Indietro" Back="true"/>
@@ -30,9 +36,23 @@
</MudChip>
</div>
<div class="action-scheda-group">
<MudIconButton Variant="Variant.Filled" Icon="@Icons.Material.Rounded.Add"
Color="Color.Warning" Size="Size.Medium"
OnClick="@(() => CreateNewScheda(group.Key))"/>
@if (NetworkService.IsNetworkAvailable())
{
<MudFab StartIcon="@Icons.Material.Rounded.Add"
Color="Color.Warning" Size="Size.Small"
OnClick="@(() => CreateNewScheda(group.Key))"/>
<MudFab StartIcon="@Icons.Material.Rounded.CloudSync" Label="Esporta reparto"
Color="Color.Success" Size="Size.Small"
OnClick="@(() => ExportReparto(group.Key))"/>
}
else
{
<MudFab StartIcon="@Icons.Material.Rounded.Add"
Label="@($"Nuova scheda su {group.Key.Descrizione}")"
Color="Color.Warning" Size="Size.Medium"
OnClick="@(() => CreateNewScheda(group.Key))"/>
}
</div>
</div>
</TitleContent>
@@ -51,13 +71,18 @@
}
</div>
<SpinnerOverlay VisibleOverlay="VisibleOverlay"/>
@code {
private List<Scheda> SchedeList { get; set; } = [];
private Dictionary<JtbFasiDto, List<Scheda>> SchedeGrouped { get; set; } = [];
private bool VisibleOverlay { get; set; }
protected override void OnInitialized()
{
NewScheda.OnNewScheda += LoadSchede;
CompleteInspection.OnComplete += HandleCompleteInspection;
LoadSchede();
}
@@ -77,6 +102,48 @@
});
}
private async void HandleCompleteInspection()
{
try
{
await InvokeAsync(() =>
{
VisibleOverlay = true;
StateHasChanged();
});
var ispezione = SteupDataService.InspectionPageState.Ispezione;
SteupDataService.InspectionPageState.Ispezione.Stato = StatusEnum.Completata;
await IntegrySteupService.CompleteInspection(ispezione.ActivityId!);
await IspezioniService.UpdateStatoIspezioneAsync(
ispezione.CodMdep,
ispezione.Data,
ispezione.Rilevatore,
StatusEnum.Completata
);
await InvokeAsync(() =>
{
VisibleOverlay = false;
StateHasChanged();
});
}
catch (Exception e)
{
Console.WriteLine(e.Message);
await InvokeAsync(() =>
{
VisibleOverlay = false;
StateHasChanged();
});
OnError(e.Message);
}
}
private void GroupSchede()
{
SchedeGrouped = SchedeList
@@ -114,12 +181,76 @@
new Scheda { Reparto = jtbFasi }
);
if (modal is {Canceled: false}) LoadSchede();
if (modal is { Canceled: false }) LoadSchede();
}
private async Task ExportReparto(JtbFasiDto jtbFasi)
{
VisibleOverlay = true;
StateHasChanged();
var ispezione = SteupDataService.InspectionPageState.Ispezione;
var saveRequest = SchedeGrouped[jtbFasi].ConvertAll(x =>
{
return new SaveRequestDto
{
LocalIdScheda = x.Id,
ActivityTypeId = x.ActivityTypeId,
CodJfas = x.CodJfas,
CodMdep = ispezione.CodMdep,
DataCreazione = ispezione.Data,
Note = x.Note,
PersonaRif = x.Responsabile,
Barcodes = x.Articoli.ConvertAll(y => y.Barcode),
Scandeza = (ScadenzaEnum)x.Scadenza,
ParentActivityId = x.Ispezione?.ActivityId
};
});
var apiResponse = await IntegrySteupService.SaveMultipleSchede(saveRequest);
if (apiResponse != null)
{
SteupDataService.InspectionPageState.Ispezione.ActivityId = apiResponse.ActivityIdIspezione;
await IspezioniService.UpdateActivityIdIspezioneAsync(ispezione.CodMdep, ispezione.Data,
UserSession.User.Username, apiResponse.ActivityIdIspezione
);
if (apiResponse.ActivityIdSchedaList.IsNullOrEmpty()) return;
foreach (var scheda in SchedeGrouped[jtbFasi])
{
scheda.ActivityId = apiResponse.ActivityIdScheda;
await IspezioniService.UpdateActivityIdSchedaAsync(scheda.Id, scheda.ActivityId);
var activityId = apiResponse.ActivityIdSchedaList!.Find(x =>
x.LocalId != null && x.LocalId == scheda.Id
)?.ActivityId;
if (activityId == null) return;
scheda.ActivityId = activityId;
await IspezioniService.UpdateActivityIdSchedaAsync(scheda.Id, scheda.ActivityId);
}
}
VisibleOverlay = false;
StateHasChanged();
}
private void OnError(string? errorMessage)
{
if (errorMessage == null) return;
_ = ModalHelper.ShowError(Dialog, errorMessage);
}
void IDisposable.Dispose()
{
NewScheda.OnNewScheda -= LoadSchede;
CompleteInspection.OnComplete -= HandleCompleteInspection;
}
}