diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ComposentComplex.razor b/WF-WebAdmin/WF-WebAdmin/Pages/ComposentComplex.razor new file mode 100644 index 0000000..ba982d0 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ComposentComplex.razor @@ -0,0 +1,14 @@ +@page "/graph" +@using Syncfusion.Blazor.Charts + + + + + + + + + + + + diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ComposentComplex.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ComposentComplex.razor.cs new file mode 100644 index 0000000..5d22acb --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ComposentComplex.razor.cs @@ -0,0 +1,92 @@ +using Microsoft.AspNetCore.Components; +using MudBlazor; +using Syncfusion.Blazor.Charts.Chart.Internal; +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 class SalesInfo + { + public string Month { get; set; } + public double SalesValue { get; set; } + } + public partial class ComposentComplex : ComponentBase + { + [Inject] public ICommentaryService CommentaryService { get; set; } = default!; + + public List Labels { get; set; } = new(); + public List ChartData { get; set; } = new(); + public List AvailableYears { get; set; } = new(); + public int SelectedYear { get; set; } + + private List AllComments = new(); + + + public List Sales = new List + { + new SalesInfo { Month = "Jan", SalesValue = 35 }, + new SalesInfo { Month = "Feb", SalesValue = 28 }, + new SalesInfo { Month = "Mar", SalesValue = 34 }, + new SalesInfo { Month = "Apr", SalesValue = 28 }, + new SalesInfo { Month = "May", SalesValue = 40 }, + new SalesInfo { Month = "Jun", SalesValue = 32 }, + new SalesInfo { Month = "Jul", SalesValue = 35 }, + new SalesInfo { Month = "Aug", SalesValue = 55 }, + new SalesInfo { Month = "Sep", SalesValue = 38 }, + new SalesInfo { Month = "Oct", SalesValue = 30 }, + new SalesInfo { Month = "Nov", SalesValue = 25 }, + new SalesInfo { Month = "Dec", SalesValue = 32 } + }; + protected override async Task OnInitializedAsync() + { + // Charger tous les commentaires + AllComments = await CommentaryService.GetCommentsAsync(); + + if (!AllComments.Any()) + { + Labels = new List { "Aucun commentaire" }; + ChartData = new List { 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 { "Aucun commentaire" }; + ChartData = new List { new double[] { 0 } }; + return; + } + + foreach (var sale in Sales) + { + sale.SalesValue = filteredComments.Count(c => c.DateCreation.Month.ToString("MMM", CultureInfo.InvariantCulture) == sale.Month); + } + + } + + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Program.cs b/WF-WebAdmin/WF-WebAdmin/Program.cs index 765abff..527dcba 100644 --- a/WF-WebAdmin/WF-WebAdmin/Program.cs +++ b/WF-WebAdmin/WF-WebAdmin/Program.cs @@ -14,6 +14,7 @@ using Blazored.Modal; using WF_WebAdmin.Service; using Microsoft.Extensions.Logging; using MudBlazor.Services; +using Syncfusion.Blazor; [assembly: RootNamespace("WF_WebAdmin")] @@ -32,6 +33,8 @@ builder.Services.AddScoped(); builder.Services.AddMudServices(); builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging")); +builder.Services.AddSyncfusionBlazor(); + builder.Services .AddBlazorise() .AddBootstrapProviders() diff --git a/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor b/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor index a9174b8..9de0104 100644 --- a/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor +++ b/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor @@ -59,6 +59,11 @@ Stats commentaires + diff --git a/WF-WebAdmin/WF-WebAdmin/WF-WebAdmin.csproj b/WF-WebAdmin/WF-WebAdmin/WF-WebAdmin.csproj index 47115cb..f11e9db 100644 --- a/WF-WebAdmin/WF-WebAdmin/WF-WebAdmin.csproj +++ b/WF-WebAdmin/WF-WebAdmin/WF-WebAdmin.csproj @@ -18,6 +18,7 @@ + diff --git a/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataCommentary.json b/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataCommentary.json index 5b39c76..b77e700 100644 --- a/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataCommentary.json +++ b/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataCommentary.json @@ -143,7 +143,7 @@ "id_comment": 21, "quote": 7, "users": 21, - "dateC": "2024-8-30", + "dateC": "2024-08-30", "comment": "Belle pensée." }, {