Files
mapo-core/MP-TAB-SERV/Shared/MainLayout.razor
T
2023-10-05 12:56:53 +02:00

154 lines
4.9 KiB
Plaintext

@using System.Diagnostics;
@inherits LayoutComponentBase
@implements IDisposable
@inject NavigationManager NavMan
@inject ListSelectDataSrv MDataService
@inject TabDataService TDataService
@inject SharedMemService MStor
@inject MessageService MServ
<PageTitle>MP-TAB-SERV</PageTitle>
<div class="page">
<main>
<div class="top-row d-flex justify-content-between text-light">
<div class="col-4">
<span>
<button class="btn btn-sm @ResetClass" @onclick="() => ForceReload()" title="Update"><i class="fa-solid fa-rotate"></i></button>
Username
</span>
<sub>[999]</sub>
</div>
<div class="col-4 text-center d-flex justify-content-center">
<a href="status-map" class="text-decoration-none text-light">
<i class="fa-solid fa-house"></i> &nbsp;
MapoTAB2
&nbsp;
<img src="/images/LogoSteamware.png" style="height: 1rem" />
</a>
</div>
<div class="col-4 text-end">
@*<button class="btn btn-sm btn-dark" @onclick="() => OnYes()">Yes!</button>*@
<div class="row w-100 slideMen">
<div class="p-0">
<SlideMenu MenuItems="@CurrMenuItems"></SlideMenu>
</div>
</div>
</div>
</div>
<article class="content d-flex">
<div class="" id="mainBody">
@Body
</div>
<div class="sidebar" id="barLat">
<NavMenu MenuItems="@CurrMenuItems"></NavMenu>
</div>
</article>
</main>
</div>
<div class="fixed-bottom">
<CmpFooter></CmpFooter>
</div>
@code {
/// <summary>
/// Elenco items da menù per pagina corrente...
/// </summary>
protected List<LinkMenu> CurrMenuItems { get; set; } = new List<LinkMenu>();
/// <summary>
/// Livello corrente del menu
/// </summary>
protected string CurrLevel { get; set; } = "";
protected string ResetClass = "btn-primary";
private void HandleLocationChanged(object? sender, LocationChangedEventArgs e)
{
// Logger.LogInformation("URL of new location: {Location}", e.Location);
CurrLevel = MStor.PageLevel(NavMan.Uri);
// recupero menù
if (MStor.DictMenu.ContainsKey(CurrLevel))
{
CurrMenuItems = MStor.DictMenu[CurrLevel];
InvokeAsync(StateHasChanged).ConfigureAwait(false);
}
}
public void Dispose()
{
NavMan.LocationChanged -= HandleLocationChanged;
}
/// <summary>
/// Init struttura dati
/// </summary>
/// <returns></returns>
protected override async Task OnInitializedAsync()
{
NavMan.LocationChanged += HandleLocationChanged;
// verifica preliminare setup mdati
if (!MStor.MenuOk)
{
var allData = await MDataService.ListLinkAll();
MStor.SetupMenu(allData);
// fix config...
var allConf = await MDataService.ConfigGetAll();
MStor.SetConfig(allConf);
// fix MSFD...
var allMSFD = await TDataService.VMSFDGetAll();
MStor.SetMsfd(allMSFD);
// non da farsi globalmente
// // fix macchine
// var allMach = await MDataService.MacchineByMatrOper(0);
// MStor.DictMacchine = allMach.ToDictionary(x => x.IdxMacchina, x => $"{x.IdxMacchina} | {x.Nome}");
}
CurrLevel = MStor.PageLevel(NavMan.Uri);
// recupero menù
if (MStor.DictMenu.ContainsKey(CurrLevel))
{
CurrMenuItems = MStor.DictMenu[CurrLevel];
}
await Task.Delay(1);
}
private static Logger Log = LogManager.GetCurrentClassLogger();
protected async Task ForceReload()
{
Stopwatch sw = new Stopwatch();
sw.Start();
Log.Info("Start ForceReload");
ResetClass = "btn-warning";
await InvokeAsync(StateHasChanged);
await MServ.ClearLocalStor();
await MServ.ClearSessionStor();
MStor.ClearCache();
await MDataService.FlushCache();
var allData = await MDataService.ListLinkAll();
MStor.SetupMenu(allData);
var allConf = await MDataService.ConfigGetAll();
MStor.SetConfig(allConf);
sw.Stop();
int delta = 400 - (int)sw.ElapsedMilliseconds;
if (delta > 0)
{
await Task.Delay(delta);
}
ResetClass = "btn-primary";
// await InvokeAsync(StateHasChanged);
Log.Info($"ForceReload completed in {sw.ElapsedMilliseconds}ms");
// ricarica pagina!
NavMan.NavigateTo("/", true);
}
private void OnYes()
{
Console.WriteLine($"{DateTime.Now} | 'Yes' button selected.");
}
}