mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-24 22:21:30 +00:00
* Add pagination to moderation cases list and tweak case dismissal task * Clean up case partial and add extended case status indicators * Redirect back to cases list after dismissing a case * Fix typo on cases list queue counter * Fix dismissal queue counter * Convert dismiss button check into pattern * Turn down case dismissal task repeat interval to every 1 hour * Use page 0 for case searching * Implement pagination on the admin users list <3 * Fix pagination button padding and update colors to match existing role colors * Fix typo in admin search placeholder * Make cases searchable by user/slot ID instead of reason Due to the current state of the moderation case entity, I can't directly query against the affected user name, so I've added the ability to search for the affected user/slot ID instead of reason. * Actually apply the desired changes instead of just fixing the counts * Grammatical nitpick in the search box placeholder
52 lines
No EOL
1.8 KiB
C#
52 lines
No EOL
1.8 KiB
C#
#nullable enable
|
|
using LBPUnion.ProjectLighthouse.Configuration;
|
|
using LBPUnion.ProjectLighthouse.Database;
|
|
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
|
|
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin;
|
|
|
|
public class AdminPanelUsersPage : BaseLayout
|
|
{
|
|
public int UserCount;
|
|
|
|
public List<UserEntity> Users = new();
|
|
|
|
public int PageAmount;
|
|
public int PageNumber;
|
|
public string SearchValue = "";
|
|
|
|
public AdminPanelUsersPage(DatabaseContext database) : base(database)
|
|
{}
|
|
|
|
public async Task<IActionResult> OnGet([FromRoute] int pageNumber, [FromQuery] string? name)
|
|
{
|
|
UserEntity? user = this.Database.UserFromWebRequest(this.Request);
|
|
if (user == null) return this.Redirect("~/login");
|
|
if (!user.IsAdmin) return this.NotFound();
|
|
|
|
if (string.IsNullOrWhiteSpace(name)) name = "";
|
|
|
|
this.SearchValue = name.Replace(" ", string.Empty);
|
|
|
|
this.UserCount = await this.Database.Users.CountAsync(u => u.Username.Contains(this.SearchValue));
|
|
|
|
this.PageNumber = pageNumber;
|
|
this.PageAmount = Math.Max(1, (int)Math.Ceiling((double)this.UserCount / ServerStatics.PageSize));
|
|
|
|
if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount)
|
|
return this.Redirect($"/admin/users/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
|
|
|
|
this.Users = await this.Database.Users
|
|
.OrderByDescending(u => u.PermissionLevel)
|
|
.ThenByDescending(u => u.UserId)
|
|
.Where(u => u.Username.Contains(this.SearchValue))
|
|
.Skip(pageNumber * ServerStatics.PageSize)
|
|
.Take(ServerStatics.PageSize)
|
|
.ToListAsync();
|
|
|
|
return this.Page();
|
|
}
|
|
} |