Gestite immagini allegate

This commit is contained in:
2026-02-24 11:33:16 +01:00
parent a4dece511f
commit c7fb4a28a4
10 changed files with 355 additions and 18 deletions

View File

@@ -49,7 +49,13 @@
</MudSelectExtended>
</CardFormModal>
@if (!AttachedList.IsNullOrEmpty())
@if (FileLoading)
{
<div class="container-attached">
<MudProgressLinear Color="Color.Primary" Indeterminate="true" Class="my-3"/>
</div>
}
else if (!AttachedList.IsNullOrEmpty())
{
<div class="container-attached">
<div class="scroll-attached">
@@ -62,7 +68,8 @@
}
<MudCardContent Class="image_card">
<MudText Typo="Typo.subtitle1"><b>@item.p.Name</b></MudText>
<MudIconButton Variant="Variant.Outlined" Icon="@Icons.Material.Rounded.Close"
<MudIconButton Variant="Variant.Outlined"
Icon="@Icons.Material.Rounded.Close"
Size="Size.Small" Color="Color.Error"
OnClick="@(() => OnRemoveAttached(item.index))"/>
</MudCardContent>
@@ -133,13 +140,15 @@
[Parameter] public required DateOnly Data { get; set; }
[Parameter] public bool IsNew { get; set; }
[Parameter] public Scheda Scheda { get; set; } = new();
private bool IsView => !NetworkService.ConnectionAvailable;
//Overlay
private bool VisibleOverlay { get; set; }
private bool SuccessAnimation { get; set; }
private bool FileLoading { get; set; }
private ConfirmUpdateActivity _confirmUpdateMessage = null!;
private MudForm _form = null!;
@@ -152,6 +161,34 @@
{
_originalScheda = Scheda.Clone();
Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter;
LoadAttached();
}
private void LoadAttached()
{
FileLoading = true;
StateHasChanged();
Task.Run(async () =>
{
var fileList = await AttachedService.GetInspectionFiles(
new Ispezione
{
CodMdep = CodMdep,
Data = Data,
Rilevatore = UserSession.User.Username
}
);
await InvokeAsync(() =>
{
AttachedList = fileList;
FileLoading = false;
StateHasChanged();
});
});
}
private async Task Save()
@@ -159,18 +196,77 @@
VisibleOverlay = true;
StateHasChanged();
if (IsNew)
await IspezioniService.AddSchedaAsync(CodMdep, Data, UserSession.User.Username, Scheda);
else
await IspezioniService.UpdateSchedaAsync(Scheda);
if (IsNew) await NewSave();
else await Update();
await AttachedService.CleanTempStorageAsync();
SuccessAnimation = true;
StateHasChanged();
await Task.Delay(1250);
MudDialog.Close(Scheda);
}
private async Task NewSave()
{
if (!AttachedList.IsNullOrEmpty())
{
foreach (var attached in AttachedList!)
{
var fileNameAdded = await AttachedService.SaveInspectionFile(
new Ispezione
{
CodMdep = CodMdep,
Data = Data,
Rilevatore = UserSession.User.Username
},
attached.FileBytes!,
attached.Name!
);
Scheda.ImageNames ??= [];
if (fileNameAdded != null)
Scheda.ImageNames.Add(fileNameAdded);
}
}
await IspezioniService.AddSchedaAsync(CodMdep, Data, UserSession.User.Username, Scheda);
}
private async Task Update()
{
if (!AttachedList.IsNullOrEmpty())
{
foreach (var attached in AttachedList!.Where(x => !x.SavedOnAppData))
{
var ispezione = new Ispezione
{
CodMdep = CodMdep,
Data = Data,
Rilevatore = UserSession.User.Username
};
if (!attached.ToRemove)
{
var fileNameAdded = await AttachedService.SaveInspectionFile(
ispezione,
attached.FileBytes!,
attached.Name!
);
Scheda.ImageNames ??= [];
if (fileNameAdded != null)
Scheda.ImageNames.Add(fileNameAdded);
}
else
_ = AttachedService.RemoveInspectionFile(ispezione, attached.Name!);
}
}
await IspezioniService.UpdateSchedaAsync(Scheda);
}
private async Task Cancel()
{
if (await CheckSavePreAction())
@@ -188,9 +284,9 @@
StateHasChanged();
}
private void RecalcDirty()
private void RecalcDirty(bool forceTrue = false)
{
IsDirty = !ValueComparer.AreEqual(Scheda, _originalScheda);
IsDirty = forceTrue || !ValueComparer.AreEqual(Scheda, _originalScheda);
if (IsDirty) LabelSave = !IsNew ? "Aggiorna" : "Salva";
else LabelSave = null;
@@ -255,6 +351,8 @@
AttachedList.Add(new AttachedDto { Name = a.Name, MimeType = a.MimeType, FileBytes = a.FileBytes });
await InvokeAsync(StateHasChanged);
RecalcDirty(true);
// Processa in background e aggiorna UI man mano (o a blocchi)
_ = Task.Run(async () =>
@@ -285,10 +383,13 @@
private void OnRemoveAttached(int index)
{
if (AttachedList is null || index < 0 || index >= AttachedList.Count)
return;
if (AttachedList is null || index < 0 || index >= AttachedList.Count) return;
if (AttachedList[index].SavedOnAppData)
AttachedList[index].ToRemove = true;
AttachedList.RemoveAt(index);
RecalcDirty(true);
StateHasChanged();
}
@@ -318,5 +419,4 @@
await InvokeAsync(StateHasChanged);
});
}
}

View File

@@ -13,6 +13,9 @@ public class AttachedDto
public string? TempPath { get; set; }
public string? ThumbPath { get; set; }
public bool SavedOnAppData { get; set; }
public bool ToRemove { get; set; }
public Stream? FileContent =>
FileBytes is null ? null : new MemoryStream(FileBytes);

View File

@@ -16,7 +16,9 @@ public class Scheda : EntityBase<Scheda>
[Required]
public string Rilevatore { get; set; } = string.Empty;
public Ispezione? Ispezione { get; set; }
public List<string>? ImageNames { get; set; }
public string? DescrizioneReparto { get; set; }
public string? ActivityTypeId { get; set; }
public string? Note { get; set; }

View File

@@ -1,4 +1,5 @@
using SteUp.Shared.Core.Dto;
using SteUp.Shared.Core.Entities;
namespace SteUp.Shared.Core.Interface.System;
@@ -6,6 +7,10 @@ public interface IAttachedService
{
Task<AttachedDto?> SelectImageFromCamera();
Task<List<AttachedDto>?> SelectImageFromGallery();
Task<List<AttachedDto>?> GetInspectionFiles(Ispezione ispezione);
Task<string?> SaveInspectionFile(Ispezione ispezione, byte[] file, string fileName, CancellationToken ct = default);
bool RemoveInspectionFile(Ispezione ispezione, string fileName);
Task<string> SaveToTempStorage(Stream file, string fileName, CancellationToken ct = default);
Task CleanTempStorageAsync(CancellationToken ct = default);

View File

@@ -138,12 +138,16 @@
.container-button {
width: 100%;
/*background: var(--mud-palette-table-striped);*/
background: var(--mud-palette-table-striped);
padding: .5rem 0;
border-radius: 20px;
margin-bottom: 2rem;
}
.container-button.mud-elevation-1 {
background: unset !important;
}
.container-button .divider {
margin: .5rem 0 .5rem 3rem;
width: unset;