|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
using Blazorise.DataGrid;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using Microsoft.Extensions.Configuration.UserSecrets;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using WF_WebAdmin.Model;
|
|
|
|
@ -10,10 +11,13 @@ namespace WF_WebAdmin.Pages
|
|
|
|
|
{
|
|
|
|
|
public partial class DeleteUser
|
|
|
|
|
{
|
|
|
|
|
[Inject]
|
|
|
|
|
public ILogger<DeleteUser> Logger { get; set; }
|
|
|
|
|
|
|
|
|
|
private List<User> users;
|
|
|
|
|
|
|
|
|
|
private bool showDeletePopup = false;
|
|
|
|
|
private bool showModifyPopup = false;
|
|
|
|
|
private List<User> users;
|
|
|
|
|
private User userToDelete = null;
|
|
|
|
|
private User selectedUser;
|
|
|
|
|
private bool showPopupDelete = false;
|
|
|
|
@ -34,22 +38,22 @@ namespace WF_WebAdmin.Pages
|
|
|
|
|
private IUserService userService { get; set; }
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public IStringLocalizer<DeleteUser> Localizer { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IStringLocalizer<DeleteUser> Localizer { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 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).
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
users = await userService.getSomeUser(MaxValue, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -59,27 +63,27 @@ namespace WF_WebAdmin.Pages
|
|
|
|
|
/// and updates the list of users and total item count if the operation is not cancelled.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e">The event arguments containing pagination details (page size and page number) and a cancellation token.</param>
|
|
|
|
|
private async Task OnReadData(DataGridReadDataEventArgs<User> e)
|
|
|
|
|
{
|
|
|
|
|
private async Task OnReadData(DataGridReadDataEventArgs<User> e)
|
|
|
|
|
{
|
|
|
|
|
// If the cancellation token is requested, exit the method without processing the request.
|
|
|
|
|
if (e.CancellationToken.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
if (!e.CancellationToken.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
totalItem = await userService.getNbUser(); // Get the total number of users
|
|
|
|
|
users = new List<User>(response.ToArray()); // Store the retrieved users in the users list
|
|
|
|
|
page = e.Page; // Update the current page number
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------- Popup remove user -------
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------- Popup remove user -------
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Displays a confirmation popup to confirm the deletion of a user.
|
|
|
|
@ -87,13 +91,13 @@ namespace WF_WebAdmin.Pages
|
|
|
|
|
/// and it sets the user to be deleted and shows the confirmation popup.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="user">The user to be deleted, which is passed to the method for confirmation.</param>
|
|
|
|
|
private void ShowConfirmation(User user)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Displays a confirmation popup for modifying a user's information.
|
|
|
|
@ -101,13 +105,13 @@ namespace WF_WebAdmin.Pages
|
|
|
|
|
/// and it sets the selected user and shows the modification confirmation popup.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="user">The user whose information is to be modified, passed to the method for confirmation.</param>
|
|
|
|
|
private void ShowModifyConfirmation(User user)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes the specified user from the system.
|
|
|
|
@ -115,95 +119,99 @@ namespace WF_WebAdmin.Pages
|
|
|
|
|
/// 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.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private async Task RemoveUser()
|
|
|
|
|
{
|
|
|
|
|
private async Task RemoveUser()
|
|
|
|
|
{
|
|
|
|
|
// Check if there is a user to delete
|
|
|
|
|
if (userToDelete != null)
|
|
|
|
|
{
|
|
|
|
|
if (userToDelete != null)
|
|
|
|
|
{
|
|
|
|
|
// Remove the selected user from the system using the user service
|
|
|
|
|
await userService.removeUser(userToDelete);
|
|
|
|
|
LoggerSaveStub.Log(Logger, LogLevel.Information, $"Supretion de l utilisateur : {userToDelete.Name}");
|
|
|
|
|
await userService.removeUser(userToDelete);
|
|
|
|
|
|
|
|
|
|
// Close the confirmation popup after the deletion
|
|
|
|
|
ClosePopup();
|
|
|
|
|
ClosePopup();
|
|
|
|
|
|
|
|
|
|
// Refresh the list of users by fetching the updated data from the user service
|
|
|
|
|
var response = await userService.getSomeUser(MaxValue, page);
|
|
|
|
|
var response = await userService.getSomeUser(MaxValue, page);
|
|
|
|
|
|
|
|
|
|
// Update the users list with the latest data
|
|
|
|
|
users = new List<User>(response.ToArray());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
users = new List<User>(response.ToArray());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 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.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private async Task ModifyUser()
|
|
|
|
|
{
|
|
|
|
|
private async Task ModifyUser()
|
|
|
|
|
{
|
|
|
|
|
// Update the selected user's information using the user service
|
|
|
|
|
await userService.updateUser(selectedUser);
|
|
|
|
|
LoggerSaveStub.Log(Logger, LogLevel.Information, $"Modification de l utilisateur : {selectedUser.Name}");
|
|
|
|
|
await userService.updateUser(selectedUser);
|
|
|
|
|
|
|
|
|
|
// Close the modification popup after the update is complete
|
|
|
|
|
ClosePopup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClosePopup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 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.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ClosePopup()
|
|
|
|
|
{
|
|
|
|
|
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 -------
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ------- Popup admin -------
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 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.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="user">The user to be promoted to admin, passed to the method for confirmation.</param>
|
|
|
|
|
private void ShowConfirmationAdmin(User user)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 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.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private async Task setAdmin()
|
|
|
|
|
{
|
|
|
|
|
private async Task setAdmin()
|
|
|
|
|
{
|
|
|
|
|
// Check if the user is not already an admin
|
|
|
|
|
if (!userToAdmin.IsAdmin)
|
|
|
|
|
{
|
|
|
|
|
if (!userToAdmin.IsAdmin)
|
|
|
|
|
{
|
|
|
|
|
// Promote the user to admin
|
|
|
|
|
userToAdmin.IsAdmin = true;
|
|
|
|
|
LoggerSaveStub.Log(Logger, LogLevel.Information, $"L utilisateur {userToAdmin.Name} a ete mis en administrateur");
|
|
|
|
|
userToAdmin.IsAdmin = true;
|
|
|
|
|
await userService.updateUser(userToAdmin); // Update the user status in the service
|
|
|
|
|
ClosePopup(); // Close the confirmation popup
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Demote the user from admin to normal user
|
|
|
|
|
userToAdmin.IsAdmin = false;
|
|
|
|
|
LoggerSaveStub.Log(Logger, LogLevel.Information, $"L utilisateur {userToAdmin.Name} n'est plus administrateur");
|
|
|
|
|
userToAdmin.IsAdmin = false;
|
|
|
|
|
await userService.updateUser(userToAdmin); // Update the user status in the service
|
|
|
|
|
ClosePopup(); // Close the confirmation popup
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|