From 2ca5cbf8a5547a0557c8823523e30dbdfd514887 Mon Sep 17 00:00:00 2001 From: mirage <119869686+ClementBobin@users.noreply.github.com> Date: Thu, 26 Mar 2026 13:34:19 +0100 Subject: [PATCH] =?UTF-8?q?refactor:=20remplace=20l=E2=80=99invocation=20d?= =?UTF-8?q?u=20composant=20Sidebar=20par=20un=20composant=20de=20vue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ArtisteController.cs | 2 +- .../ViewComponents/SidebarViewComponent.cs | 35 +++++++++++++ .../Shared/Components/Sidebar/Default.cshtml | 23 +++++++++ .../Views/Shared/_Layout.cshtml | 24 ++++----- .../Views/Shared/_Sidebar.cshtml | 51 ------------------- 5 files changed, 71 insertions(+), 64 deletions(-) create mode 100644 Webzine.WebApplication/ViewComponents/SidebarViewComponent.cs create mode 100644 Webzine.WebApplication/Views/Shared/Components/Sidebar/Default.cshtml delete mode 100644 Webzine.WebApplication/Views/Shared/_Sidebar.cshtml diff --git a/Webzine.WebApplication/Controllers/ArtisteController.cs b/Webzine.WebApplication/Controllers/ArtisteController.cs index 68b2443..b63f140 100644 --- a/Webzine.WebApplication/Controllers/ArtisteController.cs +++ b/Webzine.WebApplication/Controllers/ArtisteController.cs @@ -31,7 +31,7 @@ [HttpGet("/artiste/{nom}")] public IActionResult Index(string nom) { - this.logger.LogInformation("Tentative d'accès à l'artiste avec le nom : {NomArtiste}", nom); + this._logger.LogInformation("Tentative d'accès à l'artiste avec le nom : {NomArtiste}", nom); if (string.IsNullOrEmpty(nom)) { diff --git a/Webzine.WebApplication/ViewComponents/SidebarViewComponent.cs b/Webzine.WebApplication/ViewComponents/SidebarViewComponent.cs new file mode 100644 index 0000000..27f2c7a --- /dev/null +++ b/Webzine.WebApplication/ViewComponents/SidebarViewComponent.cs @@ -0,0 +1,35 @@ +using Microsoft.AspNetCore.Mvc; +using Webzine.Repository.Contracts; + +namespace Webzine.WebApplication.ViewComponents +{ + /// + /// View component pour la sidebar, récupère les styles depuis le repository. + /// + public class SidebarViewComponent : ViewComponent + { + private readonly IStyleRepository styleRepository; + + /// + /// Initializes a new instance of the class. + /// + /// Repository des styles injecté. + public SidebarViewComponent(IStyleRepository styleRepository) + { + this.styleRepository = styleRepository; + } + + /// + /// Récupère tous les styles triés par libellé et les passe à la vue. + /// + /// Une vue contenant la liste des styles. + public IViewComponentResult Invoke() + { + var styles = this.styleRepository.FindAll() + .OrderBy(s => s.Libelle) + .ToList(); + + return this.View(styles); + } + } +} \ No newline at end of file diff --git a/Webzine.WebApplication/Views/Shared/Components/Sidebar/Default.cshtml b/Webzine.WebApplication/Views/Shared/Components/Sidebar/Default.cshtml new file mode 100644 index 0000000..d7ce8b9 --- /dev/null +++ b/Webzine.WebApplication/Views/Shared/Components/Sidebar/Default.cshtml @@ -0,0 +1,23 @@ +@model IEnumerable + + \ No newline at end of file diff --git a/Webzine.WebApplication/Views/Shared/_Layout.cshtml b/Webzine.WebApplication/Views/Shared/_Layout.cshtml index 234b357..5d11de0 100644 --- a/Webzine.WebApplication/Views/Shared/_Layout.cshtml +++ b/Webzine.WebApplication/Views/Shared/_Layout.cshtml @@ -11,19 +11,19 @@ - - - - - @RenderBody() - - @if(ViewContext.RouteData.Values["area"]?.ToString() != "Administration") - { - - } - + + + + + @RenderBody() + + @if(ViewContext.RouteData.Values["area"]?.ToString() != "Administration") + { + @await Component.InvokeAsync("Sidebar") + } - + +