This commit is contained in:
2026-07-14 14:22:26 +02:00
parent 4e13db24f6
commit a81689bd56
4 changed files with 85 additions and 35 deletions
+11 -3
View File
@@ -42,8 +42,11 @@
Size="Size.Medium" IconSize="Size.Medium"> Size="Size.Medium" IconSize="Size.Medium">
@if (SchedaVisible) @if (SchedaVisible)
{ {
<MudFabMenuItem Disabled="!NetworkService.IsNetworkAvailable()" OnClick="@NewScheda" @if (!_isCompleted)
Label="Nuova scheda" Color="Color.Surface"/> {
<MudFabMenuItem Disabled="!NetworkService.IsNetworkAvailable()" OnClick="@NewScheda"
Label="Nuova scheda" Color="Color.Surface"/>
}
<MudFabMenuItem Disabled="!NetworkService.IsNetworkAvailable()" OnClick="@DeleteInspection" <MudFabMenuItem Disabled="!NetworkService.IsNetworkAvailable()" OnClick="@DeleteInspection"
Label="Cancella ispezione" Color="Color.Surface"/> Label="Cancella ispezione" Color="Color.Surface"/>
@@ -73,6 +76,7 @@
private bool PlusVisible { get; set; } = true; private bool PlusVisible { get; set; } = true;
private bool ShowCompleteInspection { get; set; } private bool ShowCompleteInspection { get; set; }
private bool SchedaVisible { get; set; } private bool SchedaVisible { get; set; }
private bool _isCompleted;
private ConfirmMessageBox _messageBox = null!; private ConfirmMessageBox _messageBox = null!;
@@ -138,7 +142,11 @@
var location = NavigationManager.Uri.Remove(0, NavigationManager.BaseUri.Length); var location = NavigationManager.Uri.Remove(0, NavigationManager.BaseUri.Length);
SchedaVisible = new List<string> { "ispezione" }.Contains(location); SchedaVisible = new List<string> { "ispezione" }.Contains(location);
ShowCompleteInspection = !SteupDataService.InspectionPageState.Ispezione.ActivityId.IsNullOrEmpty();
var ispezione = SteupDataService.InspectionPageState.Ispezione;
_isCompleted = ispezione.Stato == StatusEnum.Completata;
// Concludi non ha senso su un'ispezione gia completata
ShowCompleteInspection = !ispezione.ActivityId.IsNullOrEmpty() && !_isCompleted;
StateHasChanged(); StateHasChanged();
} }
@@ -178,7 +178,9 @@
PersonaRif = scheda.Responsabile, PersonaRif = scheda.Responsabile,
Barcodes = scheda.Articoli.ConvertAll(x => x.Barcode), Barcodes = scheda.Articoli.ConvertAll(x => x.Barcode),
Scandeza = (ScadenzaEnum)scheda.Scadenza, Scandeza = (ScadenzaEnum)scheda.Scadenza,
ParentActivityId = scheda.Ispezione?.ActivityId // Aggancia all'ispezione esistente: dopo la prima scheda l'id e' noto,
// così le successive non creano nuove ispezioni.
ParentActivityId = ispezione.ActivityId
} }
); );
@@ -198,6 +200,8 @@
ispezione.Rilevatore, ispezione.Rilevatore,
apiResponse.ActivityIdIspezione apiResponse.ActivityIdIspezione
); );
// Aggiorna l'id in memoria per l'iterazione successiva.
ispezione.ActivityId = apiResponse.ActivityIdIspezione;
if (scheda.ImageNames == null) continue; if (scheda.ImageNames == null) continue;
@@ -350,35 +354,41 @@
PersonaRif = x.Responsabile, PersonaRif = x.Responsabile,
Barcodes = x.Articoli.ConvertAll(y => y.Barcode), Barcodes = x.Articoli.ConvertAll(y => y.Barcode),
Scandeza = (ScadenzaEnum)x.Scadenza, Scandeza = (ScadenzaEnum)x.Scadenza,
ParentActivityId = x.Ispezione?.ActivityId // Aggancia all'ispezione esistente sul server (evita di crearne una nuova a ogni export).
ParentActivityId = ispezione.ActivityId
}; };
}); });
var apiResponse = await IntegrySteupService.SaveMultipleSchede(saveRequest); var apiResponse = await IntegrySteupService.SaveMultipleSchede(saveRequest);
if (apiResponse != null) if (apiResponse == null)
{ {
SteupDataService.InspectionPageState.Ispezione.ActivityId = apiResponse.ActivityIdIspezione; Snackbar.Add("Esportazione non riuscita. Le schede restano sul dispositivo, riprova.", Severity.Error);
return;
}
await IspezioniService.UpdateActivityIdIspezioneAsync(ispezione.CodMdep, ispezione.Data, SteupDataService.InspectionPageState.Ispezione.ActivityId = apiResponse.ActivityIdIspezione;
UserSession.User.Username, apiResponse.ActivityIdIspezione
);
if (!apiResponse.ActivityIdSchedaList.IsNullOrEmpty()) await IspezioniService.UpdateActivityIdIspezioneAsync(ispezione.CodMdep, ispezione.Data,
UserSession.User.Username, apiResponse.ActivityIdIspezione
);
if (!apiResponse.ActivityIdSchedaList.IsNullOrEmpty())
{
foreach (var scheda in SchedeGrouped[jtbFasi])
{ {
foreach (var scheda in SchedeGrouped[jtbFasi]) var activityId = apiResponse.ActivityIdSchedaList!.Find(x =>
{ x.LocalId != null && x.LocalId == scheda.Id
var activityId = apiResponse.ActivityIdSchedaList!.Find(x => )?.ActivityId;
x.LocalId != null && x.LocalId == scheda.Id
)?.ActivityId;
if (activityId == null) continue; if (activityId == null) continue;
scheda.ActivityId = activityId; scheda.ActivityId = activityId;
await IspezioniService.UpdateActivityIdSchedaAsync(scheda.Id, scheda.ActivityId); await IspezioniService.UpdateActivityIdSchedaAsync(scheda.Id, scheda.ActivityId);
}
} }
} }
Snackbar.Add("Reparto esportato", Severity.Success);
} }
catch (Exception e) catch (Exception e)
{ {
@@ -6,10 +6,12 @@
@using SteUp.Shared.Core.Interface.IntegryApi @using SteUp.Shared.Core.Interface.IntegryApi
@using SteUp.Shared.Core.Interface.LocalDb @using SteUp.Shared.Core.Interface.LocalDb
@using SteUp.Shared.Core.Interface.System @using SteUp.Shared.Core.Interface.System
@using Microsoft.Extensions.Logging
@inject IIspezioniService IspezioniService @inject IIspezioniService IspezioniService
@inject IIntegrySteupService IntegrySteupService @inject IIntegrySteupService IntegrySteupService
@inject IDialogService Dialog @inject IDialogService Dialog
@inject IFileManager FileManager @inject IFileManager FileManager
@inject ILogger<SchedaCard> Logger
<div class="scheda-card"> <div class="scheda-card">
<div class="scheda-body-section"> <div class="scheda-body-section">
@@ -139,23 +141,34 @@
PersonaRif = Scheda.Responsabile, PersonaRif = Scheda.Responsabile,
Barcodes = Scheda.Articoli.ConvertAll(x => x.Barcode), Barcodes = Scheda.Articoli.ConvertAll(x => x.Barcode),
Scandeza = (ScadenzaEnum)Scheda.Scadenza, Scandeza = (ScadenzaEnum)Scheda.Scadenza,
ParentActivityId = Scheda.Ispezione?.ActivityId // Aggancia all'ispezione esistente sul server (evita di crearne una nuova a ogni invio).
ParentActivityId = SteupDataService.InspectionPageState.Ispezione.ActivityId
} }
); );
if (apiResponse != null) if (apiResponse == null)
{ {
Scheda.ActivityId = apiResponse.ActivityIdScheda; Snackbar.Add("Invio non riuscito. La scheda resta sul dispositivo, riprova.", Severity.Error);
SteupDataService.InspectionPageState.Ispezione.ActivityId = apiResponse.ActivityIdIspezione; return;
await IspezioniService.UpdateActivityIdIspezioneAsync(Ispezione.CodMdep, Ispezione.Data,
UserSession.User.Username, apiResponse.ActivityIdIspezione
);
await IspezioniService.UpdateActivityIdSchedaAsync(Scheda.Id, Scheda.ActivityId);
// Notifica il genitore così il contatore "da inviare" del reparto si aggiorna.
await OnSchedaModified.InvokeAsync(Scheda);
} }
Scheda.ActivityId = apiResponse.ActivityIdScheda;
SteupDataService.InspectionPageState.Ispezione.ActivityId = apiResponse.ActivityIdIspezione;
await IspezioniService.UpdateActivityIdIspezioneAsync(Ispezione.CodMdep, Ispezione.Data,
UserSession.User.Username, apiResponse.ActivityIdIspezione
);
await IspezioniService.UpdateActivityIdSchedaAsync(Scheda.Id, Scheda.ActivityId);
// Notifica il genitore così il contatore "da inviare" del reparto si aggiorna.
await OnSchedaModified.InvokeAsync(Scheda);
Snackbar.Add("Scheda inviata", Severity.Success);
}
catch (Exception e)
{
Snackbar.Add("Invio non riuscito. La scheda resta sul dispositivo, riprova.", Severity.Error);
Logger.LogError(e, e.Message);
} }
finally finally
{ {
@@ -176,12 +189,23 @@
var fileList = (await FileManager.GetInspectionFiles(Ispezione, Scheda.ImageNames))? var fileList = (await FileManager.GetInspectionFiles(Ispezione, Scheda.ImageNames))?
.Where(x => x.ToUpload).ToList(); .Where(x => x.ToUpload).ToList();
if (fileList == null) return; if (fileList == null || fileList.Count == 0)
{
Snackbar.Add("Nessuna nuova foto da inviare", Severity.Info);
return;
}
foreach (var file in fileList) foreach (var file in fileList)
{ {
await IntegrySteupService.UploadFile(Scheda.ActivityId!, file.FileBytes!, file.Name!); await IntegrySteupService.UploadFile(Scheda.ActivityId!, file.FileBytes!, file.Name!);
} }
Snackbar.Add(fileList.Count == 1 ? "Foto inviata" : $"{fileList.Count} foto inviate", Severity.Success);
}
catch (Exception e)
{
Snackbar.Add("Invio foto non riuscito, riprova.", Severity.Error);
Logger.LogError(e, e.Message);
} }
finally finally
{ {
@@ -296,7 +296,9 @@
PersonaRif = Scheda.Responsabile, PersonaRif = Scheda.Responsabile,
Barcodes = Scheda.Articoli.ConvertAll(x => x.Barcode), Barcodes = Scheda.Articoli.ConvertAll(x => x.Barcode),
Scandeza = (ScadenzaEnum)Scheda.Scadenza, Scandeza = (ScadenzaEnum)Scheda.Scadenza,
ParentActivityId = IsNew ? null : Scheda.Ispezione?.ActivityId // Aggancia la scheda all'ispezione GIA esistente sul server (se sincronizzata),
// altrimenti null e il server la crea. Evita di creare una nuova ispezione a ogni salvataggio.
ParentActivityId = SteupDataService.InspectionPageState.Ispezione.ActivityId
} }
); );
} }
@@ -353,6 +355,9 @@
await IspezioniService.UpdateActivityIdIspezioneAsync(CodMdep, Data, await IspezioniService.UpdateActivityIdIspezioneAsync(CodMdep, Data,
UserSession.User.Username, apiResponse.ActivityIdIspezione UserSession.User.Username, apiResponse.ActivityIdIspezione
); );
// Tiene in memoria l'ActivityId dell'ispezione: il prossimo salvataggio nella stessa
// sessione lo userà come ParentActivityId invece di creare una nuova ispezione.
SteupDataService.InspectionPageState.Ispezione.ActivityId = apiResponse.ActivityIdIspezione;
Scheda.ActivityId = apiResponse.ActivityIdScheda; Scheda.ActivityId = apiResponse.ActivityIdScheda;
} }
@@ -393,9 +398,12 @@
await IspezioniService.UpdateSchedaAsync(Scheda); await IspezioniService.UpdateSchedaAsync(Scheda);
if (apiResponse != null) if (apiResponse != null)
{
await IspezioniService.UpdateActivityIdIspezioneAsync(CodMdep, Data, await IspezioniService.UpdateActivityIdIspezioneAsync(CodMdep, Data,
UserSession.User.Username, apiResponse.ActivityIdIspezione UserSession.User.Username, apiResponse.ActivityIdIspezione
); );
SteupDataService.InspectionPageState.Ispezione.ActivityId = apiResponse.ActivityIdIspezione;
}
} }
private async Task UploadFile(Scheda scheda) private async Task UploadFile(Scheda scheda)