Merge pull request #1753 from bolatovumar/feat/1568

Allow sorting apps by store, name or app type
This commit is contained in:
Nicolas Dorier 2020-07-28 15:18:30 +09:00 committed by GitHub
commit b7d66efb20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 76 additions and 4 deletions

View File

@ -47,9 +47,42 @@ namespace BTCPayServer.Controllers
public string CreatedAppId { get; set; }
public async Task<IActionResult> ListApps()
public async Task<IActionResult> ListApps(
string sortOrder = null,
string sortOrderColumn = null
)
{
var apps = await _AppService.GetAllApps(GetUserId());
if (sortOrder != null && sortOrderColumn != null)
{
apps = apps.OrderByDescending(app =>
{
switch (sortOrderColumn)
{
case nameof(app.AppName):
return app.AppName;
case nameof(app.StoreName):
return app.StoreName;
case nameof(app.AppType):
return app.AppType;
default:
return app.Id;
}
}).ToArray();
switch (sortOrder)
{
case "desc":
ViewData[$"{sortOrderColumn}SortOrder"] = "asc";
break;
case "asc":
apps = apps.Reverse().ToArray();
ViewData[$"{sortOrderColumn}SortOrder"] = "desc";
break;
}
}
return View(new ListAppsViewModel()
{
Apps = apps

View File

@ -31,9 +31,48 @@
<table class="table table-sm table-responsive-md">
<thead>
<tr>
<th>Store</th>
<th>Name</th>
<th>App type</th>
<th>
<a
asp-action="ListApps"
asp-route-sortOrder="@(ViewData["StoreNameSortOrder"] ?? "asc")"
asp-route-sortOrderColumn="StoreName"
class="text-nowrap"
title="@((string)ViewData["StoreNameSortOrder"] == "desc" ? "Sort by descending..." : "Sort by ascending...")"
>
Store @if (ViewData["StoreNameSortOrder"] != null)
{
<span class="fa @((string)ViewData["StoreNameSortOrder"] == "asc" ? "fa-arrow-down": "fa-arrow-up")" />
}
</a>
</th>
<th>
<a
asp-action="ListApps"
asp-route-sortOrder="@(ViewData["AppNameSortOrder"] ?? "asc")"
asp-route-sortOrderColumn="AppName"
class="text-nowrap"
title="@((string)ViewData["AppNameSortOrder"] == "desc" ? "Sort by descending..." : "Sort by ascending...")"
>
Name @if (ViewData["AppNameSortOrder"] != null)
{
<span class="fa @((string)ViewData["AppNameSortOrder"] == "asc" ? "fa-arrow-down": "fa-arrow-up")" />
}
</a>
</th>
<th>
<a
asp-action="ListApps"
asp-route-sortOrder="@(ViewData["AppTypeSortOrder"] ?? "asc")"
asp-route-sortOrderColumn="AppType"
class="text-nowrap"
title="@((string)ViewData["AppTypeSortOrder"] == "desc" ? "Sort by descending..." : "Sort by ascending...")"
>
App Type @if (ViewData["AppTypeSortOrder"] != null)
{
<span class="fa @((string)ViewData["AppTypeSortOrder"] == "asc" ? "fa-arrow-down": "fa-arrow-up")" />
}
</a>
</th>
<th style="text-align:right">Actions</th>
</tr>
</thead>