From 582bb13bcffa2f6cd85612f1da6e3ce6718f4f46 Mon Sep 17 00:00:00 2001 From: lebeaulato Date: Fri, 7 Feb 2025 12:58:26 +0100 Subject: [PATCH 01/11] =?UTF-8?q?probl=C3=A8me=20de=20pare=20feu=20mais=20?= =?UTF-8?q?j'ai=20normalement=20retir=C3=A9=20le=20login?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WF-WebAdmin/WF-WebAdmin/Pages/Accueil.razor | 2 +- WF-WebAdmin/WF-WebAdmin/Pages/Login.razor | 2 +- WF-WebAdmin/WF-WebAdmin/Shared/MainLayout.razor | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Accueil.razor b/WF-WebAdmin/WF-WebAdmin/Pages/Accueil.razor index 099d4dd..8c128e3 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/Accueil.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Accueil.razor @@ -1,4 +1,4 @@ -@page "/Accueil" +@page "/" @using WF_WebAdmin.Model Accueil diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor b/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor index f6089d6..9a49df2 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor @@ -1,4 +1,4 @@ -@page "/" +@page "/login" @using WF_WebAdmin.Model @using System.Globalization diff --git a/WF-WebAdmin/WF-WebAdmin/Shared/MainLayout.razor b/WF-WebAdmin/WF-WebAdmin/Shared/MainLayout.razor index eab28e1..2f6edf9 100644 --- a/WF-WebAdmin/WF-WebAdmin/Shared/MainLayout.razor +++ b/WF-WebAdmin/WF-WebAdmin/Shared/MainLayout.razor @@ -6,28 +6,28 @@
- @if (uLogin.Name != null) - { + @* @if (uLogin.Name != null) + { *@ - } + @* } *@
- @if (!string.IsNullOrEmpty(uLogin.Name)) + @* @if (!string.IsNullOrEmpty(uLogin.Name)) { - @* *@ + @* } else - { + {*@ - } + @* } *@
@Body From f3b95d273dfb3bb0a045ff66e695e6f4d0f1da77 Mon Sep 17 00:00:00 2001 From: lebeaulato Date: Fri, 7 Feb 2025 13:23:19 +0100 Subject: [PATCH 02/11] doc fait sur le code behind des pages --- .../WF-WebAdmin/Pages/Accueil.razor.cs | 6 + .../WF-WebAdmin/Pages/AddQuiz.razor.cs | 74 ++++- .../WF-WebAdmin/Pages/DeleteUser.razor.cs | 260 ++++++++++++------ WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs | 42 ++- WF-WebAdmin/WF-WebAdmin/Pages/Error.cshtml.cs | 13 + WF-WebAdmin/WF-WebAdmin/Pages/Login.razor.cs | 32 ++- .../WF-WebAdmin/Pages/ModifQuiz.razor.cs | 71 ++++- .../WF-WebAdmin/Pages/ModifQuote.razor.cs | 50 +++- .../WF-WebAdmin/Pages/ValidQuiz.razor.cs | 100 ++++--- .../WF-WebAdmin/Pages/ValidQuote.razor.cs | 16 +- 10 files changed, 506 insertions(+), 158 deletions(-) diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Accueil.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/Accueil.razor.cs index 797b255..8736eda 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/Accueil.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Accueil.razor.cs @@ -18,6 +18,12 @@ namespace WF_WebAdmin.Pages [Inject] public IStringLocalizer Localizer { get; set; } + + + /// + /// This method is called during the initialization of the Blazor component. + /// It is asynchronous and is used to load data or perform actions before the component is rendered. + /// protected override async Task OnInitializedAsync() { Dailyquote = await Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-dataDailyQuote.json"); diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor.cs index ff10734..760a341 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/AddQuiz.razor.cs @@ -22,40 +22,85 @@ namespace WF_WebAdmin.Pages private QuizModel QuizModel = new(); + /// + /// Handles the valid submission of a quiz form. + /// This method is triggered when the form is successfully validated and the user submits the quiz data. + /// It retrieves the current quiz count, increments it, and then adds a new quiz entry to the quiz service. + /// Finally, it navigates to the "modifquiz" page. + /// + private async void HandleValidSubmit() { - + // Declare a variable to hold the ID of the new quiz. int id; + + // Get the current number of quizzes from the quiz service. id = await quizService.getNbQuiz(); + + // Increment the quiz ID for the new quiz. id++; + + // Create a new quiz and add it using the quiz service. await quizService.addQuiz(new Quiz( - id, - validateInformation(QuizModel.Question), - validateInformation(QuizModel.AnswerA), - validateInformation(QuizModel.AnswerB), - validateInformation(QuizModel.AnswerC), - validateInformation(QuizModel.AnswerD), - validateReponse(QuizModel.CAnswer) + id, // New quiz ID + validateInformation(QuizModel.Question), // Validated question + validateInformation(QuizModel.AnswerA), // Validated answer A + validateInformation(QuizModel.AnswerB), // Validated answer B + validateInformation(QuizModel.AnswerC), // Validated answer C + validateInformation(QuizModel.AnswerD), // Validated answer D + validateReponse(QuizModel.CAnswer) // Validated correct answer )); + + // Navigate to the "modifquiz" page after adding the quiz. NavigationManager.NavigateTo("modifquiz"); } + + + /// + /// Handles the change of the correct answer for the quiz. + /// This method is triggered when the user selects or changes the correct answer for the quiz question. + /// It updates the QuizModel's Correct Answer property with the selected answer. + /// + /// The selected answer that will be marked as the correct answer. + /// The value of the selected option, typically used for validation or additional logic. private void OnCAwnserChange(string item, object checkedValue) { + // Update the correct answer in the QuizModel with the selected answer. QuizModel.CAnswer = item; } + + /// + /// Validates the provided string item. + /// This method is used to validate input data, but the validation logic is not yet implemented. + /// + /// The string input to be validated. + /// + /// Returns the input string as it is for now. The validation logic is yet to be implemented. + /// private static string validateInformation(string item) { return item; // VALIDATION A FAIRE } - private static string validateReponse(string item) + /// + /// Validates the provided answer item (A, B, C, or D) for the quiz. + /// This method ensures that the input corresponds to one of the allowed values for the correct answer. + /// If the input is invalid or null, it throws an exception and returns a default value ("A") in case of error. + /// + /// The answer item (A, B, C, or D) to be validated. + /// + /// Returns the input item if valid (A, B, C, or D). If the item is invalid or null, it returns a default value ("A"). + /// + private static string validateReponse(string item) { try { + // Check if the item is not null or empty if (!string.IsNullOrEmpty(item)) { + // Validate that the item is one of the allowed values: A, B, C, or D switch (item) { case "A": @@ -67,18 +112,23 @@ namespace WF_WebAdmin.Pages case "D": break; default: - throw new InvalidDataException("Invalid item (validateReponse) : item must be A,B,C or D " + item + "give."); + // Throw exception if the item is not one of the allowed answers + throw new InvalidDataException("Invalid item (validateReponse) : item must be A,B,C or D " + item + " given."); } } else { + // Throw exception if the item is null or empty throw new ArgumentNullException("Invalid item (validateReponse): null given."); } + + // Return the validated item return item; } - catch (Exception ex) + catch (Exception ex) { - return "A"; //Default Argument + // In case of an exception, return a default answer ("A") + return "A"; // Default Argument } } } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs index 8cdd926..af88652 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs @@ -34,96 +34,176 @@ namespace WF_WebAdmin.Pages private IUserService userService { get; set; } [Inject] - 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) - { - 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) - { - userToAdmin.IsAdmin = true; - await userService.updateUser(userToAdmin); - ClosePopup(); - } - else - { - userToAdmin.IsAdmin = false; - await userService.updateUser(userToAdmin); - ClosePopup(); - } + public IStringLocalizer Localizer { get; set; } + + + + /// + /// This method is called when the component is initialized. + /// It is an asynchronous method that retrieves a list of users from the user service. + /// The method fetches a subset of users with a specified maximum value and page number (1 in this case). + /// + protected override async Task OnInitializedAsync() + { + // Retrieve a list of users using the user service. The number of users and page number are specified. + // MaxValue determines how many users to retrieve, and '1' refers to the first page of results. + users = await userService.getSomeUser(MaxValue, 1); + } + + + + /// + /// Handles the event when data is read in the data grid. + /// This method is triggered during pagination or when data is loaded into the grid. + /// It asynchronously fetches a page of users based on the requested page size and page number, + /// and updates the list of users and total item count if the operation is not cancelled. + /// + /// The event arguments containing pagination details (page size and page number) and a cancellation token. + private async Task OnReadData(DataGridReadDataEventArgs e) + { + // If the cancellation token is requested, exit the method without processing the request. + if (e.CancellationToken.IsCancellationRequested) + { + return; + } + + // Fetch a page of users from the user service using the page size and page number provided by the event arguments. + var response = await userService.getSomeUser(e.PageSize, e.Page); + + // If the operation is not cancelled, update the total number of users and the list of users. + if (!e.CancellationToken.IsCancellationRequested) + { + totalItem = await userService.getNbUser(); // Get the total number of users + users = new List(response.ToArray()); // Store the retrieved users in the users list + page = e.Page; // Update the current page number + } + } + + // ------- Popup remove user ------- + + /// + /// Displays a confirmation popup to confirm the deletion of a user. + /// This method is triggered when the user intends to delete a user, + /// and it sets the user to be deleted and shows the confirmation popup. + /// + /// The user to be deleted, which is passed to the method for confirmation. + private void ShowConfirmation(User user) + { + // Set the user to be deleted and show the confirmation popup. + userToDelete = user; // Store the user to be deleted in a variable + showPopupDelete = true; // Display the confirmation popup + } + + + /// + /// Displays a confirmation popup for modifying a user's information. + /// This method is triggered when the user intends to modify a specific user's data, + /// and it sets the selected user and shows the modification confirmation popup. + /// + /// The user whose information is to be modified, passed to the method for confirmation. + private void ShowModifyConfirmation(User user) + { + // Set the selected user and show the modification confirmation popup. + selectedUser = user; // Store the user to be modified + showModifyPopup = true; // Display the confirmation popup for modification + } + + + /// + /// Removes the specified user from the system. + /// This method is triggered when the user confirms the deletion of a user. + /// It calls the user service to remove the user, closes the confirmation popup, + /// and then refreshes the list of users by fetching the updated data. + /// + private async Task RemoveUser() + { + // Check if there is a user to delete + if (userToDelete != null) + { + // Remove the selected user from the system using the user service + await userService.removeUser(userToDelete); + + // Close the confirmation popup after the deletion + ClosePopup(); + + // Refresh the list of users by fetching the updated data from the user service + var response = await userService.getSomeUser(MaxValue, page); + + // Update the users list with the latest data + users = new List(response.ToArray()); + } + } + + + /// + /// Modifies the selected user's information. + /// This method is triggered when the user confirms the modification of a user's details. + /// It calls the user service to update the user's information and then closes the modification popup. + /// + private async Task ModifyUser() + { + // Update the selected user's information using the user service + await userService.updateUser(selectedUser); + + // Close the modification popup after the update is complete + ClosePopup(); + } + + + /// + /// Closes all open popups in the UI by setting their visibility flags to false. + /// This method is typically called after an action (like deleting or modifying a user) + /// to hide any active popups and reset the UI state. + /// + private void ClosePopup() + { + // Set all popup visibility flags to false to hide the popups + showDeletePopup = false; // Close the delete confirmation popup + showModifyPopup = false; // Close the modify confirmation popup + showPopupDelete = false; // Close any additional delete popups + showPopupAdmin = false; // Close the admin-related popup (if any) + } + + + // ------- Popup admin ------- + /// + /// Displays a confirmation popup to confirm the promotion of a user to admin status. + /// This method is triggered when the user intends to promote a specific user to admin. + /// It sets the selected user to be promoted and shows the confirmation popup for admin promotion. + /// + /// The user to be promoted to admin, passed to the method for confirmation. + private void ShowConfirmationAdmin(User user) + { + // Set the user to be promoted to admin and show the confirmation popup. + userToAdmin = user; // Store the user to be promoted + showPopupAdmin = true; // Display the confirmation popup for admin promotion + } + + + + /// + /// Toggles the admin status of the selected user. + /// This method checks the current admin status of the user, and if the user is not an admin, + /// it promotes them to admin. If the user is already an admin, it demotes them. + /// After the change, the user's information is updated, and the confirmation popup is closed. + /// + private async Task setAdmin() + { + // Check if the user is not already an admin + if (!userToAdmin.IsAdmin) + { + // Promote the user to admin + userToAdmin.IsAdmin = true; + await userService.updateUser(userToAdmin); // Update the user status in the service + ClosePopup(); // Close the confirmation popup + } + else + { + // Demote the user from admin to normal user + userToAdmin.IsAdmin = false; + await userService.updateUser(userToAdmin); // Update the user status in the service + ClosePopup(); // Close the confirmation popup + } } } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs index 71bb9f0..40ca959 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs @@ -23,9 +23,19 @@ namespace WF_WebAdmin.Pages private List src = new List(); + + /// + /// Asynchronously initializes the component by loading data related to a quote. + /// This method fetches a specific quote based on the provided ID and populates the `quoteModel` + /// with the quote's content, language, character, source, and other associated data. + /// It also loads additional data such as character and source information for the quote. + /// protected override async Task OnInitializedAsync() { + // Fetch the quote data based on the provided ID. q = await quoteService.getOnequote(Id); + + // Populate the quoteModel with the data from the retrieved quote. quoteModel.Content = q.Content; quoteModel.Langue = q.Langue; quoteModel.Charac = q.Charac; @@ -36,30 +46,50 @@ namespace WF_WebAdmin.Pages quoteModel.DateSrc = q.DateSrc; quoteModel.UserProposition = q.UserProposition; quoteModel.IsValid = q.IsValid; + + // Fetch additional data related to the quote, such as character and source. charac = await quoteService.getChar(); src = await quoteService.getSrc(); } + /// + /// Handles the submission of a valid form for updating a quote. + /// This method takes the data from `quoteModel`, updates the selected quote (`q`) with the new values, + /// and then calls the `quoteService.updateQuote` method to persist the changes. + /// After updating, it navigates to the "modifquote" page. + /// protected async void HandleValidSubmit() { + // Update the properties of the selected quote (`q`) with the data from `quoteModel`. q.Content = quoteModel.Content; q.Langue = quoteModel.Langue; q.TitleSrc = quoteModel.TitleSrc; q.Charac = quoteModel.Charac; + + // Call the quote service to update the quote in the data source. await quoteService.updateQuote(q); + + // Navigate to the "modifquote" page after updating the quote. NavigationManager.NavigateTo("modifquote"); } + + + /// + /// Handles the language change event for the quote. + /// This method updates the `Langue` property of the `quoteModel` based on the selected language (`item`). + /// It only accepts "fr" (French) or "en" (English) as valid language options. + /// + /// The selected language ("fr" or "en") passed to the method. + /// The checked value (unused in this method but may be used for other purposes). private void OnlangChange(string item, object checkedValue) { - if(item == "fr" || item == "en") + // Check if the selected language is either "fr" or "en" + if (item == "fr" || item == "en") { + // Update the Langue property of the quoteModel with the selected language quoteModel.Langue = item; - } + } } - - - - } } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Error.cshtml.cs b/WF-WebAdmin/WF-WebAdmin/Pages/Error.cshtml.cs index 49fc22c..76bb3fe 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/Error.cshtml.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Error.cshtml.cs @@ -14,13 +14,26 @@ namespace WF_WebAdmin.Pages private readonly ILogger _logger; + + /// + /// Initializes a new instance of the class. + /// This constructor is used to inject the into the model for logging purposes. + /// + /// An instance of the used for logging error-related information. public ErrorModel(ILogger logger) { _logger = logger; } + + /// + /// Handles the GET request for the page or endpoint. + /// This method retrieves the request ID for tracing purposes, using the `Activity.Current?.Id` + /// if it's available, or the `HttpContext.TraceIdentifier` as a fallback if no current activity ID is present. + /// public void OnGet() { + // Retrieve the current request ID for tracing RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; } } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor.cs index c63b04f..c3b9167 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor.cs @@ -26,45 +26,63 @@ namespace WF_WebAdmin.Pages [Inject] public NavigationManager NavigationManager { get; set; } + + /// + /// Asynchronously initializes the component by loading user login data. + /// This method retrieves a list of user login information from a JSON file located at the specified URI + /// and populates the `usersConnexion` list with the data. + /// protected override async Task OnInitializedAsync() { + // Fetch user login data from the specified JSON file. usersConnexion = await Http.GetFromJsonAsync>($"{NavigationManager.BaseUri}fake-dataUserLogin.json"); - } + /// + /// Validates the login credentials of the user. + /// This method checks if the provided username and password match any user in the `usersConnexion` list. + /// If the credentials are correct and the user is an admin, it stores the user details and navigates to the home page. + /// If the credentials are incorrect, an error message is set for display. + /// public void validlogin() { + // Check if both the username and password are provided if (!string.IsNullOrEmpty(userLogin.Name) || !string.IsNullOrEmpty(userLogin.Mdp)) { + // Loop through the list of connected users to find a match foreach (var user in usersConnexion) { - if(userLogin.Name == user.Name && userLogin.Mdp == user.Mdp) + // Check if the username and password match the user credentials + if (userLogin.Name == user.Name && userLogin.Mdp == user.Mdp) { - if(user.IsAdmin) + // Check if the user is an admin + if (user.IsAdmin) { + // If the user is an admin, store their information and navigate to the home page uLogin.Id = userLogin.Id; uLogin.Name = user.Name; uLogin.Image = user.Image; - + + // Redirect to the homepage NavigationManager.NavigateTo(NavigationManager.BaseUri + "accueil"); return; - + } else { + // If the user is not an admin, display an error message ErrorConnexion = "Connexion échouée, le nom ou le mot de passe sont incorrectes"; } } else { + // If credentials do not match, set the error message ErrorConnexion = "Connexion échouée, le nom ou le mot de passe sont incorrectes"; } } - } - } } } \ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuiz.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuiz.razor.cs index 6ba0d53..ad67da2 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuiz.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuiz.razor.cs @@ -28,60 +28,129 @@ namespace WF_WebAdmin.Pages [Inject] public IQuizService QuizService { get; set; } + /// + /// Handles the data reading event for a data grid, fetching quiz data based on the specified page and page size. + /// This method makes an asynchronous call to retrieve a specific page of quizzes and updates the `quiz` list and pagination details. + /// If the cancellation token is requested, it exits early without making further calls or updates. + /// + /// The event arguments containing pagination details such as page size and page number. private async Task OnReadData(DataGridReadDataEventArgs e) { + // Check if the cancellation token has been requested if (e.CancellationToken.IsCancellationRequested) { return; } + // Fetch the quiz data for the specified page and page size var response = await QuizService.getSommeQuiz(e.PageSize, e.Page); + // If cancellation hasn't been requested, process the data if (!e.CancellationToken.IsCancellationRequested) { + // Get the total number of quizzes for pagination purposes totalItem = await QuizService.getNbQuiz(); + + // Update the quiz data for the current page quiz = response.ToArray(); + + // Update the current page number page = e.Page; } } + /// + /// Handles the event when the "Edit" button is clicked for a quiz. + /// This method checks if a valid quiz is passed. If so, it sets the `selectedQuiz` to the clicked quiz and shows the quiz edit modal. + /// + /// The quiz object that was clicked for editing. private void OnEditButtonClicked(Quiz quiz) { + // If the quiz is null, return early if (quiz == null) return; + + // Set the selected quiz to the one clicked by the user selectedQuiz = quiz; + + // Show the modal or UI for editing the quiz showEditQuiz = true; } + + /// + /// Closes the open popups and resets any related states. + /// This method hides the quiz edit popup, the delete confirmation popup, and resets the selected quiz to `null`. + /// private void ClosePopup() { + // Hide the edit quiz popup showEditQuiz = false; + + // Hide the delete confirmation popup showPopupDelete = false; + + // Reset the selected quiz to null selectedQuiz = null; } + + + /// + /// Edits the selected quiz by updating it in the quiz service. + /// This method asynchronously sends the updated quiz data to the service for persistence. + /// After updating the quiz, it clears the selected quiz and closes any open popups. + /// private async Task EditQuiz() { + // Update the quiz in the service await QuizService.updateQuiz(selectedQuiz); + + // Clear the selected quiz after successful update selectedQuiz = null; + + // Close the popups after the edit operation ClosePopup(); } + + /// + /// Handles the event when the delete action is triggered for a quiz. + /// This method sets the selected quiz to the one passed as a parameter and shows the delete confirmation popup. + /// + /// The quiz to be deleted. private void OnDelete(Quiz q) { + // Set the selected quiz to the one passed in selectedQuiz = q; + + // Show the delete confirmation popup showPopupDelete = true; } + + /// + /// Removes the selected quiz from the quiz service and updates the quiz list. + /// This method first checks if a quiz is selected, and if so, it deletes the quiz by calling the service. + /// After removal, it clears the `selectedQuiz`, updates the quiz list, and closes the delete confirmation popup. + /// private async void RemoveQuote() { + // Check if a quiz is selected for deletion if (selectedQuiz != null) { + // Remove the selected quiz from the service by its ID await QuizService.removeQuiz(selectedQuiz.Id); + + // Clear the selected quiz after successful removal selectedQuiz = null; + + // Update the quiz list by fetching the latest data var response = await QuizService.getSommeQuiz(MaxValue, page); quiz = response.ToArray(); } - showPopupDelete= false; + + // Close the delete confirmation popup + showPopupDelete = false; } } } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs index 8bf4ed1..e1daee8 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs @@ -28,19 +28,34 @@ namespace WF_WebAdmin.Pages [Inject] public IQuoteService QuoteService { get; set; } + + /// + /// Handles the data reading event for a data grid, fetching quote data based on the specified page and page size. + /// This method makes an asynchronous call to retrieve a specific page of quotes and updates the `quotes` list and pagination details. + /// If the cancellation token is requested, it exits early without making further calls or updates. + /// + /// The event arguments containing pagination details such as page size and page number. private async Task OnReadData(DataGridReadDataEventArgs e) { + // Check if the cancellation token has been requested if (e.CancellationToken.IsCancellationRequested) { return; } + // Fetch the quote data for the specified page and page size var response = await QuoteService.getSomeQuote(e.PageSize, e.Page); + // If cancellation hasn't been requested, process the data if (!e.CancellationToken.IsCancellationRequested) { + // Get the total number of quotes for pagination purposes totalItem = await QuoteService.getNbQuote(); + + // Update the quotes data for the current page quotes = response.ToArray(); + + // Update the current page number page = e.Page; } } @@ -51,11 +66,17 @@ namespace WF_WebAdmin.Pages selectedQuote = quote; showEditQuote = true; }*/ - + + /// + /// Closes the open popups and resets any related states. + /// This method hides the delete confirmation popup and clears the selected quote. + /// private void ClosePopup() { - /*showEditQuote = false;*/ + // Hide the delete confirmation popup showPopupDelete = false; + + // Reset the selected quote to null selectedQuote = null; } @@ -66,22 +87,43 @@ namespace WF_WebAdmin.Pages ClosePopup(); }*/ + /// + /// Handles the event when the delete action is triggered for a quote. + /// This method sets the selected quote to the one passed as a parameter and displays the delete confirmation popup. + /// + /// The quote that is being deleted. private void OnDelete(Quote q) { + // Set the selected quote to the one passed in selectedQuote = q; + + // Display the delete confirmation popup showPopupDelete = true; } + /// + /// Removes the selected quote by calling the remove service and updates the quote list. + /// This method checks if a quote is selected. If so, it removes the quote using the `QuoteService`, clears the selected quote, + /// and fetches the updated list of quotes. It also closes the delete confirmation popup after the operation. + /// private async void RemoveQuote() { + // Check if a quote is selected for removal if (selectedQuote != null) { + // Remove the selected quote using the QuoteService await QuoteService.removeQuote(selectedQuote); - selectedQuote= null; + + // Clear the selected quote after removal + selectedQuote = null; + + // Update the quotes list by fetching the latest quotes data var response = await QuoteService.getSomeQuote(MaxValue, page); quotes = response.ToArray(); } - showPopupDelete= false; + + // Close the delete confirmation popup + showPopupDelete = false; } } } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuiz.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuiz.razor.cs index 6239fdd..d2368de 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuiz.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuiz.razor.cs @@ -20,39 +20,73 @@ namespace WF_WebAdmin.Pages public NavigationManager NavigationManager { get; set; } [Inject] - public IQuizService QuizService { get; set; } - - protected override async Task OnInitializedAsync() - { - quizzes = await QuizService.getQuizzesToValidate(); - } - - private void OnValidButton(Quiz quiz) - { - ValidateQuiz(quiz); - } - - private void ValidateQuiz(Quiz quiz) - { - Console.WriteLine($"Quiz {quiz.Id} validated!"); - - Quiz newQuiz = quiz; - newQuiz.IsValid = true; - - // Mis à jour de l'état du quiz - QuizService.updateQuiz(quiz); - } - - private void OnRejectButton(Quiz quiz) - { - RejectQuiz(quiz); - } - - private void RejectQuiz(Quiz quiz) - { - Console.WriteLine($"Quiz {quiz.Id} rejected!"); - - QuizService.removeQuiz(quiz.Id); + public IQuizService QuizService { get; set; } + + + /// + /// Initializes the component asynchronously by fetching the quizzes that need validation. + /// This method retrieves a list of quizzes from the `QuizService` that are pending validation when the component is initialized. + /// + protected override async Task OnInitializedAsync() + { + // Fetch quizzes that need validation + quizzes = await QuizService.getQuizzesToValidate(); + } + + /// + /// Handles the event when the "Validate" button is clicked for a quiz. + /// This method calls the `ValidateQuiz` method, passing the specified quiz for validation. + /// + /// The quiz that is being validated. + private void OnValidButton(Quiz quiz) + { + // Call the ValidateQuiz method to validate the quiz + ValidateQuiz(quiz); + } + + /// + /// Validates the specified quiz by setting its `IsValid` property to true and updating its state in the service. + /// This method logs a message to the console indicating the quiz has been validated, then updates the quiz's validation status. + /// It then calls the `QuizService.updateQuiz` method to persist the changes. + /// + /// The quiz that is being validated. + private void ValidateQuiz(Quiz quiz) + { + // Log the validation action to the console + Console.WriteLine($"Quiz {quiz.Id} validated!"); + + // Create a new quiz instance (or modify the existing one) + Quiz newQuiz = quiz; + newQuiz.IsValid = true; + + // Update the quiz state in the QuizService + QuizService.updateQuiz(quiz); + } + + /// + /// Handles the event when the "Reject" button is clicked for a quiz. + /// This method calls the `RejectQuiz` method, passing the specified quiz to be rejected. + /// + /// The quiz that is being rejected. + private void OnRejectButton(Quiz quiz) + { + // Call the RejectQuiz method to reject the quiz + RejectQuiz(quiz); + } + + /// + /// Rejects the specified quiz by logging a rejection message and removing it from the QuizService. + /// This method logs a message to the console indicating the quiz has been rejected, and then calls the `QuizService.removeQuiz` + /// method to remove the quiz from the system. + /// + /// The quiz that is being rejected. + private void RejectQuiz(Quiz quiz) + { + // Log the rejection action to the console + Console.WriteLine($"Quiz {quiz.Id} rejected!"); + + // Remove the rejected quiz from the QuizService + QuizService.removeQuiz(quiz.Id); } } } \ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs index 4c9a4b5..779e014 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs @@ -21,11 +21,17 @@ namespace WF_WebAdmin.Pages public HttpClient Http { get; set; } [Inject] - public NavigationManager NavigationManager { get; set; } - - protected override async Task OnInitializedAsync() - { - quotes = await Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-dataQuote.json"); + public NavigationManager NavigationManager { get; set; } + + /// + /// Initializes the component asynchronously by fetching a list of quotes from a JSON file. + /// This method makes an asynchronous HTTP request to retrieve an array of `Quote` objects from a specified JSON file + /// located at the base URI, and then assigns the result to the `quotes` variable. + /// + protected override async Task OnInitializedAsync() + { + // Fetch the list of quotes from the JSON file located at the base URI + quotes = await Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-dataQuote.json"); } } } From 8739576cecb96a513e431b65d9e6e74d00f4a9b1 Mon Sep 17 00:00:00 2001 From: lebeaulato Date: Fri, 7 Feb 2025 15:48:10 +0100 Subject: [PATCH 03/11] =?UTF-8?q?pb=20de=20URL=20corrig=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WF-WebAdmin/WF-WebAdmin.sln | 3 +-- WF-WebAdmin/WF-WebAdmin/Program.cs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/WF-WebAdmin/WF-WebAdmin.sln b/WF-WebAdmin/WF-WebAdmin.sln index ae4047e..6826f29 100644 --- a/WF-WebAdmin/WF-WebAdmin.sln +++ b/WF-WebAdmin/WF-WebAdmin.sln @@ -5,7 +5,7 @@ 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}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTestWF", "UnitTestWF\UnitTestWF.csproj", "{A4EC0EC4-7A46-4F8E-99C3-4FD32F173F2F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -18,7 +18,6 @@ Global {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 diff --git a/WF-WebAdmin/WF-WebAdmin/Program.cs b/WF-WebAdmin/WF-WebAdmin/Program.cs index 51f1d46..4882d0e 100644 --- a/WF-WebAdmin/WF-WebAdmin/Program.cs +++ b/WF-WebAdmin/WF-WebAdmin/Program.cs @@ -25,7 +25,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddHttpClient(); builder.Services.AddScoped(); -builder.WebHost.UseUrls("http://0.0.0.0:5000"); +//builder.WebHost.UseUrls("http://0.0.0.0:5000"); builder.Services .AddBlazorise() From f1ec7af13c2990298eb81cfcd8cd0550e136f986 Mon Sep 17 00:00:00 2001 From: lebeaulato Date: Fri, 7 Feb 2025 15:52:18 +0100 Subject: [PATCH 04/11] =?UTF-8?q?Login=20retir=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WF-WebAdmin/WF-WebAdmin/Program.cs | 2 +- WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor | 2 +- WF-WebAdmin/WF-WebAdmin/wwwroot/fake_data_quiz.json | 13 +------------ 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/WF-WebAdmin/WF-WebAdmin/Program.cs b/WF-WebAdmin/WF-WebAdmin/Program.cs index 51f1d46..4882d0e 100644 --- a/WF-WebAdmin/WF-WebAdmin/Program.cs +++ b/WF-WebAdmin/WF-WebAdmin/Program.cs @@ -25,7 +25,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddHttpClient(); builder.Services.AddScoped(); -builder.WebHost.UseUrls("http://0.0.0.0:5000"); +//builder.WebHost.UseUrls("http://0.0.0.0:5000"); builder.Services .AddBlazorise() diff --git a/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor b/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor index 83deca9..fe5f0a7 100644 --- a/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor +++ b/WF-WebAdmin/WF-WebAdmin/Shared/NavMenu.razor @@ -15,7 +15,7 @@