Compare commits

..

No commits in common. "c165738e8ecb087cdfe39cf17bcb18c6ea155f50" and "6294ffdb01e398dda5b1a5a7719f636786c6a884" have entirely different histories.

11 changed files with 37 additions and 95 deletions

View File

@ -6,9 +6,8 @@ namespace TIAM.Models;
public class SiteViewModel : AcSiteViewModel
{
private readonly object _forLock = new();
private readonly object _forLock = new object();
public int UnreadMessagesCount { get; private set; } = 0;
public List<EmailMessage> UnreadMessages { get; } = [];
public DriverManageTransfersPageModel DriverManageTransfersPageModel { get; } = new();
@ -37,8 +36,6 @@ public class SiteViewModel : AcSiteViewModel
{
UnreadMessages.Clear();
UnreadMessages.AddRange(unreadMessages);
UnreadMessagesCount = UnreadMessages.Count;
}
}
@ -46,9 +43,8 @@ public class SiteViewModel : AcSiteViewModel
{
lock (_forLock)
{
UnreadMessagesCount = 0;
UnreadMessages.Clear();
DriverManageTransfersPageModel.ClearAll();
}
}

View File

@ -1,12 +1,13 @@
using TIAMWebApp.Shared.Application.Interfaces;
namespace TIAMMobileApp.Services
{
public class ComponentUpdateServiceMobile : ComponentUpdateServiceBase
public class ComponentUpdateServiceMobile : IComponentUpdateService
{
public override void CallRequestRefreshAll()
{
base.CallRequestRefreshAll();
}
public event Action RefreshRequested;
public void CallRequestRefresh()
{
RefreshRequested?.Invoke();
}
}
}

View File

@ -124,19 +124,18 @@
if (isSuccess)
{
await SaveToSessionInfo(user);
_logger.Info($"Saved user in db is: {user.DisplayName}, setting autenthicated state");
_adminSignalRClient.GetByIdAsync<SiteViewModel>(SignalRTags.GetSiteViewModelByUserId, signalResponseMessage =>
{
_siteViewModel.Initialize(signalResponseMessage.ResponseData!);
_logger.Debug($"UnreadMessages: {_siteViewModel.UnreadMessages.Count}");
ComponentUpdateService.CallRequestRefreshAll();
return Task.CompletedTask;
}, user.UserId).Forget();
}
await SaveToSessionInfo(user);
_logger.Info($"Saved user in db is: {user.DisplayName}, setting autenthicated state");
//NavManager.NavigateTo("/");
}
else
@ -144,8 +143,8 @@
_logger.Info("No token stored yet");
//NavManager.NavigateTo("/");
}
ComponentUpdateService.CallRequestRefresh();
//ComponentUpdateService.CallRequestRefresh();
}
protected async Task SaveToSessionInfo(UserSessionModel user)
@ -154,7 +153,7 @@
sessionService.IsAuthenticated = true;
sessionService.HasCompany = user.UserModelDto.UserProductMappings.Count > 0;
_logger.Debug($"Checking driver for: {user.UserModelDto.UserProductMappings.Count} mapping");
sessionService.IsDriver = CheckIfDriver(user.UserModelDto.UserProductMappings);
sessionService.IsDriver = await CheckIfDriver(user.UserModelDto.UserProductMappings);
if (user.UserModelDto.Id == TiamConstClient.DevAdminIds[0] || user.UserModelDto.Id == TiamConstClient.DevAdminIds[1])
{
sessionService.IsDevAdmin = true;
@ -169,23 +168,22 @@
_logger.Debug($"Saved to session: IsAuthenticated: {sessionService.IsAuthenticated}, HasCompany: {sessionService.HasCompany}, IsDriver: {sessionService.IsDriver}, IsDevAdmin: {sessionService.IsDevAdmin}, IsSysAdmin: {sessionService.IsSysAdmin}");
}
public bool CheckIfDriver(List<UserProductMapping> permissions)
public async Task<bool> CheckIfDriver(List<UserProductMapping> Permissions)
{
bool isDriver = false;
bool _isDriver = false;
foreach (UserProductMapping permission in permissions)
foreach (UserProductMapping Permission in Permissions)
{
//var permissionToCheck = await ServiceProviderDataService.GetUserProductMappingByIdAsync(Permission.Id);
_logger.Debug($"calling IsPowerOf with values: {permission.Id}, {permission.Permissions}, {1}");
var driverPermissionResult = IsBitSet(permission.Permissions, 1);
_logger.Debug($"calling IsPowerOf with values: {Permission.Id}, {Permission.Permissions}, {1}");
var driverPermissionResult = IsBitSet(Permission.Permissions, 1);
if (driverPermissionResult)
{
isDriver = true;
sessionService.DriverPersmissionId = permission.Id;
_isDriver = true;
sessionService.DriverPersmissionId = Permission.Id;
}
}
return isDriver;
return _isDriver;
}
public bool IsBitSet(int number, int power)
@ -223,7 +221,7 @@
get => CultureInfo.CurrentCulture;
set
{
if (!Equals(CultureInfo.CurrentCulture, value))
if (CultureInfo.CurrentCulture != value)
{
Thread.CurrentThread.CurrentCulture = value;
Thread.CurrentThread.CurrentUICulture = value;

View File

@ -48,7 +48,7 @@ namespace TIAMSharedUI.Pages.Components
//Something is cancelled
//args.Cancel = true;
//}
componentUpdateService.CallRequestRefresh<Navbar>();
componentUpdateService.CallRequestRefresh();
StateHasChanged();
//throw new NotImplementedException();

View File

@ -49,7 +49,7 @@ namespace TIAMSharedUI.Pages.Components
{
secureStorageHandler?.SaveToSecureStorageAsync(nameof(Setting.Locale), SelectedCulture.Name);
componentUpdateService.CallRequestRefreshAll();
componentUpdateService.CallRequestRefresh();
}

View File

@ -38,7 +38,7 @@ namespace TIAMSharedUI.Pages
[Inject]
public AuthenticationStateProvider AuthStateProvider { get; set; }
[Inject] public IComponentUpdateService componentUpdateService { get; set; }
//fill loginmodel with fake but valid data
//LoginModel loginModel = new();
@ -128,12 +128,12 @@ namespace TIAMSharedUI.Pages
_siteViewModel.Initialize(signalResponseMessage.ResponseData!);
BrowserConsoleLogWriter.Debug($"UnreadMessages: {_siteViewModel.UnreadMessages.Count}");
componentUpdateService.CallRequestRefreshAll();
return Task.CompletedTask;
}, user.UserId).Forget();
messageClass = "text-success";
resultMessage = "Successful login";
SaveToSessionInfo(user).Forget();
navManager.NavigateTo("/");
}

