117 lines
3.3 KiB
Plaintext
117 lines
3.3 KiB
Plaintext
@inherits LayoutComponentBase
|
|
@inject GPW.CORE.Services.UserStateService UState
|
|
@inject ILogger<MainLayout> Log
|
|
|
|
<UserBootstrapClient />
|
|
|
|
<PageTitle>GPW.CORE.Smart (Client)</PageTitle>
|
|
|
|
<div class="page vh-100">
|
|
<main class="vw-100">
|
|
<CmpTop IpIsLocal="@isIpLocal" CurrUser="@currUser" EC_ReturnHome="() => ReturnHome()" EC_ForceReset="() => ForceReset()" />
|
|
<article class="content p-2">
|
|
@Body
|
|
</article>
|
|
|
|
@if (dataLoaded)
|
|
{
|
|
<NavBottom CurrConf="@currConfig" IdxDipendente="@idxDip" />
|
|
}
|
|
</main>
|
|
</div>
|
|
|
|
<div id="blazor-error-ui">
|
|
An unhandled error has occurred.
|
|
<a href="" class="reload">Reload</a>
|
|
<a class="dismiss">🗙</a>
|
|
</div>
|
|
|
|
@code {
|
|
private readonly Guid _instanceId = Guid.NewGuid();
|
|
private bool _subscribed;
|
|
private bool isIpLocal = false;
|
|
private bool dataLoaded = true;
|
|
private UserDTO? currUser;
|
|
private ConfigDTO? currConfig;
|
|
|
|
private int idxDip
|
|
{
|
|
get => (currUser != null && currUser?.IdxDip != null) ? (int)currUser?.IdxDip : 0;
|
|
}
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
Log.LogInformation("MainLayout OnInitialized client instance {Id}", _instanceId);
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (!firstRender) return;
|
|
|
|
Log.LogInformation("MainLayout OnAfterRenderAsync firstRender client instance {Id}, CurrentUser {User}",
|
|
_instanceId, UState.CurrentUser?.Utente ?? "<null>");
|
|
|
|
if (!_subscribed)
|
|
{
|
|
UState.OnChange += UState_OnChange;
|
|
_subscribed = true;
|
|
Log.LogInformation("MainLayout subscribed to UserState in client instance {Id}", _instanceId);
|
|
}
|
|
|
|
if (UState.CurrentUser != null)
|
|
{
|
|
currUser = UState.CurrentUser;
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
|
|
private void UState_OnChange()
|
|
{
|
|
_ = InvokeAsync(() =>
|
|
{
|
|
Log.LogInformation("MainLayout UState_OnChange client instance {Id} invoked", _instanceId);
|
|
currUser = UState.CurrentUser;
|
|
StateHasChanged();
|
|
});
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (_subscribed)
|
|
{
|
|
UState.OnChange -= UState_OnChange;
|
|
_subscribed = false;
|
|
Log.LogInformation("MainLayout unsubscribed in Dispose client instance {Id}", _instanceId);
|
|
}
|
|
}
|
|
|
|
[Inject]
|
|
private HttpClient Http { get; set; } = null!;
|
|
[Inject]
|
|
private NavigationManager NavMan { get; set; } = null!;
|
|
|
|
private async Task ReturnHome()
|
|
{
|
|
Console.WriteLine("MainLayout.ReturnHome (Client)");
|
|
var done = await Http.PostAsync("api/cache/flush", null);
|
|
NavMan.NavigateTo("Home", true);
|
|
// => Task.CompletedTask;
|
|
}
|
|
private async Task ForceReset()
|
|
{
|
|
Console.WriteLine("MainLayout.ForceReset (Client)");
|
|
var done = await Http.PostAsync("api/cache/flush", null);
|
|
|
|
string nextPage = NavMan.ToBaseRelativePath(NavMan.Uri);
|
|
// tengo solo parte finale...
|
|
if (nextPage.Contains("/"))
|
|
{
|
|
nextPage = nextPage.Substring(nextPage.LastIndexOf("/") + 1);
|
|
}
|
|
await Task.Delay(1);
|
|
|
|
NavMan.NavigateTo($"ForceReset?nextPage={nextPage}", true);
|
|
// => Task.CompletedTask;
|
|
}
|
|
}
|