Merge pull request 'feat: #32 #33 ajout du contrôleur et du modèle de vue pour le tableau de bord de l'administration' (#66) from J1/feat/administration/dashboard into dev
Reviewed-on: http://10.4.0.131/DI1-P4-E1/Webzine/pulls/66 Reviewed-by: j.vetu <josephine.vetu@diiage.org>
This commit is contained in:
@@ -0,0 +1,82 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Webzine.Entity;
|
||||||
|
using Webzine.Entity.Fixtures;
|
||||||
|
using Webzine.WebApplication.Areas.Administration.ViewModels;
|
||||||
|
|
||||||
|
namespace Webzine.WebApplication.Areas.Administration.Controllers;
|
||||||
|
|
||||||
|
[Area("Administration")]
|
||||||
|
public class DashboardController : Controller
|
||||||
|
{
|
||||||
|
private readonly ILogger<DashboardController> _logger;
|
||||||
|
private readonly List<Titre> _titres;
|
||||||
|
private readonly List<Style> _styles;
|
||||||
|
private readonly List<Artiste> _artistes;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initialise une nouvelle instance du <see cref="DashboardController"/>.
|
||||||
|
/// Les données sont générées dynamiquement via <see cref="DataFactory"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logger">Service de journalisation injecté.</param>
|
||||||
|
public DashboardController(ILogger<DashboardController> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
|
||||||
|
_logger.LogInformation("Initialisation du contrôleur TitreController.");
|
||||||
|
|
||||||
|
var factory = new DataFactory();
|
||||||
|
|
||||||
|
_artistes = factory.GenerateArtists(10);
|
||||||
|
_styles = factory.GenerateStyles(10);
|
||||||
|
_titres = factory.GenerateTitres(30, _artistes, _styles);
|
||||||
|
|
||||||
|
factory.GenerateCommentaires(50, _titres);
|
||||||
|
|
||||||
|
_logger.LogInformation("Données fictives générées avec succès.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Affiche le tableau de bord de l'administration.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>La vue Index du tableau de bord.</returns>
|
||||||
|
public IActionResult Index()
|
||||||
|
{
|
||||||
|
var mostChronicledArtist = _titres
|
||||||
|
.GroupBy(t => t.Artiste)
|
||||||
|
.OrderByDescending(g => g.Count())
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
var topArtistAlbums = _titres
|
||||||
|
.GroupBy(t => t.Artiste)
|
||||||
|
.OrderByDescending(g => g.Select(t => t.Album).Distinct().Count())
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
var mostPlayedTrack = _titres
|
||||||
|
.OrderByDescending(t => t.NbLectures)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
var model = new DashboardViewModel
|
||||||
|
{
|
||||||
|
ArtistCount = _artistes.Count,
|
||||||
|
|
||||||
|
MostChronicledArtistName = mostChronicledArtist?.Key.Nom,
|
||||||
|
|
||||||
|
TopArtistAlbumsName = topArtistAlbums?.Key.Nom,
|
||||||
|
|
||||||
|
BiographyCount = _artistes.Count(a => !string.IsNullOrEmpty(a.Biographie)),
|
||||||
|
|
||||||
|
MostPlayedTrackId = mostPlayedTrack?.IdTitre ?? 0,
|
||||||
|
MostPlayedTrack = mostPlayedTrack?.Libelle,
|
||||||
|
|
||||||
|
TrackCount = _titres.Count,
|
||||||
|
|
||||||
|
GenreCount = _styles.Count,
|
||||||
|
|
||||||
|
TotalPlays = _titres.Sum(t => t.NbLectures),
|
||||||
|
|
||||||
|
TotalLikes = _titres.Sum(t => t.NbLikes)
|
||||||
|
};
|
||||||
|
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
namespace Webzine.WebApplication.Areas.Administration.ViewModels;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ViewModel pour le tableau de bord de l'administration du webzine.
|
||||||
|
/// </summary>
|
||||||
|
public class DashboardViewModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Définit le nombre total d'artistes chroniqués dans le webzine.
|
||||||
|
/// </summary>
|
||||||
|
public int ArtistCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Définit le nom de l'artiste le plus chroniqué dans le webzine.
|
||||||
|
/// </summary>
|
||||||
|
public string MostChronicledArtistName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Définit le nom de l'album le plus chroniqué dans le webzine.
|
||||||
|
/// </summary>
|
||||||
|
public string TopArtistAlbumsName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Définit le nombre total de biographies d'artistes dans le webzine.
|
||||||
|
/// </summary>
|
||||||
|
public int BiographyCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Définit l'identifiant de la biographie d'artiste la plus lue dans le webzine.
|
||||||
|
/// </summary>
|
||||||
|
public int MostPlayedTrackId { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Définit le nom de la biographie d'artiste la plus lue dans le webzine.
|
||||||
|
/// </summary>
|
||||||
|
public string MostPlayedTrack { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Définit le nombre total de titres chroniqués dans le webzine.
|
||||||
|
/// </summary>
|
||||||
|
public int TrackCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Définit le nombre total de genres musicaux chroniqués dans le webzine.
|
||||||
|
/// </summary>
|
||||||
|
public int GenreCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Définit le nombre total de chroniques d'albums dans le webzine.
|
||||||
|
/// </summary>
|
||||||
|
public int TotalPlays { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Définit le nombre total de likes sur les chroniques d'albums dans le webzine.
|
||||||
|
/// </summary>
|
||||||
|
public int TotalLikes { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,194 @@
|
|||||||
|
@model Webzine.WebApplication.Areas.Administration.ViewModels.DashboardViewModel
|
||||||
|
|
||||||
|
<h1 class="mb-4">Tableau de bord</h1>
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<div class="row g-4 text-center">
|
||||||
|
|
||||||
|
<!-- ARTISTS -->
|
||||||
|
<div class="col-md-4">
|
||||||
|
<a asp-area="Administration"
|
||||||
|
asp-controller="Artiste"
|
||||||
|
class="text-decoration-none">
|
||||||
|
|
||||||
|
<div class="card shadow-sm p-4 bg-light h-100 dashboard-card">
|
||||||
|
<i class="fa fa-users fa-3x text-primary mb-3"></i>
|
||||||
|
|
||||||
|
<h3 class="text-primary">
|
||||||
|
@Model.ArtistCount
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<p class="text-primary">
|
||||||
|
artistes
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- L'ARTIST LE PLUS CHRONICLED -->
|
||||||
|
<div class="col-md-4">
|
||||||
|
<a asp-area=""
|
||||||
|
asp-controller="Artiste"
|
||||||
|
asp-route-nom="@Model.MostChronicledArtistName"
|
||||||
|
class="text-decoration-none">
|
||||||
|
|
||||||
|
<div class="card shadow-sm p-4 bg-light h-100 dashboard-card">
|
||||||
|
<i class="fa fa-user fa-3x text-primary mb-3"></i>
|
||||||
|
|
||||||
|
<h3 class="text-primary">
|
||||||
|
@Model.MostChronicledArtistName
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<p class="text-primary">
|
||||||
|
artiste le plus chroniqué
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- LE PLUS D'ALBUMS -->
|
||||||
|
<div class="col-md-4">
|
||||||
|
<a asp-area=""
|
||||||
|
asp-controller="Artiste"
|
||||||
|
asp-route-nom="@Model.TopArtistAlbumsName"
|
||||||
|
class="text-decoration-none">
|
||||||
|
|
||||||
|
<div class="card shadow-sm p-4 bg-light h-100 dashboard-card">
|
||||||
|
<i class="fa fa-trophy fa-3x text-primary mb-3"></i>
|
||||||
|
|
||||||
|
<h3 class="text-primary">
|
||||||
|
@Model.TopArtistAlbumsName
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<p class="text-primary">
|
||||||
|
artiste avec le plus d'albums distincts
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- BIOGRAPHIES -->
|
||||||
|
<div class="col-md-4">
|
||||||
|
<a asp-area="Administration"
|
||||||
|
asp-controller="Titre"
|
||||||
|
class="text-decoration-none">
|
||||||
|
|
||||||
|
<div class="card shadow-sm p-4 bg-light h-100 dashboard-card">
|
||||||
|
<i class="fa fa-book fa-3x text-primary mb-3"></i>
|
||||||
|
|
||||||
|
<h3 class="text-primary">
|
||||||
|
@Model.BiographyCount
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<p class="text-primary">
|
||||||
|
biographies d'artistes
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- LA TRACK AVEC LE PLUS D'ÉCOUTE -->
|
||||||
|
<div class="col-md-4">
|
||||||
|
<a asp-area=""
|
||||||
|
asp-controller="Titre"
|
||||||
|
asp-action="Details"
|
||||||
|
asp-route-id="@Model.MostPlayedTrackId"
|
||||||
|
class="text-decoration-none">
|
||||||
|
|
||||||
|
<div class="card shadow-sm p-4 bg-light h-100 dashboard-card">
|
||||||
|
<i class="fa fa-compact-disc fa-3x text-primary mb-3"></i>
|
||||||
|
|
||||||
|
<h4 class="text-primary">
|
||||||
|
@Model.MostPlayedTrack
|
||||||
|
</h4>
|
||||||
|
|
||||||
|
<p class="text-primary">
|
||||||
|
titre le plus lu
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- TITRE NOMBRE -->
|
||||||
|
<div class="col-md-4">
|
||||||
|
<a asp-area="Administration"
|
||||||
|
asp-controller="Titre"
|
||||||
|
class="text-decoration-none">
|
||||||
|
|
||||||
|
<div class="card shadow-sm p-4 bg-light h-100 dashboard-card">
|
||||||
|
<i class="fa fa-music fa-3x text-primary mb-3"></i>
|
||||||
|
|
||||||
|
<h3 class="text-primary">
|
||||||
|
@Model.TrackCount
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<p class="text-primary">
|
||||||
|
titres
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- GENRES -->
|
||||||
|
<div class="col-md-4">
|
||||||
|
<a asp-area="Administration"
|
||||||
|
asp-controller="Styles"
|
||||||
|
class="text-decoration-none">
|
||||||
|
|
||||||
|
<div class="card shadow-sm p-4 bg-light h-100 dashboard-card">
|
||||||
|
<i class="fa fa-tags fa-3x text-primary mb-3"></i>
|
||||||
|
|
||||||
|
<h3 class="text-primary">
|
||||||
|
@Model.GenreCount
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<p class="text-primary">
|
||||||
|
styles de musique
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- NOMBRE DE LECTURES -->
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card shadow-sm p-4 bg-light h-100">
|
||||||
|
<i class="fa fa-eye fa-3x text-dark mb-3"></i>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
@Model.TotalPlays
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
lectures
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- TOTAL LIKES -->
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card shadow-sm p-4 bg-light h-100">
|
||||||
|
<i class="fa fa-thumbs-up fa-3x text-dark mb-3"></i>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
@Model.TotalLikes
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
likes
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user