diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..0d2e24d --- /dev/null +++ b/.drone.yml @@ -0,0 +1,71 @@ +kind: pipeline +name: CI +type: docker + +trigger: + event: + - push + +steps: + - name: build + image: mcr.microsoft.com/dotnet/sdk:6.0 + commands: + - cd WF-WebAdmin/WF-WebAdmin + - dotnet restore WF-WebAdmin.csproj + - dotnet build WF-WebAdmin.csproj -c Release --no-restore + - dotnet publish WF-WebAdmin.csproj -c Release --no-restore -o $CI_PROJECT_DIR/build/publish + + - name: tests + image: mcr.microsoft.com/dotnet/sdk:6.0 + commands: + - cd WF-WebAdmin/WF-WebAdmin + - dotnet restore WF-WebAdmin.csproj + - dotnet test WF-WebAdmin.csproj --no-restore + depends_on: [ build ] + + - name: code-analysis + image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dronesonarplugin-dotnet8 + commands: + - cd WF-WebAdmin/ + - dotnet restore WF-WebAdmin.sln + - dotnet sonarscanner begin /k:$${project_key} /d:sonar.host.url=$${sonar_host} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions=$${coverage_exclusions} /d:sonar.login=$${sonar_token} + - dotnet build WF-WebAdmin.sln -c Release --no-restore + - dotnet test WF-WebAdmin.sln --logger trx --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage" + - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport" + - dotnet publish WF-WebAdmin.sln -c Release --no-restore -o $CI_PROJECT_DIR/build/release + - dotnet sonarscanner end /d:sonar.login=$${sonar_token} + secrets: [ SECRET_SONAR_LOGIN ] + environment: + sonar_host: https://codefirst.iut.uca.fr/sonar/ + sonar_token: + from_secret: sonar_token + project_key: web_admin + coverage_exclusions: "Tests/**" + depends_on: [ tests ] + + - name: generate-and-deploy-docs + image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-docdeployer + failure: ignore + volumes: + - name: docs + path: /docs + commands: + - /entrypoint.sh + when: + branch: + - master + depends_on: [ build ] + + - name: docker_build + image: plugins/docker + settings: + repo: hub.codefirst.iut.uca.fr/whatthefantasy/wf-webadmin + registry: hub.codefirst.iut.uca.fr + dockerfile: Docker/Dockerfile + tags: + - latest + username: + from_secret: docker_username + password: + from_secret: docker_password + depends_on: [ build, tests, code-analysis ] diff --git a/Docker/Dockerfile b/Docker/Dockerfile new file mode 100644 index 0000000..055b3a2 --- /dev/null +++ b/Docker/Dockerfile @@ -0,0 +1,27 @@ +# 1. Étape de build (SDK .NET 6) +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +WORKDIR /src + +# Copier le csproj et restaurer les dépendances +COPY WF-WebAdmin/WF-WebAdmin/WF-WebAdmin.csproj ./ +RUN dotnet restore WF-WebAdmin.csproj + +# Copier le reste du code et compiler +COPY WF-WebAdmin/WF-WebAdmin/ ./ +RUN dotnet publish WF-WebAdmin.csproj -c Release -o /app/publish + +# 2. Étape finale (runtime .NET 6) +FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS final +WORKDIR /app + +# Désactiver le rechargement de config pour éviter les erreurs inotify +ENV ASPNETCORE_HOSTBUILDER__RELOADCONFIGONCHANGE=false + +# Copier les binaires publiés +COPY --from=build /app/publish ./ + +# Exposer le port HTTP (80) ; adapte si besoin +EXPOSE 80 + +# Lancement +ENTRYPOINT ["dotnet", "WF-WebAdmin.dll"] diff --git a/README.md b/README.md index b98784e..4e3fa78 100644 --- a/README.md +++ b/README.md @@ -61,20 +61,20 @@ L'application devrait se lancer automatiquement dans votre navigateur par défau # Blazor Apps (30 points) 🟨 En cours / ✅ Fait / ❌ Pas fait

