ça ne marche pas mais je n'y arrive pas tant pis au moins la page est propre
continuous-integration/drone/push Build is passing Details

master
Maxime ROCHER 2 months ago
parent 67b4094d81
commit f6bd5d2fc1

@ -10,10 +10,16 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" /> <PackageReference Include="coverlet.collector" Version="6.0.4">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> <PrivateAssets>all</PrivateAssets>
<PackageReference Include="xunit" Version="2.5.3" /> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" /> </PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

@ -0,0 +1,23 @@
using System;
using System.Text.Json.Serialization;
namespace WF_WebAdmin.Converter
{
public class CommentaryDTO
{
[JsonPropertyName("id_comment")]
public int Id { get; set; }
[JsonPropertyName("quote")]
public int Quote { get; set; }
[JsonPropertyName("users")]
public int IdUser { get; set; }
[JsonPropertyName("dateC")]
public string DateCreationRaw { get; set; } = string.Empty;
[JsonPropertyName("comment")]
public string Text { get; set; } = string.Empty;
}
}

@ -0,0 +1,46 @@
using System;
using System.Globalization;
using WF_WebAdmin.Converter;
namespace WF_WebAdmin.Model
{
public static class CommentaryExtensions
{
public static Commentary ToModel(this CommentaryDTO dto)
{
DateTime parsedDate = DateTime.MinValue;
if (!string.IsNullOrEmpty(dto.DateCreationRaw) &&
DateTime.TryParseExact(dto.DateCreationRaw, "yyyy-MM-dd",
CultureInfo.InvariantCulture,
DateTimeStyles.None,
out DateTime result))
{
parsedDate = result;
}
else
{
Console.Out.WriteLine($"Erreur de conversion de la date : {dto.DateCreationRaw}");
}
return new Commentary
{
Id = dto.Id,
IdUser = dto.IdUser,
DateCreation = parsedDate,
Text = dto.Text
};
}
public static CommentaryDTO ToDTO(this Commentary model)
{
return new CommentaryDTO
{
Id = model.Id,
IdUser = model.IdUser,
DateCreationRaw = model.DateCreation.ToString("yyyy-MM-dd"),
Text = model.Text
};
}
}
}

@ -1,10 +1,12 @@
namespace WF_WebAdmin.Model using System;
namespace WF_WebAdmin.Model
{ {
public class Commentary public class Commentary
{ {
//public int Id { get; set; } public int Id { get; set; }
//public int IdUser { get; set; } public int IdUser { get; set; }
public string Text { get; set; }
public DateTime DateCreation { get; set; } public DateTime DateCreation { get; set; }
public string Text { get; set; } = string.Empty;
} }
} }

@ -0,0 +1,17 @@
@page "/commentary-chart"
@using MudBlazor
<MudCard Class="p-4">
<MudCardContent>
<h3 class="text-center mb-4">Statistiques des Commentaires - Année @SelectedYear</h3>
<MudSelect T="int" Label="Sélectionner l'année" @bind-SelectedValue="SelectedYear" Dense="true" Immediate="true" OnValueChanged="UpdateChartData">
@foreach (var year in AvailableYears)
{
<MudSelectItem T="int" Value="@year">@year</MudSelectItem>
}
</MudSelect>
<MudChart ChartType="ChartType.Bar" Labels="@Labels" Data="@ChartData" />
</MudCardContent>
</MudCard>

