153 lines
4.0 KiB
C#
153 lines
4.0 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using Microsoft.JSInterop;
|
|
using StockMan.Data.DbModels;
|
|
|
|
namespace StockMan.CORE.Components
|
|
{
|
|
public partial class NewNavMenu
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public List<PermessiModel>? NavMenuLinks { get; set; } = null;
|
|
|
|
public List<PermessiModel> NavMenuLinksChild { get; set; } = new List<PermessiModel>();
|
|
|
|
[Parameter]
|
|
public string Theme { get; set; } = "";
|
|
|
|
[Parameter]
|
|
public string Title { get; set; } = "";
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Fields
|
|
|
|
protected bool isChildOpen = false;
|
|
protected bool isComp = false;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected AuthenticationStateProvider AuthenticationStateProvider { get; set; } = null!;
|
|
|
|
protected int currChildOpen { get; set; } = 0;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected void compress()
|
|
{
|
|
JSRuntime.InvokeVoidAsync("closeNav");
|
|
isComp = true;
|
|
}
|
|
|
|
protected void deCompress()
|
|
{
|
|
JSRuntime.InvokeVoidAsync("openNav");
|
|
JSRuntime.InvokeVoidAsync("showMenuBtn");
|
|
isComp = false;
|
|
}
|
|
|
|
protected void doShowChildren(int id)
|
|
{
|
|
if (currChildOpen != 0)
|
|
{
|
|
JSRuntime.InvokeVoidAsync("doHideChildren", currChildOpen);
|
|
}
|
|
else
|
|
{
|
|
currChildOpen = id;
|
|
}
|
|
isChildOpen = !isChildOpen;
|
|
|
|
NavMenuLinksChild.Clear();
|
|
if (NavMenuLinks != null)
|
|
{
|
|
var lista = NavMenuLinks.Where(x => x.GRUPPO == id).ToList();
|
|
if (lista.Count != 1)
|
|
{
|
|
foreach (var item in lista)
|
|
{
|
|
if (item.NUMERO != 0)
|
|
{
|
|
NavMenuLinksChild.Add(item);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!isChildOpen)
|
|
{
|
|
JSRuntime.InvokeVoidAsync("doShowChildren", id);
|
|
}
|
|
else
|
|
{
|
|
JSRuntime.InvokeVoidAsync("doHideChildren", id);
|
|
currChildOpen = 0;
|
|
}
|
|
}
|
|
|
|
protected bool hasChild(int group)
|
|
{
|
|
bool hasIt = false;
|
|
if (NavMenuLinks != null)
|
|
{
|
|
var lista = NavMenuLinks.Where(x => x.GRUPPO == group).ToList();
|
|
if (lista.Count != 1)
|
|
{
|
|
hasIt = true;
|
|
}
|
|
}
|
|
return hasIt;
|
|
}
|
|
|
|
protected string isActive(int gruppo)
|
|
{
|
|
string answ = "navLinkItem";
|
|
if (gruppo == currChildOpen)
|
|
{
|
|
answ = "navLinkItemActive";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await forceReload();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private string userName = "";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
private async Task forceReload()
|
|
{
|
|
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
|
var user = authState.User;
|
|
if (user.Identity != null && user.Identity.IsAuthenticated)
|
|
{
|
|
userName = $"{user.Identity.Name}";
|
|
// cercare in tabella operators e salvare sigla da registrare nei vari records sul DB
|
|
}
|
|
else
|
|
{
|
|
userName = "N.A.";
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |