Implementata gestione allegati

This commit is contained in:
2025-07-30 18:27:24 +02:00
parent 8ebc6e3b8f
commit 068723f31f
16 changed files with 422 additions and 53 deletions

View File

@@ -12,6 +12,7 @@
@inject INetworkService NetworkService
@inject IIntegryApiService IntegryApiService
@inject IMessenger Messenger
@inject IDialogService Dialog
<MudDialog Class="customDialog-form">
<DialogContent>
@@ -116,10 +117,33 @@
<div class="input-card">
<MudTextField ReadOnly="IsView" T="string?" Placeholder="Note" Variant="Variant.Text" Lines="4" @bind-Value="ActivityModel.Note" @bind-Value:after="OnAfterChangeValue" DebounceInterval="500" OnDebounceIntervalElapsed="OnAfterChangeValue"/>
</div>
@if (!IsNew)
{
<div class="container-button">
<div class="container-chip-attached">
@if (!AttachedList.IsNullOrEmpty())
{
foreach (var item in AttachedList!.Select((p, index) => new { p, index }))
{
<MudChip T="string" Color="Color.Default" OnClose="() => OnRemoveAttached(item.index)">
@item.p.Name
</MudChip>
}
}
</div>
<div class="container-button">
<MudButton Class="button-settings green-icon"
FullWidth="true"
StartIcon="@Icons.Material.Rounded.AttachFile"
Size="Size.Medium"
OnClick="OpenAddAttached"
Variant="Variant.Outlined">
Aggiungi allegati
</MudButton>
@if (!IsNew)
{
<div class="divider"></div>
<MudButton Class="button-settings gray-icon"
FullWidth="true"
StartIcon="@Icons.Material.Filled.ContentCopy"
@@ -139,10 +163,10 @@
Variant="Variant.Outlined">
Elimina
</MudButton>
</div>
}
}
</div>
</div>
<MudMessageBox @ref="ConfirmDelete" Class="c-messageBox" Title="Attenzione!" CancelText="Annulla">
<MessageContent>
Confermi la cancellazione dell'attività corrente?
@@ -154,7 +178,7 @@
</MudButton>
</YesButton>
</MudMessageBox>
<MudMessageBox @ref="ConfirmMemo" Class="c-messageBox" Title="Attenzione!" CancelText="Annulla">
<MessageContent>
Vuoi creare un promemoria?
@@ -173,7 +197,7 @@
<SelectEsito @bind-IsSheetVisible="OpenEsito" @bind-ActivityModel="ActivityModel" @bind-ActivityModel:after="OnAfterChangeEsito"/>
<AddMemo @bind-IsSheetVisible="OpenAddMemo" />
<AddMemo @bind-IsSheetVisible="OpenAddMemo"/>
@code {
[CascadingParameter] private IMudDialogInstance MudDialog { get; set; }
@@ -207,6 +231,9 @@
private MudMessageBox ConfirmDelete { get; set; }
private MudMessageBox ConfirmMemo { get; set; }
//Attached
private List<AttachedDTO>? AttachedList { get; set; }
protected override async Task OnInitializedAsync()
{
Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter;
@@ -242,6 +269,8 @@
VisibleOverlay = true;
StateHasChanged();
await SavePosition();
var response = await IntegryApiService.SaveActivity(ActivityModel);
if (response == null)
@@ -251,6 +280,8 @@
await ManageData.InsertOrUpdate(newActivity);
await SaveAttached(newActivity.ActivityId);
SuccessAnimation = true;
StateHasChanged();
@@ -259,6 +290,40 @@
MudDialog.Close(newActivity);
}
private async Task SavePosition()
{
if (AttachedList != null)
{
foreach (var attached in AttachedList)
{
if (attached.Type != AttachedDTO.TypeAttached.Position) continue;
var position = new PositionDTO
{
Description = attached.Description,
Lat = attached.Lat,
Lng = attached.Lng
};
ActivityModel.Position = await IntegryApiService.SavePosition(position);
}
}
}
private async Task SaveAttached(string activityId)
{
if (AttachedList != null)
{
foreach (var attached in AttachedList)
{
if (attached.FileContent is not null && attached.Type != AttachedDTO.TypeAttached.Position)
{
await IntegryApiService.UploadFile(activityId, attached.FileContent, attached.Name);
}
}
}
}
private bool CheckPreSave()
{
Snackbar.Clear();
@@ -395,4 +460,24 @@
Messenger.Send(new CopyActivityMessage(activityCopy));
}
private async Task OpenAddAttached()
{
var result = await ModalHelpers.OpenAddAttached(Dialog);
if (result is { Canceled: false, Data: not null } && result.Data.GetType() == typeof(AttachedDTO))
{
AttachedList ??= [];
AttachedList.Add((AttachedDTO)result.Data);
}
}
private void OnRemoveAttached(int index)
{
if (AttachedList is null || index < 0 || index >= AttachedList.Count)
return;
AttachedList.RemoveAt(index);
StateHasChanged();
}
}