diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.cs b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.cs deleted file mode 100644 index e913791..0000000 --- a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.AspNetCore.Components; -using WF_WebAdmin.Model; - -namespace WF_WebAdmin.Pages -{ - public partial class DeleteUser - { - private User[] users; - - [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"); - } - } -} diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor index 933820d..47af991 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor @@ -2,12 +2,13 @@ Gestion utilisateur -@if(users != null) -{ -

Gestion des utilisateurs

+

Gestion des utilisateurs

-

Utilisateurs présents:

+ +@if (users != null) +{ +

Utilisateurs présents:

@foreach (var user in users) {
@@ -16,10 +17,28 @@

Nom d'utilisateur : @user.Name

Email de l'utilisateur : @user.Email

Date de création de l'utilisateur : @user.DateCreation.ToShortDateString()

- +
} + + @if (showPopup) + { +
+
+

Êtes-vous sûr de vouloir supprimer cet utilisateur ?

+ + +
+
+ } + + } +else +{ +

Aucun utilisateurs présents sur le site

+} + @code { diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs new file mode 100644 index 0000000..0743f27 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs @@ -0,0 +1,52 @@ +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; + } + } + +} diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor new file mode 100644 index 0000000..d562f7a --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor @@ -0,0 +1,24 @@ +@using WF_WebAdmin.Model +@page "/modifquote" + +Corection des citation + +

Corection des citation

+ +

Ajouter une recherche

+ +@if (quotes != null) +{ + + + + + + + + + +} \ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs similarity index 68% rename from WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.cs rename to WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs index b8cd783..6bb7933 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs @@ -1,12 +1,14 @@ -using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components; using WF_WebAdmin.Model; namespace WF_WebAdmin.Pages { - public partial class ValidQuote + public partial class ModifQuote { private Quote[] quotes; + private int MaxValue = 5; + [Inject] public HttpClient Http { get; set; } @@ -15,7 +17,7 @@ namespace WF_WebAdmin.Pages protected override async Task OnInitializedAsync() { - quotes = await Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-dataValidQuote.json"); + quotes = await Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-dataModifQuote.json"); } } } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor index 595445f..da423b0 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor @@ -1,26 +1,36 @@ @page "/ValidQuote" +@using WF_WebAdmin.Model -@if(quotes != null){ -

Citations non validées

-

Citations en attente de validation:

+

Citations non validées

- @foreach(var quote in quotes) +@if (quotes is null) +{ +

Chargement des citations...

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

Aucune citation en attente de validation.

+} +else +{ +

Citations en attente de validation :

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

Identifiant de la citation :@quote.Id

-

Citation:@quote.Content

-

Personnage : @quote.Charac

-

Source : @quote.TitleSrc

-

Langue : @quote.Langue

-

@quote.UserProposition a proposé cette citation

- - +

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

+ + +
} } - - - - - diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs new file mode 100644 index 0000000..a42112a --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs @@ -0,0 +1,139 @@ +using Microsoft.AspNetCore.Components; +using Npgsql; +using System.Data; +using WF_WebAdmin.Model; +using System.Collections.Generic; +using System; +using System.Threading.Tasks; +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 List quotes; + + protected override async Task OnInitializedAsync() + { + // On charge toutes les citations dont isValide = false + quotes = await LoadNotValidatedQuotesAsync(); + } + + /// + /// Charge toutes les citations non validées (isValide = false) + /// et mappe les colonnes vers ton modèle. + /// + private async Task> LoadNotValidatedQuotesAsync() + { + 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; + } + + /// + /// Met à jour isValide = true pour la citation. + /// + private async Task ValiderQuote(int quoteId) + { + 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}"); + } + } + + /// + /// Supprime complètement la citation de la base. + /// + private async Task RejeterQuote(int quoteId) + { + 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}"); + } + } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/_Layout.cshtml b/WF-WebAdmin/WF-WebAdmin/Pages/_Layout.cshtml index db114bc..bc00141 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/_Layout.cshtml +++ b/WF-WebAdmin/WF-WebAdmin/Pages/_Layout.cshtml @@ -29,5 +29,9 @@ + + + + diff --git a/WF-WebAdmin/WF-WebAdmin/Program.cs b/WF-WebAdmin/WF-WebAdmin/Program.cs index 77896c4..d106ef6 100644 --- a/WF-WebAdmin/WF-WebAdmin/Program.cs +++ b/WF-WebAdmin/WF-WebAdmin/Program.cs @@ -1,4 +1,6 @@ -using Blazored.LocalStorage; +using Blazorise; +using Blazorise.Bootstrap; +using Blazorise.Icons.FontAwesome; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; using WF_WebAdmin.Data; @@ -12,7 +14,11 @@ builder.Services.AddSingleton(); builder.Services.AddHttpClient(); -builder.Services.AddBlazoredLocalStorage(); + +builder.Services + .AddBlazorise() + .AddBootstrapProviders() + .AddFontAwesomeIcons(); var app = builder.Build(); diff --git a/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor b/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor index 2e82fc0..5464a8c 100644 --- a/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor +++ b/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor @@ -31,6 +31,13 @@ + + + diff --git a/WF-WebAdmin/WF-WebAdmin/WF-WebAdmin.csproj b/WF-WebAdmin/WF-WebAdmin/WF-WebAdmin.csproj index 5eab720..e4eb494 100644 --- a/WF-WebAdmin/WF-WebAdmin/WF-WebAdmin.csproj +++ b/WF-WebAdmin/WF-WebAdmin/WF-WebAdmin.csproj @@ -8,10 +8,11 @@ - + + diff --git a/WF-WebAdmin/WF-WebAdmin/_Imports.razor b/WF-WebAdmin/WF-WebAdmin/_Imports.razor index d4da21d..f261bea 100644 --- a/WF-WebAdmin/WF-WebAdmin/_Imports.razor +++ b/WF-WebAdmin/WF-WebAdmin/_Imports.razor @@ -7,4 +7,5 @@ @using Microsoft.AspNetCore.Components.Web.Virtualization @using Microsoft.JSInterop @using WF_WebAdmin -@using WF_WebAdmin.Shared \ No newline at end of file +@using WF_WebAdmin.Shared +@using Blazorise.DataGrid diff --git a/WF-WebAdmin/WF-WebAdmin/wwwroot/css/site.css b/WF-WebAdmin/WF-WebAdmin/wwwroot/css/site.css index d91bb8d..9f8f5cf 100644 --- a/WF-WebAdmin/WF-WebAdmin/wwwroot/css/site.css +++ b/WF-WebAdmin/WF-WebAdmin/wwwroot/css/site.css @@ -88,4 +88,37 @@ button { .pseudo, .mail, .idUser, .dateCrea, .idQuote, .contentQuote, .CaracterQuote, .SourceQuote, .langueQuote, .UserPropositionQuote { margin-left: 10px; +} + +/*ModifQuote*/ + +.imgTab{ + width: 5vw; + height: 5vw; + object-fit: contain; +} + +/*Popup DeleteUser*/ +.divPopup { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + background-color: white border-radius:20px; + display: flex; + justify-content: center; + align-items: center; + z-index: 2; +} + +.contentPopup { + background-color: white; + padding: 20px; + border-radius: 20px; + display: flex; + flex-direction: column; + gap: 10px; + width: 300px; + text-align: center; } \ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataModifQuote.json b/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataModifQuote.json new file mode 100644 index 0000000..20f7d2a --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataModifQuote.json @@ -0,0 +1,90 @@ +[ + { + "Id": 1, + "ImgPath": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", + "Content": "Harry POTTER JE SUIS TON PERE", + "Charac": "Sirius Black", + "TitleSrc": "Harry Potter", + "Langue": "fr", + "UserProposition": "demo", + "DateSrc": "2001-01-01", + "Like": 20 + }, + { + "Id": 2, + "ImgPath": "https://tse2.mm.bing.net/th/id/OIP.zR4rzkK7q2wCcNwZd6jjegHaIC?w=163&h=180&c=7&r=0&o=5&pid=1.7", + "Content": "'Une autre citation'", + "Charac": "Un personnage", + "TitleSrc": "Un super film", + "Langue": "fr", + "DateSrc": "2002-02-02", + "Like": 0, + "UserProposition": "exploit" + }, + { + "Id": 1, + "ImgPath": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", + "Content": "Harry POTTER JE SUIS TON PERE", + "Charac": "Sirius Black", + "TitleSrc": "Harry Potter", + "Langue": "fr", + "UserProposition": "demo", + "DateSrc": "2001-01-01", + "Like": 20 + }, + { + "Id": 2, + "ImgPath": "https://tse2.mm.bing.net/th/id/OIP.zR4rzkK7q2wCcNwZd6jjegHaIC?w=163&h=180&c=7&r=0&o=5&pid=1.7", + "Content": "'Une autre citation'", + "Charac": "Un personnage", + "TitleSrc": "Un super film", + "Langue": "fr", + "DateSrc": "2002-02-02", + "Like": 0, + "UserProposition": "exploit" + }, + { + "Id": 1, + "ImgPath": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", + "Content": "Harry POTTER JE SUIS TON PERE", + "Charac": "Sirius Black", + "TitleSrc": "Harry Potter", + "Langue": "fr", + "UserProposition": "demo", + "DateSrc": "2001-01-01", + "Like": 20 + }, + { + "Id": 2, + "ImgPath": "https://tse2.mm.bing.net/th/id/OIP.zR4rzkK7q2wCcNwZd6jjegHaIC?w=163&h=180&c=7&r=0&o=5&pid=1.7", + "Content": "'Une autre citation'", + "Charac": "Un personnage", + "TitleSrc": "Un super film", + "Langue": "fr", + "DateSrc": "2002-02-02", + "Like": 0, + "UserProposition": "exploit" + }, + { + "Id": 1, + "ImgPath": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", + "Content": "Harry POTTER JE SUIS TON PERE", + "Charac": "Sirius Black", + "TitleSrc": "Harry Potter", + "Langue": "fr", + "UserProposition": "demo", + "DateSrc": "2001-01-01", + "Like": 20 + }, + { + "Id": 2, + "ImgPath": "https://tse2.mm.bing.net/th/id/OIP.zR4rzkK7q2wCcNwZd6jjegHaIC?w=163&h=180&c=7&r=0&o=5&pid=1.7", + "Content": "'Une autre citation'", + "Charac": "Un personnage", + "TitleSrc": "Un super film", + "Langue": "fr", + "DateSrc": "2002-02-02", + "Like": 0, + "UserProposition": "exploit" + } +] \ No newline at end of file