From 7bfe67a97cdd9338c5ae0ce0347f593d7f8a56bd Mon Sep 17 00:00:00 2001 From: MarcoE Date: Thu, 11 Sep 2025 16:06:19 +0200 Subject: [PATCH] Gestita pagina notifiche --- ... IntegryRegisterNotificationRestClient.cs} | 6 +- .../Core/Services/ManageDataService.cs | 14 +- .../FirebaseNotificationService.cs | 4 +- .../Push/PushNotificationDelegate.cs | 10 +- salesbook.Maui/MauiProgram.cs | 1 + salesbook.Maui/salesbook.Maui.csproj | 2 +- .../Components/Layout/NavMenu.razor | 7 +- .../Components/Pages/Calendar.razor.css | 6 +- .../Components/Pages/Notifications.razor | 155 ++++++++++++++++-- .../Components/Pages/User.razor.css | 1 + .../Components/Pages/Users.razor.css | 3 +- .../Card/NotificationCard.razor | 85 +++++++++- .../Card/NotificationCard.razor.css | 61 +++++-- .../SingleElements/Modal/ActivityForm.razor | 54 ++++-- .../Core/Dto/Activity/ActivityDTO.cs | 14 +- .../Dto/Notification/PushNotificationDTO.cs | 9 - .../Core/Dto/NotificationDataDTO.cs | 12 ++ .../Core/Dto/PageState/NotificationState.cs | 8 +- .../Core/Dto/ReadNotificationRequestDTO.cs | 15 ++ .../Core/Entity/WtbDeviceNotification.cs | 15 ++ .../Core/Entity/WtbNotification.cs | 37 +++++ .../IIntegryNotificationRestClient.cs | 7 +- .../IIntegryRegisterNotificationRestClient.cs | 8 + .../NewPushNotificationMessage.cs | 4 +- .../NewPushNotificationService.cs | 4 +- .../Services/IntegryNotificationRestClient.cs | 33 ++++ salesbook.Shared/salesbook.Shared.csproj | 2 +- salesbook.Shared/wwwroot/css/app.css | 8 +- salesbook.Shared/wwwroot/js/notifications.js | 129 ++++++++++++--- salesbook.Web/salesbook.Web.csproj | 2 +- 30 files changed, 611 insertions(+), 105 deletions(-) rename salesbook.Maui/Core/RestClient/IntegryApi/{IntegryNotificationRestClient.cs => IntegryRegisterNotificationRestClient.cs} (87%) delete mode 100644 salesbook.Shared/Core/Dto/Notification/PushNotificationDTO.cs create mode 100644 salesbook.Shared/Core/Dto/NotificationDataDTO.cs create mode 100644 salesbook.Shared/Core/Dto/ReadNotificationRequestDTO.cs create mode 100644 salesbook.Shared/Core/Entity/WtbDeviceNotification.cs create mode 100644 salesbook.Shared/Core/Entity/WtbNotification.cs create mode 100644 salesbook.Shared/Core/Interface/IntegryApi/IIntegryRegisterNotificationRestClient.cs create mode 100644 salesbook.Shared/Core/Services/IntegryNotificationRestClient.cs diff --git a/salesbook.Maui/Core/RestClient/IntegryApi/IntegryNotificationRestClient.cs b/salesbook.Maui/Core/RestClient/IntegryApi/IntegryRegisterNotificationRestClient.cs similarity index 87% rename from salesbook.Maui/Core/RestClient/IntegryApi/IntegryNotificationRestClient.cs rename to salesbook.Maui/Core/RestClient/IntegryApi/IntegryRegisterNotificationRestClient.cs index 021fc6c..39fc676 100644 --- a/salesbook.Maui/Core/RestClient/IntegryApi/IntegryNotificationRestClient.cs +++ b/salesbook.Maui/Core/RestClient/IntegryApi/IntegryRegisterNotificationRestClient.cs @@ -6,11 +6,11 @@ using salesbook.Shared.Core.Interface.IntegryApi; namespace salesbook.Maui.Core.RestClient.IntegryApi; -public class IntegryNotificationRestClient( - ILogger logger, +public class IntegryRegisterNotificationRestClient( + ILogger logger, IUserSession userSession, IIntegryApiRestClient integryApiRestClient -) : IIntegryNotificationRestClient +) : IIntegryRegisterNotificationRestClient { public async Task Register(string fcmToken, ILogger? logger1 = null) { diff --git a/salesbook.Maui/Core/Services/ManageDataService.cs b/salesbook.Maui/Core/Services/ManageDataService.cs index 9031c83..b9196a1 100644 --- a/salesbook.Maui/Core/Services/ManageDataService.cs +++ b/salesbook.Maui/Core/Services/ManageDataService.cs @@ -1,14 +1,15 @@ using AutoMapper; +using MudBlazor.Extensions; using salesbook.Shared.Core.Dto; using salesbook.Shared.Core.Dto.Activity; using salesbook.Shared.Core.Dto.Contact; using salesbook.Shared.Core.Entity; using salesbook.Shared.Core.Helpers.Enum; using salesbook.Shared.Core.Interface; -using Sentry.Protocol; -using System.Linq.Expressions; using salesbook.Shared.Core.Interface.IntegryApi; using salesbook.Shared.Core.Interface.System.Network; +using Sentry.Protocol; +using System.Linq.Expressions; namespace salesbook.Maui.Core.Services; @@ -211,6 +212,15 @@ public class ManageDataService( { var dto = mapper.Map(activity); + if (activity is { AlarmTime: not null, EstimatedTime: not null }) + { + var minuteBefore = activity.EstimatedTime.Value - activity.AlarmTime.Value; + dto.MinuteBefore = (int)Math.Abs(minuteBefore.TotalMinutes); + + dto.NotificationDate = dto.MinuteBefore == 0 ? + activity.EstimatedTime : activity.AlarmTime; + } + if (activity.CodJcom != null) { dto.Category = ActivityCategoryEnum.Commessa; diff --git a/salesbook.Maui/Core/System/Notification/FirebaseNotificationService.cs b/salesbook.Maui/Core/System/Notification/FirebaseNotificationService.cs index 2f766eb..8d0fd36 100644 --- a/salesbook.Maui/Core/System/Notification/FirebaseNotificationService.cs +++ b/salesbook.Maui/Core/System/Notification/FirebaseNotificationService.cs @@ -8,7 +8,7 @@ namespace salesbook.Maui.Core.System.Notification; public class FirebaseNotificationService( IPushManager pushManager, - IIntegryNotificationRestClient integryNotificationRestClient, + IIntegryRegisterNotificationRestClient integryRegisterNotificationRestClient, INotificationManager notificationManager ) : IFirebaseNotificationService { @@ -19,7 +19,7 @@ public class FirebaseNotificationService( var (accessState, token) = await pushManager.RequestAccess(); if (accessState == AccessState.Denied || token is null) return; - await integryNotificationRestClient.Register(token); + await integryRegisterNotificationRestClient.Register(token); } private void CreateNotificationChannel() diff --git a/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs b/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs index 8e69c40..5f0bdc7 100644 --- a/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs +++ b/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs @@ -1,5 +1,5 @@ using CommunityToolkit.Mvvm.Messaging; -using salesbook.Shared.Core.Dto.Notification; +using salesbook.Shared.Core.Entity; using salesbook.Shared.Core.Interface.IntegryApi; using salesbook.Shared.Core.Messages.Notification; using Shiny.Push; @@ -7,7 +7,7 @@ using Shiny.Push; namespace salesbook.Maui.Core.System.Notification.Push; public class PushNotificationDelegate( - IIntegryNotificationRestClient integryNotificationRestClient, + IIntegryRegisterNotificationRestClient integryRegisterNotificationRestClient, IMessenger messenger ) : IPushDelegate { @@ -20,10 +20,10 @@ public class PushNotificationDelegate( public Task OnReceived(PushNotification notification) { if (notification.Notification is null) return Task.CompletedTask; - var pushNotification = new PushNotificationDTO + var pushNotification = new WtbNotification { Title = notification.Notification.Title, - Message = notification.Notification.Message + Body = notification.Notification.Message }; messenger.Send(new NewPushNotificationMessage(pushNotification)); @@ -33,7 +33,7 @@ public class PushNotificationDelegate( public Task OnNewToken(string token) { - integryNotificationRestClient.Register(token); + integryRegisterNotificationRestClient.Register(token); return Task.CompletedTask; } diff --git a/salesbook.Maui/MauiProgram.cs b/salesbook.Maui/MauiProgram.cs index c9c7290..4abc81f 100644 --- a/salesbook.Maui/MauiProgram.cs +++ b/salesbook.Maui/MauiProgram.cs @@ -86,6 +86,7 @@ namespace salesbook.Maui //Notification builder.Services.AddNotifications(); builder.Services.AddPush(); + builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); diff --git a/salesbook.Maui/salesbook.Maui.csproj b/salesbook.Maui/salesbook.Maui.csproj index fb9eb60..9b32639 100644 --- a/salesbook.Maui/salesbook.Maui.csproj +++ b/salesbook.Maui/salesbook.Maui.csproj @@ -133,7 +133,7 @@ - + diff --git a/salesbook.Shared/Components/Layout/NavMenu.razor b/salesbook.Shared/Components/Layout/NavMenu.razor index 6880a7d..f5c158d 100644 --- a/salesbook.Shared/Components/Layout/NavMenu.razor +++ b/salesbook.Shared/Components/Layout/NavMenu.razor @@ -1,7 +1,6 @@ @using CommunityToolkit.Mvvm.Messaging @using salesbook.Shared.Core.Dto @using salesbook.Shared.Core.Dto.Activity -@using salesbook.Shared.Core.Dto.Notification @using salesbook.Shared.Core.Dto.PageState @using salesbook.Shared.Core.Entity @using salesbook.Shared.Core.Messages.Activity.Copy @@ -35,7 +34,7 @@