@ -0,0 +1,72 @@
using Microsoft.AspNetCore.Components;
using MudBlazor;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using WF_WebAdmin.Model;
using WF_WebAdmin.Service;
namespace WF_WebAdmin.Pages
{
public partial class CommentaryChart : ComponentBase
{
[Inject] public ICommentaryService CommentaryService { get; set; } = default!;
public List<string> Labels { get; set; } = new();
public List<double[]> ChartData { get; set; } = new();
public List<int> AvailableYears { get; set; } = new();
public int SelectedYear { get; set; }
private List<Commentary> AllComments = new();
protected override async Task OnInitializedAsync()
{
// Charger tous les commentaires
AllComments = await CommentaryService.GetCommentsAsync();
if (!AllComments.Any())
{
Labels = new List<string> { "Aucun commentaire" };
ChartData = new List<double[]> { new double[] { 0 } };
return;
}
AvailableYears = AllComments
.Select(c => c.DateCreation.Year)
.Distinct()
.OrderBy(y => y)
.ToList();
SelectedYear = AvailableYears.Max();
UpdateChartData(SelectedYear);
}
private void UpdateChartData(int newYear)
{
SelectedYear = newYear;
var filteredComments = AllComments
.Where(c => c.DateCreation.Year == SelectedYear)
.ToList();
if (!filteredComments.Any())
{
Labels = new List<string> { "Aucun commentaire" };
ChartData = new List<double[]> { new double[] { 0 } };
return;
}
var grouped = Enumerable.Range(1, 12)
.ToDictionary(
month => new DateTime(SelectedYear, month, 1).ToString("MMMM", CultureInfo.InvariantCulture),
month => filteredComments.Count(c => c.DateCreation.Month == month)
);
Labels = grouped.Keys.ToList();
ChartData = new List<double[]> { grouped.Values.Select(v => (double)v).ToArray() };
}
}
}

@ -13,6 +13,8 @@ using Microsoft.Extensions.Options;
using Blazored.Modal; using Blazored.Modal;
using WF_WebAdmin.Service; using WF_WebAdmin.Service;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using MudBlazor.Services;
[assembly: RootNamespace("WF_WebAdmin")] [assembly: RootNamespace("WF_WebAdmin")]
@ -24,10 +26,10 @@ builder.Services.AddSingleton<WeatherForecastService>();
builder.Services.AddScoped<IQuoteService,QuoteServiceStub>(); builder.Services.AddScoped<IQuoteService,QuoteServiceStub>();
builder.Services.AddScoped<IQuizService,QuizServiceStub>(); builder.Services.AddScoped<IQuizService,QuizServiceStub>();
builder.Services.AddScoped<IUserService, UserServiceStub>(); builder.Services.AddScoped<IUserService, UserServiceStub>();
builder.Services.AddScoped<ICommentaryService, CommentaryServiceStub>();
builder.Services.AddHttpClient(); builder.Services.AddHttpClient();
builder.Services.AddScoped<UserLogin>(); builder.Services.AddScoped<UserLogin>();
//builder.WebHost.UseUrls("http://0.0.0.0:5000"); builder.Services.AddMudServices();
builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging")); builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
builder.Services builder.Services

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Threading.Tasks;
using WF_WebAdmin.Converter;
using WF_WebAdmin.Model;
namespace WF_WebAdmin.Service
{
public class CommentaryServiceStub : ICommentaryService
{
private readonly string? _jsonFilePath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "fake-dataCommentary.json");
public async Task<List<Commentary>> GetCommentsAsync()
{
if (!File.Exists(_jsonFilePath))
{
Console.Out.WriteLine($"{_jsonFilePath} not found");
return new List<Commentary>();
}
var json = await File.ReadAllTextAsync(_jsonFilePath);
var dtoList = JsonSerializer.Deserialize<List<CommentaryDTO>>(json) ?? new List<CommentaryDTO>();
var comments = dtoList.ConvertAll(dto => dto.ToModel());
Console.Out.WriteLine($"Nombre de commentaires chargés : {comments.Count}");
return comments;
}
}
}

@ -0,0 +1,11 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using WF_WebAdmin.Model;
namespace WF_WebAdmin.Service
{
public interface ICommentaryService
{
Task<List<Commentary>> GetCommentsAsync();
}
}

@ -3,6 +3,7 @@
@inject UserLogin uLogin @inject UserLogin uLogin
<PageTitle>WF-WebAdmin</PageTitle> <PageTitle>WF-WebAdmin</PageTitle>
<MudThemeProvider />
<div class="page"> <div class="page">

@ -54,8 +54,11 @@
<span class="oi oi-list-rich" aria-hidden="true"></span> Logs <span class="oi oi-list-rich" aria-hidden="true"></span> Logs
</NavLink> </NavLink>
</div> </div>
<div class="nav-item px-3">
<MudNavLink class="nav-link" Href="/commentary-chart">
<span class="oi oi-list-rich" aria-hidden="true"></span> Stats commentaires
</MudNavLink>
</div>
</nav> </nav>
</div> </div>

