Migliorata sincronizzazione dei dati
This commit is contained in:
@@ -37,7 +37,6 @@ public class ManageDataService(
|
|||||||
ReturnPersRif = !whereCond.OnlyContact
|
ReturnPersRif = !whereCond.OnlyContact
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
_ = UpdateDbUsers(response);
|
|
||||||
|
|
||||||
clienti = response.AnagClie ?? [];
|
clienti = response.AnagClie ?? [];
|
||||||
}
|
}
|
||||||
@@ -69,7 +68,6 @@ public class ManageDataService(
|
|||||||
ReturnPersRif = !whereCond.OnlyContact
|
ReturnPersRif = !whereCond.OnlyContact
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
_ = UpdateDbUsers(response);
|
|
||||||
|
|
||||||
prospect = response.PtbPros ?? [];
|
prospect = response.PtbPros ?? [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ namespace salesbook.Maui
|
|||||||
builder.Services.AddScoped<IIntegryApiService, IntegryApiService>();
|
builder.Services.AddScoped<IIntegryApiService, IntegryApiService>();
|
||||||
builder.Services.AddScoped<ISyncDbService, SyncDbService>();
|
builder.Services.AddScoped<ISyncDbService, SyncDbService>();
|
||||||
builder.Services.AddScoped<IManageDataService, ManageDataService>();
|
builder.Services.AddScoped<IManageDataService, ManageDataService>();
|
||||||
|
builder.Services.AddScoped<PreloadService>();
|
||||||
|
|
||||||
//SessionData
|
//SessionData
|
||||||
builder.Services.AddSingleton<JobSteps>();
|
builder.Services.AddSingleton<JobSteps>();
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
@attribute [Authorize]
|
@attribute [Authorize]
|
||||||
@using salesbook.Shared.Core.Interface
|
@using salesbook.Shared.Core.Interface
|
||||||
@using salesbook.Shared.Components.Layout.Spinner
|
@using salesbook.Shared.Components.Layout.Spinner
|
||||||
|
@using salesbook.Shared.Core.Services
|
||||||
@inject IFormFactor FormFactor
|
@inject IFormFactor FormFactor
|
||||||
@inject INetworkService NetworkService
|
@inject INetworkService NetworkService
|
||||||
|
@inject PreloadService PreloadService
|
||||||
|
|
||||||
<SpinnerLayout FullScreen="true" />
|
<SpinnerLayout FullScreen="true" />
|
||||||
|
|
||||||
@@ -19,6 +21,15 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_ = StartSyncUser();
|
||||||
NavigationManager.NavigateTo("/Calendar");
|
NavigationManager.NavigateTo("/Calendar");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Task StartSyncUser()
|
||||||
|
{
|
||||||
|
return Task.Run(() =>
|
||||||
|
{
|
||||||
|
_ = PreloadService.PreloadUsersAsync();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
@using salesbook.Shared.Components.SingleElements.BottomSheet
|
@using salesbook.Shared.Components.SingleElements.BottomSheet
|
||||||
@using salesbook.Shared.Components.Layout.Spinner
|
@using salesbook.Shared.Components.Layout.Spinner
|
||||||
@using salesbook.Shared.Components.SingleElements
|
@using salesbook.Shared.Components.SingleElements
|
||||||
@using salesbook.Shared.Core.Dto.Contact
|
|
||||||
@using salesbook.Shared.Core.Dto.PageState
|
@using salesbook.Shared.Core.Dto.PageState
|
||||||
@using salesbook.Shared.Core.Dto.Users
|
@using salesbook.Shared.Core.Dto.Users
|
||||||
@using salesbook.Shared.Core.Entity
|
@using salesbook.Shared.Core.Entity
|
||||||
@@ -15,6 +14,7 @@
|
|||||||
@inject NewContactService NewContact
|
@inject NewContactService NewContact
|
||||||
@inject FilterUserDTO Filter
|
@inject FilterUserDTO Filter
|
||||||
@inject UserListState UserState
|
@inject UserListState UserState
|
||||||
|
@implements IDisposable
|
||||||
|
|
||||||
<HeaderLayout Title="Contatti"/>
|
<HeaderLayout Title="Contatti"/>
|
||||||
|
|
||||||
@@ -71,33 +71,37 @@
|
|||||||
private bool OpenFilter { get; set; }
|
private bool OpenFilter { get; set; }
|
||||||
private string TypeUser { get; set; } = "all";
|
private string TypeUser { get; set; } = "all";
|
||||||
|
|
||||||
protected override void OnInitialized()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
|
||||||
NewContact.OnContactCreated += async response => await OnUserCreated(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
||||||
{
|
|
||||||
if (firstRender)
|
|
||||||
{
|
{
|
||||||
IsLoading = true;
|
IsLoading = true;
|
||||||
StateHasChanged();
|
|
||||||
|
|
||||||
if (UserState.FilteredGroupedUserList == null && UserState.GroupedUserList == null)
|
if (!UserState.IsLoaded)
|
||||||
{
|
{
|
||||||
await LoadData();
|
UserState.OnUsersLoaded += OnUsersLoaded;
|
||||||
SetDataSession();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
await LoadData();
|
||||||
LoadFromSession();
|
LoadFromSession();
|
||||||
}
|
|
||||||
|
|
||||||
FilterUsers();
|
FilterUsers();
|
||||||
|
|
||||||
IsLoading = false;
|
|
||||||
StateHasChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NewContact.OnContactCreated += async response => await OnUserCreated(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnUsersLoaded()
|
||||||
|
{
|
||||||
|
InvokeAsync(async () =>
|
||||||
|
{
|
||||||
|
await LoadData();
|
||||||
|
LoadFromSession();
|
||||||
|
FilterUsers();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void IDisposable.Dispose()
|
||||||
|
{
|
||||||
|
UserState.OnUsersLoaded -= OnUsersLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadFromSession()
|
private void LoadFromSession()
|
||||||
@@ -106,12 +110,6 @@
|
|||||||
FilteredGroupedUserList = UserState.FilteredGroupedUserList!;
|
FilteredGroupedUserList = UserState.FilteredGroupedUserList!;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetDataSession()
|
|
||||||
{
|
|
||||||
UserState.GroupedUserList = GroupedUserList;
|
|
||||||
UserState.FilteredGroupedUserList = FilteredGroupedUserList;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task LoadData()
|
private async Task LoadData()
|
||||||
{
|
{
|
||||||
if (!Filter.IsInitialized)
|
if (!Filter.IsInitialized)
|
||||||
@@ -123,37 +121,6 @@
|
|||||||
|
|
||||||
Filter.IsInitialized = true;
|
Filter.IsInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var users = await ManageData.GetContact(new WhereCondContact {FlagStato = "A"});
|
|
||||||
|
|
||||||
var sortedUsers = users
|
|
||||||
.Where(u => !string.IsNullOrWhiteSpace(u.RagSoc))
|
|
||||||
.OrderBy(u =>
|
|
||||||
{
|
|
||||||
var firstChar = char.ToUpper(u.RagSoc[0]);
|
|
||||||
return char.IsLetter(firstChar) ? firstChar.ToString() : "ZZZ";
|
|
||||||
})
|
|
||||||
.ThenBy(u => u.RagSoc)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
GroupedUserList = [];
|
|
||||||
|
|
||||||
string? lastHeader = null;
|
|
||||||
foreach (var user in sortedUsers)
|
|
||||||
{
|
|
||||||
var firstChar = char.ToUpper(user.RagSoc[0]);
|
|
||||||
var currentLetter = char.IsLetter(firstChar) ? firstChar.ToString() : "#";
|
|
||||||
|
|
||||||
var showHeader = currentLetter != lastHeader;
|
|
||||||
lastHeader = currentLetter;
|
|
||||||
|
|
||||||
GroupedUserList.Add(new UserDisplayItem
|
|
||||||
{
|
|
||||||
User = user,
|
|
||||||
ShowHeader = showHeader,
|
|
||||||
HeaderLetter = currentLetter
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FilterUsers() => FilterUsers(false);
|
private void FilterUsers() => FilterUsers(false);
|
||||||
@@ -220,6 +187,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
FilteredGroupedUserList = result;
|
FilteredGroupedUserList = result;
|
||||||
|
|
||||||
|
IsLoading = false;
|
||||||
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OnUserCreated(CRMCreateContactResponseDTO response)
|
private async Task OnUserCreated(CRMCreateContactResponseDTO response)
|
||||||
|
|||||||
@@ -6,4 +6,16 @@ public class UserListState
|
|||||||
{
|
{
|
||||||
public List<UserDisplayItem>? GroupedUserList { get; set; }
|
public List<UserDisplayItem>? GroupedUserList { get; set; }
|
||||||
public List<UserDisplayItem>? FilteredGroupedUserList { get; set; }
|
public List<UserDisplayItem>? FilteredGroupedUserList { get; set; }
|
||||||
|
|
||||||
|
public bool IsLoaded { get; set; }
|
||||||
|
public bool IsLoading { get; set; }
|
||||||
|
|
||||||
|
public event Action? OnUsersLoaded;
|
||||||
|
|
||||||
|
public void NotifyUsersLoaded()
|
||||||
|
{
|
||||||
|
IsLoaded = true;
|
||||||
|
IsLoading = false;
|
||||||
|
OnUsersLoaded?.Invoke();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
55
salesbook.Shared/Core/Services/PreloadService.cs
Normal file
55
salesbook.Shared/Core/Services/PreloadService.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
using salesbook.Shared.Core.Dto;
|
||||||
|
using salesbook.Shared.Core.Dto.Contact;
|
||||||
|
using salesbook.Shared.Core.Dto.PageState;
|
||||||
|
using salesbook.Shared.Core.Dto.Users;
|
||||||
|
using salesbook.Shared.Core.Interface;
|
||||||
|
|
||||||
|
namespace salesbook.Shared.Core.Services;
|
||||||
|
|
||||||
|
public class PreloadService(IManageDataService manageData, UserListState userState)
|
||||||
|
{
|
||||||
|
public async Task PreloadUsersAsync()
|
||||||
|
{
|
||||||
|
if (userState.IsLoaded || userState.IsLoading)
|
||||||
|
return;
|
||||||
|
|
||||||
|
userState.IsLoading = true;
|
||||||
|
|
||||||
|
var users = await manageData.GetContact(new WhereCondContact { FlagStato = "A" });
|
||||||
|
|
||||||
|
var sorted = users
|
||||||
|
.Where(u => !string.IsNullOrWhiteSpace(u.RagSoc))
|
||||||
|
.OrderBy(u => char.IsLetter(char.ToUpper(u.RagSoc[0])) ? char.ToUpper(u.RagSoc[0]).ToString() : "ZZZ")
|
||||||
|
.ThenBy(u => u.RagSoc)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
userState.GroupedUserList = BuildGroupedList(sorted);
|
||||||
|
userState.FilteredGroupedUserList = userState.GroupedUserList;
|
||||||
|
|
||||||
|
userState.NotifyUsersLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<UserDisplayItem> BuildGroupedList(List<ContactDTO> users)
|
||||||
|
{
|
||||||
|
var grouped = new List<UserDisplayItem>();
|
||||||
|
string? lastHeader = null;
|
||||||
|
|
||||||
|
foreach (var user in users)
|
||||||
|
{
|
||||||
|
var firstChar = char.ToUpper(user.RagSoc[0]);
|
||||||
|
var currentLetter = char.IsLetter(firstChar) ? firstChar.ToString() : "#";
|
||||||
|
|
||||||
|
var showHeader = currentLetter != lastHeader;
|
||||||
|
lastHeader = currentLetter;
|
||||||
|
|
||||||
|
grouped.Add(new UserDisplayItem
|
||||||
|
{
|
||||||
|
User = user,
|
||||||
|
ShowHeader = showHeader,
|
||||||
|
HeaderLetter = currentLetter
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return grouped;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user