This repository has been archived on 2025-05-14. You can view files and clone it, but cannot push or open issues or pull requests.
Pavel Vesely cf6643aef3 Client fixes
Client is partially done.
227 warnings left out of 1500
I like Rider
2020-03-15 15:19:35 +01:00

206 lines
5.2 KiB
Plaintext

@namespace Oqtane.Modules.Controls
@inherits ModuleBase
@typeparam TAbleItem
<p>
@if(Format == "Table")
{
<table class="@Class">
<thead>
<tr>@Header</tr>
</thead>
<tbody>
@foreach (var item in ItemList)
{
<tr>@Row(item)</tr>
@if (Detail != null)
{
<tr>@Detail(item)</tr>
}
}
</tbody>
</table>
}
@if(Format == "Grid")
{
<div class="@Class">
<div class="row">@Header</div>
@foreach (var item in ItemList)
{
<div class="row">@Row(item)</div>
@if (Detail != null)
{
<div class="row">@Detail(item)</div>
}
}
</div>
}
<div class="mx-auto text-center">
@if (_page > _maxPages)
{
<button class="btn btn-secondary" @onclick=@(async () => SetPagerSize("back"))><span class="oi oi-media-skip-backward" title="back" aria-hidden="true"></span></button>
}
@if (_endPage > 1)
{
<button class="btn btn-secondary" @onclick=@(async () => NavigateToPage("previous"))><span class="oi oi-chevron-left" title="previous" aria-hidden="true"></span></button>
@for (int i = _startPage; i <= _endPage; i++)
{
var pager = i;
<button class="btn @((pager == _page) ? "btn-primary" : "btn-link")" @onclick=@(async () => UpdateList(pager))>
@pager
</button>
}
<button class="btn btn-secondary" @onclick=@(async () => NavigateToPage("next"))><span class="oi oi-chevron-right" title="next" aria-hidden="true"></span></button>
}
@if (_endPage < _pages)
{
<button class="btn btn-secondary" @onclick=@(async () => SetPagerSize("forward"))><span class="oi oi-media-skip-forward" title="forward" aria-hidden="true"></span></button>
}
@if (_endPage > 1)
{
<span class="btn btn-link disabled">Page @_page of @_pages</span>
}
</div>
</p>
@code {
int _pages = 0;
int _page = 1;
int _maxItems;
int _maxPages;
int _startPage;
int _endPage;
[Parameter]
public string Format { get; set; }
[Parameter]
public RenderFragment Header { get; set; }
[Parameter]
public RenderFragment<TAbleItem> Row { get; set; }
[Parameter]
public RenderFragment<TAbleItem> Detail { get; set; }
[Parameter]
public IEnumerable<TAbleItem> Items { get; set; }
[Parameter]
public string PageSize { get; set; }
[Parameter]
public string DisplayPages { get; set; }
[Parameter]
public string Class { get; set; }
IEnumerable<TAbleItem> ItemList { get; set; }
protected override void OnParametersSet()
{
if (string.IsNullOrEmpty(Format))
{
Format = "Table";
}
if (string.IsNullOrEmpty(Class))
{
if (Format == "Table")
{
Class = "table table-borderless";
}
else
{
Class = "container";
}
}
if (string.IsNullOrEmpty(PageSize))
{
_maxItems = 10;
}
else
{
_maxItems = int.Parse(PageSize);
}
if (string.IsNullOrEmpty(DisplayPages))
{
_maxPages = 5;
}
else
{
_maxPages = int.Parse(DisplayPages);
}
if (Items != null)
{
ItemList = Items.Skip((_page - 1) * _maxItems).Take(_maxItems);
_pages = (int)Math.Ceiling(Items.Count() / (decimal)_maxItems);
}
SetPagerSize("forward");
}
public void UpdateList(int currentPage)
{
ItemList = Items.Skip((currentPage - 1) * _maxItems).Take(_maxItems);
_page = currentPage;
StateHasChanged();
}
public void SetPagerSize(string direction)
{
if (direction == "forward")
{
if (_endPage + 1 < _pages)
{
_startPage = _endPage + 1;
}
else
{
_startPage = 1;
}
if (_endPage + _maxPages < _pages)
{
_endPage = _startPage + _maxPages - 1;
}
else
{
_endPage = _pages;
}
StateHasChanged();
}
else if (direction == "back")
{
_endPage = _startPage - 1;
_startPage = _startPage - _maxPages;
}
}
public void NavigateToPage(string direction)
{
if (direction == "next")
{
if (_page < _pages)
{
if (_page == _endPage)
{
SetPagerSize("forward");
}
_page += 1;
}
}
else if (direction == "previous")
{
if (_page > 1)
{
if (_page == _startPage)
{
SetPagerSize("back");
}
_page -= 1;
}
}
UpdateList(_page);
}
}