From 360da3b6580673ca20c9a23ea9945033dd2fd945 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 24 May 2021 12:03:12 +0200 Subject: [PATCH] MOdifica puntamento DataPager con parametri --- MP.Stats/Components/ChartScarti.razor | 44 ++--- MP.Stats/Components/ChartScarti.razor.cs | 9 +- MP.Stats/Components/DataPager.razor | 237 +++++------------------ MP.Stats/Components/DataPager.razor.cs | 186 ++++++++++++++++++ MP.Stats/Pages/Controlli.razor | 2 +- MP.Stats/Pages/Diario.razor | 2 +- MP.Stats/Pages/Oee.razor | 2 +- MP.Stats/Pages/UserLog.razor | 2 +- 8 files changed, 256 insertions(+), 228 deletions(-) create mode 100644 MP.Stats/Components/DataPager.razor.cs diff --git a/MP.Stats/Components/ChartScarti.razor b/MP.Stats/Components/ChartScarti.razor index d64d42bb..5dd6b477 100644 --- a/MP.Stats/Components/ChartScarti.razor +++ b/MP.Stats/Components/ChartScarti.razor @@ -1,34 +1,32 @@ -@using MP.Stats.Data - -
+
@if (ListScarti == null || ListScarti.Count == 0) { -
-
No Chart Data
-
+
+
No Chart Data
+
} else { -
-
    - @foreach (var item in @ParetoData) +
    +
      + @foreach (var item in @ParetoData) { -
    • - @item.label - @item.value -
    • +
    • + @item.label + @item.value +
    • } -
    -
    -
    -
    -
    - -
    -
    - -
    +
+
+
+
+
+ +
+
+
+
}
\ No newline at end of file diff --git a/MP.Stats/Components/ChartScarti.razor.cs b/MP.Stats/Components/ChartScarti.razor.cs index f67e7626..f865fae6 100644 --- a/MP.Stats/Components/ChartScarti.razor.cs +++ b/MP.Stats/Components/ChartScarti.razor.cs @@ -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) diff --git a/MP.Stats/Components/DataPager.razor b/MP.Stats/Components/DataPager.razor index 424d7640..22928184 100644 --- a/MP.Stats/Components/DataPager.razor +++ b/MP.Stats/Components/DataPager.razor @@ -1,48 +1,46 @@ -@inject Services.BlazorTimer Timer - -
+
@if (totalCount > 0) { - - - - - - - - - - - - @for (int i = @startPage; i <= endPage; ++i) + + + + + + + + + + + + @for (int i = @startPage; i <= endPage; ++i) { var pageNum = i; - - - @pageNum - - + + + @pageNum + + } - - - - - - - - - - - + + + + + + + + + + + }
@if (!showLoading) { - @totalCount records + @totalCount records }
@@ -50,9 +48,9 @@
@if (showLoading) { - - - + + + }
@@ -60,163 +58,16 @@
@if (totalCount > 0) { -
- row/pag:  - -
+
+ row/pag:  + +
}
-
- -@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 numRecordChanged { get; set; } - [Parameter] - public EventCallback numPageChanged { get; set; } - - private void reportChange() - { - numRecordChanged.InvokeAsync(PageSize); - } - private void reportChangePage() - { - numPageChanged.InvokeAsync(currPage); - } - -} \ No newline at end of file +
\ No newline at end of file diff --git a/MP.Stats/Components/DataPager.razor.cs b/MP.Stats/Components/DataPager.razor.cs new file mode 100644 index 00000000..ba72a2ff --- /dev/null +++ b/MP.Stats/Components/DataPager.razor.cs @@ -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 numPageChanged { get; set; } + + [Parameter] + public EventCallback 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 + } +} \ No newline at end of file diff --git a/MP.Stats/Pages/Controlli.razor b/MP.Stats/Pages/Controlli.razor index 4afbf04a..86af993f 100644 --- a/MP.Stats/Pages/Controlli.razor +++ b/MP.Stats/Pages/Controlli.razor @@ -54,6 +54,6 @@ }
\ No newline at end of file diff --git a/MP.Stats/Pages/Diario.razor b/MP.Stats/Pages/Diario.razor index ac381528..3077ef42 100644 --- a/MP.Stats/Pages/Diario.razor +++ b/MP.Stats/Pages/Diario.razor @@ -57,6 +57,6 @@ } \ No newline at end of file diff --git a/MP.Stats/Pages/Oee.razor b/MP.Stats/Pages/Oee.razor index 2beb55a2..e38e8080 100644 --- a/MP.Stats/Pages/Oee.razor +++ b/MP.Stats/Pages/Oee.razor @@ -64,6 +64,6 @@ } \ No newline at end of file diff --git a/MP.Stats/Pages/UserLog.razor b/MP.Stats/Pages/UserLog.razor index 4dc6b64b..32416756 100644 --- a/MP.Stats/Pages/UserLog.razor +++ b/MP.Stats/Pages/UserLog.razor @@ -67,6 +67,6 @@ } \ No newline at end of file