Mise à jour de 'WF-WebAdmin/WF-WebAdmin/Pages/ModifQuiz.razor.cs'
continuous-integration/drone/push Build is passing Details

master
parent f6bd5d2fc1
commit c358e55aa2

@ -1,162 +1,162 @@
using Blazorise.DataGrid; using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using System.Security.Claims; using System.Security.Claims;
using WF_WebAdmin.Model; using WF_WebAdmin.Model;
using WF_WebAdmin.Service; using WF_WebAdmin.Service;
namespace WF_WebAdmin.Pages namespace WF_WebAdmin.Pages
{ {
public partial class ModifQuiz public partial class ModifQuiz
{ {
private Quiz[] quiz; private Quiz[] quiz;
private int MaxValue = 5; private int MaxValue = 5;
private int totalItem; private int totalItem;
private bool showEditQuiz = false; private bool showEditQuiz = false;
private Quiz? selectedQuiz; private Quiz? selectedQuiz;
private bool showPopupDelete = false; private bool showPopupDelete = false;
private int page = 1; private int page = 1;
[Inject] [Inject]
public ILogger<ModifQuiz> Logger { get; set; } public ILogger<ModifQuiz> Logger { get; set; }
[Inject] [Inject]
public IStringLocalizer<ModifQuiz> Localizer { get; set; } public IStringLocalizer<ModifQuiz> Localizer { get; set; }
[Inject] [Inject]
public IQuizService QuizService { get; set; } public IQuizService QuizService { get; set; }
/// <summary> /// <summary>
/// Handles the data reading event for a data grid, fetching quiz data based on the specified page and page size. /// 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. /// 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. /// If the cancellation token is requested, it exits early without making further calls or updates.
/// </summary> /// </summary>
/// <param name="e">The event arguments containing pagination details such as page size and page number.</param> /// <param name="e">The event arguments containing pagination details such as page size and page number.</param>
private async Task OnReadData(DataGridReadDataEventArgs<Quiz> e) private async Task OnReadData(DataGridReadDataEventArgs<Quiz> e)
{ {
// Check if the cancellation token has been requested // Check if the cancellation token has been requested
if (e.CancellationToken.IsCancellationRequested) if (e.CancellationToken.IsCancellationRequested)
{ {
return; return;
} }
// Fetch the quiz data for the specified page and page size // Fetch the quiz data for the specified page and page size
var response = await QuizService.getSommeQuiz(e.PageSize, e.Page); var response = await QuizService.getSommeQuiz(e.PageSize, e.Page);
// If cancellation hasn't been requested, process the data // If cancellation hasn't been requested, process the data
if (!e.CancellationToken.IsCancellationRequested) if (!e.CancellationToken.IsCancellationRequested)
{ {
// Get the total number of quizzes for pagination purposes // Get the total number of quizzes for pagination purposes
totalItem = await QuizService.getNbQuiz(); totalItem = await QuizService.getNbQuiz();
// Update the quiz data for the current page // Update the quiz data for the current page
quiz = response.ToArray(); quiz = response.ToArray();
// Update the current page number // Update the current page number
page = e.Page; page = e.Page;
} }
} }
/// <summary> /// <summary>
/// Handles the event when the "Edit" button is clicked for a quiz. /// 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. /// 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.
/// </summary> /// </summary>
/// <param name="quiz">The quiz object that was clicked for editing.</param> /// <param name="quiz">The quiz object that was clicked for editing.</param>
private void OnEditButtonClicked(Quiz quiz) private void OnEditButtonClicked(Quiz quiz)
{ {
// If the quiz is null, return early // If the quiz is null, return early
if (quiz == null) return; if (quiz == null) return;
// Set the selected quiz to the one clicked by the user // Set the selected quiz to the one clicked by the user
selectedQuiz = quiz; selectedQuiz = quiz;
// Show the modal or UI for editing the quiz // Show the modal or UI for editing the quiz
showEditQuiz = true; showEditQuiz = true;
} }
/// <summary> /// <summary>
/// Closes the open popups and resets any related states. /// 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`. /// This method hides the quiz edit popup, the delete confirmation popup, and resets the selected quiz to `null`.
/// </summary> /// </summary>
private void ClosePopup() private void ClosePopup()
{ {
// Hide the edit quiz popup // Hide the edit quiz popup
showEditQuiz = false; showEditQuiz = false;
// Hide the delete confirmation popup // Hide the delete confirmation popup
showPopupDelete = false; showPopupDelete = false;
// Reset the selected quiz to null // Reset the selected quiz to null
selectedQuiz = null; selectedQuiz = null;
} }
/// <summary> /// <summary>
/// Edits the selected quiz by updating it in the quiz service. /// Edits the selected quiz by updating it in the quiz service.
/// This method asynchronously sends the updated quiz data to the service for persistence. /// 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. /// After updating the quiz, it clears the selected quiz and closes any open popups.
/// </summary> /// </summary>
private async Task EditQuiz() private async Task EditQuiz()
{ {
// Update the quiz in the service // Update the quiz in the service
LoggerSaveStub.Log(Logger, LogLevel.Information, $"Editing the question {selectedQuiz.Question}"); LoggerSaveStub.Log(Logger, LogLevel.Information, $"Editing the question {selectedQuiz.Question}");
await QuizService.updateQuiz(selectedQuiz); await QuizService.updateQuiz(selectedQuiz);
// Clear the selected quiz after successful update // Clear the selected quiz after successful update
selectedQuiz = null; selectedQuiz = null;
// Close the popups after the edit operation // Close the popups after the edit operation
ClosePopup(); ClosePopup();
} }
/// <summary> /// <summary>
/// Handles the event when the delete action is triggered for a quiz. /// 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. /// This method sets the selected quiz to the one passed as a parameter and shows the delete confirmation popup.
/// </summary> /// </summary>
/// <param name="q">The quiz to be deleted.</param> /// <param name="q">The quiz to be deleted.</param>
private void OnDelete(Quiz q) private void OnDelete(Quiz q)
{ {
// Set the selected quiz to the one passed in // Set the selected quiz to the one passed in
selectedQuiz = q; selectedQuiz = q;
// Show the delete confirmation popup // Show the delete confirmation popup
showPopupDelete = true; showPopupDelete = true;
} }
/// <summary> /// <summary>
/// Removes the selected quiz from the quiz service and updates the quiz list. /// 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. /// 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. /// After removal, it clears the `selectedQuiz`, updates the quiz list, and closes the delete confirmation popup.
/// </summary> /// </summary>
private async void RemoveQuote() private async Task RemoveQuote()
{ {
// Check if a quiz is selected for deletion // Check if a quiz is selected for deletion
if (selectedQuiz != null) if (selectedQuiz != null)
{ {
// Remove the selected quiz from the service by its ID // Remove the selected quiz from the service by its ID
LoggerSaveStub.Log(Logger, LogLevel.Information, $"Delete the question {selectedQuiz.Question}"); LoggerSaveStub.Log(Logger, LogLevel.Information, $"Delete the question {selectedQuiz.Question}");
await QuizService.removeQuiz(selectedQuiz.Id); await QuizService.removeQuiz(selectedQuiz.Id);
// Clear the selected quiz after successful removal // Clear the selected quiz after successful removal
selectedQuiz = null; selectedQuiz = null;
// Update the quiz list by fetching the latest data // Update the quiz list by fetching the latest data
var response = await QuizService.getSommeQuiz(MaxValue, page); var response = await QuizService.getSommeQuiz(MaxValue, page);
quiz = response.ToArray(); quiz = response.ToArray();
} }
// Close the delete confirmation popup // Close the delete confirmation popup
showPopupDelete = false; showPopupDelete = false;
} }
} }
} }

Loading…
Cancel
Save