✅ Mise en place d'une page de visualisation des données avec pagination (2 points)
-🟨 Page d'ajout d'un élement avec validation (2 point)
-🟨 Page d'édition d'un élement avec validation (2 point)
+✅ Page d'ajout d'un élement avec validation (2 point)
+✅ Page d'édition d'un élement avec validation (2 point)
✅ Supression d'un élement avec une confirmation (2 point)
🟨 Composant complexe (5 point)
🟨 Use API (Get / Insert / Update / Delete) (3 point)
-❌ Utilisation IOC & DI (4 point)
-🟨 Localisation & Globalisation (au moins deux langues) (1 point)
-🟨 Utilisation de la configuration (1 point)
+✅ Utilisation IOC & DI (4 point)
+✅ Localisation & Globalisation (au moins deux langues) (1 point)
+❌ Utilisation de la configuration (1 point)
🟨 Logs (2 point)
❌ Propreté du code (Vous pouvez vous servir de sonarqube) (2 point)
✅ IHM (Design global, placement des boutons, ...) (2 point)
✅ Emplacement du code (Pas de code dans les vues) (2 point)
# Documentation (10 points) -🟨Le Readme (2 points)
-❌Description du fonctionnement de la solution client (illustrutration au niveau du code) (6 points)
-✅Merge request (2 points)
+✅ Le Readme (2 points)
+❌ Description du fonctionnement de la solution client (illustrutration au niveau du code) (6 points)
+✅ Merge request (2 points)
diff --git a/WF-WebAdmin/UnitTestWF/UnitTest1.cs b/WF-WebAdmin/UnitTestWF/UnitTest1.cs new file mode 100644 index 0000000..35e952c --- /dev/null +++ b/WF-WebAdmin/UnitTestWF/UnitTest1.cs @@ -0,0 +1,11 @@ +namespace UnitTestWF +{ + public class UnitTest1 + { + [Fact] + public void Test1() + { + + } + } +} \ No newline at end of file diff --git a/WF-WebAdmin/UnitTestWF/UnitTestWF.csproj b/WF-WebAdmin/UnitTestWF/UnitTestWF.csproj new file mode 100644 index 0000000..9c5b30a --- /dev/null +++ b/WF-WebAdmin/UnitTestWF/UnitTestWF.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + diff --git a/WF-WebAdmin/WF-WebAdmin.sln b/WF-WebAdmin/WF-WebAdmin.sln index f97bd2a..ae4047e 100644 --- a/WF-WebAdmin/WF-WebAdmin.sln +++ b/WF-WebAdmin/WF-WebAdmin.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.9.34723.18 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WF-WebAdmin", "WF-WebAdmin\WF-WebAdmin.csproj", "{0E8D1007-ADDC-4103-847D-8EE48ACCDC62}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestWF", "UnitTestWF\UnitTestWF.csproj", "{A4EC0EC4-7A46-4F8E-99C3-4FD32F173F2F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {0E8D1007-ADDC-4103-847D-8EE48ACCDC62}.Debug|Any CPU.Build.0 = Debug|Any CPU {0E8D1007-ADDC-4103-847D-8EE48ACCDC62}.Release|Any CPU.ActiveCfg = Release|Any CPU {0E8D1007-ADDC-4103-847D-8EE48ACCDC62}.Release|Any CPU.Build.0 = Release|Any CPU + {A4EC0EC4-7A46-4F8E-99C3-4FD32F173F2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4EC0EC4-7A46-4F8E-99C3-4FD32F173F2F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A4EC0EC4-7A46-4F8E-99C3-4FD32F173F2F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A4EC0EC4-7A46-4F8E-99C3-4FD32F173F2F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WF-WebAdmin/WF-WebAdmin/Controllers/CultureController.cs b/WF-WebAdmin/WF-WebAdmin/Controllers/CultureController.cs new file mode 100644 index 0000000..834b808 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Controllers/CultureController.cs @@ -0,0 +1,34 @@ +using Microsoft.AspNetCore.Localization; +using Microsoft.AspNetCore.Mvc; + +namespace WF_WebAdmin.Controllers +{ + /// + /// The culture controller. + /// + [Route("[controller]/[action]")] + public class CultureController : Controller + { + /// + /// Sets the culture. + /// + /// The culture. + /// The redirect URI. + /// + /// The action result. + /// + public IActionResult SetCulture(string culture, string redirectUri) + { + if (culture != null) + { + // Define a cookie with the selected culture + this.HttpContext.Response.Cookies.Append( + CookieRequestCultureProvider.DefaultCookieName, + CookieRequestCultureProvider.MakeCookieValue( + new RequestCulture(culture))); + } + + return this.LocalRedirect(redirectUri); + } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Converter/QuoteDTO.cs b/WF-WebAdmin/WF-WebAdmin/Converter/QuoteDTO.cs index 092db9d..26a68a8 100644 --- a/WF-WebAdmin/WF-WebAdmin/Converter/QuoteDTO.cs +++ b/WF-WebAdmin/WF-WebAdmin/Converter/QuoteDTO.cs @@ -9,7 +9,7 @@ namespace WF_WebAdmin.Converter public string Content { get; set; } public int Likes { get; set; } public string Langue { get; set; } - public bool? IsValide { get; set; } + public bool IsValide { get; set; } public string? Reason { get; set; } public int? IdCaracter { get; set; } public string NameCharac { get; set; } @@ -21,7 +21,7 @@ namespace WF_WebAdmin.Converter public int? IdImg { get; set; } public string ImgPath { get; set; } - public QuoteDTO(int id_quote,string content,int likes,string langue,bool? isValide,string? reason,int? id_caracter,string name_charac,int? id_source,string title,DateTime date,int? id_user_verif,string name_user ,int? id_img,string img_path) + public QuoteDTO(int id_quote,string content,int likes,string langue,bool isValide,string? reason,int? id_caracter,string name_charac,int? id_source,string title,DateTime date,int? id_user_verif,string name_user ,int? id_img,string img_path) { this.Id = id_quote; this.Content = content; diff --git a/WF-WebAdmin/WF-WebAdmin/Converter/QuoteExtension.cs b/WF-WebAdmin/WF-WebAdmin/Converter/QuoteExtension.cs index 088520a..a7bd57f 100644 --- a/WF-WebAdmin/WF-WebAdmin/Converter/QuoteExtension.cs +++ b/WF-WebAdmin/WF-WebAdmin/Converter/QuoteExtension.cs @@ -6,13 +6,13 @@ namespace WF_WebAdmin.Converter { public QuoteDTO QuoteToDTO(Quote q) { - QuoteDTO quote = new QuoteDTO(q.Id, q.Content, q.Like, q.Langue, null,null, null,q.Charac,null,q.TitleSrc,q.DateSrc,null,q.UserProposition,null,q.ImgPath); + QuoteDTO quote = new QuoteDTO(q.Id, q.Content, q.Like, q.Langue, q.IsValid,null, null,q.Charac,null,q.TitleSrc,q.DateSrc,null,q.UserProposition,null,q.ImgPath); return quote; } public Quote DTOToQuote(QuoteDTO q) { - Quote quote = new Quote(q.Id, q.Content,q.NameCharac,q.ImgPath,q.TitleSrc,q.DateSrc,q.Likes,q.Langue,q.NameUser); + Quote quote = new Quote(q.Id, q.Content,q.NameCharac,q.ImgPath,q.TitleSrc,q.DateSrc,q.Likes,q.Langue,q.NameUser,q.IsValide); return quote; } } diff --git a/WF-WebAdmin/WF-WebAdmin/Model/Character.cs b/WF-WebAdmin/WF-WebAdmin/Model/Character.cs new file mode 100644 index 0000000..a5e1d87 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Model/Character.cs @@ -0,0 +1,8 @@ +namespace WF_WebAdmin.Model +{ + public class Character + { + public int id_caracter { get; set; } + public string caracter { get; set; } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Model/Quiz.cs b/WF-WebAdmin/WF-WebAdmin/Model/Quiz.cs index c6035df..a72be08 100644 --- a/WF-WebAdmin/WF-WebAdmin/Model/Quiz.cs +++ b/WF-WebAdmin/WF-WebAdmin/Model/Quiz.cs @@ -9,6 +9,36 @@ namespace WF_WebAdmin.Model public string AnswerC { get; set; } public string AnswerD { get; set; } public string CAnswer { get; set; } + public bool IsValid { get; set; } public string UserProposition { get; set; } + + public Quiz(int id, string question, string answerA, string answerB, string answerC, string answerD, string cAnswer, bool isValid, string userProposition) + { + Id = id; + Question = question; + AnswerA = answerA; + AnswerB = answerB; + AnswerC = answerC; + AnswerD = answerD; + CAnswer = cAnswer; + IsValid = isValid; + UserProposition = userProposition; + } + + public Quiz(int id, string question, string answerA, string answerB, string answerC, string answerD, string cAnswer) + { + Id = id; + Question = question; + AnswerA = answerA; + AnswerB = answerB; + AnswerC = answerC; + AnswerD = answerD; + CAnswer = cAnswer; + IsValid = true; + UserProposition = "Admin"; + } + + public Quiz() {} + } } \ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/Model/QuizModel.cs b/WF-WebAdmin/WF-WebAdmin/Model/QuizModel.cs new file mode 100644 index 0000000..ce5c8fa --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Model/QuizModel.cs @@ -0,0 +1,30 @@ +using System.ComponentModel.DataAnnotations; + +namespace WF_WebAdmin.Model +{ + public class QuizModel + { + [Required] + [StringLength(200, ErrorMessage = "La question ne peut pas depasser les 200 caractère.")] + public string Question { get; set; } + + [Required] + [StringLength(50, ErrorMessage = "La réponse ne peut pas depasser les 50 caractère.")] + public string AnswerA { get; set; } + + [Required] + [StringLength(50, ErrorMessage = "La réponse ne peut pas depasser les 50 caractère.")] + public string AnswerB { get; set; } + + [Required] + [StringLength(50, ErrorMessage = "La réponse ne peut pas depasser les 50 caractère.")] + public string AnswerC { get; set; } + + [Required] + [StringLength(50, ErrorMessage = "La réponse ne peut pas depasser les 50 caractère.")] + public string AnswerD { get; set; } + + [Required] + public string CAnswer { get; set; } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Model/Quote.cs b/WF-WebAdmin/WF-WebAdmin/Model/Quote.cs index 5a56083..ffc7f05 100644 --- a/WF-WebAdmin/WF-WebAdmin/Model/Quote.cs +++ b/WF-WebAdmin/WF-WebAdmin/Model/Quote.cs @@ -13,8 +13,9 @@ namespace WF_WebAdmin.Model public string TitleSrc { get; set; } public DateTime DateSrc { get; set; } public string UserProposition { get; set; } + public bool IsValid { get; set; } - public Quote(int id, string content, string charac, string imgPath, string titleSrc, DateTime dateSrc, int like, string langue, string userProposition) + public Quote(int id, string content, string charac, string imgPath, string titleSrc, DateTime dateSrc, int like, string langue, string userProposition, bool isvalid) { Id = id; Content = content; @@ -25,6 +26,7 @@ namespace WF_WebAdmin.Model Like = like; Langue = langue; UserProposition = userProposition; + IsValid = isvalid; } /* public int Id { get; set; } diff --git a/WF-WebAdmin/WF-WebAdmin/Model/QuoteModel.cs b/WF-WebAdmin/WF-WebAdmin/Model/QuoteModel.cs new file mode 100644 index 0000000..1db3196 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Model/QuoteModel.cs @@ -0,0 +1,27 @@ +using System.ComponentModel.DataAnnotations; + +namespace WF_WebAdmin.Model +{ + public class QuoteModel + { + public int Id { get; set; } + + [Required] + [StringLength(300, ErrorMessage = "La citation ne peut pas dépasser les 300 caractère.")] + public string Content { get; set; } + + public int Like { get; set; } + + [Required] + [StringLength(2, ErrorMessage = "La langue ne peut pas dépasser 2 caractère.")] + public string Langue { get; set; } + + + public string Charac { get; set; } + public string ImgPath { get; set; } + public string TitleSrc { get; set; } + public DateTime DateSrc { get; set; } + public string UserProposition { get; set; } + public bool IsValid { get; set; } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Model/Source.cs b/WF-WebAdmin/WF-WebAdmin/Model/Source.cs new file mode 100644 index 0000000..99c390a --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Model/Source.cs @@ -0,0 +1,11 @@ +namespace WF_WebAdmin.Model +{ + public class Source + { + public int id_source { get; set; } + + public string title { get; set; } + + public int date { get; set; } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Model/User.cs b/WF-WebAdmin/WF-WebAdmin/Model/User.cs index 599ee8e..9e398dd 100644 --- a/WF-WebAdmin/WF-WebAdmin/Model/User.cs +++ b/WF-WebAdmin/WF-WebAdmin/Model/User.cs @@ -2,6 +2,7 @@ { public class User { + public int Id { get; set; } public string Image { get; set; } public string Name { get; set; } public string Email { get; set; } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Accueil.razor b/WF-WebAdmin/WF-WebAdmin/Pages/Accueil.razor index 1cd75b6..099d4dd 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/Accueil.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Accueil.razor @@ -1,11 +1,11 @@ @page "/Accueil" - +@using WF_WebAdmin.Model Accueil -

Bienvenu sur le tableau de bord de What the Fantasy

+

@Localizer["AccueilWelcome"]

-

Citation du jour

+

@Localizer["AccueilTitle"]

@if (Dailyquote != null) { @@ -15,8 +15,8 @@

@quote.Content

-

Personnage : @quote.Charac

-

Source : @quote.TitleSrc

+

@Localizer["AccueilCharacter"] @quote.Charac

+

@Localizer["AccueilSrc"] @quote.TitleSrc

} @@ -24,9 +24,9 @@ } else { -

Aucune citation du jour

+

@Localizer["AccueilNoQuote"]

} -

Changement de la citation manuellement

- +

@Localizer["AccueilManualChange"]

+ diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Accueil.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/Accueil.razor.cs index 379853e..797b255 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/Accueil.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Accueil.razor.cs @@ -1,5 +1,6 @@ using Blazorise.DataGrid; using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Localization; using WF_WebAdmin.Model; @@ -15,6 +16,8 @@ namespace WF_WebAdmin.Pages [Inject] public NavigationManager NavigationManager { get; set; } + [Inject] + public IStringLocalizer Localizer { get; set; } protected override async Task OnInitializedAsync() { Dailyquote = await Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-dataDailyQuote.json"); diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor b/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor new file mode 100644 index 0000000..5505f94 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor @@ -0,0 +1,58 @@ +@using WF_WebAdmin.Model; + +@page "/add" + +

@Localizer["TitleAddQuiz"]

+ + + + + + +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ + +
\ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor.cs new file mode 100644 index 0000000..ff10734 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor.cs @@ -0,0 +1,85 @@ +using Microsoft.AspNetCore.Components; +using WF_WebAdmin.Service; +using WF_WebAdmin.Model; +using Microsoft.AspNetCore.Mvc; +using System.Text.RegularExpressions; +using Microsoft.Extensions.Localization; + + +namespace WF_WebAdmin.Pages +{ + public partial class AddQuiz + { + + [Inject] + public IStringLocalizer Localizer { get; set; } + + [Inject] + private IQuizService quizService { get; set; } + + [Inject] + public NavigationManager NavigationManager { get; set; } + + private QuizModel QuizModel = new(); + + private async void HandleValidSubmit() + { + + int id; + id = await quizService.getNbQuiz(); + id++; + await quizService.addQuiz(new Quiz( + id, + validateInformation(QuizModel.Question), + validateInformation(QuizModel.AnswerA), + validateInformation(QuizModel.AnswerB), + validateInformation(QuizModel.AnswerC), + validateInformation(QuizModel.AnswerD), + validateReponse(QuizModel.CAnswer) + )); + NavigationManager.NavigateTo("modifquiz"); + } + + private void OnCAwnserChange(string item, object checkedValue) + { + QuizModel.CAnswer = item; + } + + private static string validateInformation(string item) + { + return item; // VALIDATION A FAIRE + } + + private static string validateReponse(string item) + { + try + { + if (!string.IsNullOrEmpty(item)) + { + switch (item) + { + case "A": + break; + case "B": + break; + case "C": + break; + case "D": + break; + default: + throw new InvalidDataException("Invalid item (validateReponse) : item must be A,B,C or D " + item + "give."); + } + } + else + { + throw new ArgumentNullException("Invalid item (validateReponse): null given."); + } + return item; + } + catch (Exception ex) + { + return "A"; //Default Argument + } + } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor index c0c86ce..10ce548 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor @@ -1,36 +1,54 @@ @page "/deleteuser" +@using WF_WebAdmin.Model Gestion utilisateur -

Gestion des utilisateurs

+

@Localizer["TitleUser"]

@if(users == null) { -

Aucun utilisateur présent sur le site

+

@Localizer["UserNobody"]

} else { -

Utilisateurs présents:

+ + + + + + + + + +

@Localizer["UserHere"]

+ @foreach (var user in users) { -
+
@if (user.IsAdmin) { -

Nom d'utilisateur : @user.Name (Administrateur)

+ +

@Localizer["UserName"] @user.Name (@Localizer["UserAdmin"])

} else { -

Nom d'utilisateur : @user.Name

+

@Localizer["UserName"] @user.Name

} -

Email de l'utilisateur : @user.Email

-

Date de création du compte : @user.DateCreation.ToShortDateString()

+

@Localizer["UserEmail"] @user.Email

+

@Localizer["UserDate"] @user.DateCreation.ToShortDateString()

@if(user.Comments != null) { -

▶ Commentaire(s) posté(s) par @user.Name :

+

▶ @Localizer["UserComment"] @user.Name :

@foreach (var comment in user.Comments) {

@comment.DateCreation.ToShortDateString() - @comment.Text

@@ -38,51 +56,63 @@ else } else { -

Aucun commentaire sur le site

+

@Localizer["UserNoComment"]

} - + + @if (!user.IsAdmin) { - + } else { - + }
- } + @if (showPopupDelete) {
-

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

- +

@Localizer["UserPopupTitle"]

+ + +
+
+ } + @if (showModifyPopup) + { +
+
+

Modifier les informations de l'utilisateur :

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

Êtes-vous sûr de vouloir changer le rôle de cet utilisateur ?

- - +

@Localizer["UserPopupTitle2"]

+ +
} } - - - -@code { - -} diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs index a2c46da..e363cee 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs @@ -1,86 +1,137 @@ -using Microsoft.AspNetCore.Components; -using Microsoft.Extensions.Configuration.UserSecrets; +using Blazorise.DataGrid; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Configuration.UserSecrets; using Microsoft.Extensions.Logging; -using WF_WebAdmin.Model; - -namespace WF_WebAdmin.Pages -{ - public partial class DeleteUser - { +using Microsoft.Extensions.Localization; +using System.Collections.Generic; +using WF_WebAdmin.Model; +using WF_WebAdmin.Service; + +namespace WF_WebAdmin.Pages +{ + public partial class DeleteUser + { [Inject] public ILogger Logger { get; set; } private List users; - - private bool showPopupDelete = false; - private User userToDelete = null; - - private bool showPopupAdmin = false; - private User userToAdmin = null; + private bool showDeletePopup = false; + private bool showModifyPopup = false; + private List users; + private User userToDelete = null; + private User selectedUser; + private bool showPopupDelete = false; + private bool showPopupAdmin = false; + private User userToAdmin = null; + private int MaxValue = 5; + private int totalItem; + private int page = 1; + + + [Inject] + public HttpClient Http { get; set; } + + [Inject] + public NavigationManager NavigationManager { get; set; } + + [Inject] + private IUserService userService { get; set; } + [Inject] - public HttpClient Http { get; set; } - - [Inject] - public NavigationManager NavigationManager { get; set; } - - protected override async Task OnInitializedAsync() - { - users = await Http.GetFromJsonAsync>($"{NavigationManager.BaseUri}fake-dataUsers.json"); - } - - - - // ------- Popup remove user ------- - private void ShowConfirmation(User user) - { + public IStringLocalizer Localizer { get; set; } + + + + protected override async Task OnInitializedAsync() + { + users = await userService.getSomeUser(MaxValue, 1); + } + + private async Task OnReadData(DataGridReadDataEventArgs e) + { + if (e.CancellationToken.IsCancellationRequested) + { + return; + } + + + var response = await userService.getSomeUser(e.PageSize, e.Page); + + if (!e.CancellationToken.IsCancellationRequested) + { + totalItem = await userService.getNbUser(); + users = new List(response.ToArray()); + page = e.Page; + } + } + + // ------- Popup remove user ------- + private void ShowConfirmation(User user) + { LoggerSaveStub.Log(Logger,LogLevel.Information, $"Demande de supretion de l utilisateur : { user.Name }"); - userToDelete = user; - showPopupDelete = true; - } - - - - private async Task RemoveUser() - { - if (userToDelete != null) + userToDelete = user; + showPopupDelete = true; + } + + private void ShowModifyConfirmation(User user) + { + // Afficher la modale et mémoriser l'utilisateur à supprimer + selectedUser = user; + showModifyPopup = true; + } + + private async Task RemoveUser() + { + if (userToDelete != null) + { + await userService.removeUser(userToDelete); + ClosePopup(); + var response = await userService.getSomeUser(MaxValue, page); + users = new List(response.ToArray()); + } + } + + private async Task ModifyUser() + { + await userService.updateUser(selectedUser); + ClosePopup(); + } + + private void ClosePopup() + { + showDeletePopup = false; + showModifyPopup = false; + showPopupDelete = false; + showPopupAdmin = false; + } + + + // ------- Popup admin ------- + private void ShowConfirmationAdmin(User user) + { + userToAdmin = user; + showPopupAdmin = true; + } + + + + private async Task setAdmin() + { + if (!userToAdmin.IsAdmin) { - users.RemoveAll(u => u.Name == userToDelete.Name); - ClosePopup(); - } - } - - private void ClosePopup() - { - showPopupDelete = false; - showPopupAdmin = false; - } - - - // ------- Popup admin ------- - private void ShowConfirmationAdmin(User user) - { - userToAdmin = user; - showPopupAdmin = true; - } - - - - private async Task Admin() - { - if (!userToAdmin.IsAdmin) - { - userToAdmin.IsAdmin = true; - ClosePopup(); - } + userToAdmin.IsAdmin = true; + await userService.updateUser(userToAdmin); + ClosePopup(); + } else { - userToAdmin.IsAdmin = false; + userToAdmin.IsAdmin = false; + await userService.updateUser(userToAdmin); ClosePopup(); - } - } - + } + } + } - -} +} diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor new file mode 100644 index 0000000..edb3822 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor @@ -0,0 +1,48 @@ +@using WF_WebAdmin.Model +@page "/edit/{Id:int}" + +

Editer

+ + + + + +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ + +
\ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs new file mode 100644 index 0000000..71bb9f0 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs @@ -0,0 +1,65 @@ +using Microsoft.AspNetCore.Components; +using WF_WebAdmin.Model; +using WF_WebAdmin.Service; + +namespace WF_WebAdmin.Pages +{ + public partial class Edit + { + [Parameter] + public int Id { get; set; } + + [Inject] + private IQuoteService quoteService { get; set; } + + [Inject] + public NavigationManager NavigationManager { get; set; } + + private Quote q{ get; set; } + + private QuoteModel quoteModel = new(); + + private List charac = new List(); + + private List src = new List(); + + protected override async Task OnInitializedAsync() + { + q = await quoteService.getOnequote(Id); + quoteModel.Content = q.Content; + quoteModel.Langue = q.Langue; + quoteModel.Charac = q.Charac; + quoteModel.TitleSrc = q.TitleSrc; + quoteModel.Id = q.Id; + quoteModel.Like = q.Like; + quoteModel.ImgPath = q.ImgPath; + quoteModel.DateSrc = q.DateSrc; + quoteModel.UserProposition = q.UserProposition; + quoteModel.IsValid = q.IsValid; + charac = await quoteService.getChar(); + src = await quoteService.getSrc(); + } + + protected async void HandleValidSubmit() + { + q.Content = quoteModel.Content; + q.Langue = quoteModel.Langue; + q.TitleSrc = quoteModel.TitleSrc; + q.Charac = quoteModel.Charac; + await quoteService.updateQuote(q); + NavigationManager.NavigateTo("modifquote"); + } + + private void OnlangChange(string item, object checkedValue) + { + if(item == "fr" || item == "en") + { + quoteModel.Langue = item; + } + } + + + + + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor b/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor index 411b655..f6089d6 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor @@ -1,22 +1,24 @@ @page "/" @using WF_WebAdmin.Model +@using System.Globalization -

▶ Connexion ◀

+

▶@Localizer["LoginTitle"]◀