MOdifica puntamento DataPager con parametri

This commit is contained in:
Samuele Locatelli
2021-05-24 12:03:12 +02:00
parent 6ba7b7d842
commit 360da3b658
8 changed files with 256 additions and 228 deletions
+21 -23
View File
@@ -1,34 +1,32 @@
@using MP.Stats.Data
<div class="row">
<div class="row">
@if (ListScarti == null || ListScarti.Count == 0)
{
<div class="col-12">
<div class="alert alert-secondary text-center h4"><span class="oi oi-graph"></span> No Chart Data</div>
</div>
<div class="col-12">
<div class="alert alert-secondary text-center h4"><span class="oi oi-graph"></span> No Chart Data</div>
</div>
}
else
{
<div class="col-2 pr-0" style="max-height: 15em; overflow:hidden; overflow-y: auto;">
<ul class="list-group list-group-sm small">
@foreach (var item in @ParetoData)
<div class="col-2 pr-0" style="max-height: 15em; overflow:hidden; overflow-y: auto;">
<ul class="list-group list-group-sm small">
@foreach (var item in @ParetoData)
{
<li class="list-group-item p-1 d-flex justify-content-between align-items-center">
@item.label
<span class="badge badge-primary badge-pill">@item.value</span>
</li>
<li class="list-group-item p-1 d-flex justify-content-between align-items-center">
@item.label
<span class="badge badge-primary badge-pill">@item.value</span>
</li>
}
</ul>
</div>
<div class="col-10">
<div class="row">
<div class="col-6">
<BarChart @ref="ParetoGuasti" TItem="double" OptionsObject="barChartOptions" />
</div>
<div class="col-6">
<LineChart @ref="NumGuasti" TItem="double" OptionsObject="lineChartOptions" />
</div>
</ul>
</div>
<div class="col-10">
<div class="row">
<div class="col-6">
<BarChart @ref="ParetoGuasti" TItem="double" OptionsObject="barChartOptions" />
</div>
<div class="col-6">
<LineChart @ref="NumGuasti" TItem="double" OptionsObject="lineChartOptions" />
</div>
</div>
</div>
}
</div>
+1 -8
View File
@@ -156,7 +156,7 @@ namespace MP.Stats.Components
{
Label = "Numero Scarti Periodo",
Data = TSData.Select(x => x.Value).ToList(),
BackgroundColor = backgroundColors(1),
BorderColor = backgroundColors(1),
Fill = true,
PointRadius = 2,
SteppedLine = true,
@@ -219,13 +219,6 @@ namespace MP.Stats.Components
return answ;
}
//protected override async Task OnAfterRenderAsync(bool firstRender)
//{
// if (firstRender)
// {
// await HandleRedraw();
// }
//}
protected async Task HandleRedraw()
{
if (ParetoGuasti != null)
+44 -193
View File
@@ -1,48 +1,46 @@
@inject Services.BlazorTimer Timer
<div class="row">
<div class="row">
<div class="col-6 col-lg-10 text-left">
<div class="row">
<div class="col-9 small">
@if (totalCount > 0)
{
<Pagination>
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="1">
<i class="fas fa-angle-double-left"></i>
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@prevBlock.ToString()">
<span aria-hidden="true"><i class="fas fa-angle-left"></i></span>
</PaginationLink>
</PaginationItem>
@for (int i = @startPage; i <= endPage; ++i)
<Pagination>
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="1">
<i class="fas fa-angle-double-left"></i>
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@prevBlock.ToString()">
<span aria-hidden="true"><i class="fas fa-angle-left"></i></span>
</PaginationLink>
</PaginationItem>
@for (int i = @startPage; i <= endPage; ++i)
{
var pageNum = i;
<PaginationItem Active="@(currPage.Equals(pageNum))">
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@pageNum.ToString()">
@pageNum
</PaginationLink>
</PaginationItem>
<PaginationItem Active="@(currPage.Equals(pageNum))">
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@pageNum.ToString()">
@pageNum
</PaginationLink>
</PaginationItem>
}
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@nextBlock.ToString()">
<i class="fas fa-angle-right"></i>
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@LastPage.ToString()">
<i class="fas fa-angle-double-right"></i>
</PaginationLink>
</PaginationItem>
</Pagination>
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@nextBlock.ToString()">
<i class="fas fa-angle-right"></i>
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@LastPage.ToString()">
<i class="fas fa-angle-double-right"></i>
</PaginationLink>
</PaginationItem>
</Pagination>
}
</div>
<div class="col-3">
@if (!showLoading)
{
<span>@totalCount records</span>
<span>@totalCount records</span>
}
</div>
</div>
@@ -50,9 +48,9 @@
<div class="col-12 small">
@if (showLoading)
{
<Progress>
<ProgressBar Value="@percLoading" Striped="true" Animated="true" />
</Progress>
<Progress>
<ProgressBar Value="@percLoading" Striped="true" Animated="true" />
</Progress>
}
</div>
</div>
@@ -60,163 +58,16 @@
<div class="col-6 col-lg-2 text-right">
@if (totalCount > 0)
{
<div class="input-group input-group-sm">
row/pag:&nbsp;
<select @bind="@PageSize" class="form-control form-control-sm">
<option value="5">5</option>
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
</div>
<div class="input-group input-group-sm">
row/pag:&nbsp;
<select @bind="@PageSize" class="form-control form-control-sm">
<option value="5">5</option>
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
</div>
}
</div>
</div>
@code {
void HandlePaginationItemClick(string page)
{
currPage = int.Parse(page);
reportChangePage();
}
private int numPages { get; set; } = 10;
// calcola un set 1..numPOages centrato sulla pagina corrente...
private int startPage
{
get
{
int answ = (int)(currPage / numPages) * numPages;
answ = answ > 0 ? answ : 1;
return answ;
}
}
private int endPage
{
get
{
int answ = (int)(currPage / numPages) * numPages + numPages;
answ = answ < LastPage ? answ : LastPage;
return answ;
}
}
private int prevBlock
{
get
{
int answ = currPage - numPages;
answ = answ > 0 ? answ : 1;
return answ;
}
}
private int nextBlock
{
get
{
int answ = currPage + numPages;
answ = answ < LastPage ? answ : LastPage;
return answ;
}
}
private int LastPage
{
get
{
return Math.Max((int)Math.Ceiling(totalCount / (double)PageSize), 1);
}
}
protected override Task OnInitializedAsync()
{
showLoading = false;
return base.OnInitializedAsync();
}
protected int percLoading { get; set; } = 0;
protected bool _showLoading = false;
[Parameter]
public bool showLoading
{
get
{
return _showLoading;
}
set
{
if (value)
{
Random random = new Random();
percLoading = random.Next(30, 90);
}
else
{
percLoading = 5;
}
_showLoading = value;
}
}
[Parameter]
public int totalCount { get; set; } = 0;
protected int _numRecord { get; set; } = 10;
protected int _numPage { get; set; } = 1;
[Parameter]
public int PageSize
{
get
{
return _numRecord;
}
set
{
bool doReport = !_numRecord.Equals(value);
if (doReport)
{
_numRecord = value;
reportChange();
}
}
}
[Parameter]
public int currPage
{
get
{
return _numPage;
}
set
{
bool doReport = !_numPage.Equals(value);
if (doReport)
{
_numPage = value;
reportChangePage();
}
}
}
[Parameter]
public EventCallback<int> numRecordChanged { get; set; }
[Parameter]
public EventCallback<int> numPageChanged { get; set; }
private void reportChange()
{
numRecordChanged.InvokeAsync(PageSize);
}
private void reportChangePage()
{
numPageChanged.InvokeAsync(currPage);
}
}
</div>
+186
View File
@@ -0,0 +1,186 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using MP.Stats.Components;
using MP.Stats.Data;
namespace MP.Stats.Components
{
public partial class DataPager
{
#region Protected Fields
protected bool _showLoading = false;
#endregion Protected Fields
#region Private Properties
private int endPage
{
get
{
int answ = (int)(currPage / numPages) * numPages + numPages;
answ = answ < LastPage ? answ : LastPage;
return answ;
}
}
private int LastPage
{
get
{
return Math.Max((int)Math.Ceiling(totalCount / (double)PageSize), 1);
}
}
private int nextBlock
{
get
{
int answ = currPage + numPages;
answ = answ < LastPage ? answ : LastPage;
return answ;
}
}
private int numPages { get; set; } = 10;
private int prevBlock
{
get
{
int answ = currPage - numPages;
answ = answ > 0 ? answ : 1;
return answ;
}
}
// calcola un set 1..numPOages centrato sulla pagina corrente...
private int startPage
{
get
{
int answ = (int)(currPage / numPages) * numPages;
answ = answ > 0 ? answ : 1;
return answ;
}
}
[Inject]
private Services.BlazorTimer Timer { get; set; }
#endregion Private Properties
#region Protected Properties
protected int _numPage { get; set; } = 1;
protected int _numRecord { get; set; } = 10;
protected int percLoading { get; set; } = 0;
#endregion Protected Properties
#region Public Properties
[Parameter]
public int currPage
{
get
{
return _numPage;
}
set
{
bool doReport = !_numPage.Equals(value);
if (doReport)
{
_numPage = value;
reportChangePage();
}
}
}
[Parameter]
public EventCallback<int> numPageChanged { get; set; }
[Parameter]
public EventCallback<int> numRecordChanged { get; set; }
[Parameter]
public int PageSize
{
get
{
return _numRecord;
}
set
{
bool doReport = !_numRecord.Equals(value);
if (doReport)
{
_numRecord = value;
reportChange();
}
}
}
[Parameter]
public bool showLoading
{
get
{
return _showLoading;
}
set
{
if (value)
{
Random random = new Random();
percLoading = random.Next(30, 90);
}
else
{
percLoading = 5;
}
_showLoading = value;
}
}
[Parameter]
public int totalCount { get; set; } = 0;
#endregion Public Properties
#region Private Methods
private void reportChange()
{
numRecordChanged.InvokeAsync(PageSize);
}
private void reportChangePage()
{
numPageChanged.InvokeAsync(currPage);
}
#endregion Private Methods
#region Protected Methods
protected void HandlePaginationItemClick(string page)
{
currPage = int.Parse(page);
}
protected override async Task OnInitializedAsync()
{
await Task.Run(() => showLoading = false);
}
#endregion Protected Methods
}
}
+1 -1
View File
@@ -54,6 +54,6 @@
}
</div>
<div class="card-footer py-1">
<DataPager PageSize="@numRecord" currPage="@currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" totalCount="@totalCount" showLoading="@isLoading" />
<DataPager PageSize="numRecord" currPage="currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" totalCount="totalCount" showLoading="isLoading" />
</div>
</div>
+1 -1
View File
@@ -57,6 +57,6 @@
}
</div>
<div class="card-footer py-1">
<DataPager PageSize="@numRecord" currPage="@currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" totalCount="@totalCount" showLoading="@isLoading" />
<DataPager PageSize="numRecord" currPage="currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" totalCount="totalCount" showLoading="isLoading" />
</div>
</div>
+1 -1
View File
@@ -64,6 +64,6 @@
}
</div>
<div class="card-footer py-1">
<DataPager PageSize="@numRecord" currPage="@currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" totalCount="@totalCount" showLoading="@isLoading" />
<DataPager PageSize="numRecord" currPage="currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" totalCount="totalCount" showLoading="isLoading" />
</div>
</div>
+1 -1
View File
@@ -67,6 +67,6 @@
}
</div>
<div class="card-footer py-1">
<DataPager PageSize="@numRecord" currPage="@currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" totalCount="@totalCount" showLoading="@isLoading" />
<DataPager PageSize="numRecord" currPage="currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" totalCount="totalCount" showLoading="isLoading" />
</div>
</div>