145 lines
4.0 KiB
C#
145 lines
4.0 KiB
C#
using AyCode.Interfaces.StorageHandlers;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.Extensions.Localization;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using AyCode.Core.Loggers;
|
|
using AyCode.Services.Loggers;
|
|
using TIAM.Core.Loggers;
|
|
using TIAM.Resources;
|
|
using TIAMSharedUI.Resources;
|
|
using TIAMWebApp.Shared.Application.Interfaces;
|
|
using TIAMWebApp.Shared.Application.Utility;
|
|
using TIAMSharedUI.Pages.Components;
|
|
using TIAMWebApp.Shared.Application.Models.ClientSide;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace TIAMSharedUI.Shared.Components
|
|
{
|
|
public partial class Navbar : ComponentBase
|
|
{
|
|
[Inject]
|
|
public required IEnumerable<IAcLogWriterClientBase> LogWriters { get; set; }
|
|
|
|
[Inject]
|
|
public ISecureStorageHandler SecureStorageHandler { get; set; }
|
|
|
|
[Inject]
|
|
public ISessionService sessionService { get; set; }
|
|
[Inject]
|
|
public IStringLocalizer<TIAMResources> localizer { get; set; }
|
|
|
|
[Inject]
|
|
public NavigationManager navigationManager { get; set; }
|
|
|
|
[Inject]
|
|
public IComponentUpdateService componentUpdateService { get; set; }
|
|
|
|
[Inject]
|
|
private IUserDataService UserDataService { get; set; }
|
|
|
|
private bool enableLogin = true;
|
|
private bool enableEvents = false;
|
|
private bool enableTransfer = true;
|
|
private bool enableLanguage = false;
|
|
private bool enableApi = true;
|
|
private bool enableChat = true;
|
|
|
|
private bool collapseNavMenu = true;
|
|
private bool myUser = false;
|
|
private bool hasProperty = false;
|
|
|
|
private ILogger _logger;
|
|
|
|
//componentUpdateService.RefreshRequested += RefreshMe;
|
|
|
|
public Navbar()
|
|
{
|
|
|
|
}
|
|
|
|
private void RefreshMe()
|
|
{
|
|
_logger.Debug($"Navbar refresh called! {DateTime.Now} ");
|
|
|
|
OnInitialized();
|
|
StateHasChanged();
|
|
}
|
|
|
|
private void ToggleNavMenu()
|
|
{
|
|
collapseNavMenu = !collapseNavMenu;
|
|
}
|
|
|
|
private void NavigateBack()
|
|
{
|
|
|
|
}
|
|
|
|
private async Task SignOut()
|
|
{
|
|
bool serverResult;
|
|
string userDetailsStr = await SecureStorageHandler.GetFromSecureStorageAsync(nameof(Setting.UserBasicDetails));
|
|
if (!string.IsNullOrEmpty(userDetailsStr))
|
|
{
|
|
var userBasicDetail = JsonConvert.DeserializeObject<UserBasicDetails>(userDetailsStr);
|
|
serverResult = await UserDataService.Logout(userBasicDetail.RefreshToken);
|
|
}
|
|
|
|
await SecureStorageHandler.ClearAllSecureStorageAsync();
|
|
sessionService.User = null;
|
|
sessionService.IsAuthenticated = false;
|
|
navigationManager.NavigateTo("/");
|
|
myUser = false;
|
|
}
|
|
|
|
private void ThrowSomeError()
|
|
{
|
|
throw new Exception();
|
|
}
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
base.OnInitialized();
|
|
|
|
_logger = new LoggerClient<Navbar>(LogWriters.ToArray());
|
|
|
|
|
|
_logger.Debug($"Navbar OnInit {DateTime.Now} ");
|
|
|
|
if (sessionService.User != null)
|
|
{
|
|
myUser = true;
|
|
}
|
|
else
|
|
{
|
|
_logger.Debug($"Navbar myUser false! {DateTime.Now} ");
|
|
myUser = false;
|
|
}
|
|
|
|
var properties = sessionService.User?.HasProperties;
|
|
|
|
if (properties == null)
|
|
return;
|
|
|
|
hasProperty = properties.Count > 0;
|
|
|
|
foreach (var property in properties)
|
|
{
|
|
_logger.Detail($"First property: {property.Value} ");
|
|
}
|
|
}
|
|
|
|
protected override void OnAfterRender(bool firstRender)
|
|
{
|
|
base.OnAfterRender(firstRender);
|
|
|
|
if (firstRender)
|
|
componentUpdateService.RefreshRequested += RefreshMe;
|
|
}
|
|
}
|
|
}
|