Add pagination to wallet transactions page

close #1771
This commit is contained in:
Umar Bolatov 2020-07-24 21:33:02 -07:00
parent 310f6a385c
commit df1447b917
No known key found for this signature in database
GPG Key ID: 2C1F9AEB371D2A28
3 changed files with 83 additions and 3 deletions

View File

@ -259,7 +259,11 @@ namespace BTCPayServer.Controllers
[Route("{walletId}/transactions")]
public async Task<IActionResult> WalletTransactions(
[ModelBinder(typeof(WalletIdModelBinder))]
WalletId walletId, string labelFilter = null)
WalletId walletId,
string labelFilter = null,
int skip = 0,
int count = 50
)
{
DerivationSchemeSettings paymentMethod = GetDerivationSchemeSettings(walletId);
if (paymentMethod == null)
@ -271,7 +275,12 @@ namespace BTCPayServer.Controllers
var transactions = await wallet.FetchTransactions(paymentMethod.AccountDerivation);
var walletBlob = await walletBlobAsync;
var walletTransactionsInfo = await walletTransactionsInfoAsync;
var model = new ListTransactionsViewModel();
var model = new ListTransactionsViewModel
{
Skip = skip,
Count = count,
Total = 0
};
if (transactions == null)
{
TempData.SetStatusMessageModel(new StatusMessageModel()
@ -309,7 +318,8 @@ namespace BTCPayServer.Controllers
model.Transactions.Add(vm);
}
model.Transactions = model.Transactions.OrderByDescending(t => t.Timestamp).ToList();
model.Total = model.Transactions.Count;
model.Transactions = model.Transactions.OrderByDescending(t => t.Timestamp).Skip(skip).Take(count).ToList();
}
return View(model);

View File

@ -19,5 +19,8 @@ namespace BTCPayServer.Models.WalletViewModels
}
public HashSet<Label> Labels { get; set; } = new HashSet<Label>();
public List<TransactionViewModel> Transactions { get; set; } = new List<TransactionViewModel>();
public int Skip { get; set; }
public int Count { get; set; }
public int Total { get; set; }
}
}

View File

@ -204,5 +204,72 @@
}
</tbody>
</table>
<nav class="w-100">
@if (Model.Total != 0)
{
<ul class="pagination float-left">
<li class="page-item @(Model.Skip == 0 ? "disabled" : null)">
<a class="page-link" tabindex="-1" href="@ListTransactionsPage(-1, Model.Count)">&laquo;</a>
</li>
<li class="page-item disabled">
@if (Model.Total <= Model.Count)
{
<span class="page-link">
1@Model.Transactions.Count
</span>
}
else
{
<span class="page-link">
@(Model.Skip + 1)@(Model.Skip + Model.Transactions.Count), Total: @Model.Total
</span>
}
</li>
<li class="page-item @(Model.Total > (Model.Skip + Model.Transactions.Count) ? null : "disabled")">
<a class="page-link" href="@ListTransactionsPage(1, Model.Count)">&raquo;</a>
</li>
</ul>
}
<ul class="pagination float-right">
<li class="page-item disabled">
<span class="page-link">Page Size:</span>
</li>
<li class="page-item @(Model.Count == 50 ? "active" : null)">
<a class="page-link" href="@ListTransactionsPage(0, 50)">50</a>
</li>
<li class="page-item @(Model.Count == 100 ? "active" : null)">
<a class="page-link" href="@ListTransactionsPage(0, 100)">100</a>
</li>
<li class="page-item @(Model.Count == 250 ? "active" : null)">
<a class="page-link" href="@ListTransactionsPage(0, 250)">250</a>
</li>
<li class="page-item @(Model.Count == 500 ? "active" : null)">
<a class="page-link" href="@ListTransactionsPage(0, 500)">500</a>
</li>
</ul>
</nav>
@{
string ListTransactionsPage(int prevNext, int count)
{
var skip = Model.Skip;
if (prevNext == -1)
{
skip = Math.Max(0, Model.Skip - Model.Count);
}
else if (prevNext == 1)
{
skip = Model.Skip + count;
}
var act = Url.Action("WalletTransactions", new
{
labelFilter = Context.Request.Query["labelFilter"],
skip = skip,
count = count,
});
return act;
}
}
</div>
</div>