Code Smells from Pages/DeleteUser
continuous-integration/drone/push Build is passing Details

master
tomivt 2 months ago
parent cc616955bc
commit ccf7e35f39

@ -5,7 +5,7 @@
<h3>@Localizer["TitleUser"]</h3>
@if(users == null)
@if(_users == null)
{
<p><strong>@Localizer["UserNobody"]</strong></p>
}
@ -13,10 +13,10 @@
else
{
<DataGrid TItem="User"
Data="@users"
Data="@_users"
PageSize="@MaxValue"
ReadData="@OnReadData"
TotalItems="@totalItem"
TotalItems="@_totalItem"
ShowPager
Responsive>
@ -29,7 +29,7 @@ else
<p>@Localizer["UserHere"]</p>
@foreach (var user in users)
@foreach (var user in _users)
{
<div class="userDiv" id="@user.Id">
<img class="imgProfil" src="@user.Image" />
@ -74,7 +74,7 @@ else
</div>
<!-- Fenêtre de confirmation de suppression -->
@if (showPopupDelete)
@if (_showPopupDelete)
{
<div class="divPopup">
<div class="contentPopup">
@ -84,17 +84,17 @@ else
</div>
</div>
}
@if (showModifyPopup)
@if (_showModifyPopup)
{
<div class="divPopup">
<div class="contentPopup">
<p>Modifier les informations de l'utilisateur :</p>
<label>Nom d'utilisateur:</label>
<input type="text" @bind="selectedUser.Name"/>
<input type="text" @bind="_selectedUser.Name"/>
<label>Email:</label>
<input type="email" @bind="selectedUser.Email" />
<input type="email" @bind="_selectedUser.Email" />
<label>Image:</label>
<input type="text" @bind="selectedUser.Image" />
<input type="text" @bind="_selectedUser.Image" />
<button @onclick="ModifyUser">Sauvegarder</button>
<button @onclick="ClosePopup">Annuler</button>
</div>
@ -103,7 +103,7 @@ else
}
<!-- Fenêtre de confirmation d'ajout admin-->
@if (showPopupAdmin)
@if (_showPopupAdmin)
{
<div class="divPopup">
<div class="contentPopup">

@ -14,30 +14,30 @@ namespace WF_WebAdmin.Pages
[Inject]
public ILogger<DeleteUser>? Logger { get; set; }
private List<User> users;
private List<User>? _users;
private bool showModifyPopup = false;
private User userToDelete = null;
private User selectedUser;
private bool showPopupDelete = false;
private bool showPopupAdmin = false;
private User userToAdmin = null;
private int MaxValue = 5;
private int totalItem;
private int page = 1;
private bool _showModifyPopup = false;
private User? _userToDelete = null;
private User? _selectedUser;
private bool _showPopupDelete = false;
private bool _showPopupAdmin = false;
private User? _userToAdmin = null;
private const int MaxValue = 5;
private int _totalItem;
private int _page = 1;
[Inject]
public HttpClient Http { get; set; }
public HttpClient? Http { get; set; }
[Inject]
public NavigationManager NavigationManager { get; set; }
public NavigationManager? NavigationManager { get; set; }
[Inject]
private IUserService userService { get; set; }
private IUserService? UserService { get; set; }
[Inject]
public IStringLocalizer<DeleteUser> Localizer { get; set; }
public IStringLocalizer<DeleteUser>? Localizer { get; set; }
@ -50,7 +50,7 @@ namespace WF_WebAdmin.Pages
{
// 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);
}
@ -71,14 +71,14 @@ namespace WF_WebAdmin.Pages
}
// 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)
{
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
_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
}
}
@ -90,11 +90,11 @@ 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
_userToDelete = user; // Store the user to be deleted in a variable
_showPopupDelete = true; // Display the confirmation popup
}
@ -104,11 +104,11 @@ 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
_selectedUser = user; // Store the user to be modified
_showModifyPopup = true; // Display the confirmation popup for modification
}
@ -121,20 +121,20 @@ namespace WF_WebAdmin.Pages
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
LoggerSaveStub.Log(Logger, LogLevel.Information, $"Delete user {userToDelete.Name}");
await userService.removeUser(userToDelete);
LoggerSaveStub.Log(Logger, LogLevel.Information, $"Delete user {_userToDelete.Name}");
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);
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());
}
}
@ -147,8 +147,8 @@ namespace WF_WebAdmin.Pages
private async Task ModifyUser()
{
// Update the selected user's information using the user service
LoggerSaveStub.Log(Logger, LogLevel.Information, $"Modification of user {selectedUser.Name}");
await userService.updateUser(selectedUser);
LoggerSaveStub.Log(Logger, LogLevel.Information, $"Modification of user {_selectedUser.Name}");
await UserService.updateUser(_selectedUser);
// Close the modification popup after the update is complete
ClosePopup();
@ -163,9 +163,9 @@ namespace WF_WebAdmin.Pages
private void ClosePopup()
{
// Set all popup visibility flags to false to hide the popups
showModifyPopup = false; // Close the modify confirmation popup
showPopupDelete = false; // Close any additional delete popups
showPopupAdmin = false; // Close the admin-related popup (if any)
_showModifyPopup = false; // Close the modify confirmation popup
_showPopupDelete = false; // Close any additional delete popups
_showPopupAdmin = false; // Close the admin-related popup (if any)
}
@ -176,11 +176,11 @@ namespace WF_WebAdmin.Pages
/// 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
_userToAdmin = user; // Store the user to be promoted
_showPopupAdmin = true; // Display the confirmation popup for admin promotion
}
@ -194,20 +194,20 @@ namespace WF_WebAdmin.Pages
private async Task setAdmin()
{
// Check if the user is not already an admin
if (!userToAdmin.IsAdmin)
if (!_userToAdmin.IsAdmin)
{
// Promote the user to admin
LoggerSaveStub.Log(Logger, LogLevel.Information, $"User {userToAdmin.Name} is now administrator");
userToAdmin.IsAdmin = true;
await userService.updateUser(userToAdmin); // Update the user status in the service
LoggerSaveStub.Log(Logger, LogLevel.Information, $"User {_userToAdmin.Name} is now administrator");
_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
LoggerSaveStub.Log(Logger, LogLevel.Information, $"User {userToAdmin.Name} is no longer an administator");
userToAdmin.IsAdmin = false;
await userService.updateUser(userToAdmin); // Update the user status in the service
LoggerSaveStub.Log(Logger, LogLevel.Information, $"User {_userToAdmin.Name} is no longer an administator");
_userToAdmin.IsAdmin = false;
await UserService.updateUser(_userToAdmin); // Update the user status in the service
ClosePopup(); // Close the confirmation popup
}
}

