140 lines
3.3 KiB
C#
140 lines
3.3 KiB
C#
using GPW.CORE.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace GPW.CORE.Smart8.Client.Components
|
|
{
|
|
public partial class NavBottom : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public ConfigDTO CurrConf { get; set; } = null!;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
if (_subscribed)
|
|
{
|
|
UState.OnChange -= UState_OnChange;
|
|
_subscribed = false;
|
|
}
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Methods
|
|
|
|
protected override void OnAfterRender(bool firstRender)
|
|
{
|
|
//base.OnAfterRender(firstRender);
|
|
if (!_subscribed)
|
|
{
|
|
_subscribed = true;
|
|
UState.OnChange += UState_OnChange;
|
|
}
|
|
}
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
base.OnInitialized();
|
|
Console.WriteLine($"NavBottom | Initialized");
|
|
}
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
base.OnParametersSet();
|
|
Console.WriteLine($"NavBottom | Params | baseUrl: {CurrConf.BaseUrl} | ver: {CurrConf.Versione} | idxDip: {IdxDipendente}");
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private bool _subscribed = false;
|
|
private string hideButtonCSS = "visible";
|
|
private string hideMenuCSS = "hidden";
|
|
private int IdxDipendente = 0;
|
|
private bool isVisible = false;
|
|
|
|
private bool DataLoaded
|
|
{
|
|
get => CurrConf != null && IdxDipendente > 0;
|
|
}
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private bool isActive { get; set; } = false;
|
|
|
|
[Inject]
|
|
private NavigationManager NavMan { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private UserStateService UState { get; set; } = null!;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void goTo(string target)
|
|
{
|
|
NavMan.NavigateTo($"{CurrConf.BaseUrl}{target}", true);
|
|
Console.WriteLine($"NavBottom | NavTo: {target}");
|
|
}
|
|
|
|
private void goToAbout()
|
|
{
|
|
goTo("About");
|
|
}
|
|
|
|
private void goToAdmin()
|
|
{
|
|
goTo("Admin");
|
|
}
|
|
|
|
private void goToIndex()
|
|
{
|
|
goTo("Index");
|
|
}
|
|
|
|
private void goToMPF()
|
|
{
|
|
goTo("DayOff");
|
|
}
|
|
|
|
private void hideMenu()
|
|
{
|
|
isVisible = false;
|
|
hideMenuCSS = "hidden; height: 0%;";
|
|
hideButtonCSS = "visible";
|
|
}
|
|
|
|
private void showMenu()
|
|
{
|
|
if (IdxDipendente > 0)
|
|
{
|
|
isVisible = true;
|
|
hideMenuCSS = "visible; height: 22%; display:block;";
|
|
hideButtonCSS = "hidden";
|
|
}
|
|
}
|
|
|
|
private void UState_OnChange()
|
|
{
|
|
// siamo in un callback non-UI thread: usa InvokeAsync
|
|
_ = InvokeAsync(() =>
|
|
{
|
|
if (UState.CurrentUser != null)
|
|
IdxDipendente = UState.CurrentUser.IdxDip;
|
|
|
|
StateHasChanged();
|
|
});
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |