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

master
parent 611de18362
commit d2188b3de8

@ -1,135 +1,135 @@
using Blazorise.DataGrid; using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
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 ModifQuote public partial class ModifQuote
{ {
private Quote[] quotes; private Quote[] quotes;
private int MaxValue = 5; private int MaxValue = 5;
private int totalItem; private int totalItem;
/*private bool showEditQuote = false;*/ /*private bool showEditQuote = false;*/
private Quote? selectedQuote; private Quote? selectedQuote;
private bool showPopupDelete = false; private bool showPopupDelete = false;
private int page = 1; private int page = 1;
[Inject] [Inject]
public ILogger<ModifQuote> Logger { get; set; } public ILogger<ModifQuote> Logger { get; set; }
[Inject] [Inject]
public IStringLocalizer<ModifQuote> Localizer { get; set; } public IStringLocalizer<ModifQuote> Localizer { get; set; }
[Inject] [Inject]
public IQuoteService QuoteService { get; set; } public IQuoteService QuoteService { get; set; }
/// <summary> /// <summary>
/// Handles the data reading event for a data grid, fetching quote data based on the specified page and page size. /// 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. /// 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. /// 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<Quote> e) private async Task OnReadData(DataGridReadDataEventArgs<Quote> 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 quote data for the specified page and page size // Fetch the quote data for the specified page and page size
var response = await QuoteService.getSomeQuote(e.PageSize, e.Page); var response = await QuoteService.getSomeQuote(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 quotes for pagination purposes // Get the total number of quotes for pagination purposes
totalItem = await QuoteService.getNbQuote(); totalItem = await QuoteService.getNbQuote();
// Update the quotes data for the current page // Update the quotes data for the current page
quotes = response.ToArray(); quotes = response.ToArray();
// Update the current page number // Update the current page number
page = e.Page; page = e.Page;
} }
} }
/*private void OnEditButtonClicked(Quote quote) /*private void OnEditButtonClicked(Quote quote)
{ {
if (selectedQuote == null) return; if (selectedQuote == null) return;
selectedQuote = quote; selectedQuote = quote;
showEditQuote = true; showEditQuote = 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 delete confirmation popup and clears the selected quote. /// This method hides the delete confirmation popup and clears the selected quote.
/// </summary> /// </summary>
private void ClosePopup() private void ClosePopup()
{ {
// Hide the delete confirmation popup // Hide the delete confirmation popup
showPopupDelete = false; showPopupDelete = false;
// Reset the selected quote to null // Reset the selected quote to null
selectedQuote = null; selectedQuote = null;
} }
/*private async Task EditQuote() /*private async Task EditQuote()
{ {
await QuoteService.updateQuote(selectedQuote); await QuoteService.updateQuote(selectedQuote);
selectedQuote = null; selectedQuote = null;
ClosePopup(); ClosePopup();
}*/ }*/
/// <summary> /// <summary>
/// Handles the event when the delete action is triggered for a quote. /// 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. /// This method sets the selected quote to the one passed as a parameter and displays the delete confirmation popup.
/// </summary> /// </summary>
/// <param name="q">The quote that is being deleted.</param> /// <param name="q">The quote that is being deleted.</param>
private void OnDelete(Quote q) private void OnDelete(Quote q)
{ {
// Set the selected quote to the one passed in // Set the selected quote to the one passed in
selectedQuote = q; selectedQuote = q;
// Display the delete confirmation popup // Display the delete confirmation popup
showPopupDelete = true; showPopupDelete = true;
} }
/// <summary> /// <summary>
/// Removes the selected quote by calling the remove service and updates the quote list. /// 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, /// 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. /// and fetches the updated list of quotes. It also closes the delete confirmation popup after the operation.
/// </summary> /// </summary>
private async void RemoveQuote() private async Task RemoveQuote()
{ {
// Check if a quote is selected for removal // Check if a quote is selected for removal
if (selectedQuote != null) if (selectedQuote != null)
{ {
// Remove the selected quote using the QuoteService // Remove the selected quote using the QuoteService
LoggerSaveStub.Log(Logger, LogLevel.Information, $"The quote {selectedQuote.Content} has been deleted"); LoggerSaveStub.Log(Logger, LogLevel.Information, $"The quote {selectedQuote.Content} has been deleted");
await QuoteService.removeQuote(selectedQuote); await QuoteService.removeQuote(selectedQuote);
// Clear the selected quote after removal // Clear the selected quote after removal
selectedQuote = null; selectedQuote = null;
// Update the quotes list by fetching the latest quotes data // Update the quotes list by fetching the latest quotes data
var response = await QuoteService.getSomeQuote(MaxValue, page); var response = await QuoteService.getSomeQuote(MaxValue, page);
quotes = response.ToArray(); quotes = response.ToArray();
} }
// Close the delete confirmation popup // Close the delete confirmation popup
showPopupDelete = false; showPopupDelete = false;
} }
} }
} }

Loading…
Cancel
Save