112 lines
3.0 KiB
C#
112 lines
3.0 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using MP.AppAuth.Models;
|
|
|
|
namespace MP.IOC.Components.Layout
|
|
{
|
|
public partial class NavMenu
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> EC_compressUpdated { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected AuthenticationStateProvider AuthStateProvider { get; set; } = null!;
|
|
|
|
protected string hideText { get => showText ? "" : "invisible"; }
|
|
|
|
[Inject]
|
|
protected NavigationManager NavManager { get; set; } = null!;
|
|
|
|
protected string pageName
|
|
{
|
|
get
|
|
{
|
|
string pName = NavManager.ToBaseRelativePath(NavManager.Uri).ToLower();
|
|
if (pName.Contains("?"))
|
|
{
|
|
pName = pName.Substring(0, pName.IndexOf("?"));
|
|
}
|
|
return pName;
|
|
}
|
|
}
|
|
|
|
protected bool showText { get; set; } = true;
|
|
|
|
protected List<PermessiModel> UserPerm { get; set; } = new List<PermessiModel>();
|
|
|
|
protected List<UserDirittiModel> UserRight { get; set; } = new List<UserDirittiModel>();
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await ReloadData();
|
|
}
|
|
|
|
protected void ToggleCompress()
|
|
{
|
|
showText = !showText;
|
|
EC_compressUpdated.InvokeAsync(showText);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private bool collapseNavMenu = true;
|
|
|
|
private bool onlyIcon = false;
|
|
private string SafePages = "";
|
|
private string userName = "";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
[Inject]
|
|
private IConfiguration ConfMan { get; set; } = null!;
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
private string NavMenuCssClass => collapseNavMenu ? "collapse" : null;
|
|
|
|
private string? TextCss => onlyIcon ? "d-none" : "";
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
// sistemo elenco pagine safe...
|
|
SafePages = ConfMan.GetValue<string>("ServerConf:SafePages").ToLower() ?? "";
|
|
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
|
|
var user = authState.User;
|
|
if (user.Identity != null && user.Identity.IsAuthenticated)
|
|
{
|
|
userName = $"{user.Identity.Name}";
|
|
}
|
|
else
|
|
{
|
|
userName = "N.A.";
|
|
}
|
|
isLoading = false;
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
private void ToggleNavMenu()
|
|
{
|
|
collapseNavMenu = !collapseNavMenu;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |