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

@@ -5,10 +5,10 @@
@using SteUp.Shared.Components.SingleElements.MessageBox
@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.Interface.System
@using SteUp.Shared.Core.Interface.System.Network
@using SteUp.Shared.Core.Messages.Scanner
@inject INetworkService NetworkService
@inject IDialogService Dialog
@@ -27,7 +27,7 @@
<div class="content">
<CardFormModal Title="Reparto" Loading="SteupDataService.Reparti.IsNullOrEmpty()">
<MudSelectExtended ReadOnly="IsView" T="JtbFasiDto?" Variant="Variant.Text"
<MudSelectExtended T="JtbFasiDto?" Variant="Variant.Text"
@bind-Value="Scheda.Reparto" ToStringFunc="@(x => x?.Descrizione)"
@bind-Value:after="OnAfterChangeReparto" Required="true"
RequiredError="Reparto obbligatorio">
@@ -41,7 +41,7 @@
</CardFormModal>
<CardFormModal Title="Motivo" Loading="SteupDataService.TipiAttività.IsNullOrEmpty()">
<MudSelectExtended ReadOnly="@(IsView || Scheda.CodJfas.IsNullOrEmpty())" T="string?"
<MudSelectExtended ReadOnly="@Scheda.CodJfas.IsNullOrEmpty()" T="string?"
Variant="Variant.Text"
@bind-Value="Scheda.ActivityTypeId" @bind-Value:after="OnAfterChangeValue"
Required="true" RequiredError="Motivo obbligatorio">
@@ -75,10 +75,13 @@
}
<MudCardContent Class="image_card">
<MudText Typo="Typo.subtitle1"><b>@item.p.Name</b></MudText>
<MudIconButton Variant="Variant.Outlined"
Icon="@Icons.Material.Rounded.Close"
Size="Size.Small" Color="Color.Error"
OnClick="@(() => OnRemoveAttached(item.index))"/>
@if (IsNew)
{
<MudIconButton Variant="Variant.Outlined"
Icon="@Icons.Material.Rounded.Close"
Size="Size.Small" Color="Color.Error"
OnClick="@(() => OnRemoveAttached(item.index))"/>
}
</MudCardContent>
</MudCard>
}
@@ -87,19 +90,16 @@
</CardFormModal>
}
@if (!IsView)
{
<div class="container-button ripple-container">
<MudButton Class="button-settings green-icon"
FullWidth="true"
StartIcon="@Icons.Material.Rounded.AttachFile"
Size="Size.Medium"
OnClick="@OpenAddAttached"
Variant="Variant.Outlined">
Aggiungi foto
</MudButton>
</div>
}
<div class="container-button ripple-container">
<MudButton Class="button-settings green-icon"
FullWidth="true"
StartIcon="@Icons.Material.Rounded.AttachFile"
Size="Size.Medium"
OnClick="@OpenAddAttached"
Variant="Variant.Outlined">
Aggiungi foto
</MudButton>
</div>
<CardFormModal Title="Articoli">
<div class="input-manual-barcode">
@@ -113,7 +113,8 @@
<div class="art-list">
@foreach (var articolo in Scheda.Articoli)
{
<MudChip T="string" OnClose="@(() => RemoveArt(articolo.Barcode))" style="height: auto;">
<MudChip T="string" OnClose="@(() => RemoveArt(articolo.Barcode))"
style="height: auto;">
<MudStack Direction="Column" Spacing="0" class="py-1">
<MudText Typo="Typo.subtitle2" Style="line-height: 1.1; font-weight: 700;">
@articolo.Descrizione
@@ -143,23 +144,23 @@
}
<CardFormModal Title="Scadenza">
<MudSelectExtended FullWidth="true" ReadOnly="@IsView" T="int" Variant="Variant.Text"
<MudSelectExtended FullWidth="true" T="int" Variant="Variant.Text"
@bind-Value="@Scheda.Scadenza" @bind-Value:after="OnAfterChangeValue">
<MudSelectItemExtended Class="custom-item-select" Text="24H" Value="24"/>
<MudSelectItemExtended Class="custom-item-select" Text="1 Settimana" Value="168"/>
<MudSelectItemExtended Class="custom-item-select" Text="1 Mese" Value="730"/>
<MudSelectItemExtended Class="custom-item-select" Text="2 Mesi" Value="1460"/>
<MudSelectItemExtended Class="custom-item-select" Text="24H" Value="3"/>
<MudSelectItemExtended Class="custom-item-select" Text="1 Settimana" Value="2"/>
<MudSelectItemExtended Class="custom-item-select" Text="1 Mese" Value="1"/>
<MudSelectItemExtended Class="custom-item-select" Text="2 Mesi" Value="0"/>
</MudSelectExtended>
</CardFormModal>
<CardFormModal Title="Responsabile">
<MudTextField FullWidth="true" ReadOnly="IsView" T="string?" Variant="Variant.Text"
<MudTextField FullWidth="true" T="string?" Variant="Variant.Text"
@bind-Value="Scheda.Responsabile" @bind-Value:after="OnAfterChangeValue"
DebounceInterval="500" OnDebounceIntervalElapsed="OnAfterChangeValue"/>
</CardFormModal>
<CardFormModal Title="Note">
<MudTextField ReadOnly="IsView" T="string?" Variant="Variant.Text" Lines="3"
<MudTextField T="string?" Variant="Variant.Text" Lines="3"
@bind-Value="Scheda.Note" @bind-Value:after="OnAfterChangeValue"
DebounceInterval="500" OnDebounceIntervalElapsed="OnAfterChangeValue"/>
</CardFormModal>
@@ -187,7 +188,7 @@
@code {
[CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = null!;
[Parameter] public required string CodMdep { get; set; }
[Parameter] public required DateOnly Data { get; set; }
[Parameter] public required DateTime Data { get; set; }
[Parameter] public bool IsNew { get; set; }
[Parameter] public Scheda Scheda { get; set; } = new();
@@ -214,7 +215,7 @@
protected override void OnInitialized()
{
Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter;
OnScannerService.OnNewScanSuccessful += HandleNewScanSuccessful;
OnScannerService.OnErrorScan += OnErrorScan;
@@ -226,6 +227,8 @@
private void LoadAttached()
{
if (Scheda.ImageNames == null) return;
FileLoading = true;
StateHasChanged();
@@ -237,7 +240,8 @@
CodMdep = CodMdep,
Data = Data,
Rilevatore = UserSession.User.Username
}
},
Scheda.ImageNames
);
await InvokeAsync(() =>
@@ -254,9 +258,40 @@
{
VisibleOverlay = true;
StateHasChanged();
SaveSchedaResponseDto? apiResponse = null;
try
{
if (!IsView)
{
apiResponse = await IntegrySteupService.SaveScheda(
new SaveRequestDto
{
LocalIdScheda = Scheda.Id,
ActivityTypeId = Scheda.ActivityTypeId,
CodJfas = Scheda.CodJfas,
CodMdep = CodMdep,
DataCreazione = Data,
Note = Scheda.Note,
PersonaRif = Scheda.Responsabile,
Barcodes = Scheda.Articoli.ConvertAll(x => x.Barcode),
Scandeza = (ScadenzaEnum)Scheda.Scadenza,
ParentActivityId = IsNew ? null : Scheda.Ispezione?.ActivityId
}
);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
await ModalHelper.ShowError(Dialog, e.Message);
}
if (IsNew) await NewSave();
else await Update();
if (IsNew) await NewSave(apiResponse);
else await Update(apiResponse);
if (Scheda.ActivityId.IsValorized()) await UploadFile(Scheda.ActivityId!);
await AttachedService.CleanTempStorageAsync();
@@ -268,7 +303,7 @@
MudDialog.Close(Scheda);
}
private async Task NewSave()
private async Task NewSave(SaveSchedaResponseDto? apiResponse)
{
if (!AttachedList.IsNullOrEmpty())
{
@@ -291,10 +326,18 @@
}
}
if (apiResponse != null)
{
await IspezioniService.UpdateActivityIdIspezioneAsync(CodMdep, Data,
UserSession.User.Username, apiResponse.ActivityIdIspezione
);
Scheda.ActivityId = apiResponse.ActivityIdScheda;
}
await IspezioniService.AddSchedaAsync(CodMdep, Data, UserSession.User.Username, Scheda);
}
private async Task Update()
private async Task Update(SaveSchedaResponseDto? apiResponse)
{
if (!AttachedList.IsNullOrEmpty())
{
@@ -324,7 +367,33 @@
}
}
Scheda.ActivityId = apiResponse?.ActivityIdScheda;
await IspezioniService.UpdateSchedaAsync(Scheda);
if (apiResponse != null)
await IspezioniService.UpdateActivityIdIspezioneAsync(CodMdep, Data,
UserSession.User.Username, apiResponse.ActivityIdIspezione
);
}
private async Task UploadFile(string activityId)
{
if (AttachedList.IsNullOrEmpty()) return;
var ispezione = new Ispezione
{
CodMdep = CodMdep,
Data = Data,
Rilevatore = UserSession.User.Username
};
foreach (var file in AttachedList!.Where(x => x.ToUpload))
{
if (file.FileBytes == null || file.Name == null) continue;
await IntegrySteupService.UploadFile(activityId, file.FileBytes, file.Name);
await AttachedService.MoveInspectionFileFromToUploadToFinal(ispezione, file.Name);
}
}
private async Task Cancel()
@@ -436,6 +505,7 @@
var target = AttachedList![AttachedList.Count - attachedList.Count + i];
target.TempPath = origUrl;
target.ThumbPath = thumbUrl;
target.ToUpload = true;
StateHasChanged();
});
}
@@ -456,7 +526,7 @@
Snackbar.Add("Selezionare prima il reparto", Severity.Error);
return;
}
OnLoading = true;
TextLoading = "Download articoli in griglia";
StateHasChanged();
@@ -477,25 +547,27 @@
}
catch (Exception e)
{
Console.WriteLine(e.Message);
await InvokeAsync(() =>
{
OnLoading = false;
TextLoading = null;
StateHasChanged();
OnError(e.Message);
});
return;
}
var modal = await ModalHelper.OpenSelectArt(Dialog, articoli);
await InvokeAsync(() =>
{
OnLoading = false;
TextLoading = null;
StateHasChanged();
});
@@ -581,17 +653,17 @@
{
OnLoading = false;
StateHasChanged();
if (art != null)
{
RecalcDirty(true);
Scheda.Articoli.Add(new SchedaArticolo
{
Barcode = art.Barcode,
Descrizione = art.Descrizione
});
StateHasChanged();
}
else
@@ -602,12 +674,14 @@
}
catch (Exception e)
{
Console.WriteLine(e.Message);
await InvokeAsync(() =>
{
OnLoading = false;
StateHasChanged();
});
OnError(e.Message);
}
}
@@ -627,7 +701,7 @@
{
var index = Scheda.Articoli.FindIndex(x => x.Barcode.Equals(barcode));
if (index < 0) return;
RecalcDirty(true);
Scheda.Articoli.RemoveAt(index);
StateHasChanged();