@ -6,15 +6,15 @@ namespace WF_WebAdmin.Service
{
public Task removeUser(User user);
public Task updateRole(User user);
public Task updateRole(User? user);
public Task downgradeRole(User user);
public Task downgradeRole(User? user);
public Task updateUser(User user);
public Task updateUser(User? user);
public Task<List<User>> getAllUser();
public Task<List<User>> getSomeUser(int nb, int page);
public Task<List<User>?> getSomeUser(int nb, int page);
public Task<User> getOneUser(int id);

@ -55,7 +55,7 @@ public class UserServiceStub : IUserService
/// This method updates the `IsAdmin` property of the specified user to `true`, indicating that the user is an administrator.
/// It then calls the <see cref="updateUser"/> method to persist the updated user information.
/// </remarks>
public Task updateRole(User user)
public Task updateRole(User? user)
{
user.IsAdmin = true;
return updateUser(user);
@ -71,7 +71,7 @@ public class UserServiceStub : IUserService
/// This method updates the `IsAdmin` property of the specified user to `false`, removing their administrator status.
/// It then calls the <see cref="updateUser"/> method to persist the updated user information.
/// </remarks>
public Task downgradeRole(User user)
public Task downgradeRole(User? user)
{
user.IsAdmin = false;
return updateUser(user);
@ -113,7 +113,7 @@ public class UserServiceStub : IUserService
/// It returns the corresponding subset of users for the given page. If the page exceeds the available number of users,
/// it returns the last `nb` users available.
/// </remarks>
public async Task<List<User>> getSomeUser(int nb, int page)
public async Task<List<User>?> getSomeUser(int nb, int page)
{
var users = await getAllUser();
if ((page - 1) * nb + nb > users.Count)
@ -177,7 +177,7 @@ public class UserServiceStub : IUserService
/// If a user with the given ID is found, it updates their details (Name, Email, Image, IsAdmin) based on the provided `user` object.
/// After updating the user, the modified list of users is saved back to the JSON file using the <see cref="saveUsersJson"/> method.
/// </remarks>
public async Task updateUser(User user)
public async Task updateUser(User? user)
{
var data = await getAllUser();
var person = data.FirstOrDefault(p => p.Id == user.Id);

Loading…
Cancel
Save