diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b49c263..f74c311 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,5 @@ variables: - VERS_MAIN: '1.0' + VERS_MAIN: '1.1' NEW_REL: '' NUM_REL: '0.1.2.3' NUM_DEB: '0.1.2-beta.3' diff --git a/EgwCoreLib.Razor/DataPager.razor b/EgwCoreLib.Razor/DataPager.razor new file mode 100644 index 0000000..b3f6b1a --- /dev/null +++ b/EgwCoreLib.Razor/DataPager.razor @@ -0,0 +1,56 @@ +
+
+
+
+ @if (totalCount > 0) + { +
    +
  • +
  • + @for (int i = @startPage; i <= endPage; ++i) + { + var pageNum = i; +
  • + } +
  • +
  • +
+ } +
+
+
+
+ @if (showLoading) + { +
+
+
+ } +
+
+
+
+
+
+ @if (!showLoading) + { + @totalCount records + } +
+
+ @if (totalCount > 0) + { +
+ +
+ } +
+
+
+
\ No newline at end of file diff --git a/EgwCoreLib.Razor/DataPager.razor.cs b/EgwCoreLib.Razor/DataPager.razor.cs new file mode 100644 index 0000000..158080f --- /dev/null +++ b/EgwCoreLib.Razor/DataPager.razor.cs @@ -0,0 +1,198 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Components; +using System.Net.Http; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Components.Forms; +using Microsoft.AspNetCore.Components.Routing; +using Microsoft.AspNetCore.Components.Web; +using Microsoft.AspNetCore.Components.Web.Virtualization; +using Microsoft.JSInterop; + +namespace EgwCoreLib.Razor +{ + public partial class DataPager : ComponentBase + { + #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 .. numPages centrato sulla pagina corrente... + private int startPage + { + get + { + int answ = (int)(currPage / numPages) * numPages; + answ = answ > 0 ? answ : 1; + return answ; + } + } + + #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 string cssActive(int numPage) + { + string answ = ""; + if (numPage == currPage) + { + answ = "active"; + } + return answ; + } + + protected override async Task OnInitializedAsync() + { + await Task.Run(() => showLoading = false); + } + + protected void PaginationItemClick(int page) + { + currPage = page; + } + + #endregion Protected Methods + } +} \ No newline at end of file