From 7080fa845014e6e06106c3322c55e20ca3b0eb2f Mon Sep 17 00:00:00 2001 From: Christophe Date: Mon, 13 Apr 2026 23:04:21 +0200 Subject: [PATCH] Ajout d'un menu general en haut du site --- ChessCubing.App/Components/SiteMenu.razor | 112 ++++++++++ .../Components/UserAccessBar.razor | 108 --------- ChessCubing.App/Layout/MainLayout.razor | 21 ++ ChessCubing.App/Pages/ApplicationPage.razor | 1 - ChessCubing.App/Pages/Home.razor | 7 - ChessCubing.App/Pages/RulesPage.razor | 1 - README.md | 3 +- styles.css | 209 +++++++++++++----- 8 files changed, 290 insertions(+), 172 deletions(-) create mode 100644 ChessCubing.App/Components/SiteMenu.razor delete mode 100644 ChessCubing.App/Components/UserAccessBar.razor diff --git a/ChessCubing.App/Components/SiteMenu.razor b/ChessCubing.App/Components/SiteMenu.razor new file mode 100644 index 0000000..90dc54b --- /dev/null +++ b/ChessCubing.App/Components/SiteMenu.razor @@ -0,0 +1,112 @@ +@using System.Security.Claims +@inject NavigationManager Navigation + + + +@code { + private static readonly string[] HomePaths = ["", "index.html"]; + private static readonly string[] ApplicationPaths = ["application", "application.html"]; + private static readonly string[] RulesPaths = ["reglement", "reglement.html"]; + + private string LoginHref => BuildAuthHref("login", EffectiveReturnUrl); + private string RegisterHref => BuildAuthHref("register", EffectiveReturnUrl); + private string LogoutHref => BuildAuthHref("logout", "/"); + + private string CurrentPath + { + get + { + var absolutePath = new Uri(Navigation.Uri).AbsolutePath; + return absolutePath.Trim('/'); + } + } + + private string EffectiveReturnUrl + { + get + { + var absolutePath = new Uri(Navigation.Uri).AbsolutePath; + if (absolutePath.StartsWith("/authentication/", StringComparison.OrdinalIgnoreCase)) + { + return "/"; + } + + return string.IsNullOrWhiteSpace(absolutePath) + ? "/" + : absolutePath; + } + } + + private string BuildNavLinkClass(string[] paths) + => IsCurrentPage(paths) ? "site-menu-link is-active" : "site-menu-link"; + + private string? BuildAriaCurrent(string[] paths) + => IsCurrentPage(paths) ? "page" : null; + + private bool IsCurrentPage(string[] paths) + => paths.Any(path => string.Equals(CurrentPath, path, StringComparison.OrdinalIgnoreCase)); + + private static string BuildAuthHref(string action, string returnUrl) + => $"authentication/{action}?returnUrl={Uri.EscapeDataString(returnUrl)}"; + + private static string BuildDisplayName(ClaimsPrincipal user) + => user.Identity?.Name + ?? user.FindFirst("name")?.Value + ?? user.FindFirst("preferred_username")?.Value + ?? "Utilisateur connecte"; + + private static string BuildMeta(ClaimsPrincipal user) + => user.FindFirst("email")?.Value + ?? "Session active"; +} diff --git a/ChessCubing.App/Components/UserAccessBar.razor b/ChessCubing.App/Components/UserAccessBar.razor deleted file mode 100644 index 2620f19..0000000 --- a/ChessCubing.App/Components/UserAccessBar.razor +++ /dev/null @@ -1,108 +0,0 @@ -@using System.Security.Claims -@inject NavigationManager Navigation - - - -
-
- Compte Keycloak - @BuildDisplayName(authState.User) - @BuildMeta(authState.User) -
- -
-
- -
-
- Compte Keycloak - Connexion optionnelle - Le site reste accessible sans connexion. Vous pouvez vous connecter ou creer un compte si besoin. -
- -
-
- -
-
- Compte Keycloak - Connexion optionnelle - Le site reste accessible sans connexion. Chaque compte conserve son propre etat de match dans ce navigateur. -
- -
-
-
- -@code { - [Parameter] - public string? ReturnUrl { get; set; } - - private string LoginHref => BuildAuthHref("login", EffectiveReturnUrl); - private string RegisterHref => BuildAuthHref("register", EffectiveReturnUrl); - private string LogoutHref => BuildAuthHref("logout", "/"); - - private string EffectiveReturnUrl - { - get - { - if (!string.IsNullOrWhiteSpace(ReturnUrl)) - { - return ReturnUrl!; - } - - var relativePath = Navigation.ToBaseRelativePath(Navigation.Uri); - if (string.IsNullOrWhiteSpace(relativePath)) - { - return "/"; - } - - return relativePath.StartsWith("/", StringComparison.Ordinal) - ? relativePath - : $"/{relativePath}"; - } - } - - private static string BuildAuthHref(string action, string returnUrl) - => $"authentication/{action}?returnUrl={Uri.EscapeDataString(returnUrl)}"; - - private static string BuildDisplayName(ClaimsPrincipal user) - => user.Identity?.Name - ?? user.FindFirst("name")?.Value - ?? user.FindFirst("preferred_username")?.Value - ?? "Utilisateur connecte"; - - private static string BuildMeta(ClaimsPrincipal user) - { - var details = new List(); - var email = user.FindFirst("email")?.Value; - if (!string.IsNullOrWhiteSpace(email)) - { - details.Add(email); - } - - var roles = user.FindAll("role") - .Select(claim => claim.Value) - .Where(value => !string.IsNullOrWhiteSpace(value)) - .Distinct(StringComparer.OrdinalIgnoreCase) - .OrderBy(value => value, StringComparer.OrdinalIgnoreCase) - .ToArray(); - - if (roles.Length > 0) - { - details.Add($"Roles : {string.Join(", ", roles)}"); - } - - return details.Count > 0 - ? string.Join(" | ", details) - : "Session authentifiee via Keycloak."; - } -} diff --git a/ChessCubing.App/Layout/MainLayout.razor b/ChessCubing.App/Layout/MainLayout.razor index 4f3f76d..200d7c3 100644 --- a/ChessCubing.App/Layout/MainLayout.razor +++ b/ChessCubing.App/Layout/MainLayout.razor @@ -1,3 +1,24 @@ @inherits LayoutComponentBase +@inject NavigationManager Navigation + +@if (!HideGlobalMenu) +{ + +} @Body + +@code { + private bool HideGlobalMenu + { + get + { + var currentPath = new Uri(Navigation.Uri).AbsolutePath.Trim('/'); + + return string.Equals(currentPath, "chrono", StringComparison.OrdinalIgnoreCase) + || string.Equals(currentPath, "chrono.html", StringComparison.OrdinalIgnoreCase) + || string.Equals(currentPath, "cube", StringComparison.OrdinalIgnoreCase) + || string.Equals(currentPath, "cube.html", StringComparison.OrdinalIgnoreCase); + } + } +} diff --git a/ChessCubing.App/Pages/ApplicationPage.razor b/ChessCubing.App/Pages/ApplicationPage.razor index da8e335..b8e469f 100644 --- a/ChessCubing.App/Pages/ApplicationPage.razor +++ b/ChessCubing.App/Pages/ApplicationPage.razor @@ -23,7 +23,6 @@ Accueil du site Consulter le reglement -