Gestite immagini allegate
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user