Finish Firebase

This commit is contained in:
2025-09-11 16:08:13 +02:00
66 changed files with 1385 additions and 61 deletions

View File

@@ -0,0 +1,10 @@
using System.Text.Json.Serialization;
namespace salesbook.Maui.Core.RestClient.IntegryApi.Dto;
public class RegisterDeviceDTO
{
[JsonPropertyName("userDeviceToken")]
public WtbUserDeviceTokenDTO UserDeviceToken { get; set; }
}

View File

@@ -0,0 +1,22 @@
using System.Text.Json.Serialization;
namespace salesbook.Maui.Core.RestClient.IntegryApi.Dto;
public class WtbUserDeviceTokenDTO
{
[JsonPropertyName("type")]
public string Type => "wtb_user_device_tokens";
[JsonPropertyName("deviceToken")]
public string DeviceToken { get; set; }
[JsonPropertyName("userName")]
public string Username { get; set; }
[JsonPropertyName("appName")]
public int AppName => 7; //salesbook
[JsonPropertyName("platform")]
public string Platform { get; set; }
}

View File

@@ -0,0 +1,38 @@
using IntegryApiClient.Core.Domain.Abstraction.Contracts.Account;
using IntegryApiClient.Core.Domain.RestClient.Contacts;
using Microsoft.Extensions.Logging;
using salesbook.Maui.Core.RestClient.IntegryApi.Dto;
using salesbook.Shared.Core.Interface.IntegryApi;
namespace salesbook.Maui.Core.RestClient.IntegryApi;
public class IntegryRegisterNotificationRestClient(
ILogger<IntegryRegisterNotificationRestClient> logger,
IUserSession userSession,
IIntegryApiRestClient integryApiRestClient
) : IIntegryRegisterNotificationRestClient
{
public async Task Register(string fcmToken, ILogger? logger1 = null)
{
logger1 ??= logger;
var userDeviceToken = new RegisterDeviceDTO()
{
UserDeviceToken = new WtbUserDeviceTokenDTO()
{
DeviceToken = fcmToken,
Platform = OperatingSystem.IsAndroid() ? "Android" : "iOS",
Username = userSession.User.Username
}
};
try
{
await integryApiRestClient.AuthorizedPost<object>($"device_tokens/insert", userDeviceToken,
logger: logger1);
}
catch (Exception ex)
{
SentrySdk.CaptureException(ex);
}
}
}

View File

