From ef9d748045ef4894cd46bd154eae0c2eb874cd9d Mon Sep 17 00:00:00 2001 From: Louis GUICHARD-MONTGUERS Date: Wed, 15 Jan 2025 14:13:45 +0100 Subject: [PATCH] vue validQuote + lien avec le json et ajout bouttons --- .../WF-WebAdmin/Pages/DeleteUser.razor.cs | 94 ++++++------ .../WF-WebAdmin/Pages/ValidQuiz.razor.cs | 2 +- .../WF-WebAdmin/Pages/ValidQuote.razor | 62 ++++---- .../WF-WebAdmin/Pages/ValidQuote.razor.cs | 136 +++--------------- 4 files changed, 108 insertions(+), 186 deletions(-) diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs index 0743f27..b1dc0b6 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs @@ -1,52 +1,52 @@ -using Microsoft.AspNetCore.Components; -using Microsoft.Extensions.Configuration.UserSecrets; -using WF_WebAdmin.Model; - -namespace WF_WebAdmin.Pages -{ - public partial class DeleteUser - { +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Configuration.UserSecrets; +using WF_WebAdmin.Model; + +namespace WF_WebAdmin.Pages +{ + public partial class DeleteUser + { private List users; - private bool showPopup = false; - private User userToDelete = null; - [Inject] - public HttpClient Http { get; set; } - - [Inject] - public NavigationManager NavigationManager { get; set; } - - protected override async Task OnInitializedAsync() - { - users = await Http.GetFromJsonAsync>($"{NavigationManager.BaseUri}fake-dataUser.json"); - } - - - - - private void ShowConfirmation(User user) - { - // Afficher la modale et mémoriser l'utilisateur à supprimer - userToDelete = user; - showPopup = true; - } - - - - private async Task RemoveUser() - { - if (userToDelete != null) - { - users.RemoveAll(u => u.Id == userToDelete.Id); - ClosePopup(); - } - } - - private void ClosePopup() - { - showPopup = false; - } + private bool showPopup = false; + private User userToDelete = null; + [Inject] + public HttpClient Http { get; set; } + + [Inject] + public NavigationManager NavigationManager { get; set; } + + protected override async Task OnInitializedAsync() + { + users = await Http.GetFromJsonAsync>($"{NavigationManager.BaseUri}fake-dataUser.json"); + } + + + + + private void ShowConfirmation(User user) + { + // Afficher la modale et mémoriser l'utilisateur à supprimer + userToDelete = user; + showPopup = true; + } + + + + private async Task RemoveUser() + { + if (userToDelete != null) + { + users.RemoveAll(u => u.Id == userToDelete.Id); + ClosePopup(); + } + } + + private void ClosePopup() + { + showPopup = false; + } } -} +} diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuiz.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuiz.razor.cs index d907e84..a28b797 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuiz.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuiz.razor.cs @@ -7,7 +7,7 @@ namespace WF_WebAdmin.Pages public partial class ValidQuiz { private Quiz[] quizzes; - private int totalQuizzes; + [Inject] public HttpClient Http { get; set; } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor index da423b0..001eb89 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor @@ -3,34 +3,46 @@

Citations non validées

-@if (quotes is null) +@if (quotes == null) { -

Chargement des citations...

-} -else if (quotes.Count == 0) -{ -

Aucune citation en attente de validation.

+

Chargement des quotes ...

} else { -

Citations en attente de validation :

- - @foreach (var quote in quotes) - { -
-

ID : @quote.Id

-

Contenu : @quote.Content

-

Langue : @quote.Langue

-

Likes : @quote.Like

- -

Personnage : @quote.Charac

-

Image : @quote.ImgPath

-

Source : @quote.TitleSrc

-

Date de source : @quote.DateSrc.ToShortDateString()

-

Utilisateur proposition : @quote.UserProposition

+

Quotes en attente de validation :

- - -
- } + + + + + + + + + + + + + + @foreach (var quote in quotes) + { + + + + + + + +
+ + +
+ + } + +
#citationpersonnagesourcelanguedateactions
@quote.Id@quote.Content@quote.Charac@quote.TitleSrc@quote.Langue@quote.DateSrc
} diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs index a42112a..a92d02b 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs @@ -10,130 +10,40 @@ using System.Linq; namespace WF_WebAdmin.Pages { public partial class ValidQuote - { - // Chaîne de connexion à adapter - private const string connectionString = - "Host=localhost;Port=5432;Database=wikifantasy3;Username=postgres;Password=postgres"; + { + private Quote[] quotes; + + + [Inject] + public HttpClient Http { get; set; } - private List quotes; + [Inject] + public NavigationManager NavigationManager { get; set; } protected override async Task OnInitializedAsync() { - // On charge toutes les citations dont isValide = false - quotes = await LoadNotValidatedQuotesAsync(); + quotes = await Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-dataValidQuote.json"); } - /// - /// Charge toutes les citations non validées (isValide = false) - /// et mappe les colonnes vers ton modèle. - /// - private async Task> LoadNotValidatedQuotesAsync() + private void OnValidButton(Quote quote) { - var result = new List(); - - try - { - using var con = new NpgsqlConnection(connectionString); - await con.OpenAsync(); - - // Sélection des colonnes réellement présentes en DB - // + placeholders pour les autres - var sql = @" - SELECT - id_quote AS Id, - content AS Content, - likes AS ""Like"", - langue AS Langue, - -- Champs pas vraiment en DB : placeholders - '' AS Charac, - '' AS ImgPath, - '' AS TitleSrc, - now() AS DateSrc, - '' AS UserProposition - FROM quote - WHERE isValide = false - "; - - using var cmd = new NpgsqlCommand(sql, con); - using var reader = await cmd.ExecuteReaderAsync(); - - while (await reader.ReadAsync()) - { - var q = new Quote - { - Id = reader.GetInt32(reader.GetOrdinal("Id")), - Content = reader.GetString(reader.GetOrdinal("Content")), - Like = reader.GetInt32(reader.GetOrdinal("Like")), - Langue = reader.GetString(reader.GetOrdinal("Langue")), - // placeholders - Charac = reader.GetString(reader.GetOrdinal("Charac")), - ImgPath = reader.GetString(reader.GetOrdinal("ImgPath")), - TitleSrc = reader.GetString(reader.GetOrdinal("TitleSrc")), - DateSrc = reader.GetDateTime(reader.GetOrdinal("DateSrc")), - UserProposition = reader.GetString(reader.GetOrdinal("UserProposition")) - }; - result.Add(q); - } - } - catch (Exception ex) - { - Console.WriteLine($"[Erreur] LoadNotValidatedQuotesAsync : {ex.Message}"); - } - - return result; + ValidateQuote(quote); + } + + private void ValidateQuote(Quote quote) + { + Console.WriteLine($"Quote {quote.Id} validated!"); } - /// - /// Met à jour isValide = true pour la citation. - /// - private async Task ValiderQuote(int quoteId) + private void OnRejectButton(Quote quote) { - try - { - using var con = new NpgsqlConnection(connectionString); - await con.OpenAsync(); - - var sql = "UPDATE quote SET isValide = true WHERE id_quote = @Id"; - using var cmd = new NpgsqlCommand(sql, con); - cmd.Parameters.AddWithValue("Id", quoteId); - - int rowsAffected = await cmd.ExecuteNonQueryAsync(); - if (rowsAffected > 0) - { - // Supprime la quote de la liste pour l'enlever de l'affichage - quotes.RemoveAll(q => q.Id == quoteId); - } - } - catch (Exception ex) - { - Console.WriteLine($"[Erreur] ValiderQuote : {ex.Message}"); - } + RejectQuote(quote); } - /// - /// Supprime complètement la citation de la base. - /// - private async Task RejeterQuote(int quoteId) + private void RejectQuote(Quote quote) { - try - { - using var con = new NpgsqlConnection(connectionString); - await con.OpenAsync(); - - var sql = "DELETE FROM quote WHERE id_quote = @Id"; - using var cmd = new NpgsqlCommand(sql, con); - cmd.Parameters.AddWithValue("Id", quoteId); - - int rowsAffected = await cmd.ExecuteNonQueryAsync(); - if (rowsAffected > 0) - { - quotes.RemoveAll(q => q.Id == quoteId); - } - } - catch (Exception ex) - { - Console.WriteLine($"[Erreur] RejeterQuote : {ex.Message}"); - } - } - } + Console.WriteLine($"Quote {quote.Id} rejected!"); + } + } + } -- 2.36.3