Files
StockMan/StockMan.CORE/Components/NewNavMenu.razor.cs
T
Samuele Locatelli f3d7ae055d CodeMaid vari
2023-03-02 08:46:06 +01:00

122 lines
3.1 KiB
C#

using Microsoft.AspNetCore.Components;
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; } = "";
[Parameter]
public string User { get; set; } = "";
#endregion Public Properties
#region Protected Fields
protected bool isChildOpen = false;
protected bool isComp = false;
#endregion Protected Fields
#region Protected Properties
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;
}
#endregion Protected Methods
}
}