View File

@ -20,13 +20,11 @@
@using TIAM.Entities.Emails
@using AyCode.Blazor.Components.Services
@using AyCode.Core.Extensions
@using TIAM.Models
@using TIAM.Services
@inherits UserBasePageComponent
@inject IEnumerable<IAcLogWriterClientBase> LogWriters
@inject AdminSignalRClient AdminSignalRClient;
@inject SiteViewModel SiteViewModel;
@inject IComponentUpdateService ComponentUpdateService
<MessageDetailGrid CssClass="my-grid" @ref="_messageGrid"
Logger="_logger"
@ -140,9 +138,6 @@
emailMessage.IsReaded = true;
_messageGrid.UpdateDataItemAsync(emailMessage).Forget();
SiteViewModel.UnreadMessages.RemoveAll(x => x.Id == emailMessage.Id);
ComponentUpdateService.CallRequestRefreshAll();
//InvokeAsync(StateHasChanged).ContinueWith(x => _messageGrid.UpdateDataItemAsync(emailMessage).Forget());
}
}

View File

@ -80,7 +80,7 @@
@{
string url3 = $"user/messages/{userId}";
<NavLink class="nav-link" href="@url3">
<i class="fa-solid fa-envelope">@(" (" + SiteViewModel.UnreadMessages.Count + ")")</i>
<i class="fa-solid fa-envelope"></i>
</NavLink>
}
</li>

View File

@ -195,7 +195,7 @@ namespace TIAMSharedUI.Shared.Components
base.OnAfterRender(firstRender);
if (firstRender)
componentUpdateService.GetOrAddComponent<Navbar>().RefreshRequested += RefreshMe;
componentUpdateService.RefreshRequested += RefreshMe;
}
}
}

View File

@ -1,11 +1,13 @@
using TIAMWebApp.Shared.Application.Interfaces;
namespace TIAMWebApp.Client.Services
{
public class ComponentUpdateServiceWeb : ComponentUpdateServiceBase
public class ComponentUpdateServiceWeb : IComponentUpdateService
{
public override void CallRequestRefreshAll()
public event Action? RefreshRequested;
public void CallRequestRefresh()
{
base.CallRequestRefreshAll();
RefreshRequested?.Invoke();
}
}
}

View File

@ -1,58 +1,8 @@
using Microsoft.AspNetCore.Components;
namespace TIAMWebApp.Shared.Application.Interfaces
namespace TIAMWebApp.Shared.Application.Interfaces
{
public abstract class ComponentUpdateServiceBase : IComponentUpdateService
{
protected Dictionary<Type, IComponentUpdateItem> ComponentsByType = [];
public virtual void CallRequestRefreshAll()
{
foreach (var component in ComponentsByType.Values)
component.CallRequestRefresh();
}
public void CallRequestRefresh<T>() where T : class, IComponent
{
if (ComponentsByType.TryGetValue(typeof(T), out var componentUpdateItem))
componentUpdateItem.CallRequestRefresh();
}
public IComponentUpdateItem GetOrAddComponent<T>() where T : class, IComponent
{
var componentType = typeof(T);
if (ComponentsByType.TryGetValue(componentType, out var componentUpdateItem))
return componentUpdateItem;
componentUpdateItem = new ComponentUpdateItem();
ComponentsByType.Add(componentType, componentUpdateItem);
return componentUpdateItem;
}
}
public class ComponentUpdateItem : IComponentUpdateItem
{
public event Action? RefreshRequested;
public virtual void CallRequestRefresh()
{
RefreshRequested?.Invoke();
}
}
public interface IComponentUpdateItem
{
event Action? RefreshRequested;
void CallRequestRefresh();
}
public interface IComponentUpdateService
{
void CallRequestRefreshAll();
void CallRequestRefresh<T>() where T : class, IComponent;
IComponentUpdateItem GetOrAddComponent<T>() where T : class, IComponent;
event Action RefreshRequested;
void CallRequestRefresh();
}
}