@ -15,6 +15,7 @@
<PackageReference Include="bootstrap" Version="5.3.3" /> <PackageReference Include="bootstrap" Version="5.3.3" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="9.0.1" /> <PackageReference Include="Microsoft.Extensions.Localization" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="9.0.1" /> <PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="9.0.1" />
<PackageReference Include="MudBlazor" Version="6.2.0" />
<PackageReference Include="Npgsql" Version="9.0.2" /> <PackageReference Include="Npgsql" Version="9.0.2" />
<PackageReference Include="Blazored.Modal" Version="7.2.0" /> <PackageReference Include="Blazored.Modal" Version="7.2.0" />
</ItemGroup> </ItemGroup>

@ -10,4 +10,5 @@
@using WF_WebAdmin.Shared @using WF_WebAdmin.Shared
@using Blazorise.DataGrid @using Blazorise.DataGrid
@using Blazored.Modal @using Blazored.Modal
@using MudBlazor

@ -0,0 +1,5 @@
{
"version": "3.0",
"defaultProvider": "cdnjs",
"libraries": []
}

@ -0,0 +1,359 @@
[
{
"id_comment": 1,
"quote": 1,
"users": 1,
"dateC": "2024-10-10",
"comment": "coucou"
},
{
"id_comment": 2,
"quote": 1,
"users": 2,
"dateC": "2024-10-11",
"comment": "Super citation !"
},
{
"id_comment": 3,
"quote": 1,
"users": 3,
"dateC": "2024-10-12",
"comment": "Très inspirant."
},
{
"id_comment": 4,
"quote": 2,
"users": 4,
"dateC": "2024-10-13",
"comment": "J'adore cette phrase."
},
{
"id_comment": 5,
"quote": 2,
"users": 5,
"dateC": "2024-10-14",
"comment": "Citation profonde."
},
{
"id_comment": 6,
"quote": 2,
"users": 6,
"dateC": "2024-10-15",
"comment": "Belle pensée."
},
{
"id_comment": 7,
"quote": 3,
"users": 7,
"dateC": "2024-10-16",
"comment": "Très motivant."
},
{
"id_comment": 8,
"quote": 3,
"users": 8,
"dateC": "2024-10-17",
"comment": "Citation puissante."
},
{
"id_comment": 9,
"quote": 3,
"users": 9,
"dateC": "2024-10-18",
"comment": "Paroles sages."
},
{
"id_comment": 10,
"quote": 4,
"users": 10,
"dateC": "2024-10-19",
"comment": "Très réfléchi."
},
{
"id_comment": 11,
"quote": 4,
"users": 11,
"dateC": "2024-10-20",
"comment": "Citation magnifique."
},
{
"id_comment": 12,
"quote": 4,
"users": 12,
"dateC": "2024-10-21",
"comment": "Très touchant."
},
{
"id_comment": 13,
"quote": 5,
"users": 13,
"dateC": "2024-10-22",
"comment": "Citation parfaite."
},
{
"id_comment": 14,
"quote": 5,
"users": 14,
"dateC": "2024-10-23",
"comment": "Très émouvant."
},
{
"id_comment": 15,
"quote": 5,
"users": 15,
"dateC": "2024-10-24",
"comment": "Citation merveilleuse."
},
{
"id_comment": 16,
"quote": 6,
"users": 16,
"dateC": "2024-10-25",
"comment": "Très poétique."
},
{
"id_comment": 17,
"quote": 6,
"users": 17,
"dateC": "2024-10-26",
"comment": "Citation exceptionnelle."
},
{
"id_comment": 18,
"quote": 6,
"users": 18,
"dateC": "2024-10-27",
"comment": "Très inspirant."
},
{
"id_comment": 19,
"quote": 7,
"users": 19,
"dateC": "2024-10-28",
"comment": "J'adore cette phrase."
},
{
"id_comment": 20,
"quote": 7,
"users": 20,
"dateC": "2024-10-29",
"comment": "Citation profonde."
},
{
"id_comment": 21,
"quote": 7,
"users": 21,
"dateC": "2024-8-30",
"comment": "Belle pensée."
},
{
"id_comment": 22,
"quote": 8,
"users": 22,
"dateC": "2024-10-31",
"comment": "Très motivant."
},
{
"id_comment": 23,
"quote": 8,
"users": 23,
"dateC": "2024-11-01",
"comment": "Citation puissante."
},
{
"id_comment": 24,
"quote": 8,
"users": 24,
"dateC": "2024-11-02",
"comment": "Paroles sages."
},
{
"id_comment": 25,
"quote": 9,
"users": 25,
"dateC": "2024-11-03",
"comment": "Très réfléchi."
},
{
"id_comment": 26,
"quote": 9,
"users": 26,
"dateC": "2024-11-04",
"comment": "Citation magnifique."
},
{
"id_comment": 27,
"quote": 9,
"users": 27,
"dateC": "2024-11-05",
"comment": "Très touchant."
},
{
"id_comment": 28,
"quote": 10,
"users": 28,
"dateC": "2024-11-06",
"comment": "Citation parfaite."
},
{
"id_comment": 29,
"quote": 10,
"users": 29,
"dateC": "2024-11-07",
"comment": "Très émouvant."
},
{
"id_comment": 30,
"quote": 10,
"users": 30,
"dateC": "2024-11-08",
"comment": "Citation merveilleuse."
},
{
"id_comment": 31,
"quote": 11,
"users": 31,
"dateC": "2024-11-09",
"comment": "Très poétique."
},
{
"id_comment": 32,
"quote": 11,
"users": 32,
"dateC": "2024-11-10",
"comment": "Citation exceptionnelle."
},
{
"id_comment": 33,
"quote": 11,
"users": 33,
"dateC": "2024-11-11",
"comment": "Très inspirant."
},
{
"id_comment": 34,
"quote": 12,
"users": 34,
"dateC": "2024-11-12",
"comment": "J'adore cette phrase."
},
{
"id_comment": 35,
"quote": 12,
"users": 35,
"dateC": "2024-11-13",
"comment": "Citation profonde."
},
{
"id_comment": 36,
"quote": 12,
"users": 36,
"dateC": "2024-11-14",
"comment": "Belle pensée."
},
{
"id_comment": 37,
"quote": 13,
"users": 37,
"dateC": "2024-11-15",
"comment": "Très motivant."
},
{
"id_comment": 38,
"quote": 13,
"users": 38,
"dateC": "2024-11-16",
"comment": "Citation puissante."
},
{
"id_comment": 39,
"quote": 13,
"users": 39,
"dateC": "2024-11-17",
"comment": "Paroles sages."
},
{
"id_comment": 40,
"quote": 14,
"users": 40,
"dateC": "2024-11-18",
"comment": "Très réfléchi."
},
{
"id_comment": 41,
"quote": 14,
"users": 41,
"dateC": "2024-11-19",
"comment": "Citation magnifique."
},
{
"id_comment": 42,
"quote": 14,
"users": 42,
"dateC": "2024-11-20",
"comment": "Très touchant."
},
{
"id_comment": 43,
"quote": 15,
"users": 43,
"dateC": "2024-11-21",
"comment": "Citation parfaite."
},
{
"id_comment": 44,
"quote": 15,
"users": 44,
"dateC": "2024-11-22",
"comment": "Très émouvant."
},
{
"id_comment": 45,
"quote": 15,
"users": 45,
"dateC": "2024-11-23",
"comment": "Citation merveilleuse."
},
{
"id_comment": 46,
"quote": 16,
"users": 46,
"dateC": "2024-11-24",
"comment": "Très poétique."
},
{
"id_comment": 47,
"quote": 16,
"users": 47,
"dateC": "2024-11-25",
"comment": "Citation exceptionnelle."
},
{
"id_comment": 48,
"quote": 16,
"users": 48,
"dateC": "2024-11-26",
"comment": "Très inspirant."
},
{
"id_comment": 49,
"quote": 17,
"users": 49,
"dateC": "2024-11-27",
"comment": "J'adore cette phrase."
},
{
"id_comment": 50,
"quote": 17,
"users": 50,
"dateC": "2024-11-28",
"comment": "Citation profonde."
},
{
"id_comment": 51,
"quote": 17,
"users": 51,
"dateC": "2024-11-29",
"comment": "Belle pensée."
}
]

@ -1,9 +0,0 @@
[
{
"id_comment": 1,
"quote": 1,
"users": 1,
"dateC":"2024-10-10",
"comment": "coucou"
}
]
Loading…
Cancel
Save