Mise à jour de 'WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs'
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
611de18362
commit
d2188b3de8
@ -1,135 +1,135 @@
|
||||
using Blazorise.DataGrid;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Security.Claims;
|
||||
using WF_WebAdmin.Model;
|
||||
using WF_WebAdmin.Service;
|
||||
|
||||
namespace WF_WebAdmin.Pages
|
||||
{
|
||||
public partial class ModifQuote
|
||||
{
|
||||
private Quote[] quotes;
|
||||
|
||||
private int MaxValue = 5;
|
||||
|
||||
private int totalItem;
|
||||
|
||||
/*private bool showEditQuote = false;*/
|
||||
|
||||
private Quote? selectedQuote;
|
||||
|
||||
private bool showPopupDelete = false;
|
||||
|
||||
private int page = 1;
|
||||
|
||||
[Inject]
|
||||
public ILogger<ModifQuote> Logger { get; set; }
|
||||
|
||||
[Inject]
|
||||
public IStringLocalizer<ModifQuote> Localizer { get; set; }
|
||||
|
||||
[Inject]
|
||||
public IQuoteService QuoteService { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="e">The event arguments containing pagination details such as page size and page number.</param>
|
||||
private async Task OnReadData(DataGridReadDataEventArgs<Quote> 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;
|
||||
}
|
||||
}
|
||||
|
||||
/*private void OnEditButtonClicked(Quote quote)
|
||||
{
|
||||
if (selectedQuote == null) return;
|
||||
selectedQuote = quote;
|
||||
showEditQuote = true;
|
||||
}*/
|
||||
|
||||
/// <summary>
|
||||
/// Closes the open popups and resets any related states.
|
||||
/// This method hides the delete confirmation popup and clears the selected quote.
|
||||
/// </summary>
|
||||
private void ClosePopup()
|
||||
{
|
||||
// Hide the delete confirmation popup
|
||||
showPopupDelete = false;
|
||||
|
||||
// Reset the selected quote to null
|
||||
selectedQuote = null;
|
||||
}
|
||||
|
||||
/*private async Task EditQuote()
|
||||
{
|
||||
await QuoteService.updateQuote(selectedQuote);
|
||||
selectedQuote = null;
|
||||
ClosePopup();
|
||||
}*/
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="q">The quote that is being deleted.</param>
|
||||
private void OnDelete(Quote q)
|
||||
{
|
||||
// Set the selected quote to the one passed in
|
||||
selectedQuote = q;
|
||||
|
||||
// Display the delete confirmation popup
|
||||
showPopupDelete = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
private async void RemoveQuote()
|
||||
{
|
||||
// Check if a quote is selected for removal
|
||||
if (selectedQuote != null)
|
||||
{
|
||||
// Remove the selected quote using the QuoteService
|
||||
LoggerSaveStub.Log(Logger, LogLevel.Information, $"The quote {selectedQuote.Content} has been deleted");
|
||||
await QuoteService.removeQuote(selectedQuote);
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
// Close the delete confirmation popup
|
||||
showPopupDelete = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
using Blazorise.DataGrid;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Security.Claims;
|
||||
using WF_WebAdmin.Model;
|
||||
using WF_WebAdmin.Service;
|
||||
|
||||
namespace WF_WebAdmin.Pages
|
||||
{
|
||||
public partial class ModifQuote
|
||||
{
|
||||
private Quote[] quotes;
|
||||
|
||||
private int MaxValue = 5;
|
||||
|
||||
private int totalItem;
|
||||
|
||||
/*private bool showEditQuote = false;*/
|
||||
|
||||
private Quote? selectedQuote;
|
||||
|
||||
private bool showPopupDelete = false;
|
||||
|
||||
private int page = 1;
|
||||
|
||||
[Inject]
|
||||
public ILogger<ModifQuote> Logger { get; set; }
|
||||
|
||||
[Inject]
|
||||
public IStringLocalizer<ModifQuote> Localizer { get; set; }
|
||||
|
||||
[Inject]
|
||||
public IQuoteService QuoteService { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="e">The event arguments containing pagination details such as page size and page number.</param>
|
||||
private async Task OnReadData(DataGridReadDataEventArgs<Quote> 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;
|
||||
}
|
||||
}
|
||||
|
||||
/*private void OnEditButtonClicked(Quote quote)
|
||||
{
|
||||
if (selectedQuote == null) return;
|
||||
selectedQuote = quote;
|
||||
showEditQuote = true;
|
||||
}*/
|
||||
|
||||
/// <summary>
|
||||
/// Closes the open popups and resets any related states.
|
||||
/// This method hides the delete confirmation popup and clears the selected quote.
|
||||
/// </summary>
|
||||
private void ClosePopup()
|
||||
{
|
||||
// Hide the delete confirmation popup
|
||||
showPopupDelete = false;
|
||||
|
||||
// Reset the selected quote to null
|
||||
selectedQuote = null;
|
||||
}
|
||||
|
||||
/*private async Task EditQuote()
|
||||
{
|
||||
await QuoteService.updateQuote(selectedQuote);
|
||||
selectedQuote = null;
|
||||
ClosePopup();
|
||||
}*/
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="q">The quote that is being deleted.</param>
|
||||
private void OnDelete(Quote q)
|
||||
{
|
||||
// Set the selected quote to the one passed in
|
||||
selectedQuote = q;
|
||||
|
||||
// Display the delete confirmation popup
|
||||
showPopupDelete = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
private async Task RemoveQuote()
|
||||
{
|
||||
// Check if a quote is selected for removal
|
||||
if (selectedQuote != null)
|
||||
{
|
||||
// Remove the selected quote using the QuoteService
|
||||
LoggerSaveStub.Log(Logger, LogLevel.Information, $"The quote {selectedQuote.Content} has been deleted");
|
||||
await QuoteService.removeQuote(selectedQuote);
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
// Close the delete confirmation popup
|
||||
showPopupDelete = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue