generated from Integry/Template_NetMauiBlazorHybrid
Aggiunta pagination nella tab Commesse
This commit is contained in:
@@ -6,6 +6,7 @@ public class NetworkService : INetworkService
|
|||||||
{
|
{
|
||||||
public bool IsNetworkAvailable()
|
public bool IsNetworkAvailable()
|
||||||
{
|
{
|
||||||
|
return false;
|
||||||
return Connectivity.Current.NetworkAccess == NetworkAccess.Internet;
|
return Connectivity.Current.NetworkAccess == NetworkAccess.Internet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,21 +9,28 @@
|
|||||||
@using salesbook.Shared.Components.SingleElements
|
@using salesbook.Shared.Components.SingleElements
|
||||||
@using salesbook.Shared.Core.Dto.JobProgress
|
@using salesbook.Shared.Core.Dto.JobProgress
|
||||||
@using salesbook.Shared.Core.Dto.PageState
|
@using salesbook.Shared.Core.Dto.PageState
|
||||||
|
@implements IAsyncDisposable
|
||||||
@inject IManageDataService ManageData
|
@inject IManageDataService ManageData
|
||||||
@inject IMapper Mapper
|
@inject IMapper Mapper
|
||||||
@inject IDialogService Dialog
|
@inject IDialogService Dialog
|
||||||
@inject IIntegryApiService IntegryApiService
|
@inject IIntegryApiService IntegryApiService
|
||||||
@inject UserPageState UserState
|
@inject UserPageState UserState
|
||||||
|
|
||||||
<HeaderLayout BackTo="Indietro" LabelSave="Modifica" OnSave="() => OpenUserForm(Anag)" Back="true" BackOnTop="true" Title="" ShowProfile="false"/>
|
<HeaderLayout BackTo="Indietro"
|
||||||
|
LabelSave="Modifica"
|
||||||
|
OnSave="() => OpenUserForm(Anag)"
|
||||||
|
Back="true"
|
||||||
|
BackOnTop="true"
|
||||||
|
Title=""
|
||||||
|
ShowProfile="false" />
|
||||||
|
|
||||||
@if (IsLoading)
|
@if (IsLoading)
|
||||||
{
|
{
|
||||||
<SpinnerLayout FullScreen="true"/>
|
<SpinnerLayout FullScreen="true" />
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<div class="container content">
|
<div class="container content" style="overflow: auto;" id="topPage">
|
||||||
<div class="container-primary-info">
|
<div class="container-primary-info">
|
||||||
<div class="section-primary-info">
|
<div class="section-primary-info">
|
||||||
<MudAvatar Style="height: 70px; width: 70px; font-size: 2rem; font-weight: bold" Color="Color.Secondary">
|
<MudAvatar Style="height: 70px; width: 70px; font-size: 2rem; font-weight: bold" Color="Color.Secondary">
|
||||||
@@ -32,11 +39,11 @@ else
|
|||||||
|
|
||||||
<div class="personal-info">
|
<div class="personal-info">
|
||||||
<span class="info-nome">@Anag.RagSoc</span>
|
<span class="info-nome">@Anag.RagSoc</span>
|
||||||
@if (Anag.Indirizzo != null)
|
@if (!string.IsNullOrEmpty(Anag.Indirizzo))
|
||||||
{
|
{
|
||||||
<span class="info-section">@Anag.Indirizzo</span>
|
<span class="info-section">@Anag.Indirizzo</span>
|
||||||
}
|
}
|
||||||
@if (Anag is { Citta: not null, Cap: not null, Prov: not null })
|
@if (!string.IsNullOrEmpty(Anag.Cap) && !string.IsNullOrEmpty(Anag.Citta) && !string.IsNullOrEmpty(Anag.Prov))
|
||||||
{
|
{
|
||||||
<span class="info-section">@($"{Anag.Cap} - {Anag.Citta} ({Anag.Prov})")</span>
|
<span class="info-section">@($"{Anag.Cap} - {Anag.Citta} ({Anag.Prov})")</span>
|
||||||
}
|
}
|
||||||
@@ -51,9 +58,7 @@ else
|
|||||||
{
|
{
|
||||||
<div>
|
<div>
|
||||||
<span class="info-title">Telefono</span>
|
<span class="info-title">Telefono</span>
|
||||||
<span class="info-text">
|
<span class="info-text">@Anag.Telefono</span>
|
||||||
@Anag.Telefono
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,9 +66,7 @@ else
|
|||||||
{
|
{
|
||||||
<div>
|
<div>
|
||||||
<span class="info-title">P. IVA</span>
|
<span class="info-title">P. IVA</span>
|
||||||
<span class="info-text">
|
<span class="info-text">@Anag.PartIva</span>
|
||||||
@Anag.PartIva
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
@@ -73,9 +76,7 @@ else
|
|||||||
{
|
{
|
||||||
<div>
|
<div>
|
||||||
<span class="info-title">E-mail</span>
|
<span class="info-title">E-mail</span>
|
||||||
<span class="info-text">
|
<span class="info-text">@Anag.EMail</span>
|
||||||
@Anag.EMail
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,47 +84,41 @@ else
|
|||||||
{
|
{
|
||||||
<div>
|
<div>
|
||||||
<span class="info-title">Agente</span>
|
<span class="info-title">Agente</span>
|
||||||
<span class="info-text">
|
<span class="info-text">@Agente.FullName</span>
|
||||||
@Agente.FullName
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="radio" class="tab-toggle" name="tab-toggle" id="tab1" checked>
|
<input type="radio" class="tab-toggle" name="tab-toggle" id="tab1" checked="@(ActiveTab == 0)">
|
||||||
<input type="radio" class="tab-toggle" name="tab-toggle" id="tab2">
|
<input type="radio" class="tab-toggle" name="tab-toggle" id="tab2" checked="@(ActiveTab == 1)">
|
||||||
|
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<ul class="tab-list">
|
<ul class="tab-list">
|
||||||
<li class="tab-item">
|
<li class="tab-item">
|
||||||
<label class="tab-trigger" for="tab1">Contatti</label>
|
<label class="tab-trigger" for="tab1" @onclick="() => SwitchTab(0)">Contatti</label>
|
||||||
</li>
|
</li>
|
||||||
<li class="tab-item">
|
<li class="tab-item">
|
||||||
<label class="tab-trigger" for="tab2">Commesse</label>
|
<label class="tab-trigger" for="tab2" @onclick="() => SwitchTab(1)">Commesse</label>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- contenuti -->
|
|
||||||
<div class="tab-container">
|
<div class="tab-container">
|
||||||
<div class="tab-content">
|
<!-- Tab Contatti -->
|
||||||
<!-- Contatti -->
|
<div class="tab-content" style="display: @(ActiveTab == 0 ? "block" : "none")">
|
||||||
@if (PersRif is { Count: > 0 })
|
@if (PersRif?.Count > 0)
|
||||||
{
|
{
|
||||||
<div class="container-pers-rif">
|
<div class="container-pers-rif">
|
||||||
<Virtualize Items="PersRif" Context="person">
|
@foreach (var person in PersRif)
|
||||||
@{
|
{
|
||||||
var index = PersRif.IndexOf(person);
|
<ContactCard Contact="person" />
|
||||||
var isLast = index == PersRif.Count - 1;
|
@if (person != PersRif.Last())
|
||||||
}
|
|
||||||
<ContactCard Contact="person"/>
|
|
||||||
@if (!isLast)
|
|
||||||
{
|
{
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
}
|
}
|
||||||
</Virtualize>
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,26 +132,90 @@ else
|
|||||||
</MudButton>
|
</MudButton>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-content">
|
|
||||||
<!-- Commesse -->
|
<!-- Tab Commesse -->
|
||||||
@if (LoadCommessa)
|
<div class="tab-content" style="display: @(ActiveTab == 1 ? "block" : "none")">
|
||||||
|
@if (IsLoadingCommesse)
|
||||||
{
|
{
|
||||||
<MudProgressLinear Color="Color.Primary" Indeterminate="true" Class="my-7"/>
|
<MudProgressLinear Color="Color.Primary" Indeterminate="true" Class="my-7" />
|
||||||
}
|
}
|
||||||
else
|
else if (Commesse?.Count == 0)
|
||||||
{
|
{
|
||||||
@if (Commesse.IsNullOrEmpty())
|
<NoDataAvailable Text="Nessuna commessa presente" />
|
||||||
{
|
|
||||||
<NoDataAvailable Text="Nessuna commessa presente"/>
|
|
||||||
}
|
}
|
||||||
else
|
else if (Commesse != null)
|
||||||
{
|
{
|
||||||
|
<!-- Filtri e ricerca -->
|
||||||
|
<div class="input-card clearButton">
|
||||||
|
<MudTextField T="string?"
|
||||||
|
Placeholder="Cerca..."
|
||||||
|
Variant="Variant.Text"
|
||||||
|
@bind-Value="SearchTerm"
|
||||||
|
OnDebounceIntervalElapsed="() => ApplyFilters()"
|
||||||
|
DebounceInterval="500" />
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="commesse-container">
|
<div class="commesse-container">
|
||||||
<Virtualize Items="Commesse" Context="commessa">
|
@if (IsLoadingSteps)
|
||||||
<CommessaCard Steps="@Steps[commessa.CodJcom]" RagSoc="@Anag.RagSoc" Commessa="commessa"/>
|
{
|
||||||
</Virtualize>
|
<MudProgressLinear Color="Color.Primary" Indeterminate="true" Class="my-3" />
|
||||||
|
}
|
||||||
|
|
||||||
|
@foreach (var commessa in CurrentPageCommesse)
|
||||||
|
{
|
||||||
|
<div class="commessa-wrapper" style="@(IsLoadingStep(commessa.CodJcom) ? "opacity: 0.7;" : "")">
|
||||||
|
@if (Steps.TryGetValue(commessa.CodJcom, out var steps))
|
||||||
|
{
|
||||||
|
<CommessaCard Steps="@steps" RagSoc="@Anag.RagSoc" Commessa="commessa" />
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<CommessaCard Steps="null" RagSoc="@Anag.RagSoc" Commessa="commessa" />
|
||||||
|
@if (IsLoadingStep(commessa.CodJcom))
|
||||||
|
{
|
||||||
|
<MudProgressLinear Indeterminate="true" Color="Color.Primary" Class="my-1" Style="height: 2px;" />
|
||||||
|
}
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@if (TotalPages > 1)
|
||||||
|
{
|
||||||
|
<div class="custom-pagination">
|
||||||
|
<MudPagination BoundaryCount="1" MiddleCount="1" Count="@TotalPages"
|
||||||
|
@bind-Selected="CurrentPage"
|
||||||
|
Color="Color.Primary"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="SelectedPageSize">
|
||||||
|
<MudSelect @bind-Value="SelectedPageSize"
|
||||||
|
Variant="Variant.Text"
|
||||||
|
Label="Elementi per pagina"
|
||||||
|
Dense="true"
|
||||||
|
Style="width: 100%;">
|
||||||
|
<MudSelectItem Value="5">5</MudSelectItem>
|
||||||
|
<MudSelectItem Value="10">10</MudSelectItem>
|
||||||
|
<MudSelectItem Value="20">15</MudSelectItem>
|
||||||
|
</MudSelect>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<MudScrollToTop Selector="#topPage" VisibleCssClass="visible absolute" TopOffset="100" HiddenCssClass="invisible">
|
||||||
|
<MudFab Size="Size.Small" Color="Color.Primary" StartIcon="@Icons.Material.Rounded.KeyboardArrowUp" />
|
||||||
|
</MudScrollToTop>
|
||||||
|
}
|
||||||
|
|
||||||
|
@* <div class="commesse-stats mt-4">
|
||||||
|
<MudChip T="string" Size="Size.Small" Color="Color.Info">
|
||||||
|
Visualizzate: @CurrentPageCommesse.Count() / @FilteredCommesse.Count()
|
||||||
|
</MudChip>
|
||||||
|
@if (!string.IsNullOrEmpty(SearchTerm))
|
||||||
|
{
|
||||||
|
<MudChip T="string" Size="Size.Small" Color="Color.Warning" OnClose="ClearSearch">
|
||||||
|
Filtro: "@SearchTerm"
|
||||||
|
</MudChip>
|
||||||
|
}
|
||||||
|
</div> *@
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -164,34 +223,173 @@ else
|
|||||||
}
|
}
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
[Parameter] public string CodContact { get; set; }
|
[Parameter] public string CodContact { get; set; } = string.Empty;
|
||||||
[Parameter] public bool IsContact { get; set; }
|
[Parameter] public bool IsContact { get; set; }
|
||||||
|
|
||||||
|
// Dati principali
|
||||||
private ContactDTO Anag { get; set; } = new();
|
private ContactDTO Anag { get; set; } = new();
|
||||||
private List<PersRifDTO>? PersRif { get; set; }
|
private List<PersRifDTO>? PersRif { get; set; }
|
||||||
private List<JtbComt>? Commesse { get; set; }
|
private List<JtbComt>? Commesse { get; set; }
|
||||||
private StbUser? Agente { get; set; }
|
private StbUser? Agente { get; set; }
|
||||||
private Dictionary<string, List<CRMJobStepDTO>?> Steps { get; set; } = [];
|
private Dictionary<string, List<CRMJobStepDTO>?> Steps { get; set; } = new();
|
||||||
|
|
||||||
|
// Stati di caricamento
|
||||||
private bool IsLoading { get; set; } = true;
|
private bool IsLoading { get; set; } = true;
|
||||||
private bool LoadCommessa { get; set; } = true;
|
private bool IsLoadingCommesse { get; set; } = true;
|
||||||
|
private bool IsLoadingSteps { get; set; } = false;
|
||||||
|
private readonly HashSet<string> _loadingSteps = new();
|
||||||
|
|
||||||
|
// Gestione tab
|
||||||
|
private int ActiveTab { get; set; } = 0;
|
||||||
|
|
||||||
|
// Paginazione e filtri
|
||||||
|
private int _currentPage = 1;
|
||||||
|
private int _selectedPageSize = 5;
|
||||||
|
private string _searchTerm = string.Empty;
|
||||||
|
private List<JtbComt> _filteredCommesse = new();
|
||||||
|
|
||||||
|
// Cancellation tokens per gestire le richieste asincrone
|
||||||
|
private CancellationTokenSource? _loadingCts;
|
||||||
|
private CancellationTokenSource? _stepsCts;
|
||||||
|
|
||||||
|
// Timer per il debounce della ricerca
|
||||||
|
private Timer? _searchTimer;
|
||||||
|
private const int SearchDelayMs = 300;
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
|
||||||
|
private int CurrentPage
|
||||||
|
{
|
||||||
|
get => _currentPage;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_currentPage != value)
|
||||||
|
{
|
||||||
|
_currentPage = value;
|
||||||
|
_ = LoadStepsForCurrentPageAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int SelectedPageSize
|
||||||
|
{
|
||||||
|
get => _selectedPageSize;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_selectedPageSize != value)
|
||||||
|
{
|
||||||
|
_selectedPageSize = value;
|
||||||
|
_currentPage = 1;
|
||||||
|
ApplyFilters();
|
||||||
|
_ = LoadStepsForCurrentPageAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string SearchTerm
|
||||||
|
{
|
||||||
|
get => _searchTerm;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_searchTerm != value)
|
||||||
|
{
|
||||||
|
_searchTerm = value;
|
||||||
|
|
||||||
|
// Debounce della ricerca
|
||||||
|
_searchTimer?.Dispose();
|
||||||
|
_searchTimer = new Timer(async _ => await InvokeAsync(ApplyFilters), null, SearchDelayMs, Timeout.Infinite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<JtbComt> FilteredCommesse
|
||||||
|
{
|
||||||
|
get => _filteredCommesse;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_filteredCommesse = value;
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int TotalPages =>
|
||||||
|
FilteredCommesse.Count == 0 ? 1 : (int)Math.Ceiling(FilteredCommesse.Count / (double)SelectedPageSize);
|
||||||
|
|
||||||
|
private IEnumerable<JtbComt> CurrentPageCommesse =>
|
||||||
|
FilteredCommesse.Skip((CurrentPage - 1) * SelectedPageSize).Take(SelectedPageSize);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Lifecycle Methods
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
if (UserState.CodUser != null && UserState.CodUser.Equals(CodContact))
|
try
|
||||||
|
{
|
||||||
|
_loadingCts = new CancellationTokenSource();
|
||||||
|
|
||||||
|
if (UserState.CodUser?.Equals(CodContact) == true)
|
||||||
{
|
{
|
||||||
LoadDataFromSession();
|
LoadDataFromSession();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await LoadData();
|
await LoadDataAsync();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// Log dell'errore
|
||||||
|
Console.WriteLine($"Errore in OnInitializedAsync: {ex.Message}");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
IsLoading = false;
|
IsLoading = false;
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async Task LoadData()
|
public async ValueTask DisposeAsync()
|
||||||
|
{
|
||||||
|
_loadingCts?.Cancel();
|
||||||
|
_loadingCts?.Dispose();
|
||||||
|
_stepsCts?.Cancel();
|
||||||
|
_stepsCts?.Dispose();
|
||||||
|
_searchTimer?.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Data Loading Methods
|
||||||
|
|
||||||
|
private async Task LoadDataAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Caricamento dati principali
|
||||||
|
await LoadAnagAsync();
|
||||||
|
await LoadPersRifAsync();
|
||||||
|
|
||||||
|
// Caricamento agente
|
||||||
|
if (!string.IsNullOrEmpty(Anag.CodVage))
|
||||||
|
{
|
||||||
|
Agente = (await ManageData.GetTable<StbUser>(x => x.UserCode != null && x.UserCode.Equals(Anag.CodVage)))
|
||||||
|
.LastOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Salvataggio in sessione
|
||||||
|
SaveDataToSession();
|
||||||
|
|
||||||
|
// Caricamento commesse in background
|
||||||
|
_ = Task.Run(async () => await LoadCommesseAsync());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Errore nel caricamento dati: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadAnagAsync()
|
||||||
{
|
{
|
||||||
if (IsContact)
|
if (IsContact)
|
||||||
{
|
{
|
||||||
@@ -203,67 +401,9 @@ else
|
|||||||
var pros = (await ManageData.GetTable<PtbPros>(x => x.CodPpro.Equals(CodContact))).Last();
|
var pros = (await ManageData.GetTable<PtbPros>(x => x.CodPpro.Equals(CodContact))).Last();
|
||||||
Anag = Mapper.Map<ContactDTO>(pros);
|
Anag = Mapper.Map<ContactDTO>(pros);
|
||||||
}
|
}
|
||||||
|
|
||||||
await LoadPersRif();
|
|
||||||
_ = LoadCommesse();
|
|
||||||
|
|
||||||
if (Anag.CodVage != null)
|
|
||||||
{
|
|
||||||
Agente = (await ManageData.GetTable<StbUser>(x => x.UserCode != null && x.UserCode.Equals(Anag.CodVage))).LastOrDefault();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetDataSession();
|
private async Task LoadPersRifAsync()
|
||||||
}
|
|
||||||
|
|
||||||
private void LoadDataFromSession()
|
|
||||||
{
|
|
||||||
Anag = UserState.Anag;
|
|
||||||
PersRif = UserState.PersRif;
|
|
||||||
Commesse = UserState.Commesse;
|
|
||||||
Agente = UserState.Agente;
|
|
||||||
Steps = UserState.Steps;
|
|
||||||
|
|
||||||
SortCommesse();
|
|
||||||
|
|
||||||
LoadCommessa = false;
|
|
||||||
StateHasChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetDataSession()
|
|
||||||
{
|
|
||||||
UserState.CodUser = CodContact;
|
|
||||||
UserState.Anag = Anag;
|
|
||||||
UserState.PersRif = PersRif;
|
|
||||||
UserState.Agente = Agente;
|
|
||||||
UserState.Steps = Steps;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task LoadCommesse()
|
|
||||||
{
|
|
||||||
await Task.Run(async () =>
|
|
||||||
{
|
|
||||||
Commesse = await ManageData.GetTable<JtbComt>(x => x.CodAnag != null && x.CodAnag.Equals(CodContact));
|
|
||||||
UserState.Commesse = Commesse;
|
|
||||||
|
|
||||||
foreach (var commessa in Commesse)
|
|
||||||
{
|
|
||||||
var steps = (await IntegryApiService.RetrieveJobProgress(commessa.CodJcom)).Steps;
|
|
||||||
Steps.Add(commessa.CodJcom, steps);
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadCommessa = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
SortCommesse();
|
|
||||||
StateHasChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SortCommesse()
|
|
||||||
{
|
|
||||||
Commesse = Commesse?.OrderBy(x => x.LastUpd.HasValue).ThenBy(x => x.LastUpd).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task LoadPersRif()
|
|
||||||
{
|
{
|
||||||
if (IsContact)
|
if (IsContact)
|
||||||
{
|
{
|
||||||
@@ -277,19 +417,224 @@ else
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task LoadCommesseAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IsLoadingCommesse = true;
|
||||||
|
|
||||||
|
Commesse = await ManageData.GetTable<JtbComt>(x => x.CodAnag != null && x.CodAnag.Equals(CodContact));
|
||||||
|
|
||||||
|
// Ordinamento ottimizzato
|
||||||
|
Commesse = Commesse?
|
||||||
|
.OrderByDescending(x => x.LastUpd ?? DateTime.MinValue)
|
||||||
|
.ThenByDescending(x => x.CodJcom)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
UserState.Commesse = Commesse;
|
||||||
|
|
||||||
|
ApplyFilters();
|
||||||
|
|
||||||
|
// Caricamento steps per la prima pagina
|
||||||
|
await LoadStepsForCurrentPageAsync();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Errore nel caricamento commesse: {ex.Message}");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsLoadingCommesse = false;
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadDataFromSession()
|
||||||
|
{
|
||||||
|
Anag = UserState.Anag;
|
||||||
|
PersRif = UserState.PersRif;
|
||||||
|
Commesse = UserState.Commesse;
|
||||||
|
Agente = UserState.Agente;
|
||||||
|
Steps = UserState.Steps ?? new Dictionary<string, List<CRMJobStepDTO>?>();
|
||||||
|
|
||||||
|
ApplyFilters();
|
||||||
|
|
||||||
|
IsLoadingCommesse = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveDataToSession()
|
||||||
|
{
|
||||||
|
UserState.CodUser = CodContact;
|
||||||
|
UserState.Anag = Anag;
|
||||||
|
UserState.PersRif = PersRif;
|
||||||
|
UserState.Agente = Agente;
|
||||||
|
UserState.Steps = Steps;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Steps Loading Methods
|
||||||
|
|
||||||
|
private async Task LoadStepsForCurrentPageAsync()
|
||||||
|
{
|
||||||
|
if (CurrentPageCommesse?.Any() != true) return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_stepsCts?.Cancel();
|
||||||
|
_stepsCts = new CancellationTokenSource();
|
||||||
|
var token = _stepsCts.Token;
|
||||||
|
|
||||||
|
IsLoadingSteps = true;
|
||||||
|
|
||||||
|
var tasksToLoad = new List<Task>();
|
||||||
|
var semaphore = new SemaphoreSlim(3); // Limita a 3 richieste simultanee
|
||||||
|
|
||||||
|
foreach (var commessa in CurrentPageCommesse.Where(c => !Steps.ContainsKey(c.CodJcom)))
|
||||||
|
{
|
||||||
|
if (token.IsCancellationRequested) break;
|
||||||
|
|
||||||
|
tasksToLoad.Add(LoadStepForCommessaAsync(commessa.CodJcom, semaphore, token));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tasksToLoad.Any())
|
||||||
|
{
|
||||||
|
await Task.WhenAll(tasksToLoad);
|
||||||
|
UserState.Steps = Steps;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
// Operazione annullata, non fare nulla
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Errore nel caricamento steps: {ex.Message}");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsLoadingSteps = false;
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadStepForCommessaAsync(string codJcom, SemaphoreSlim semaphore, CancellationToken token)
|
||||||
|
{
|
||||||
|
await semaphore.WaitAsync(token);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_loadingSteps.Add(codJcom);
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
|
||||||
|
var jobProgress = await IntegryApiService.RetrieveJobProgress(codJcom);
|
||||||
|
|
||||||
|
if (!token.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
Steps[codJcom] = jobProgress.Steps;
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Errore nel caricamento step per {codJcom}: {ex.Message}");
|
||||||
|
if (!token.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
Steps[codJcom] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_loadingSteps.Remove(codJcom);
|
||||||
|
semaphore.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsLoadingStep(string codJcom) => _loadingSteps.Contains(codJcom);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region UI Methods
|
||||||
|
|
||||||
|
private void SwitchTab(int tabIndex)
|
||||||
|
{
|
||||||
|
ActiveTab = tabIndex;
|
||||||
|
|
||||||
|
// Se si passa alle commesse e non sono ancora state caricate
|
||||||
|
if (tabIndex == 1 && Commesse == null)
|
||||||
|
{
|
||||||
|
_ = Task.Run(async () => await LoadCommesseAsync());
|
||||||
|
} else if (tabIndex == 1 && Steps.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
_ = Task.Run(async () => await LoadStepsForCurrentPageAsync());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyFilters()
|
||||||
|
{
|
||||||
|
if (Commesse == null)
|
||||||
|
{
|
||||||
|
FilteredCommesse = new List<JtbComt>();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var filtered = Commesse.AsEnumerable();
|
||||||
|
|
||||||
|
// Filtro per testo di ricerca
|
||||||
|
if (!string.IsNullOrWhiteSpace(SearchTerm))
|
||||||
|
{
|
||||||
|
var searchLower = SearchTerm.ToLowerInvariant();
|
||||||
|
filtered = filtered.Where(c =>
|
||||||
|
c.CodJcom?.ToLowerInvariant().Contains(searchLower) == true ||
|
||||||
|
c.Descrizione?.ToLowerInvariant().Contains(searchLower) == true ||
|
||||||
|
c.CodAnag?.ToLowerInvariant().Contains(searchLower) == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
FilteredCommesse = filtered.ToList();
|
||||||
|
|
||||||
|
// Reset della pagina se necessario
|
||||||
|
if (CurrentPage > TotalPages && TotalPages > 0)
|
||||||
|
{
|
||||||
|
_currentPage = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carica gli steps per la pagina corrente
|
||||||
|
_ = LoadStepsForCurrentPageAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ClearSearch()
|
||||||
|
{
|
||||||
|
SearchTerm = string.Empty;
|
||||||
|
ApplyFilters();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Modal Methods
|
||||||
|
|
||||||
private async Task OpenPersRifForm()
|
private async Task OpenPersRifForm()
|
||||||
{
|
{
|
||||||
var result = await ModalHelpers.OpenPersRifForm(Dialog, null, Anag, PersRif);
|
var result = await ModalHelpers.OpenPersRifForm(Dialog, null, Anag, PersRif);
|
||||||
|
|
||||||
if (result is { Canceled: false, Data: not null } && result.Data.GetType() == typeof(PersRifDTO))
|
if (result is { Canceled: false, Data: not null } && result.Data.GetType() == typeof(PersRifDTO))
|
||||||
{
|
{
|
||||||
await LoadPersRif();
|
await LoadPersRifAsync();
|
||||||
|
UserState.PersRif = PersRif;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OpenUserForm(ContactDTO anag)
|
private async Task OpenUserForm(ContactDTO anag)
|
||||||
{
|
{
|
||||||
var result = await ModalHelpers.OpenUserForm(Dialog, anag);
|
var result = await ModalHelpers.OpenUserForm(Dialog, anag);
|
||||||
|
|
||||||
|
if (result is { Canceled: false })
|
||||||
|
{
|
||||||
|
// Aggiorna i dati se necessario
|
||||||
|
await LoadAnagAsync();
|
||||||
|
SaveDataToSession();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -165,10 +165,6 @@
|
|||||||
gap: 1.25rem;
|
gap: 1.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.commesse-container ::deep > div:first-child:not(.activity-card) {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*--------------
|
/*--------------
|
||||||
TabPanel
|
TabPanel
|
||||||
----------------*/
|
----------------*/
|
||||||
@@ -242,14 +238,13 @@
|
|||||||
.tab-container {
|
.tab-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
overflow: hidden;
|
|
||||||
width: -webkit-fill-available;
|
width: -webkit-fill-available;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab-content {
|
.tab-content {
|
||||||
display: none;
|
display: none;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
overflow-y: auto;
|
overflow-y: hidden;
|
||||||
animation: fade .3s ease;
|
animation: fade .3s ease;
|
||||||
padding: .5rem;
|
padding: .5rem;
|
||||||
}
|
}
|
||||||
@@ -275,3 +270,13 @@
|
|||||||
transform: translateY(0);
|
transform: translateY(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.custom-pagination ::deep ul { padding-left: 0 !important; }
|
||||||
|
|
||||||
|
.SelectedPageSize {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.FilterSection {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
@@ -38,6 +38,13 @@ a, .btn-link {
|
|||||||
height: 90vh;
|
height: 90vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.content::-webkit-scrollbar { width: 3px; }
|
||||||
|
|
||||||
|
.content::-webkit-scrollbar-thumb {
|
||||||
|
background: #bbb;
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
h1:focus { outline: none; }
|
h1:focus { outline: none; }
|
||||||
|
|
||||||
.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
|
.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
|
||||||
@@ -97,9 +104,7 @@ h1:focus { outline: none; }
|
|||||||
color: var(--mud-palette-text-primary) !important;
|
color: var(--mud-palette-text-primary) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.custom_popover .mud-divider {
|
.custom_popover .mud-divider { border-color: var(--mud-palette-text-primary) !important; }
|
||||||
border-color: var(--mud-palette-text-primary) !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.custom_popover .mud-list-padding { padding: 3px 0px 3px 0px !important; }
|
.custom_popover .mud-list-padding { padding: 3px 0px 3px 0px !important; }
|
||||||
|
|
||||||
@@ -196,9 +201,7 @@ h1:focus { outline: none; }
|
|||||||
padding-left: calc(var(--m-page-x) * 0.5) !important;
|
padding-left: calc(var(--m-page-x) * 0.5) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mud-message-box > .mud-dialog-title > h6 {
|
.mud-message-box > .mud-dialog-title > h6 { font-weight: 800 !important; }
|
||||||
font-weight: 800 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mud-dialog-actions button {
|
.mud-dialog-actions button {
|
||||||
margin-left: .5rem !important;
|
margin-left: .5rem !important;
|
||||||
|
|||||||
Reference in New Issue
Block a user