105 lines
3.5 KiB
C#
105 lines
3.5 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Routing;
|
|
|
|
namespace Lux.UI.Components.Layout
|
|
{
|
|
public partial class NavMenu
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> EC_compressUpdated { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
NavigationManager.LocationChanged -= OnLocationChanged;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
protected string hideText { get => showText ? "" : "invisible"; }
|
|
protected string subArtCss { get => showText ? "ps-5" : ""; }
|
|
|
|
protected string? NavMenuCssClass => collapseNavMenu ? "collapse" : null;
|
|
|
|
protected string? TextCss => onlyIcon ? "d-none" : "";
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
currentUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
|
|
NavigationManager.LocationChanged += OnLocationChanged;
|
|
UpdateDict();
|
|
}
|
|
|
|
protected void ToggleCompress()
|
|
{
|
|
showText = !showText;
|
|
EC_compressUpdated.InvokeAsync(showText);
|
|
}
|
|
protected void ToggleNavMenu()
|
|
{
|
|
collapseNavMenu = !collapseNavMenu;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private bool collapseNavMenu = true;
|
|
private string? currentUrl;
|
|
private bool onlyIcon = false;
|
|
|
|
private Dictionary<string, List<string>> NameDict = new Dictionary<string, List<string>>();
|
|
private Dictionary<string, List<string>> IconDict = new Dictionary<string, List<string>>();
|
|
private Dictionary<string, List<string>> PageDict = new Dictionary<string, List<string>>();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private bool showText { get; set; } = true;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void OnLocationChanged(object? sender, LocationChangedEventArgs e)
|
|
{
|
|
currentUrl = NavigationManager.ToBaseRelativePath(e.Location);
|
|
StateHasChanged();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiornamento dizionari per pagine raggruppate in sottomenu
|
|
/// </summary>
|
|
private void UpdateDict()
|
|
{
|
|
// Inserimento nomi segnaposto nav-item
|
|
NameDict.Add("Articoli", new List<string>() { "Articoli", "Buy", "Sell" });
|
|
NameDict.Add("Ciclo prod", new List<string>() { "Ciclo prod", "Risorse", "Cicli" });
|
|
NameDict.Add("Contatti", new List<string>() { "Contatti", "Clienti", "Fornitori" });
|
|
|
|
// Inserimento icone
|
|
IconDict.Add("Articoli", new List<string>() { "fa-book-open", "fa-book", "fa-book-bookmark" });
|
|
IconDict.Add("Ciclo prod", new List<string>() { "fa-industry", "fa-location-dot", "fa-route" });
|
|
IconDict.Add("Contatti", new List<string>() { "fa-address-book", "fa-users", "fa-stamp" });
|
|
|
|
// Inserimento reindirizzamento elementi sotto menu
|
|
PageDict.Add("Articoli", new List<string>() { "Items", "SellItems" });
|
|
PageDict.Add("Ciclo prod", new List<string>() { "Resources", "JobRoute" });
|
|
PageDict.Add("Contatti", new List<string>() { "Customer", "Dealer" });
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |