Files
SteUP_Dotnet/SteUp.Shared/Components/SingleElements/Modal/ModalFormScheda.razor
2026-02-19 09:52:18 +01:00

211 lines
8.7 KiB
Plaintext

@using SteUp.Shared.Components.Layout
@using SteUp.Shared.Components.Layout.Overlay
@using SteUp.Shared.Components.SingleElements.Card.ModalForm
@using SteUp.Shared.Core.Dto
@using SteUp.Shared.Core.Entities
@using SteUp.Shared.Core.Interface.IntegryApi
@using SteUp.Shared.Core.Interface.System.Network
@inject INetworkService NetworkService
@inject IDialogService Dialog
@inject IIntegryApiService IntegryApiService
<MudDialog Class="customDialog-form">
<DialogContent>
<HeaderLayout Cancel="true" OnCancel="@(() => MudDialog.Cancel())" LabelSave="@LabelSave"
OnSave="Save" Title="Scheda"/>
<div class="content">
<CardFormModal Title="Reparto" Loading="SteupDataService.Reparti.IsNullOrEmpty()">
<MudSelectExtended ReadOnly="IsView" T="JtbFasiDto?" Variant="Variant.Text"
@bind-Value="Scheda.Reparto" ToStringFunc="@(x => x?.Descrizione)"
@bind-Value:after="OnAfterChangeValue">
@foreach (var fasi in SteupDataService.Reparti)
{
<MudSelectItemExtended Class="custom-item-select" Value="@fasi">
@fasi.Descrizione
</MudSelectItemExtended>
}
</MudSelectExtended>
</CardFormModal>
<CardFormModal Title="Motivo" Loading="SteupDataService.TipiAttività.IsNullOrEmpty()">
<MudSelectExtended ReadOnly="IsView" T="string?" Variant="Variant.Text"
@bind-Value="Scheda.ActivityTypeId" @bind-Value:after="OnAfterChangeValue">
@foreach (var type in SteupDataService.TipiAttività)
{
<MudSelectItemExtended Class="custom-item-select"
Value="@type.ActivityTypeId">@type.ActivityTypeId</MudSelectItemExtended>
}
</MudSelectExtended>
</CardFormModal>
@* <div class="container-chip-attached"> *@
@* @if (!AttachedList.IsNullOrEmpty()) *@
@* { *@
@* foreach (var item in AttachedList!.Select((p, index) => new { p, index })) *@
@* { *@
@* if (item.p.Type == AttachedDTO.TypeAttached.Position) *@
@* { *@
@* <MudChip T="string" Icon="@Icons.Material.Rounded.LocationOn" Color="Color.Success" *@
@* OnClick="@(() => OpenPosition(item.p))" *@
@* OnClose="@(() => OnRemoveAttached(item.index))"> *@
@* @item.p.Description *@
@* </MudChip> *@
@* } *@
@* else *@
@* { *@
@* <MudChip T="string" Color="Color.Default" OnClick="@(() => OpenAttached(item.p))" *@
@* OnClose="@(() => OnRemoveAttached(item.index))"> *@
@* @item.p.Name *@
@* </MudChip> *@
@* } *@
@* } *@
@* } *@
@* *@
@* @if (!IsLoading) *@
@* { *@
@* if (ActivityFileList != null) *@
@* { *@
@* foreach (var file in ActivityFileList) *@
@* { *@
@* <MudChip T="string" OnClick="@(() => OpenAttached(file.FileName))" *@
@* OnClose="@(() => DeleteAttach(file))" Color="Color.Default"> *@
@* @file.FileName *@
@* </MudChip> *@
@* } *@
@* } *@
@* } *@
@* else *@
@* { *@
@* <MudProgressLinear Color="Color.Primary" Indeterminate="true" Class="my-7"/> *@
@* } *@
@* </div> *@
@if (!IsView)
{
<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 foto
</MudButton>
</div>
}
<CardFormModal Title="Scadenza">
<MudSelectExtended FullWidth="true" ReadOnly="@IsView" 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"/>
</MudSelectExtended>
</CardFormModal>
<CardFormModal Title="Responsabile">
<MudTextField FullWidth="true" ReadOnly="IsView" 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"
@bind-Value="Scheda.Note" @bind-Value:after="OnAfterChangeValue"
DebounceInterval="500" OnDebounceIntervalElapsed="OnAfterChangeValue"/>
</CardFormModal>
<div class="container-button">
<MudButton Class="button-settings blue-icon"
FullWidth="true"
StartIcon="@Icons.Material.Rounded.Description"
Size="Size.Medium"
OnClick="@SuggestActivityDescription"
Variant="Variant.Outlined">
Suggerisci note descrittive
</MudButton>
</div>
</div>
</DialogContent>
</MudDialog>
<SpinnerOverlay VisibleOverlay="VisibleOverlay" SuccessAnimation="SuccessAnimation"/>
@code {
[CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = null!;
private Scheda Scheda { get; set; } = new();
private bool IsNew { get; set; }
private bool IsLoading { get; set; }
private bool IsView => !NetworkService.ConnectionAvailable;
//Overlay
private bool VisibleOverlay { get; set; }
private bool SuccessAnimation { get; set; }
private string? LabelSave { get; set; }
protected override async Task OnInitializedAsync()
{
Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter;
}
private async Task Save()
{
}
private async Task OpenAddAttached()
{
var result = await ModalHelper.OpenAddAttached(Dialog);
// if (result is { Canceled: false, Data: not null } && result.Data.GetType() == typeof(AttachedDTO))
// {
// var attached = (AttachedDTO)result.Data;
//
// if (attached.Type == AttachedDTO.TypeAttached.Position)
// CanAddPosition = false;
//
// AttachedList ??= [];
// AttachedList.Add(attached);
// }
}
private void OnAfterChangeValue()
{
if (!IsNew)
LabelSave = "Aggiorna";
StateHasChanged();
}
private void SuggestActivityDescription()
{
if (Scheda.ActivityTypeId == null)
{
Snackbar.Add("Indicare prima il motivo", Severity.Error);
return;
}
VisibleOverlay = true;
StateHasChanged();
_ = Task.Run(async () =>
{
var activityDescriptions = await IntegryApiService.SuggestActivityDescription(Scheda.ActivityTypeId);
var modal = await ModalHelper.OpenSuggestActivityDescription(Dialog, activityDescriptions);
if (modal is { Canceled: false, Data: not null })
Scheda.Note = modal.Data!.ToString();
VisibleOverlay = false;
await InvokeAsync(StateHasChanged);
});
}
}