@@ -1,10 +1,13 @@
using AutoMapper; using AutoMapper;
using MudBlazor.Extensions;
using salesbook.Shared.Core.Dto; using salesbook.Shared.Core.Dto;
using salesbook.Shared.Core.Dto.Activity; using salesbook.Shared.Core.Dto.Activity;
using salesbook.Shared.Core.Dto.Contact; using salesbook.Shared.Core.Dto.Contact;
using salesbook.Shared.Core.Entity; using salesbook.Shared.Core.Entity;
using salesbook.Shared.Core.Helpers.Enum; using salesbook.Shared.Core.Helpers.Enum;
using salesbook.Shared.Core.Interface; using salesbook.Shared.Core.Interface;
using salesbook.Shared.Core.Interface.IntegryApi;
using salesbook.Shared.Core.Interface.System.Network;
using Sentry.Protocol; using Sentry.Protocol;
using System.Linq.Expressions; using System.Linq.Expressions;
@@ -209,6 +212,15 @@ public class ManageDataService(
{ {
var dto = mapper.Map<ActivityDTO>(activity); var dto = mapper.Map<ActivityDTO>(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) if (activity.CodJcom != null)
{ {
dto.Category = ActivityCategoryEnum.Commessa; dto.Category = ActivityCategoryEnum.Commessa;

View File

@@ -1,5 +1,6 @@
using salesbook.Shared.Core.Helpers; using salesbook.Shared.Core.Helpers;
using salesbook.Shared.Core.Interface; using salesbook.Shared.Core.Interface;
using salesbook.Shared.Core.Interface.IntegryApi;
namespace salesbook.Maui.Core.Services; namespace salesbook.Maui.Core.Services;

View File

@@ -1,6 +1,7 @@
using salesbook.Shared.Core.Interface; using salesbook.Shared.Core.Interface;
using salesbook.Shared.Core.Interface.System.Network;
namespace salesbook.Maui.Core.Services; namespace salesbook.Maui.Core.System.Network;
public class NetworkService : INetworkService public class NetworkService : INetworkService
{ {

View File

@@ -0,0 +1,37 @@
using salesbook.Shared.Core.Interface;
using salesbook.Shared.Core.Interface.IntegryApi;
using Shiny;
using Shiny.Notifications;
using Shiny.Push;
namespace salesbook.Maui.Core.System.Notification;
public class FirebaseNotificationService(
IPushManager pushManager,
IIntegryRegisterNotificationRestClient integryRegisterNotificationRestClient,
INotificationManager notificationManager
) : IFirebaseNotificationService
{
public async Task InitFirebase()
{
CreateNotificationChannel();
var (accessState, token) = await pushManager.RequestAccess();
if (accessState == AccessState.Denied || token is null) return;
await integryRegisterNotificationRestClient.Register(token);
}
private void CreateNotificationChannel()
{
var channel = new Channel
{
Identifier = "salesbook_push",
Description = "Notifiche push di SalesBook",
Importance = ChannelImportance.High,
Actions = []
};
notificationManager.AddChannel(channel);
}
}

View File

@@ -0,0 +1,45 @@
using CommunityToolkit.Mvvm.Messaging;
using salesbook.Shared.Core.Entity;
using salesbook.Shared.Core.Interface.IntegryApi;
using salesbook.Shared.Core.Messages.Notification;
using Shiny.Push;
namespace salesbook.Maui.Core.System.Notification.Push;
public class PushNotificationDelegate(
IIntegryRegisterNotificationRestClient integryRegisterNotificationRestClient,
IMessenger messenger
) : IPushDelegate
{
public Task OnEntry(PushNotification notification)
{
// fires when the user taps on a push notification
return Task.CompletedTask;
}
public Task OnReceived(PushNotification notification)
{
if (notification.Notification is null) return Task.CompletedTask;
var pushNotification = new WtbNotification
{
Title = notification.Notification.Title,
Body = notification.Notification.Message
};
messenger.Send(new NewPushNotificationMessage(pushNotification));
return Task.CompletedTask;
}
public Task OnNewToken(string token)
{
integryRegisterNotificationRestClient.Register(token);
return Task.CompletedTask;
}
public Task OnUnRegistered(string token)
{
// fires when a push notification change is set by the operating system or provider
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,9 @@
using salesbook.Shared.Core.Interface.System.Notification;
using Shiny.Notifications;
namespace salesbook.Maui.Core.System.Notification;
public class ShinyNotificationManager(INotificationManager notificationManager) : IShinyNotificationManager
{
public Task RequestAccess() => notificationManager.RequestAccess();
}

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>API_KEY</key>
<string>AIzaSyC_QtQpsVortjzgl-B7__IQZ-85lOct55E</string>
<key>GCM_SENDER_ID</key>
<string>830771692001</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>it.integry.salesbook</string>
<key>PROJECT_ID</key>
<string>salesbook-smetar</string>
<key>STORAGE_BUCKET</key>
<string>salesbook-smetar.firebasestorage.app</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
<false></false>
<key>IS_APPINVITE_ENABLED</key>
<true></true>
<key>IS_GCM_ENABLED</key>
<true></true>
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:830771692001:ios:59d8b1d8570ac81f3752a0</string>
</dict>
</plist>

View File

@@ -1,4 +1,3 @@
using AutoMapper;
using CommunityToolkit.Maui; using CommunityToolkit.Maui;
using CommunityToolkit.Mvvm.Messaging; using CommunityToolkit.Mvvm.Messaging;
using IntegryApiClient.MAUI; using IntegryApiClient.MAUI;
@@ -6,17 +5,26 @@ using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using MudBlazor.Services; using MudBlazor.Services;
using MudExtensions.Services; using MudExtensions.Services;
using salesbook.Maui.Core.RestClient.IntegryApi;
using salesbook.Maui.Core.Services; using salesbook.Maui.Core.Services;
using salesbook.Maui.Core.System.Network;
using salesbook.Maui.Core.System.Notification;
using salesbook.Maui.Core.System.Notification.Push;
using salesbook.Shared; using salesbook.Shared;
using salesbook.Shared.Core.Dto; using salesbook.Shared.Core.Dto;
using salesbook.Shared.Core.Dto.PageState; using salesbook.Shared.Core.Dto.PageState;
using salesbook.Shared.Core.Helpers; using salesbook.Shared.Core.Helpers;
using salesbook.Shared.Core.Interface; using salesbook.Shared.Core.Interface;
using salesbook.Shared.Core.Interface.IntegryApi;
using salesbook.Shared.Core.Interface.System.Network;
using salesbook.Shared.Core.Interface.System.Notification;
using salesbook.Shared.Core.Messages.Activity.Copy; using salesbook.Shared.Core.Messages.Activity.Copy;
using salesbook.Shared.Core.Messages.Activity.New; using salesbook.Shared.Core.Messages.Activity.New;
using salesbook.Shared.Core.Messages.Back; using salesbook.Shared.Core.Messages.Back;
using salesbook.Shared.Core.Messages.Contact; using salesbook.Shared.Core.Messages.Contact;
using salesbook.Shared.Core.Messages.Notification;
using salesbook.Shared.Core.Services; using salesbook.Shared.Core.Services;
using Shiny;
namespace salesbook.Maui namespace salesbook.Maui
{ {
@@ -24,7 +32,7 @@ namespace salesbook.Maui
{ {
private const string AppToken = "f0484398-1f8b-42f5-ab79-5282c164e1d8"; private const string AppToken = "f0484398-1f8b-42f5-ab79-5282c164e1d8";
public static MauiApp CreateMauiApp() public static MauiAppBuilder CreateMauiAppBuilder()
{ {
InteractiveRenderSettings.ConfigureBlazorHybridRenderModes(); InteractiveRenderSettings.ConfigureBlazorHybridRenderModes();
@@ -33,6 +41,7 @@ namespace salesbook.Maui
.UseMauiApp<App>() .UseMauiApp<App>()
.UseIntegry(appToken: AppToken, useLoginAzienda: true) .UseIntegry(appToken: AppToken, useLoginAzienda: true)
.UseMauiCommunityToolkit() .UseMauiCommunityToolkit()
.UseShiny()
.UseSentry(options => .UseSentry(options =>
{ {
options.Dsn = "https://453b6b38f94fd67e40e0d5306d6caff8@o4508499810254848.ingest.de.sentry.io/4509605099667536"; options.Dsn = "https://453b6b38f94fd67e40e0d5306d6caff8@o4508499810254848.ingest.de.sentry.io/4509605099667536";
@@ -63,14 +72,24 @@ namespace salesbook.Maui
builder.Services.AddSingleton<JobSteps>(); builder.Services.AddSingleton<JobSteps>();
builder.Services.AddSingleton<UserPageState>(); builder.Services.AddSingleton<UserPageState>();
builder.Services.AddSingleton<UserListState>(); builder.Services.AddSingleton<UserListState>();
builder.Services.AddSingleton<NotificationState>();
builder.Services.AddSingleton<FilterUserDTO>(); builder.Services.AddSingleton<FilterUserDTO>();
//Message //Message
builder.Services.AddScoped<IMessenger, WeakReferenceMessenger>(); builder.Services.AddSingleton<IMessenger, WeakReferenceMessenger>();
builder.Services.AddScoped<NewActivityService>(); builder.Services.AddSingleton<NewActivityService>();
builder.Services.AddScoped<BackNavigationService>(); builder.Services.AddSingleton<BackNavigationService>();
builder.Services.AddScoped<CopyActivityService>(); builder.Services.AddSingleton<CopyActivityService>();
builder.Services.AddScoped<NewContactService>(); builder.Services.AddSingleton<NewContactService>();
builder.Services.AddSingleton<NewPushNotificationService>();
//Notification
builder.Services.AddNotifications();
builder.Services.AddPush<PushNotificationDelegate>();
builder.Services.AddSingleton<IIntegryRegisterNotificationRestClient, IntegryRegisterNotificationRestClient>();
builder.Services.AddSingleton<IIntegryNotificationRestClient, IntegryNotificationRestClient>();
builder.Services.AddSingleton<IFirebaseNotificationService, FirebaseNotificationService>();
builder.Services.AddSingleton<IShinyNotificationManager, ShinyNotificationManager>();
#if DEBUG #if DEBUG
builder.Services.AddBlazorWebViewDeveloperTools(); builder.Services.AddBlazorWebViewDeveloperTools();
@@ -82,7 +101,7 @@ namespace salesbook.Maui
builder.Services.AddSingleton<INetworkService, NetworkService>(); builder.Services.AddSingleton<INetworkService, NetworkService>();
builder.Services.AddSingleton<LocalDbService>(); builder.Services.AddSingleton<LocalDbService>();
return builder.Build(); return builder;
} }
} }
} }

View File

@@ -1,9 +1,24 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="it.integry.salesbook">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:usesCleartextTraffic="true" android:supportsRtl="true"></application> <application android:allowBackup="true" android:icon="@mipmap/appicon" android:usesCleartextTraffic="true" android:supportsRtl="true">
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BATTERY_STATS" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
</manifest> </manifest>

View File

@@ -0,0 +1,13 @@
using salesbook.Maui.Core;
using salesbook.Shared.Core.Interface.System.Battery;
namespace salesbook.Maui;
public static class AndroidModule
{
public static MauiAppBuilder RegisterAndroidAppServices(this MauiAppBuilder mauiAppBuilder)
{
mauiAppBuilder.Services.AddSingleton<IBatteryOptimizationManagerService, BatteryOptimizationManagerService>();
return mauiAppBuilder;
}
}

View File

@@ -0,0 +1,28 @@
using Android.App;
using Android.Content;
using Android.OS;
using Android.Provider;
using salesbook.Shared.Core.Interface.System.Battery;
using Application = Android.App.Application;
namespace salesbook.Maui.Core;
public class BatteryOptimizationManagerService : IBatteryOptimizationManagerService
{
public bool IsBatteryOptimizationEnabled()
{
var packageName = AppInfo.PackageName;
var pm = (PowerManager)Application.Context.GetSystemService(Context.PowerService)!;
return !pm.IsIgnoringBatteryOptimizations(packageName);
}
public void OpenBatteryOptimizationSettings(Action<bool> onCompleted)
{
var packageName = AppInfo.PackageName;
var intent = new Intent(Settings.ActionRequestIgnoreBatteryOptimizations);
intent.SetData(Android.Net.Uri.Parse("package:" + packageName));
((MainActivity)Platform.CurrentActivity!).StartActivityForResult(intent, (result, _) => { onCompleted(result == Result.Ok); });
}
}

View File

@@ -1,13 +1,42 @@
using Android.App; using Android.App;
using Android.Content;
using Android.Content.PM; using Android.Content.PM;
namespace salesbook.Maui namespace salesbook.Maui
{ {
[Activity(Theme = "@style/Maui.SplashTheme", [Activity(
Theme = "@style/Maui.SplashTheme",
MainLauncher = true, MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode |
ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
[IntentFilter(
[
Shiny.ShinyPushIntents.NotificationClickAction
],
Categories =
[
"android.intent.category.DEFAULT"
]
)]
public class MainActivity : MauiAppCompatActivity public class MainActivity : MauiAppCompatActivity
{ {
private readonly IDictionary<int, Action<Result, Intent>> _onActivityResultSubscriber =
new Dictionary<int, Action<Result, Intent>>();
public void StartActivityForResult(Intent intent, Action<Result, Intent> onResultAction)
{
var requestCode = new Random(DateTime.Now.Millisecond).Next();
_onActivityResultSubscriber.Add(requestCode, onResultAction);
StartActivityForResult(intent, requestCode);
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
if (_onActivityResultSubscriber.TryGetValue(requestCode, out var value))
value(resultCode, data);
base.OnActivityResult(requestCode, resultCode, data);
}
} }
} }

View File

@@ -1,16 +1,16 @@
using Android.App; using Android.App;
using Android.Runtime; using Android.Runtime;
namespace salesbook.Maui namespace salesbook.Maui;
{
[Application(HardwareAccelerated = true)]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); [Application(HardwareAccelerated = true)]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
} }
}
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiAppBuilder()
.RegisterAndroidAppServices().Build();
}

View File

@@ -1,10 +1,24 @@
using Foundation; using Foundation;
using UIKit;
namespace salesbook.Maui namespace salesbook.Maui
{ {
[Register("AppDelegate")] [Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate public class AppDelegate : MauiUIApplicationDelegate
{ {
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiAppBuilder()
.RegisterIosAppServices().Build();
[Export("application:didRegisterForRemoteNotificationsWithDeviceToken:")]
public void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
=> global::Shiny.Hosting.Host.Lifecycle.OnRegisteredForRemoteNotifications(deviceToken);
[Export("application:didFailToRegisterForRemoteNotificationsWithError:")]
public void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
=> global::Shiny.Hosting.Host.Lifecycle.OnFailedToRegisterForRemoteNotifications(error);
[Export("application:didReceiveRemoteNotification:fetchCompletionHandler:")]
public void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
=> global::Shiny.Hosting.Host.Lifecycle.OnDidReceiveRemoteNotification(userInfo, completionHandler);
} }
} }

View File

@@ -0,0 +1,12 @@
using salesbook.Shared.Core.Interface.System.Battery;
namespace salesbook.Maui.Core;
public class BatteryOptimizationManagerService : IBatteryOptimizationManagerService
{
public bool IsBatteryOptimizationEnabled() => true;
public void OpenBatteryOptimizationSettings(Action<bool> onCompleted)
{
}
}

View File

@@ -45,5 +45,9 @@
<key>NSPhotoLibraryAddUsageDescription</key> <key>NSPhotoLibraryAddUsageDescription</key>
<string>Permette all'app di salvare file o immagini nella tua libreria fotografica se necessario.</string> <string>Permette all'app di salvare file o immagini nella tua libreria fotografica se necessario.</string>
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
</dict> </dict>
</plist> </plist>

View File

@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>C617.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategorySystemBootTime</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>35F9.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryDiskSpace</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>E174.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>CA92.1</string>
</array>
</dict>
</array>
<key>NSPrivacyCollectedDataTypes</key>
<array>
<!--user info-->
<dict>
<key>NSPrivacyCollectedDataTypeUserID</key>
<string>NSPrivacyCollectedDataTypeLocation</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<true />
<key>NSPrivacyCollectedDataTypeTracking</key>
<false />
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
</array>
</dict>
<dict>
<key>NSPrivacyCollectedDataTypeEmailAddress</key>
<string>NSPrivacyCollectedDataTypeLocation</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<true />
<key>NSPrivacyCollectedDataTypeTracking</key>
<false />
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
</array>
</dict>
<dict>
<key>NSPrivacyCollectedDataTypePhoneNumber</key>
<string>NSPrivacyCollectedDataTypeLocation</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<true />
<key>NSPrivacyCollectedDataTypeTracking</key>
<false />
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
</array>
</dict>
<!--crashlytics/analytics-->
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypeOtherDiagnosticData</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<false />
<key>NSPrivacyCollectedDataTypeTracking</key>
<false />
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
</array>
</dict>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypeCrashData</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<true />
<key>NSPrivacyCollectedDataTypeTracking</key>
<false />
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
</array>
</dict>
</array>
</dict>
</plist>

View File

@@ -0,0 +1,13 @@
using salesbook.Maui.Core;
using salesbook.Shared.Core.Interface.System.Battery;
namespace salesbook.Maui;
public static class iOSModule
{
public static MauiAppBuilder RegisterIosAppServices(this MauiAppBuilder mauiAppBuilder)
{
mauiAppBuilder.Services.AddSingleton<IBatteryOptimizationManagerService, BatteryOptimizationManagerService>();
return mauiAppBuilder;
}
}

View File

@@ -0,0 +1,29 @@
{
"project_info": {
"project_number": "830771692001",
"project_id": "salesbook-smetar",
"storage_bucket": "salesbook-smetar.firebasestorage.app"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:830771692001:android:06bc5a9706bc9bef3752a0",
"android_client_info": {
"package_name": "it.integry.salesbook"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyB43ai_Ph0phO_OkBC1wAOazKZUV9KsLaM"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}

View File

@@ -83,14 +83,26 @@
<ProvisioningType>manual</ProvisioningType> <ProvisioningType>manual</ProvisioningType>
</PropertyGroup> </PropertyGroup>
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios' OR $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'"> <ItemGroup Condition="$(TargetFramework.Contains('-ios'))">
<!-- <!--
<BundleResource Include="Platforms\iOS\PrivacyInfo.xcprivacy" LogicalName="PrivacyInfo.xcprivacy" /> // For scheduled notifications, you need to setup "Time Sensitive Notifications" in the Apple Developer Portal for your app provisioning and uncomment below
// <CustomEntitlements Include="com.apple.developer.usernotifications.time-sensitive" Type="Boolean" Value="true" Visible="false" />
<CustomEntitlements Include="keychain-access-groups" Type="StringArray" Value="%24(AppIdentifierPrefix)$(ApplicationId)" Visible="false" /> -->
<CustomEntitlements Include="aps-environment" Type="string" Value="development" Condition="'$(Configuration)' == 'Debug'" Visible="false" /> <CustomEntitlements Include="aps-environment" Type="string" Value="development" Condition="'$(Configuration)' == 'Debug'" Visible="false" />
<CustomEntitlements Include="aps-environment" Type="string" Value="production" Condition="'$(Configuration)' == 'Release'" Visible="false" /> <CustomEntitlements Include="aps-environment" Type="string" Value="production" Condition="'$(Configuration)' == 'Release'" Visible="false" />
--> </ItemGroup>
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios' OR $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">
<BundleResource Include="Platforms\iOS\PrivacyInfo.xcprivacy" LogicalName="PrivacyInfo.xcprivacy" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0-android'">
<GoogleServicesJson Include="google-services.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</GoogleServicesJson>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0-ios'">
<BundleResource Include="GoogleService-Info.plist" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'"> <ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
@@ -121,13 +133,16 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="12.0.0" /> <PackageReference Include="CommunityToolkit.Maui" Version="12.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" /> <PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="IntegryApiClient.MAUI" Version="1.1.6" /> <PackageReference Include="IntegryApiClient.MAUI" Version="1.2.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.6" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.6" />
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.81" /> <PackageReference Include="Microsoft.Maui.Controls" Version="9.0.81" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="9.0.81" /> <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="9.0.81" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="9.0.81" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="9.0.81" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.6" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.6" />
<PackageReference Include="Sentry.Maui" Version="5.11.2" /> <PackageReference Include="Sentry.Maui" Version="5.11.2" />
<PackageReference Include="Shiny.Hosting.Maui" Version="3.3.4" />
<PackageReference Include="Shiny.Notifications" Version="3.3.4" />
<PackageReference Include="Shiny.Push" Version="3.3.4" />
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" /> <PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
</ItemGroup> </ItemGroup>

View File

@@ -53,6 +53,7 @@
<script src="_content/salesbook.Shared/js/main.js"></script> <script src="_content/salesbook.Shared/js/main.js"></script>
<script src="_content/salesbook.Shared/js/calendar.js"></script> <script src="_content/salesbook.Shared/js/calendar.js"></script>
<script src="_content/salesbook.Shared/js/alphaScroll.js"></script> <script src="_content/salesbook.Shared/js/alphaScroll.js"></script>
<script src="_content/salesbook.Shared/js/notifications.js"></script>
</body> </body>

View File

@@ -1,5 +1,7 @@
@using System.Globalization @using System.Globalization
@using salesbook.Shared.Core.Interface @using salesbook.Shared.Core.Interface
@using salesbook.Shared.Core.Interface.IntegryApi
@using salesbook.Shared.Core.Interface.System.Network
@using salesbook.Shared.Core.Messages.Back @using salesbook.Shared.Core.Messages.Back
@inherits LayoutComponentBase @inherits LayoutComponentBase
@inject IJSRuntime JS @inject IJSRuntime JS
@@ -55,7 +57,7 @@
private bool _showWarning; private bool _showWarning;
private DateTime _lastApiCheck = DateTime.MinValue; private DateTime _lastApiCheck = DateTime.MinValue;
private const int DelaySeconds = 60; private const int DelaySeconds = 180;
private CancellationTokenSource? _cts; private CancellationTokenSource? _cts;

View File

@@ -1,13 +1,17 @@
@using CommunityToolkit.Mvvm.Messaging @using CommunityToolkit.Mvvm.Messaging
@using salesbook.Shared.Core.Dto @using salesbook.Shared.Core.Dto
@using salesbook.Shared.Core.Dto.Activity @using salesbook.Shared.Core.Dto.Activity
@using salesbook.Shared.Core.Dto.PageState
@using salesbook.Shared.Core.Entity @using salesbook.Shared.Core.Entity
@using salesbook.Shared.Core.Messages.Activity.Copy @using salesbook.Shared.Core.Messages.Activity.Copy
@using salesbook.Shared.Core.Messages.Activity.New @using salesbook.Shared.Core.Messages.Activity.New
@using salesbook.Shared.Core.Messages.Contact @using salesbook.Shared.Core.Messages.Contact
@using salesbook.Shared.Core.Messages.Notification
@inject IDialogService Dialog @inject IDialogService Dialog
@inject IMessenger Messenger @inject IMessenger Messenger
@inject CopyActivityService CopyActivityService @inject CopyActivityService CopyActivityService
@inject NewPushNotificationService NewPushNotificationService
@inject NotificationState Notification
<div class="container animated-navbar @(IsVisible ? "show-nav" : "hide-nav") @(IsVisible ? PlusVisible ? "with-plus" : "without-plus" : "with-plus")"> <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")"> <nav class="navbar @(IsVisible ? PlusVisible ? "with-plus" : "without-plus" : "with-plus")">
@@ -30,12 +34,14 @@
</NavLink> </NavLink>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<NavLink class="nav-link" href="Notifications" Match="NavLinkMatch.All"> <MudBadge Content="Notification.Count" Visible="Notification.Count > 0" Color="Color.Error" Overlap="true">
<div class="d-flex flex-column"> <NavLink class="nav-link" href="Notifications" Match="NavLinkMatch.All">
<i class="ri-notification-4-line"></i> <div class="d-flex flex-column">
<span>Notifiche</span> <i class="ri-notification-4-line"></i>
</div> <span>Notifiche</span>
</NavLink> </div>
</NavLink>
</MudBadge>
</li> </li>
</ul> </ul>
</div> </div>
@@ -63,8 +69,9 @@
protected override Task OnInitializedAsync() protected override Task OnInitializedAsync()
{ {
CopyActivityService.OnCopyActivity += async dto => await CreateActivity(dto); CopyActivityService.OnCopyActivity += async dto => await CreateActivity(dto);
NewPushNotificationService.OnNotificationReceived += NewNotificationReceived;
NavigationManager.LocationChanged += (_, args) => NavigationManager.LocationChanged += (_, args) =>
{ {
var location = args.Location.Remove(0, NavigationManager.BaseUri.Length); var location = args.Location.Remove(0, NavigationManager.BaseUri.Length);
@@ -104,4 +111,10 @@
Messenger.Send(new NewContactMessage((CRMCreateContactResponseDTO)result.Data)); Messenger.Send(new NewContactMessage((CRMCreateContactResponseDTO)result.Data));
} }
} }
private void NewNotificationReceived(WtbNotification notification)
{
Notification.ReceivedNotifications.Add(notification);
InvokeAsync(StateHasChanged);
}
} }

View File

@@ -24,6 +24,7 @@
padding-bottom: 1rem; padding-bottom: 1rem;
overflow-x: hidden; overflow-x: hidden;
overflow-y: visible; overflow-y: visible;
min-height: 7rem;
} }
.week-slider.expanded { .week-slider.expanded {
@@ -31,7 +32,7 @@
grid-template-columns: repeat(7, 1fr); grid-template-columns: repeat(7, 1fr);
gap: 0.4rem; gap: 0.4rem;
padding: 1rem; padding: 1rem;
overflow-y: auto; overflow-y: hidden;
} }
.week-slider.expand-animation { animation: expandFromCenter 0.3s ease forwards; } .week-slider.expand-animation { animation: expandFromCenter 0.3s ease forwards; }
@@ -122,8 +123,7 @@
flex-direction: column; flex-direction: column;
-ms-overflow-style: none; -ms-overflow-style: none;
scrollbar-width: none; scrollbar-width: none;
padding-bottom: 16vh; padding-bottom: 9vh;
height: calc(100% - 130px);
} }
.appointments.ah-calendar-m { height: calc(100% - 315px) !important; } .appointments.ah-calendar-m { height: calc(100% - 315px) !important; }

View File

@@ -11,6 +11,7 @@
@using salesbook.Shared.Core.Dto.PageState @using salesbook.Shared.Core.Dto.PageState
@using salesbook.Shared.Core.Entity @using salesbook.Shared.Core.Entity
@using salesbook.Shared.Core.Interface @using salesbook.Shared.Core.Interface
@using salesbook.Shared.Core.Interface.IntegryApi
@inject JobSteps JobSteps @inject JobSteps JobSteps
@inject IManageDataService ManageData @inject IManageDataService ManageData
@inject IIntegryApiService IntegryApiService @inject IIntegryApiService IntegryApiService

View File

@@ -2,9 +2,13 @@
@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.Interface.System.Network
@using salesbook.Shared.Core.Interface.System.Notification
@using salesbook.Shared.Core.Services @using salesbook.Shared.Core.Services
@inject IFormFactor FormFactor @inject IFormFactor FormFactor
@inject INetworkService NetworkService @inject INetworkService NetworkService
@inject IFirebaseNotificationService FirebaseNotificationService
@inject IShinyNotificationManager NotificationManager
@inject PreloadService PreloadService @inject PreloadService PreloadService
<SpinnerLayout FullScreen="true" /> <SpinnerLayout FullScreen="true" />
@@ -13,6 +17,17 @@
{ {
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
await CheckAndRequestPermissions();
try
{
await FirebaseNotificationService.InitFirebase();
}
catch (Exception e)
{
Console.WriteLine($"Firebase init: {e.Message}");
}
var lastSyncDate = LocalStorage.Get<DateTime>("last-sync"); var lastSyncDate = LocalStorage.Get<DateTime>("last-sync");
if (!FormFactor.IsWeb() && NetworkService.ConnectionAvailable && lastSyncDate.Equals(DateTime.MinValue)) if (!FormFactor.IsWeb() && NetworkService.ConnectionAvailable && lastSyncDate.Equals(DateTime.MinValue))
@@ -25,6 +40,14 @@
NavigationManager.NavigateTo("/Calendar"); NavigationManager.NavigateTo("/Calendar");
} }
private async Task CheckAndRequestPermissions()
{
await NotificationManager.RequestAccess();
// if (BatteryOptimizationManagerService.IsBatteryOptimizationEnabled())
// BatteryOptimizationManagerService.OpenBatteryOptimizationSettings(_ => { });
}
private Task StartSyncUser() private Task StartSyncUser()
{ {
return Task.Run(() => return Task.Run(() =>

View File

@@ -1,6 +1,7 @@
@page "/login" @page "/login"
@using salesbook.Shared.Components.Layout.Spinner @using salesbook.Shared.Components.Layout.Spinner
@using salesbook.Shared.Core.Interface @using salesbook.Shared.Core.Interface
@using salesbook.Shared.Core.Interface.System.Network
@using salesbook.Shared.Core.Services @using salesbook.Shared.Core.Services
@inject IUserAccountService UserAccountService @inject IUserAccountService UserAccountService
@inject AppAuthenticationStateProvider AuthenticationStateProvider @inject AppAuthenticationStateProvider AuthenticationStateProvider

View File

@@ -1,14 +1,179 @@
@page "/Notifications" @page "/Notifications"
@attribute [Authorize] @attribute [Authorize]
@using salesbook.Shared.Components.Layout @using salesbook.Shared.Components.Layout
@using salesbook.Shared.Components.Layout.Spinner
@using salesbook.Shared.Components.SingleElements @using salesbook.Shared.Components.SingleElements
@using salesbook.Shared.Core.Dto.PageState
@using salesbook.Shared.Core.Entity
@using salesbook.Shared.Core.Interface.IntegryApi
@using salesbook.Shared.Core.Messages.Notification
@inject NotificationState Notification
@inject NewPushNotificationService NewPushNotificationService
@inject IJSRuntime JS
@inject IIntegryNotificationRestClient IntegryNotificationRestClient
<HeaderLayout Title="Notifiche" /> <HeaderLayout Title="Notifiche" />
<div class="container"> <div class="container">
<NoDataAvailable Text="Nessuna notifica meno recente" /> @if (Loading)
{
<SpinnerLayout FullScreen="true" />
}
else
{
if (Notification.ReceivedNotifications.IsNullOrEmpty() && Notification.UnreadNotifications.IsNullOrEmpty() && Notification.NotificationsRead.IsNullOrEmpty())
{
<NoDataAvailable Text="Nessuna notifica meno recente" />
}
else
{
<div class="list" id="list">
@foreach(var notification in Notification.ReceivedNotifications)
{
<NotificationCard Unread="true" Notification="notification" />
}
@foreach(var notification in Notification.UnreadNotifications)
{
<NotificationCard Unread="true" Notification="notification" />
}
@foreach (var notification in Notification.NotificationsRead)
{
<NotificationCard Notification="notification" />
}
</div>
}
}
</div> </div>
@code { @code {
private DotNetObjectReference<Notifications>? _objectReference;
private bool Loading { get; set; } = true;
protected override Task OnInitializedAsync()
{
_objectReference = DotNetObjectReference.Create(this);
NewPushNotificationService.OnNotificationReceived += NewNotificationReceived;
return Task.CompletedTask;
}
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)
{
InvokeAsync(StateHasChanged);
}
[JSInvokable]
public async Task Delete(string id)
{
Loading = true;
_ = InvokeAsync(StateHasChanged);
if (!long.TryParse(id, out var notificationId)) return;
var removed = false;
if (Notification.ReceivedNotifications.RemoveAll(x => x.Id == notificationId) > 0)
removed = true;
else if (Notification.UnreadNotifications.RemoveAll(x => x.Id == notificationId) > 0)
removed = true;
else if (Notification.NotificationsRead.RemoveAll(x => x.Id == notificationId) > 0)
removed = true;
if (!removed) return;
OrderNotificationList();
Loading = false;
_ = InvokeAsync(StateHasChanged);
_ = Task.Run(() =>
{
_ = IntegryNotificationRestClient.Delete(notificationId);
});
}
[JSInvokable]
public async Task MarkAsRead(string id)
{
Loading = true;
_ = InvokeAsync(StateHasChanged);
var notificationId = long.Parse(id);
var wtbNotification = Notification.ReceivedNotifications
.FindLast(x => x.Id == notificationId);
if (wtbNotification == null)
{
wtbNotification = Notification.UnreadNotifications
.FindLast(x => x.Id == notificationId);
Notification.UnreadNotifications.Remove(wtbNotification!);
}
else
{
Notification.ReceivedNotifications.Remove(wtbNotification);
}
wtbNotification = await IntegryNotificationRestClient.MarkAsRead(notificationId);
Notification.NotificationsRead.Add(wtbNotification);
OrderNotificationList();
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();
}
} }

View File

@@ -0,0 +1,6 @@
.list {
display: flex;
flex-direction: column;
align-items: center;
gap: 12px;
}

View File

@@ -3,6 +3,7 @@
@using salesbook.Shared.Components.Layout @using salesbook.Shared.Components.Layout
@using salesbook.Shared.Core.Authorization.Enum @using salesbook.Shared.Core.Authorization.Enum
@using salesbook.Shared.Core.Interface @using salesbook.Shared.Core.Interface
@using salesbook.Shared.Core.Interface.System.Network
@using salesbook.Shared.Core.Services @using salesbook.Shared.Core.Services
@inject AppAuthenticationStateProvider AuthenticationStateProvider @inject AppAuthenticationStateProvider AuthenticationStateProvider
@inject INetworkService NetworkService @inject INetworkService NetworkService

View File

@@ -10,6 +10,7 @@
@using salesbook.Shared.Core.Dto.Activity @using salesbook.Shared.Core.Dto.Activity
@using salesbook.Shared.Core.Dto.JobProgress @using salesbook.Shared.Core.Dto.JobProgress
@using salesbook.Shared.Core.Dto.PageState @using salesbook.Shared.Core.Dto.PageState
@using salesbook.Shared.Core.Interface.IntegryApi
@implements IAsyncDisposable @implements IAsyncDisposable
@inject IManageDataService ManageData @inject IManageDataService ManageData
@inject IMapper Mapper @inject IMapper Mapper

View File

@@ -143,6 +143,7 @@
max-height: 32vh; max-height: 32vh;
overflow: auto; overflow: auto;
scrollbar-width: none; scrollbar-width: none;
padding: 1rem 0;
} }
.container-pers-rif::-webkit-scrollbar { display: none; } .container-pers-rif::-webkit-scrollbar { display: none; }

View File

@@ -5,8 +5,7 @@
flex-direction: column; flex-direction: column;
-ms-overflow-style: none; -ms-overflow-style: none;
scrollbar-width: none; scrollbar-width: none;
padding-bottom: 70px; padding-bottom: 9vh;
height: 100%;
} }
.users .divider { .users .divider {

View File

@@ -2,6 +2,7 @@
@using salesbook.Shared.Core.Dto @using salesbook.Shared.Core.Dto
@using salesbook.Shared.Core.Interface @using salesbook.Shared.Core.Interface
@using salesbook.Shared.Components.Layout.Overlay @using salesbook.Shared.Components.Layout.Overlay
@using salesbook.Shared.Core.Interface.IntegryApi
@inject IIntegryApiService IntegryApiService @inject IIntegryApiService IntegryApiService
<div class="bottom-sheet-backdrop @(IsSheetVisible ? "show" : "")" @onclick="CloseBottomSheet"></div> <div class="bottom-sheet-backdrop @(IsSheetVisible ? "show" : "")" @onclick="CloseBottomSheet"></div>

View File

@@ -1,5 +1,6 @@
@using salesbook.Shared.Core.Dto @using salesbook.Shared.Core.Dto
@using salesbook.Shared.Core.Interface @using salesbook.Shared.Core.Interface
@using salesbook.Shared.Core.Interface.IntegryApi
@inject IIntegryApiService IntegryApiService @inject IIntegryApiService IntegryApiService
@inject IAttachedService AttachedService @inject IAttachedService AttachedService

View File

@@ -0,0 +1,86 @@
@using salesbook.Shared.Core.Entity
<div class="row" id="@Notification.Id">
<div class="behind-left">
<button class="read-btn">
<MudIcon Icon="@Icons.Material.Rounded.Check" />
</button>
</div>
<div class="behind-right">
<button class="trash-btn">
<MudIcon Icon="@Icons.Material.Rounded.Delete" />
</button>
</div>
<div class="notification-card">
@if (Notification.NotificationData is { Type: not null })
{
@switch (Notification.NotificationData.Type)
{
case "memo":
<div class="avatar"><MudIcon Icon="@Icons.Material.Rounded.ContentPaste" /></div>
break;
case "newPlanned":
<div class="avatar"><MudIcon Icon="@Icons.Material.Rounded.CalendarMonth" /></div>
break;
}
}
<div class="notification-body">
<div class="title-row">
<div class="title">@Notification.Title</div>
<div class="section-time">
<div class="notification-time">@GetTimeAgo(Notification.StartDate)</div>
@if (Unread)
{
<span class="unread-dot"></span>
}
</div>
</div>
@if (
Notification.StartDate < DateTime.Today && Notification.Body != null && Notification.Body.Contains("Oggi")
)
{
<MudText Typo="Typo.caption" Class="subtitle">@Notification.Body.Replace("Oggi", $"{Notification.StartDate:d}")</MudText>
}
else
{
<MudText Typo="Typo.caption" Class="subtitle">@Notification.Body</MudText>
}
</div>
</div>
</div>
@code {
[Parameter] public bool Unread { get; set; }
[Parameter] public WtbNotification Notification { get; set; } = new();
private static string GetTimeAgo(DateTime? timestamp)
{
if (timestamp is null) return "";
var difference = DateTime.Now - timestamp.Value;
switch (difference.TotalMinutes)
{
case < 1:
return "Adesso";
case < 60:
return $"{(int)difference.TotalMinutes} minuti fa";
default:
{
switch (difference.TotalHours)
{
case < 2:
return $"{(int)difference.TotalHours} ora fa";
case < 24:
return $"{timestamp.Value:t}";
default:
{
return difference.TotalDays < 7 ? $"{(int)difference.TotalDays}g fa" : timestamp.Value.ToString("dd/MM/yyyy");
}
}
}
}
}
}

View File

@@ -0,0 +1,105 @@
.row {
position: relative;
overflow: hidden;
border-radius: var(--mud-default-borderradius);
box-shadow: var(--custom-box-shadow);
width: 100%;
}
.behind-left, .behind-right {
position: absolute;
inset: 0;
display: flex;
align-items: center;
z-index: 0;
}
.behind-right {
justify-content: flex-end;
padding-right: 14px;
background: var(--mud-palette-error);
}
.behind-left {
justify-content: flex-start;
padding-left: 14px;
background: var(--mud-palette-info);
}
.read-btn, .trash-btn {
color: white;
padding: 10px 15px;
cursor: pointer;
}
.notification-card {
position: relative;
z-index: 1;
display: flex;
align-items: center;
padding: 12px;
gap: 12px;
background: var(--mud-palette-background);
transition: transform .2s ease;
touch-action: pan-y;
will-change: transform;
transform: translateX(0);
}
.avatar {
min-width: 42px;
height: 42px;
border-radius: 12px;
display: grid;
place-items: center;
background: var(--mud-palette-background);
border: 1px solid var(--mud-palette-divider);
font-weight: bold;
color: var(--mud-palette-primary);
}
.notification-body {
width: 100%
}
.title-row {
display: flex;
gap: 8px;
justify-items: center;
align-items: flex-start;
justify-content: space-between;
}
.unread-dot {
width: 10px;
height: 10px;
background-color: var(--mud-palette-error);
border-radius: 50%;
}
.title {
font-weight: 700;
margin-bottom: unset !important;
}
.section-time {
display: flex;
align-items: center;
gap: .5rem;
}
.notification-time {
font-size: 13px;
color: #94a3b8;
line-height: normal;
}
.collapsing {
transition: height .22s ease, margin .22s ease, opacity .22s ease;
overflow: hidden;
}
.subtitle {
font-size: 12px;
color: var(--mud-palette-drawer-text);
}

View File

@@ -9,6 +9,8 @@
@using salesbook.Shared.Core.Dto.Contact @using salesbook.Shared.Core.Dto.Contact
@using salesbook.Shared.Core.Entity @using salesbook.Shared.Core.Entity
@using salesbook.Shared.Core.Interface @using salesbook.Shared.Core.Interface
@using salesbook.Shared.Core.Interface.IntegryApi
@using salesbook.Shared.Core.Interface.System.Network
@using salesbook.Shared.Core.Messages.Activity.Copy @using salesbook.Shared.Core.Messages.Activity.Copy
@inject IManageDataService ManageData @inject IManageDataService ManageData
@inject INetworkService NetworkService @inject INetworkService NetworkService
@@ -72,9 +74,18 @@
<div class="divider"></div> <div class="divider"></div>
<div class="form-container"> <div class="form-container">
<span>Avviso</span> <span class="disable-full-width">Avviso</span>
<MudSwitch ReadOnly="IsView" T="bool" Disabled="true" Color="Color.Primary"/> <MudSelectExtended FullWidth="true" ReadOnly="@(IsView || ActivityModel.EstimatedTime == null)" T="int" Variant="Variant.Text" @bind-Value="ActivityModel.MinuteBefore" @bind-Value:after="OnAfterChangeTimeBefore" Class="customIcon-select" AdornmentIcon="@Icons.Material.Filled.Code">
<MudSelectItemExtended Class="custom-item-select" Text="Nessuno" Value="-1">Nessuno</MudSelectItemExtended>
<MudSelectItemExtended Class="custom-item-select" Text="All'ora pianificata" Value="0">All'ora pianificata</MudSelectItemExtended>
<MudSelectItemExtended Class="custom-item-select" Text="15 minuti prima" Value="15">15 minuti prima</MudSelectItemExtended>
<MudSelectItemExtended Class="custom-item-select" Text="30 minuti prima" Value="30">30 minuti prima</MudSelectItemExtended>
<MudSelectItemExtended Class="custom-item-select" Text="1 ora prima" Value="60">1 ora prima</MudSelectItemExtended>
<MudSelectItemExtended Class="custom-item-select" Text="2 ore prima" Value="120">2 ore prima</MudSelectItemExtended>
<MudSelectItemExtended Class="custom-item-select" Text="1 giorno prima" Value="1440">1 giorno prima</MudSelectItemExtended>
<MudSelectItemExtended Class="custom-item-select" Text="1 settimana prima" Value="10080">1 settimana prima</MudSelectItemExtended>
</MudSelectExtended>
</div> </div>
</div> </div>
@@ -82,7 +93,7 @@
<div class="form-container"> <div class="form-container">
<span class="disable-full-width">Assegnata a</span> <span class="disable-full-width">Assegnata a</span>
<MudSelectExtended FullWidth="true" ReadOnly="IsView" T="string?" Variant="Variant.Text" @bind-Value="ActivityModel.UserName" @bind-Value:after="OnAfterChangeValue" Class="customIcon-select" AdornmentIcon="@Icons.Material.Filled.Code"> <MudSelectExtended FullWidth="true" ReadOnly="IsView" T="string?" Variant="Variant.Text" @bind-Value="ActivityModel.UserName" @bind-Value:after="OnUserChanged" Class="customIcon-select" AdornmentIcon="@Icons.Material.Filled.Code">
@foreach (var user in Users) @foreach (var user in Users)
{ {
<MudSelectItemExtended Class="custom-item-select" Value="@user.UserName">@user.FullName</MudSelectItemExtended> <MudSelectItemExtended Class="custom-item-select" Value="@user.UserName">@user.FullName</MudSelectItemExtended>
@@ -374,17 +385,22 @@
return false; return false;
} }
private async Task LoadData() private Task LoadData()
{ {
if (!IsNew && Id != null) return Task.Run(async () =>
{ {
ActivityFileList = await IntegryApiService.GetActivityFile(Id); if (!IsNew && Id != null)
} {
ActivityFileList = await IntegryApiService.GetActivityFile(Id);
}
Users = await ManageData.GetTable<StbUser>(); Users = await ManageData.GetTable<StbUser>();
ActivityResult = await ManageData.GetTable<StbActivityResult>(); ActivityResult = await ManageData.GetTable<StbActivityResult>();
Clienti = await ManageData.GetClienti(new WhereCondContact {FlagStato = "A"}); Clienti = await ManageData.GetClienti(new WhereCondContact {FlagStato = "A"});
Pros = await ManageData.GetProspect(); Pros = await ManageData.GetProspect();
await InvokeAsync(StateHasChanged);
});
} }
private async Task LoadActivityType() private async Task LoadActivityType()
@@ -446,6 +462,24 @@
OnAfterChangeValue(); OnAfterChangeValue();
} }
private void OnAfterChangeTimeBefore()
{
if (ActivityModel.EstimatedTime != null)
{
if (ActivityModel.MinuteBefore != -1)
{
ActivityModel.NotificationDate = ActivityModel.MinuteBefore == 0 ?
ActivityModel.EstimatedTime : ActivityModel.EstimatedTime.Value.AddMinutes(ActivityModel.MinuteBefore * -1);
}
else
{
ActivityModel.NotificationDate = null;
}
}
OnAfterChangeValue();
}
private void OnAfterChangeValue() private void OnAfterChangeValue()
{ {
if (!IsNew) if (!IsNew)

View File

@@ -5,6 +5,8 @@
@using salesbook.Shared.Core.Entity @using salesbook.Shared.Core.Entity
@using salesbook.Shared.Components.SingleElements.BottomSheet @using salesbook.Shared.Components.SingleElements.BottomSheet
@using salesbook.Shared.Core.Dto.Contact @using salesbook.Shared.Core.Dto.Contact
@using salesbook.Shared.Core.Interface.IntegryApi
@using salesbook.Shared.Core.Interface.System.Network
@inject IManageDataService ManageData @inject IManageDataService ManageData
@inject INetworkService NetworkService @inject INetworkService NetworkService
@inject IIntegryApiService IntegryApiService @inject IIntegryApiService IntegryApiService

View File

@@ -2,6 +2,8 @@
@using salesbook.Shared.Components.Layout @using salesbook.Shared.Components.Layout
@using salesbook.Shared.Core.Interface @using salesbook.Shared.Core.Interface
@using salesbook.Shared.Components.Layout.Overlay @using salesbook.Shared.Components.Layout.Overlay
@using salesbook.Shared.Core.Interface.IntegryApi
@using salesbook.Shared.Core.Interface.System.Network
@inject IManageDataService ManageData @inject IManageDataService ManageData
@inject INetworkService NetworkService @inject INetworkService NetworkService
@inject IIntegryApiService IntegryApiService @inject IIntegryApiService IntegryApiService

View File

@@ -1,4 +1,5 @@
using salesbook.Shared.Core.Entity; using System.Text.Json.Serialization;
using salesbook.Shared.Core.Entity;
using salesbook.Shared.Core.Helpers.Enum; using salesbook.Shared.Core.Helpers.Enum;
namespace salesbook.Shared.Core.Dto.Activity; namespace salesbook.Shared.Core.Dto.Activity;
@@ -10,6 +11,11 @@ public class ActivityDTO : StbActivity
public ActivityCategoryEnum Category { get; set; } public ActivityCategoryEnum Category { get; set; }
public bool Complete { get; set; } public bool Complete { get; set; }
//Notification
public int MinuteBefore { get; set; } = -1;
[JsonPropertyName("notificationDate")]
public DateTime? NotificationDate { get; set; }
public bool Deleted { get; set; } public bool Deleted { get; set; }
public PositionDTO? Position { get; set; } public PositionDTO? Position { get; set; }
@@ -23,6 +29,9 @@ public class ActivityDTO : StbActivity
{ {
return Commessa == other.Commessa && return Commessa == other.Commessa &&
Cliente == other.Cliente && Cliente == other.Cliente &&
Position == other.Position &&
MinuteBefore == other.MinuteBefore &&
NotificationDate == other.NotificationDate &&
Category == other.Category && Category == other.Category &&
Complete == other.Complete && ActivityId == other.ActivityId && ActivityResultId == other.ActivityResultId && ActivityTypeId == other.ActivityTypeId && DataInsAct.Equals(other.DataInsAct) && ActivityDescription == other.ActivityDescription && ParentActivityId == other.ParentActivityId && TipoAnag == other.TipoAnag && CodAnag == other.CodAnag && CodJcom == other.CodJcom && CodJfas == other.CodJfas && Nullable.Equals(EstimatedDate, other.EstimatedDate) && Nullable.Equals(EstimatedTime, other.EstimatedTime) && Nullable.Equals(AlarmDate, other.AlarmDate) && Nullable.Equals(AlarmTime, other.AlarmTime) && Nullable.Equals(EffectiveDate, other.EffectiveDate) && Nullable.Equals(EffectiveTime, other.EffectiveTime) && ResultDescription == other.ResultDescription && Nullable.Equals(EstimatedEnddate, other.EstimatedEnddate) && Nullable.Equals(EstimatedEndtime, other.EstimatedEndtime) && Nullable.Equals(EffectiveEnddate, other.EffectiveEnddate) && Nullable.Equals(EffectiveEndtime, other.EffectiveEndtime) && UserCreator == other.UserCreator && UserName == other.UserName && Nullable.Equals(PercComp, other.PercComp) && Nullable.Equals(EstimatedHours, other.EstimatedHours) && CodMart == other.CodMart && PartitaMag == other.PartitaMag && Matricola == other.Matricola && Priorita == other.Priorita && Nullable.Equals(ActivityPlayCounter, other.ActivityPlayCounter) && ActivityEvent == other.ActivityEvent && Guarantee == other.Guarantee && Note == other.Note && Rfid == other.Rfid && IdLotto == other.IdLotto && PersonaRif == other.PersonaRif && HrNum == other.HrNum && Gestione == other.Gestione && Nullable.Equals(DataOrd, other.DataOrd) && NumOrd == other.NumOrd && IdStep == other.IdStep && IdRiga == other.IdRiga && Nullable.Equals(OraInsAct, other.OraInsAct) && IndiceGradimento == other.IndiceGradimento && NoteGradimento == other.NoteGradimento && FlagRisolto == other.FlagRisolto && FlagTipologia == other.FlagTipologia && OreRapportino == other.OreRapportino && UserModifier == other.UserModifier && Nullable.Equals(OraModAct, other.OraModAct) && Nullable.Equals(OraViewAct, other.OraViewAct) && CodVdes == other.CodVdes && CodCmac == other.CodCmac && WrikeId == other.WrikeId && CodMgrp == other.CodMgrp && PlanId == other.PlanId; Complete == other.Complete && ActivityId == other.ActivityId && ActivityResultId == other.ActivityResultId && ActivityTypeId == other.ActivityTypeId && DataInsAct.Equals(other.DataInsAct) && ActivityDescription == other.ActivityDescription && ParentActivityId == other.ParentActivityId && TipoAnag == other.TipoAnag && CodAnag == other.CodAnag && CodJcom == other.CodJcom && CodJfas == other.CodJfas && Nullable.Equals(EstimatedDate, other.EstimatedDate) && Nullable.Equals(EstimatedTime, other.EstimatedTime) && Nullable.Equals(AlarmDate, other.AlarmDate) && Nullable.Equals(AlarmTime, other.AlarmTime) && Nullable.Equals(EffectiveDate, other.EffectiveDate) && Nullable.Equals(EffectiveTime, other.EffectiveTime) && ResultDescription == other.ResultDescription && Nullable.Equals(EstimatedEnddate, other.EstimatedEnddate) && Nullable.Equals(EstimatedEndtime, other.EstimatedEndtime) && Nullable.Equals(EffectiveEnddate, other.EffectiveEnddate) && Nullable.Equals(EffectiveEndtime, other.EffectiveEndtime) && UserCreator == other.UserCreator && UserName == other.UserName && Nullable.Equals(PercComp, other.PercComp) && Nullable.Equals(EstimatedHours, other.EstimatedHours) && CodMart == other.CodMart && PartitaMag == other.PartitaMag && Matricola == other.Matricola && Priorita == other.Priorita && Nullable.Equals(ActivityPlayCounter, other.ActivityPlayCounter) && ActivityEvent == other.ActivityEvent && Guarantee == other.Guarantee && Note == other.Note && Rfid == other.Rfid && IdLotto == other.IdLotto && PersonaRif == other.PersonaRif && HrNum == other.HrNum && Gestione == other.Gestione && Nullable.Equals(DataOrd, other.DataOrd) && NumOrd == other.NumOrd && IdStep == other.IdStep && IdRiga == other.IdRiga && Nullable.Equals(OraInsAct, other.OraInsAct) && IndiceGradimento == other.IndiceGradimento && NoteGradimento == other.NoteGradimento && FlagRisolto == other.FlagRisolto && FlagTipologia == other.FlagTipologia && OreRapportino == other.OreRapportino && UserModifier == other.UserModifier && Nullable.Equals(OraModAct, other.OraModAct) && Nullable.Equals(OraViewAct, other.OraViewAct) && CodVdes == other.CodVdes && CodCmac == other.CodCmac && WrikeId == other.WrikeId && CodMgrp == other.CodMgrp && PlanId == other.PlanId;
} }
@@ -97,6 +106,9 @@ public class ActivityDTO : StbActivity
hashCode.Add(Cliente); hashCode.Add(Cliente);
hashCode.Add(Category); hashCode.Add(Category);
hashCode.Add(Complete); hashCode.Add(Complete);
hashCode.Add(Position);
hashCode.Add(MinuteBefore);
hashCode.Add(NotificationDate);
return hashCode.ToHashCode(); return hashCode.ToHashCode();
} }
} }

View File

@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;
namespace salesbook.Shared.Core.Dto;
public class NotificationDataDTO
{
[JsonPropertyName("activityId")]
public string? ActivityId { get; set; }
[JsonPropertyName("type")]
public string? Type { get; set; }
}

View File

@@ -0,0 +1,12 @@
using salesbook.Shared.Core.Entity;
namespace salesbook.Shared.Core.Dto.PageState;
public class NotificationState
{
public List<WtbNotification> ReceivedNotifications { get; set; } = [];
public List<WtbNotification> UnreadNotifications { get; set; } = [];
public List<WtbNotification> NotificationsRead { get; set; } = [];
public int Count => ReceivedNotifications.Count() + UnreadNotifications.Count();
}

View File

@@ -0,0 +1,15 @@
using System.Text.Json.Serialization;
namespace salesbook.Shared.Core.Dto;
public class ReadNotificationRequestDTO
{
[JsonPropertyName("deviceToken")]
public string DeviceToken { get; set; }
[JsonPropertyName("username")]
public string Username { get; set; }
[JsonPropertyName("notificationId")]
public long NotificationId { get; set; }
}

View File

@@ -0,0 +1,15 @@
using System.Text.Json.Serialization;
namespace salesbook.Shared.Core.Entity;
public class WtbDeviceNotification
{
[JsonPropertyName("userDeviceId")]
public long? UserDeviceId { get; set; }
[JsonPropertyName("notificationId")]
public long? NotificationId { get; set; }
[JsonPropertyName("readDate")]
public DateTime? ReadDate { get; set; }
}

View File

@@ -0,0 +1,37 @@
using System.Text.Json.Serialization;
using salesbook.Shared.Core.Dto;
namespace salesbook.Shared.Core.Entity;
public class WtbNotification
{
[JsonPropertyName("id")]
public long Id { get; set; }
[JsonPropertyName("title")]
public string? Title { get; set; }
[JsonPropertyName("body")]
public string? Body { get; set; }
[JsonPropertyName("imageUrl")]
public string? ImageUrl { get; set; }
[JsonPropertyName("notificationData")]
public NotificationDataDTO? NotificationData { get; set; }
[JsonPropertyName("startDate")]
public DateTime? StartDate { get; set; }
[JsonPropertyName("endDate")]
public DateTime? EndDate { get; set; }
[JsonPropertyName("persistent")]
public bool? Persistent { get; set; }
[JsonPropertyName("topics")]
public List<string>? Topics { get; set; }
[JsonPropertyName("wtbDeviceNotifications")]
public List<WtbDeviceNotification>? WtbDeviceNotifications { get; set; }
}

View File

@@ -0,0 +1,6 @@
namespace salesbook.Shared.Core.Interface;
public interface IFirebaseNotificationService
{
Task InitFirebase();
}

View File

@@ -4,7 +4,7 @@ using salesbook.Shared.Core.Dto.Contact;
using salesbook.Shared.Core.Dto.JobProgress; using salesbook.Shared.Core.Dto.JobProgress;
using salesbook.Shared.Core.Entity; using salesbook.Shared.Core.Entity;
namespace salesbook.Shared.Core.Interface; namespace salesbook.Shared.Core.Interface.IntegryApi;
public interface IIntegryApiService public interface IIntegryApiService
{ {

View File

@@ -0,0 +1,11 @@
using salesbook.Shared.Core.Entity;
namespace salesbook.Shared.Core.Interface.IntegryApi;
public interface IIntegryNotificationRestClient
{
Task<List<WtbNotification>> Get();
Task<WtbNotification> MarkAsRead(long id);
Task Delete(long id);
Task DeleteAll();
}

View File

@@ -0,0 +1,8 @@
using Microsoft.Extensions.Logging;
namespace salesbook.Shared.Core.Interface.IntegryApi;
public interface IIntegryRegisterNotificationRestClient
{
Task Register(string fcmToken, ILogger? logger1 = null);
}

View File

@@ -0,0 +1,8 @@
namespace salesbook.Shared.Core.Interface.System.Battery;
public interface IBatteryOptimizationManagerService
{
bool IsBatteryOptimizationEnabled();
void OpenBatteryOptimizationSettings(Action<bool> onCompleted);
}

View File

@@ -1,4 +1,4 @@
namespace salesbook.Shared.Core.Interface; namespace salesbook.Shared.Core.Interface.System.Network;
public interface INetworkService public interface INetworkService
{ {

View File

@@ -0,0 +1,6 @@
namespace salesbook.Shared.Core.Interface.System.Notification;
public interface IShinyNotificationManager
{
Task RequestAccess();
}

View File

@@ -0,0 +1,6 @@
using CommunityToolkit.Mvvm.Messaging.Messages;
using salesbook.Shared.Core.Entity;
namespace salesbook.Shared.Core.Messages.Notification;
public class NewPushNotificationMessage(WtbNotification value) : ValueChangedMessage<WtbNotification>(value);

View File

@@ -0,0 +1,14 @@
using CommunityToolkit.Mvvm.Messaging;
using salesbook.Shared.Core.Entity;
namespace salesbook.Shared.Core.Messages.Notification;
public class NewPushNotificationService
{
public event Action<WtbNotification>? OnNotificationReceived;
public NewPushNotificationService(IMessenger messenger)
{
messenger.Register<NewPushNotificationMessage>(this, (_, o) => { OnNotificationReceived?.Invoke(o.Value); });
}
}

View File

@@ -7,6 +7,7 @@ using salesbook.Shared.Core.Entity;
using salesbook.Shared.Core.Interface; using salesbook.Shared.Core.Interface;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using salesbook.Shared.Core.Dto.Contact; using salesbook.Shared.Core.Dto.Contact;
using salesbook.Shared.Core.Interface.IntegryApi;
namespace salesbook.Shared.Core.Services; namespace salesbook.Shared.Core.Services;

View File

@@ -0,0 +1,33 @@
using IntegryApiClient.Core.Domain.Abstraction.Contracts.Account;
using IntegryApiClient.Core.Domain.RestClient.Contacts;
using salesbook.Shared.Core.Dto;
using salesbook.Shared.Core.Entity;
using salesbook.Shared.Core.Interface.IntegryApi;
namespace salesbook.Shared.Core.Services;
public class IntegryNotificationRestClient(
IUserSession userSession,
IIntegryApiRestClient integryApiRestClient) : IIntegryNotificationRestClient
{
public Task<List<WtbNotification>> Get()
{
var queryParams = new Dictionary<string, object>
{
{ "mode", "ENABLED" },
{ "forUser", userSession.User.Username }
};
return integryApiRestClient.Get<List<WtbNotification>>("notification", queryParams)!;
}
public Task<WtbNotification> MarkAsRead(long id) =>
integryApiRestClient.Post<WtbNotification>("notification/read",
new ReadNotificationRequestDTO { NotificationId = id, Username = userSession.User.Username })!;
public Task Delete(long id) =>
integryApiRestClient.Delete<object>($"notification/{id}", null);
public Task DeleteAll() =>
integryApiRestClient.Delete<object>($"notification/all/{userSession.User.Username}", null);
}

View File

@@ -24,7 +24,7 @@
<PackageReference Include="AutoMapper" Version="14.0.0" /> <PackageReference Include="AutoMapper" Version="14.0.0" />
<PackageReference Include="CodeBeam.MudBlazor.Extensions" Version="8.2.2" /> <PackageReference Include="CodeBeam.MudBlazor.Extensions" Version="8.2.2" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" /> <PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="IntegryApiClient.Core" Version="1.1.6" /> <PackageReference Include="IntegryApiClient.Core" Version="1.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="9.0.6" /> <PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="9.0.6" />
<PackageReference Include="Microsoft.Maui.Essentials" Version="9.0.81" /> <PackageReference Include="Microsoft.Maui.Essentials" Version="9.0.81" />
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" /> <PackageReference Include="sqlite-net-pcl" Version="1.9.172" />

View File

@@ -22,8 +22,12 @@ a, .btn-link {
color: inherit; color: inherit;
} }
/*ServicesIsDown" : "SystemOk" : "NetworkKo*/ article {
display: flex;
flex-direction: column;
}
/*ServicesIsDown" : "SystemOk" : "NetworkKo*/
.Connection { .Connection {
padding: 0 .75rem; padding: 0 .75rem;
font-weight: 700; font-weight: 700;
@@ -58,6 +62,8 @@ a, .btn-link {
transform: translateY(-35px); transform: translateY(-35px);
} }
.page > .Connection.Hide ~ main .bottom-sheet-container.show { bottom: -35px; }
.btn-primary { .btn-primary {
color: #fff; color: #fff;
background-color: var(--primary-color); background-color: var(--primary-color);

View File

@@ -0,0 +1,168 @@
const FIRST_THRESHOLD = 80;
const SECOND_THRESHOLD = 160;
const CLOSE_THRESHOLD = 40;
const MAX_SWIPE = 200;
let dotnetHelper;
window.initNotifications = (dotnetRef) => {
dotnetHelper = dotnetRef;
document.querySelectorAll('.row').forEach(initRow);
};
function initRow(row) {
const card = row.querySelector('.notification-card');
const btnTrash = row.querySelector('.trash-btn');
const btnRead = row.querySelector('.read-btn');
const behindRight = row.querySelector('.behind-right'); // cestino
const behindLeft = row.querySelector('.behind-left'); // mark as read
let startX = 0, currentX = 0, dragging = false;
let open = null; // "left", "right" oppure null
// inizializza nascosti
behindRight.style.visibility = "hidden";
behindLeft.style.visibility = "hidden";
// funzione di utilità → controlla se c'è unread-dot
function canMarkAsRead() {
return row.querySelector('.unread-dot') !== null;
}
card.addEventListener('pointerdown', (e) => {
if (e.pointerType === 'mouse' && e.button !== 0) return;
dragging = true;
startX = e.clientX;
card.setPointerCapture(e.pointerId);
card.style.transition = 'none';
});
card.addEventListener('pointermove', (e) => {
if (!dragging) return;
const dx = e.clientX - startX;
if (dx > 0 && !canMarkAsRead() && !open) {
currentX = 0;
return; // niente movimento
}
let translate = dx;
if (!open) {
translate = Math.max(-MAX_SWIPE, Math.min(MAX_SWIPE, dx));
} else if (open === "left") {
translate = Math.min(MAX_SWIPE, FIRST_THRESHOLD + dx);
} else if (open === "right") {
translate = Math.max(-MAX_SWIPE, -FIRST_THRESHOLD + dx);
}
currentX = translate;
card.style.transform = `translateX(${translate}px)`;
// mostra/nascondi i behind in tempo reale
if (currentX < 0) {
behindRight.style.visibility = "visible"; // cestino
behindLeft.style.visibility = "hidden";
} else if (currentX > 0) {
behindLeft.style.visibility = "visible"; // mark as read
behindRight.style.visibility = "hidden";
} else {
behindLeft.style.visibility = "hidden";
behindRight.style.visibility = "hidden";
}
});
function endDrag() {
if (!dragging) return;
dragging = false;
card.style.transition = 'transform .2s ease';
// blocca swipe destro se non consentito
if (currentX > 0 && !canMarkAsRead() && !open) {
card.style.transform = 'translateX(0)';
currentX = 0;
open = null;
behindRight.style.visibility = "hidden";
behindLeft.style.visibility = "hidden";
return;
}
// Swipe a sinistra → elimina
if (!open && currentX < 0) {
if (currentX < -SECOND_THRESHOLD) {
card.style.transform = `translateX(-${MAX_SWIPE}px)`;
setTimeout(() => removeRow(row), 200);
} else if (currentX < -FIRST_THRESHOLD) {
card.style.transform = `translateX(-${FIRST_THRESHOLD}px)`;
open = "right";
} else {
card.style.transform = 'translateX(0)';
open = null;
behindRight.style.visibility = "hidden";
behindLeft.style.visibility = "hidden";
}
}
// Swipe a destra → mark as read SOLO se consentito
else if (!open && currentX > 0) {
if (currentX > SECOND_THRESHOLD) {
card.style.transform = `translateX(${MAX_SWIPE}px)`;
setTimeout(() => markAsRead(row), 200);
} else if (currentX > FIRST_THRESHOLD) {
card.style.transform = `translateX(${FIRST_THRESHOLD}px)`;
open = "left";
} else {
card.style.transform = 'translateX(0)';
open = null;
behindRight.style.visibility = "hidden";
behindLeft.style.visibility = "hidden";
}
}
// Se già aperta, gestisci chiusura
else {
if (open === "right" && currentX > -FIRST_THRESHOLD + CLOSE_THRESHOLD) {
card.style.transform = 'translateX(0)';
open = null;
behindRight.style.visibility = "hidden";
behindLeft.style.visibility = "hidden";
} else if (open === "left" && currentX < FIRST_THRESHOLD - CLOSE_THRESHOLD) {
card.style.transform = 'translateX(0)';
open = null;
behindRight.style.visibility = "hidden";
behindLeft.style.visibility = "hidden";
} else if (open) {
card.style.transform = `translateX(${open === "right" ? -FIRST_THRESHOLD : FIRST_THRESHOLD}px)`;
}
}
}
card.addEventListener('pointerup', endDrag);
card.addEventListener('pointercancel', endDrag);
btnTrash.addEventListener('click', () => removeRow(row));
btnRead.addEventListener('click', () => markAsRead(row));
}
function removeRow(row) {
//collapseAndRemove(row);
dotnetHelper.invokeMethodAsync('Delete', row.id);
}
function markAsRead(row) {
//collapseAndRemove(row);
dotnetHelper.invokeMethodAsync('MarkAsRead', row.id);
}
function collapseAndRemove(row) {
const h = row.getBoundingClientRect().height;
row.style.height = h + 'px';
row.classList.add('collapsing');
requestAnimationFrame(() => {
row.style.opacity = '0';
row.style.marginTop = '0';
row.style.marginBottom = '0';
row.style.height = '0';
});
setTimeout(() => row.remove(), 220);
}

View File

@@ -1,4 +1,5 @@
using salesbook.Shared.Core.Interface; using salesbook.Shared.Core.Interface;
using salesbook.Shared.Core.Interface.System.Network;
namespace salesbook.Web.Core.Services; namespace salesbook.Web.Core.Services;

View File

@@ -5,6 +5,8 @@ using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using MudBlazor.Services; using MudBlazor.Services;
using salesbook.Shared.Components; using salesbook.Shared.Components;
using salesbook.Shared.Core.Interface; using salesbook.Shared.Core.Interface;
using salesbook.Shared.Core.Interface.IntegryApi;
using salesbook.Shared.Core.Interface.System.Network;
using salesbook.Shared.Core.Services; using salesbook.Shared.Core.Services;
using salesbook.Web.Core.Services; using salesbook.Web.Core.Services;

View File

@@ -16,7 +16,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="IntegryApiClient.Blazor" Version="1.1.6" /> <PackageReference Include="IntegryApiClient.Blazor" Version="1.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="9.0.6" /> <PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="9.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.6" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.6" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.6" />