From 223e74c49083f89cdddc2d0b6a007c93dce8499e Mon Sep 17 00:00:00 2001 From: MarcoE Date: Fri, 12 Sep 2025 15:42:56 +0200 Subject: [PATCH] Migliorata gestione e visualizzazione notifiche --- .../Core/Services/ManageDataService.cs | 35 +++++++++++ .../Push/PushNotificationDelegate.cs | 2 +- salesbook.Maui/MauiProgram.cs | 7 ++- .../Components/Layout/NavMenu.razor | 14 ++++- .../Layout/Spinner/OverlayLayout.razor | 12 ++++ .../Layout/Spinner/OverlayLayout.razor.css | 18 ++++++ salesbook.Shared/Components/Pages/Home.razor | 11 ++++ .../Components/Pages/Notifications.razor | 61 ++++--------------- .../Components/Pages/Notifications.razor.css | 15 +++++ .../BottomSheet/SearchAddress.razor | 1 - .../Card/NotificationCard.razor | 35 ++++++++++- .../Core/Interface/IManageDataService.cs | 1 + .../Core/Interface/INotificationService.cs | 7 +++ .../Loaded/NotificationsLoadedMessage.cs | 5 ++ .../Loaded/NotificationsLoadedService.cs | 13 ++++ .../NewPushNotificationMessage.cs | 2 +- .../NewPushNotificationService.cs | 2 +- .../Core/Services/NotificationService.cs | 45 ++++++++++++++ salesbook.Shared/wwwroot/css/app.css | 1 + .../wwwroot/css/default-theme.css | 2 +- 20 files changed, 229 insertions(+), 60 deletions(-) create mode 100644 salesbook.Shared/Components/Layout/Spinner/OverlayLayout.razor create mode 100644 salesbook.Shared/Components/Layout/Spinner/OverlayLayout.razor.css create mode 100644 salesbook.Shared/Core/Interface/INotificationService.cs create mode 100644 salesbook.Shared/Core/Messages/Notification/Loaded/NotificationsLoadedMessage.cs create mode 100644 salesbook.Shared/Core/Messages/Notification/Loaded/NotificationsLoadedService.cs rename salesbook.Shared/Core/Messages/Notification/{ => NewPush}/NewPushNotificationMessage.cs (58%) rename salesbook.Shared/Core/Messages/Notification/{ => NewPush}/NewPushNotificationService.cs (85%) create mode 100644 salesbook.Shared/Core/Services/NotificationService.cs diff --git a/salesbook.Maui/Core/Services/ManageDataService.cs b/salesbook.Maui/Core/Services/ManageDataService.cs index b9196a1..cf6081a 100644 --- a/salesbook.Maui/Core/Services/ManageDataService.cs +++ b/salesbook.Maui/Core/Services/ManageDataService.cs @@ -10,6 +10,7 @@ using salesbook.Shared.Core.Interface.IntegryApi; using salesbook.Shared.Core.Interface.System.Network; using Sentry.Protocol; using System.Linq.Expressions; +using salesbook.Shared.Core.Helpers; namespace salesbook.Maui.Core.Services; @@ -159,6 +160,35 @@ public class ManageDataService( } } + public async Task> GetActivityTryLocalDb(WhereCondActivity whereCond) + { + List? activities; + + activities = await localDb.Get(x => + (whereCond.ActivityId != null && x.ActivityId != null && whereCond.ActivityId.Equals(x.ActivityId)) || + (whereCond.Start != null && whereCond.End != null && x.EffectiveDate == null && + x.EstimatedDate >= whereCond.Start && x.EstimatedDate <= whereCond.End) || + (x.EffectiveDate >= whereCond.Start && x.EffectiveDate <= whereCond.End) || + (whereCond.ActivityId == null && (whereCond.Start == null || whereCond.End == null)) + ); + + if (activities.IsNullOrEmpty() && networkService.ConnectionAvailable) + { + activities = await integryApiService.RetrieveActivity( + new CRMRetrieveActivityRequestDTO + { + StarDate = whereCond.Start, + EndDate = whereCond.End, + ActivityId = whereCond.ActivityId + } + ); + + _ = UpdateDb(activities); + } + + return await MapActivity(activities); + } + public async Task> GetActivity(WhereCondActivity whereCond, bool useLocalDb) { List? activities; @@ -187,6 +217,11 @@ public class ManageDataService( ); } + return await MapActivity(activities); + } + + private async Task> MapActivity(List? activities) + { if (activities == null) return []; var codJcomList = activities diff --git a/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs b/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs index 5f0bdc7..97b9964 100644 --- a/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs +++ b/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs @@ -1,7 +1,7 @@ using CommunityToolkit.Mvvm.Messaging; using salesbook.Shared.Core.Entity; using salesbook.Shared.Core.Interface.IntegryApi; -using salesbook.Shared.Core.Messages.Notification; +using salesbook.Shared.Core.Messages.Notification.NewPush; using Shiny.Push; namespace salesbook.Maui.Core.System.Notification.Push; diff --git a/salesbook.Maui/MauiProgram.cs b/salesbook.Maui/MauiProgram.cs index 4abc81f..199c320 100644 --- a/salesbook.Maui/MauiProgram.cs +++ b/salesbook.Maui/MauiProgram.cs @@ -22,7 +22,8 @@ using salesbook.Shared.Core.Messages.Activity.Copy; using salesbook.Shared.Core.Messages.Activity.New; using salesbook.Shared.Core.Messages.Back; using salesbook.Shared.Core.Messages.Contact; -using salesbook.Shared.Core.Messages.Notification; +using salesbook.Shared.Core.Messages.Notification.Loaded; +using salesbook.Shared.Core.Messages.Notification.NewPush; using salesbook.Shared.Core.Services; using Shiny; @@ -81,8 +82,9 @@ namespace salesbook.Maui builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); + builder.Services.AddSingleton(); builder.Services.AddSingleton(); - + //Notification builder.Services.AddNotifications(); builder.Services.AddPush(); @@ -90,6 +92,7 @@ namespace salesbook.Maui builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); + builder.Services.AddSingleton(); #if DEBUG builder.Services.AddBlazorWebViewDeveloperTools(); diff --git a/salesbook.Shared/Components/Layout/NavMenu.razor b/salesbook.Shared/Components/Layout/NavMenu.razor index f5c158d..f1634b0 100644 --- a/salesbook.Shared/Components/Layout/NavMenu.razor +++ b/salesbook.Shared/Components/Layout/NavMenu.razor @@ -6,12 +6,14 @@ @using salesbook.Shared.Core.Messages.Activity.Copy @using salesbook.Shared.Core.Messages.Activity.New @using salesbook.Shared.Core.Messages.Contact -@using salesbook.Shared.Core.Messages.Notification +@using salesbook.Shared.Core.Messages.Notification.Loaded +@using salesbook.Shared.Core.Messages.Notification.NewPush @inject IDialogService Dialog @inject IMessenger Messenger @inject CopyActivityService CopyActivityService @inject NewPushNotificationService NewPushNotificationService @inject NotificationState Notification +@inject NotificationsLoadedService NotificationsLoadedService