Files
StockMan/StockMan.CORE/Components/NewNavMenu.razor.cs
T
zaccaria.majid d351a351f2 continuo grafico
2023-02-08 17:39:48 +01:00

119 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using System.Net.Http;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Web.Virtualization;
using Microsoft.JSInterop;
using StockMan.CORE;
using StockMan.CORE.Shared;
using StockMan.CORE.Data;
using StockMan.Data.DbModels;
using Microsoft.Extensions.Hosting;
using System.Diagnostics.Contracts;
namespace StockMan.CORE.Components
{
public partial class NewNavMenu
{
[Parameter]
public List<PermessiModel>? NavMenuLinks { get; set; } = null;
[Parameter]
public string Title { get; set; } = "";
[Parameter]
public string User { get; set; } = "";
[Parameter]
public string Theme { get; set; } = "";
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
protected bool isComp = false;
protected bool isChildOpen = false;
public List<PermessiModel> NavMenuLinksChild { get; set; } = new List<PermessiModel>();
protected int currChildOpen { get; set; } = 0;
protected void compress()
{
JSRuntime.InvokeVoidAsync("closeNav");
isComp = true;
}
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 string isActive(int gruppo)
{
string answ = "navLinkItem";
if (gruppo == currChildOpen)
{
answ = "navLinkItemActive";
}
return answ;
}
protected void deCompress()
{
JSRuntime.InvokeVoidAsync("openNav");
JSRuntime.InvokeVoidAsync("showMenuBtn");
isComp = false;
}
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;
}
}
}