Files
FA_WEB/OrdersManagement/Components/Layout/MainLayout.razor

101 lines
3.8 KiB
Plaintext

@inherits LayoutComponentBase
@using System.Security.Claims
@using Microsoft.AspNetCore.Components.Authorization
@using Syncfusion.Blazor.Navigations
@using static Syncfusion.Blazor.Navigations.Orientation
@using Syncfusion.Blazor.Buttons
@inject NavigationManager NavigationManager
@inject CustomAuthenticationStateProvider AuthenticationStateProvider
<div class="page h-100 d-flex flex-column">
<main class="container-fluid d-flex flex-column h-100">
<div class="bb-top-row px-4 d-flex justify-content-between align-items-center mb-3 shadow-sm"
style="background-color: #f8f9fa;">
<div class="d-flex align-items-center" style="margin: 10px">
<img src="logo.svg" class="me-2" width="35" height="35" alt="Icon">
<h3 class="text-primary m-0">FA Krosno Manager</h3>
</div>
@* <div class="d-flex align-items-center"> *@
@* @if (IsAuthenticated) *@
@* { *@
@* <span class="me-2">Jesteś zalogowany jako <strong>@UserName</strong></span> *@
@* <SfButton CssClass="e-primary" IsPrimary="true" @onclick="Logout">Wyloguj</SfButton> *@
@* } *@
@* else *@
@* { *@
@* <a href="/login" class="text-muted">Zaloguj</a> *@
@* } *@
@* </div> *@
</div>
<div class="row gx-1 flex-grow-1">
<div class="col-auto custom-menu-width">
<SfMenu TValue="MenuItem" HamburgerMode="true" Orientation="Vertical" Title="Menu">
<MenuItems>
<MenuItem Text="Zamówienia DELFOR" Url="/" IconCss="fa-solid fa-landmark"></MenuItem>
<MenuItem Text="Zarządzanie Indeksami" Url="/Products" IconCss="fa-solid fa-basket-shopping"></MenuItem>
<MenuItem Text="Magazyn" Url="/Warehouse" IconCss="fa-solid fa-warehouse"></MenuItem>
@if (IsAdminRoute())
{
<MenuItem Text="Administracja" Url="/Admin/PK" IconCss="fa-solid fa-screwdriver-wrench">
<MenuItems>
<MenuItem Text="Użytkownicy" Url = "/Admin/PK/UsersManager" IconCss="fa-solid fa-user-tie"></MenuItem>
<MenuItem Text="Scheduler" Url = "/Admin/PK/Scheduler" IconCss="fa-solid fa-calendar-week"></MenuItem>
<MenuItem Text="Zamówienia klienta EDI" Url="/Admin/PK/EdiCustomerOrders" IconCss="fa-solid fa-list-check"></MenuItem>
<MenuItem Text="Zamówienia klienta" Url="/Admin/PK/CustomerOrders" IconCss="fa-solid fa-database"></MenuItem>
</MenuItems>
</MenuItem>
}
</MenuItems>
<MenuAnimationSettings Effect="MenuEffect.SlideDown" Duration="800"></MenuAnimationSettings>
</SfMenu>
</div>
<article class="content col d-flex flex-column">
<div class="py-2 flex-grow-1">@Body</div>
<footer class="text-center text-muted py-2">
<small>FA Krosno Manager © @(DateTime.Now.Year)</small>
</footer>
</article>
</div>
</main>
</div>
@code {
private bool IsAuthenticated { get; set; }
private string UserName { get; set; } = string.Empty;
private bool IsAdminRoute()
{
var path = new Uri(NavigationManager.Uri).AbsolutePath;
return path.StartsWith("/admin", StringComparison.OrdinalIgnoreCase);
}
protected override void OnInitialized()
{
// ClaimsPrincipal currentUser = AuthenticationStateProvider.GetCurrentUser();
// IsAuthenticated = currentUser.Identity?.IsAuthenticated == true;
// UserName = currentUser.Identity?.Name ?? "Nieznany użytkownik";
//
// AuthenticationStateProvider.AuthenticationStateChanged += OnAuthenticationStateChanged;
}
private async void OnAuthenticationStateChanged(Task<AuthenticationState> task)
{
var authState = await task;
IsAuthenticated = authState.User.Identity?.IsAuthenticated ?? false;
UserName = IsAuthenticated ? authState.User.Identity?.Name ?? "Nieznany użytkownik" : string.Empty;
StateHasChanged();
}
private void Logout()
{
NavigationManager.NavigateTo("/");
}
}
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>