btcpayserver/BTCPayServer/Components/Pager/Default.cshtml
Dennis Reimann ed497cab99
Hide pagination & page size when not necessary (#2122)
* UI: Hide pagination and page size when not necessary

* UI: Use pager component for notifications list

* UI: Use pager component for wallet transactions list

* UI: Improve pager component

* Fix from code review
2020-12-12 15:21:37 +09:00

86 lines
2.8 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@model BasePagingViewModel
@{
var pageSizeOptions = new [] { 50, 100, 250, 500 };
}
@if (Model.Total > pageSizeOptions.Min())
{
<nav aria-label="..." class="w-100">
@if (Model.Total > Model.Count)
{
<ul class="pagination float-left">
<li class="page-item @(Model.Skip == 0 ? "disabled" : null)">
<a class="page-link" tabindex="-1" href="@NavigatePages(-1, Model.Count)">&laquo;</a>
</li>
<li class="page-item disabled">
@if (Model.Total <= Model.Count)
{
<span class="page-link">
1@Model.Total
</span>
}
else
{
<span class="page-link">
@(Model.Skip + 1)@(Model.Skip + Model.Count), Total: @Model.Total
</span>
}
</li>
<li class="page-item @(Model.Total > (Model.Skip + Model.Count) ? null : "disabled")">
<a class="page-link" href="@NavigatePages(1, Model.Count)">&raquo;</a>
</li>
</ul>
}
@if (Model.Total >= pageSizeOptions.Min())
{
<ul class="pagination float-right">
<li class="page-item disabled">
<span class="page-link">Page Size:</span>
</li>
@foreach (int pageSize in pageSizeOptions)
{
if (Model.Total >= pageSize)
{
<li class="page-item @(Model.Count == pageSize ? "active" : null)">
<a class="page-link" href="@NavigatePages(0, pageSize)">@pageSize</a>
</li>
}
}
</ul>
}
</nav>
}
@{
string NavigatePages(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 query = new Dictionary<string, object>
{
{ "searchTerm", Model.SearchTerm },
{ "timezoneOffset", Model.TimezoneOffset },
{ "skip", skip },
{ "count", count }
};
if (Model.PaginationQuery != null)
{
// merge both, prefering the `query` properties in case of duplicate keys
query = query.Concat(Model.PaginationQuery)
.GroupBy(e => e.Key)
.ToDictionary(g => g.Key, g => g.First().Value);
}
return Url.Action(null, query);
}
}