Migliorata gestione e visualizzazione notifiche
This commit is contained in:
@@ -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<List<ActivityDTO>> GetActivityTryLocalDb(WhereCondActivity whereCond)
|
||||
{
|
||||
List<StbActivity>? activities;
|
||||
|
||||
activities = await localDb.Get<StbActivity>(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<List<ActivityDTO>> GetActivity(WhereCondActivity whereCond, bool useLocalDb)
|
||||
{
|
||||
List<StbActivity>? activities;
|
||||
@@ -187,6 +217,11 @@ public class ManageDataService(
|
||||
);
|
||||
}
|
||||
|
||||
return await MapActivity(activities);
|
||||
}
|
||||
|
||||
private async Task<List<ActivityDTO>> MapActivity(List<StbActivity>? activities)
|
||||
{
|
||||
if (activities == null) return [];
|
||||
|
||||
var codJcomList = activities
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,6 +82,7 @@ namespace salesbook.Maui
|
||||
builder.Services.AddSingleton<BackNavigationService>();
|
||||
builder.Services.AddSingleton<CopyActivityService>();
|
||||
builder.Services.AddSingleton<NewContactService>();
|
||||
builder.Services.AddSingleton<NotificationsLoadedService>();
|
||||
builder.Services.AddSingleton<NewPushNotificationService>();
|
||||
|
||||
//Notification
|
||||
@@ -90,6 +92,7 @@ namespace salesbook.Maui
|
||||
builder.Services.AddSingleton<IIntegryNotificationRestClient, IntegryNotificationRestClient>();
|
||||
builder.Services.AddSingleton<IFirebaseNotificationService, FirebaseNotificationService>();
|
||||
builder.Services.AddSingleton<IShinyNotificationManager, ShinyNotificationManager>();
|
||||
builder.Services.AddSingleton<INotificationService, NotificationService>();
|
||||
|
||||
#if DEBUG
|
||||
builder.Services.AddBlazorWebViewDeveloperTools();
|
||||
|
||||
@@ -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
|
||||
|
||||
<div class="container animated-navbar @(IsVisible ? "show-nav" : "hide-nav") @(IsVisible ? PlusVisible ? "with-plus" : "without-plus" : "with-plus")">
|
||||
<nav class="navbar @(IsVisible ? PlusVisible ? "with-plus" : "without-plus" : "with-plus")">
|
||||
@@ -68,8 +70,7 @@
|
||||
|
||||
protected override Task OnInitializedAsync()
|
||||
{
|
||||
CopyActivityService.OnCopyActivity += async dto => await CreateActivity(dto);
|
||||
NewPushNotificationService.OnNotificationReceived += NewNotificationReceived;
|
||||
InitMessage();
|
||||
|
||||
NavigationManager.LocationChanged += (_, args) =>
|
||||
{
|
||||
@@ -117,4 +118,11 @@
|
||||
Notification.ReceivedNotifications.Add(notification);
|
||||
InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private void InitMessage()
|
||||
{
|
||||
CopyActivityService.OnCopyActivity += async dto => await CreateActivity(dto);
|
||||
NewPushNotificationService.OnNotificationReceived += NewNotificationReceived;
|
||||
NotificationsLoadedService.OnNotificationsLoaded += () => InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<MudOverlay Visible="Visible" DarkBackground="false">
|
||||
<div class="overlay-container">
|
||||
<span>Caricamento</span>
|
||||
|
||||
<MudProgressLinear Color="Color.Primary" Rounded="true" Size="Size.Medium" Indeterminate="true" />
|
||||
</div>
|
||||
</MudOverlay>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public bool Visible { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
.overlay-container {
|
||||
background: var(--mud-palette-background);
|
||||
width: 20rem;
|
||||
height: 6rem;
|
||||
padding: 0 1rem;
|
||||
display: flex;
|
||||
gap: .5rem;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
border-radius: 20px;
|
||||
box-shadow: var(--custom-box-shadow);
|
||||
}
|
||||
|
||||
.overlay-container > span {
|
||||
text-align: center;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
}
|
||||
@@ -1,15 +1,19 @@
|
||||
@page "/"
|
||||
@attribute [Authorize]
|
||||
@using CommunityToolkit.Mvvm.Messaging
|
||||
@using salesbook.Shared.Core.Interface
|
||||
@using salesbook.Shared.Components.Layout.Spinner
|
||||
@using salesbook.Shared.Core.Interface.System.Network
|
||||
@using salesbook.Shared.Core.Interface.System.Notification
|
||||
@using salesbook.Shared.Core.Messages.Notification.Loaded
|
||||
@using salesbook.Shared.Core.Services
|
||||
@inject IFormFactor FormFactor
|
||||
@inject INetworkService NetworkService
|
||||
@inject IFirebaseNotificationService FirebaseNotificationService
|
||||
@inject IShinyNotificationManager NotificationManager
|
||||
@inject INotificationService NotificationService
|
||||
@inject PreloadService PreloadService
|
||||
@inject IMessenger Messenger
|
||||
|
||||
<SpinnerLayout FullScreen="true" />
|
||||
|
||||
@@ -17,6 +21,7 @@
|
||||
{
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadNotification();
|
||||
await CheckAndRequestPermissions();
|
||||
|
||||
try
|
||||
@@ -40,6 +45,12 @@
|
||||
NavigationManager.NavigateTo("/Calendar");
|
||||
}
|
||||
|
||||
private async Task LoadNotification()
|
||||
{
|
||||
await NotificationService.LoadNotification();
|
||||
Messenger.Send(new NotificationsLoadedMessage());
|
||||
}
|
||||
|
||||
private async Task CheckAndRequestPermissions()
|
||||
{
|
||||
await NotificationManager.RequestAccess();
|
||||
|
||||
@@ -1,20 +1,25 @@
|
||||
@page "/Notifications"
|
||||
@attribute [Authorize]
|
||||
@using CommunityToolkit.Mvvm.Messaging
|
||||
@using salesbook.Shared.Components.Layout
|
||||
@using salesbook.Shared.Components.Layout.Spinner
|
||||
@using salesbook.Shared.Components.SingleElements
|
||||
@using salesbook.Shared.Core.Dto.PageState
|
||||
@using salesbook.Shared.Core.Entity
|
||||
@using salesbook.Shared.Core.Interface
|
||||
@using salesbook.Shared.Core.Interface.IntegryApi
|
||||
@using salesbook.Shared.Core.Messages.Notification
|
||||
@using salesbook.Shared.Core.Messages.Notification.Loaded
|
||||
@using salesbook.Shared.Core.Messages.Notification.NewPush
|
||||
@inject NotificationState Notification
|
||||
@inject NewPushNotificationService NewPushNotificationService
|
||||
@inject IJSRuntime JS
|
||||
@inject IIntegryNotificationRestClient IntegryNotificationRestClient
|
||||
@inject INotificationService NotificationService
|
||||
@inject IMessenger Messenger
|
||||
|
||||
<HeaderLayout Title="Notifiche" />
|
||||
|
||||
<div class="container">
|
||||
<div class="container container-notifications">
|
||||
@if (Loading)
|
||||
{
|
||||
<SpinnerLayout FullScreen="true" />
|
||||
@@ -50,7 +55,7 @@
|
||||
|
||||
@code {
|
||||
private DotNetObjectReference<Notifications>? _objectReference;
|
||||
private bool Loading { get; set; } = true;
|
||||
private bool Loading { get; set; }
|
||||
|
||||
protected override Task OnInitializedAsync()
|
||||
{
|
||||
@@ -62,37 +67,6 @@
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await JS.InvokeVoidAsync("initNotifications", _objectReference);
|
||||
|
||||
if (firstRender)
|
||||
{
|
||||
await LoadData();
|
||||
Loading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
var allNotifications = await IntegryNotificationRestClient.Get();
|
||||
var allIds = allNotifications.Select(n => n.Id).ToHashSet();
|
||||
|
||||
Notification.ReceivedNotifications = Notification.ReceivedNotifications
|
||||
.Where(r => !allIds.Contains(r.Id))
|
||||
.ToList();
|
||||
|
||||
Notification.UnreadNotifications = allNotifications
|
||||
.Where(x =>
|
||||
x.WtbDeviceNotifications == null ||
|
||||
x.WtbDeviceNotifications.Any(y => y.ReadDate == null))
|
||||
.ToList();
|
||||
|
||||
Notification.NotificationsRead = allNotifications
|
||||
.Where(x =>
|
||||
x.WtbDeviceNotifications != null &&
|
||||
x.WtbDeviceNotifications.All(y => y.ReadDate != null))
|
||||
.ToList();
|
||||
|
||||
OrderNotificationList();
|
||||
}
|
||||
|
||||
private void NewNotificationReceived(WtbNotification notification)
|
||||
@@ -119,7 +93,7 @@
|
||||
|
||||
if (!removed) return;
|
||||
|
||||
OrderNotificationList();
|
||||
NotificationService.OrderNotificationList();
|
||||
Loading = false;
|
||||
_ = InvokeAsync(StateHasChanged);
|
||||
|
||||
@@ -127,6 +101,8 @@
|
||||
{
|
||||
_ = IntegryNotificationRestClient.Delete(notificationId);
|
||||
});
|
||||
|
||||
Messenger.Send(new NotificationsLoadedMessage());
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
@@ -155,23 +131,12 @@
|
||||
wtbNotification = await IntegryNotificationRestClient.MarkAsRead(notificationId);
|
||||
Notification.NotificationsRead.Add(wtbNotification);
|
||||
|
||||
OrderNotificationList();
|
||||
NotificationService.OrderNotificationList();
|
||||
Messenger.Send(new NotificationsLoadedMessage());
|
||||
Loading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void OrderNotificationList()
|
||||
{
|
||||
Notification.ReceivedNotifications = Notification.ReceivedNotifications
|
||||
.OrderByDescending(x => x.StartDate).ToList();
|
||||
|
||||
Notification.UnreadNotifications = Notification.UnreadNotifications
|
||||
.OrderByDescending(x => x.StartDate).ToList();
|
||||
|
||||
Notification.NotificationsRead = Notification.NotificationsRead
|
||||
.OrderByDescending(x => x.StartDate).ToList();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_objectReference?.Dispose();
|
||||
|
||||
@@ -1,6 +1,21 @@
|
||||
.container-notifications {
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
padding: .2rem 0 75px 0;
|
||||
}
|
||||
|
||||
.list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.container-notifications::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.container-notifications::-webkit-scrollbar-thumb {
|
||||
background: #bbb;
|
||||
border-radius: 3px;
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
@using salesbook.Shared.Components.Layout.Spinner
|
||||
@using salesbook.Shared.Core.Dto
|
||||
@using salesbook.Shared.Core.Interface
|
||||
@using salesbook.Shared.Components.Layout.Overlay
|
||||
@using salesbook.Shared.Core.Interface.IntegryApi
|
||||
@inject IIntegryApiService IntegryApiService
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
@using salesbook.Shared.Components.Layout.Spinner
|
||||
@using salesbook.Shared.Core.Dto.Activity
|
||||
@using salesbook.Shared.Core.Entity
|
||||
@using salesbook.Shared.Core.Interface
|
||||
@inject IManageDataService ManageDataService
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService Dialog
|
||||
|
||||
<div class="row" id="@Notification.Id">
|
||||
<div class="row" id="@Notification.Id" @onclick="OpenActivity">
|
||||
<div class="behind-left">
|
||||
<button class="read-btn">
|
||||
<MudIcon Icon="@Icons.Material.Rounded.Check" />
|
||||
@@ -51,10 +57,35 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<OverlayLayout Visible="VisibleOverlay" />
|
||||
|
||||
@code {
|
||||
[Parameter] public bool Unread { get; set; }
|
||||
[Parameter] public WtbNotification Notification { get; set; } = new();
|
||||
|
||||
private bool VisibleOverlay { get; set; }
|
||||
|
||||
private async Task OpenActivity()
|
||||
{
|
||||
if(Notification.NotificationData?.ActivityId == null) return;
|
||||
var activityId = Notification.NotificationData.ActivityId;
|
||||
|
||||
Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter;
|
||||
Snackbar.Clear();
|
||||
|
||||
VisibleOverlay = true;
|
||||
StateHasChanged();
|
||||
|
||||
var activity = (await ManageDataService.GetActivityTryLocalDb(new WhereCondActivity { ActivityId = activityId })).LastOrDefault();
|
||||
|
||||
VisibleOverlay = false;
|
||||
StateHasChanged();
|
||||
|
||||
if (activity == null) Snackbar.Add("Impossibile aprire l'attivit<69>", Severity.Error);
|
||||
|
||||
_ = ModalHelpers.OpenActivityForm(Dialog, activity, null);
|
||||
}
|
||||
|
||||
private static string GetTimeAgo(DateTime? timestamp)
|
||||
{
|
||||
if (timestamp is null) return "";
|
||||
@@ -77,7 +108,7 @@
|
||||
return $"{timestamp.Value:t}";
|
||||
default:
|
||||
{
|
||||
return difference.TotalDays < 7 ? $"{(int)difference.TotalDays}g fa" : timestamp.Value.ToString("dd/MM/yyyy");
|
||||
return timestamp.Value.ToString("dd/MM/yyyy");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public interface IManageDataService
|
||||
Task<List<ContactDTO>> GetContact(WhereCondContact whereCond);
|
||||
Task<ContactDTO?> GetSpecificContact(string codAnag, bool IsContact);
|
||||
|
||||
Task<List<ActivityDTO>> GetActivityTryLocalDb(WhereCondActivity whereCond);
|
||||
Task<List<ActivityDTO>> GetActivity(WhereCondActivity whereCond, bool useLocalDb = false);
|
||||
|
||||
Task InsertOrUpdate<T>(T objectToSave);
|
||||
|
||||
7
salesbook.Shared/Core/Interface/INotificationService.cs
Normal file
7
salesbook.Shared/Core/Interface/INotificationService.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace salesbook.Shared.Core.Interface;
|
||||
|
||||
public interface INotificationService
|
||||
{
|
||||
Task LoadNotification();
|
||||
void OrderNotificationList();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
using CommunityToolkit.Mvvm.Messaging.Messages;
|
||||
|
||||
namespace salesbook.Shared.Core.Messages.Notification.Loaded;
|
||||
|
||||
public class NotificationsLoadedMessage(object? value = null) : ValueChangedMessage<object?>(value);
|
||||
@@ -0,0 +1,13 @@
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
|
||||
namespace salesbook.Shared.Core.Messages.Notification.Loaded;
|
||||
|
||||
public class NotificationsLoadedService
|
||||
{
|
||||
public event Action? OnNotificationsLoaded;
|
||||
|
||||
public NotificationsLoadedService(IMessenger messenger)
|
||||
{
|
||||
messenger.Register<NotificationsLoadedMessage>(this, (_, _) => { OnNotificationsLoaded?.Invoke(); });
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using CommunityToolkit.Mvvm.Messaging.Messages;
|
||||
using salesbook.Shared.Core.Entity;
|
||||
|
||||
namespace salesbook.Shared.Core.Messages.Notification;
|
||||
namespace salesbook.Shared.Core.Messages.Notification.NewPush;
|
||||
|
||||
public class NewPushNotificationMessage(WtbNotification value) : ValueChangedMessage<WtbNotification>(value);
|
||||
@@ -1,7 +1,7 @@
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using salesbook.Shared.Core.Entity;
|
||||
|
||||
namespace salesbook.Shared.Core.Messages.Notification;
|
||||
namespace salesbook.Shared.Core.Messages.Notification.NewPush;
|
||||
|
||||
public class NewPushNotificationService
|
||||
{
|
||||
45
salesbook.Shared/Core/Services/NotificationService.cs
Normal file
45
salesbook.Shared/Core/Services/NotificationService.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using salesbook.Shared.Core.Dto.PageState;
|
||||
using salesbook.Shared.Core.Interface;
|
||||
using salesbook.Shared.Core.Interface.IntegryApi;
|
||||
|
||||
namespace salesbook.Shared.Core.Services;
|
||||
|
||||
public class NotificationService(
|
||||
IIntegryNotificationRestClient integryNotificationRestClient,
|
||||
NotificationState Notification
|
||||
) : INotificationService
|
||||
{
|
||||
public async Task LoadNotification()
|
||||
{
|
||||
var allNotifications = await integryNotificationRestClient.Get();
|
||||
var allIds = allNotifications.Select(n => n.Id).ToHashSet();
|
||||
|
||||
Notification.ReceivedNotifications = Notification.ReceivedNotifications
|
||||
.Where(r => !allIds.Contains(r.Id))
|
||||
.ToList();
|
||||
|
||||
Notification.UnreadNotifications = allNotifications
|
||||
.Where(x =>
|
||||
x.WtbDeviceNotifications == null ||
|
||||
x.WtbDeviceNotifications.Any(y => y.ReadDate == null))
|
||||
.ToList();
|
||||
|
||||
Notification.NotificationsRead = allNotifications
|
||||
.Where(x =>
|
||||
x.WtbDeviceNotifications != null &&
|
||||
x.WtbDeviceNotifications.All(y => y.ReadDate != null))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public void OrderNotificationList()
|
||||
{
|
||||
Notification.ReceivedNotifications = Notification.ReceivedNotifications
|
||||
.OrderByDescending(x => x.StartDate).ToList();
|
||||
|
||||
Notification.UnreadNotifications = Notification.UnreadNotifications
|
||||
.OrderByDescending(x => x.StartDate).ToList();
|
||||
|
||||
Notification.NotificationsRead = Notification.NotificationsRead
|
||||
.OrderByDescending(x => x.StartDate).ToList();
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ article {
|
||||
}
|
||||
|
||||
/*ServicesIsDown" : "SystemOk" : "NetworkKo*/
|
||||
|
||||
.Connection {
|
||||
padding: 0 .75rem;
|
||||
font-weight: 700;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
/*Utility*/
|
||||
--exception-box-shadow: 1px 2px 5px rgba(0, 0, 0, 0.3);
|
||||
--custom-box-shadow: 1px 2px 5px var(--gray-for-shadow);
|
||||
--mud-default-borderradius: 12px !important;
|
||||
--mud-default-borderradius: 20px !important;
|
||||
--m-page-x: 1rem;
|
||||
--mh-header: 4rem;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user