mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-21 22:11:48 +01:00
Add user email search and sort (#2305)
* Add user sort by email * Add user search by email
This commit is contained in:
parent
0c766a2714
commit
a64f71f186
2 changed files with 79 additions and 10 deletions
|
@ -19,13 +19,37 @@ namespace BTCPayServer.Controllers
|
|||
public partial class ServerController
|
||||
{
|
||||
[Route("server/users")]
|
||||
public async Task<IActionResult> ListUsers(UsersViewModel model)
|
||||
public async Task<IActionResult> ListUsers(
|
||||
UsersViewModel model,
|
||||
string sortOrder = null
|
||||
)
|
||||
{
|
||||
model = this.ParseListQuery(model ?? new UsersViewModel());
|
||||
var users = _UserManager.Users;
|
||||
model.Total = await users.CountAsync();
|
||||
model.Users = await users
|
||||
.Skip(model.Skip).Take(model.Count)
|
||||
|
||||
var usersQuery = _UserManager.Users;
|
||||
if (!string.IsNullOrWhiteSpace(model.SearchTerm))
|
||||
{
|
||||
usersQuery = usersQuery.Where(u => u.Email.Contains(model.SearchTerm));
|
||||
}
|
||||
|
||||
if (sortOrder != null)
|
||||
{
|
||||
switch (sortOrder)
|
||||
{
|
||||
case "desc":
|
||||
ViewData["NextUserEmailSortOrder"] = "asc";
|
||||
usersQuery = usersQuery.OrderByDescending(user => user.Email);
|
||||
break;
|
||||
case "asc":
|
||||
usersQuery = usersQuery.OrderBy(user => user.Email);
|
||||
ViewData["NextUserEmailSortOrder"] = "desc";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
model.Users = await usersQuery
|
||||
.Skip(model.Skip)
|
||||
.Take(model.Count)
|
||||
.Select(u => new UsersViewModel.UserViewModel
|
||||
{
|
||||
Name = u.UserName,
|
||||
|
@ -33,7 +57,9 @@ namespace BTCPayServer.Controllers
|
|||
Id = u.Id,
|
||||
Verified = u.EmailConfirmed || !u.RequiresEmailConfirmation,
|
||||
Created = u.Created
|
||||
}).ToListAsync();
|
||||
})
|
||||
.ToListAsync();
|
||||
model.Total = await usersQuery.CountAsync();
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,26 @@
|
|||
@model UsersViewModel
|
||||
@{
|
||||
ViewData.SetActivePageAndTitle(ServerNavPages.Users);
|
||||
var nextUserEmailSortOrder = (string)ViewData["NextUserEmailSortOrder"];
|
||||
String userEmailSortOrder = null;
|
||||
switch (nextUserEmailSortOrder)
|
||||
{
|
||||
case "asc":
|
||||
userEmailSortOrder = "desc";
|
||||
break;
|
||||
case "desc":
|
||||
userEmailSortOrder = "asc";
|
||||
break;
|
||||
}
|
||||
|
||||
var sortIconClass = "fa-sort";
|
||||
if (userEmailSortOrder != null)
|
||||
{
|
||||
sortIconClass = $"fa-sort-alpha-{userEmailSortOrder}";
|
||||
}
|
||||
|
||||
var sortByDesc = "Sort by descending...";
|
||||
var sortByAsc = "Sort by ascending...";
|
||||
}
|
||||
|
||||
<partial name="_StatusMessage"/>
|
||||
|
@ -11,9 +31,22 @@
|
|||
<span class="fa fa-plus"></span> Add User
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-12 col-sm-8 col-lg-6 mb-3">
|
||||
|
||||
<form
|
||||
asp-action="ListUsers"
|
||||
asp-route-sortOrder="@(userEmailSortOrder)"
|
||||
>
|
||||
<div class="input-group">
|
||||
<input asp-for="SearchTerm" class="form-control" placeholder="Search by email..." />
|
||||
<div class="input-group-append">
|
||||
<button type="submit" class="btn btn-secondary" title="Search by email">
|
||||
<span class="fa fa-search"></span> Search
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<span asp-validation-for="SearchTerm" class="text-danger"></span>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -22,7 +55,17 @@
|
|||
<table class="table table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Email</th>
|
||||
<th>
|
||||
<a
|
||||
asp-action="ListUsers"
|
||||
asp-route-sortOrder="@(nextUserEmailSortOrder ?? "asc")"
|
||||
class="text-nowrap"
|
||||
title="@(nextUserEmailSortOrder == "desc" ? sortByAsc : sortByDesc)"
|
||||
>
|
||||
Email
|
||||
<span class="fa @(sortIconClass)" />
|
||||
</a>
|
||||
</th>
|
||||
<th>Created</th>
|
||||
<th>Verified</th>
|
||||
<th class="text-right">Actions</th>
|
||||
|
@ -52,7 +95,7 @@
|
|||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
<vc:pager view-model="Model"></vc:pager>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue