From fb805d9f495fb844c882d6176770ae33a6556c32 Mon Sep 17 00:00:00 2001 From: Ivan Josipovic <9521987+IvanJosipovic@users.noreply.github.com> Date: Tue, 22 Oct 2019 21:52:16 -0700 Subject: [PATCH 1/3] Added nuget download count --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 347f1210..ae86d326 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # BlazorTable [![Demo](https://img.shields.io/badge/Live-Demo-Blue?style=flat-square)](https://BlazorTable.netlify.com/) [![Nuget (with prereleases)](https://img.shields.io/nuget/vpre/BlazorTable.svg?style=flat-square)](https://www.nuget.org/packages/BlazorTable) +[![Nuget (with prereleases)](https://img.shields.io/nuget/dt/BlazorTable.svg?style=flat-square)](https://www.nuget.org/packages/BlazorTable) ![](https://github.com/IvanJosipovic/BlazorTable/workflows/CI/CD/badge.svg) **Work in progress!** From 95a4422639a1b9309d3b04582197013a2ed5921e Mon Sep 17 00:00:00 2001 From: Ivan Josipovic <9521987+IvanJosipovic@users.noreply.github.com> Date: Wed, 23 Oct 2019 08:26:23 -0700 Subject: [PATCH 2/3] removed IFilterManager --- src/BlazorTable/Components/Column.razor | 5 +- src/BlazorTable/Components/Column.razor.cs | 3 +- .../Components/FilterManager.razor | 2 +- .../Components/FilterManager.razor.cs | 5 +- src/BlazorTable/Filters/BooleanFilter.razor | 2 +- .../Filters/BooleanFilter.razor.cs | 51 ++++----- src/BlazorTable/Filters/NumberFilter.razor | 2 +- src/BlazorTable/Filters/NumberFilter.razor.cs | 100 +++++++++--------- src/BlazorTable/Filters/StringFilter.razor | 2 +- src/BlazorTable/Filters/StringFilter.razor.cs | 74 ++++++------- src/BlazorTable/Interfaces/IColumn.cs | 13 ++- src/BlazorTable/Interfaces/IFilter.cs | 3 +- src/BlazorTable/Interfaces/IFilterManager.cs | 13 --- 13 files changed, 133 insertions(+), 142 deletions(-) delete mode 100644 src/BlazorTable/Interfaces/IFilterManager.cs diff --git a/src/BlazorTable/Components/Column.razor b/src/BlazorTable/Components/Column.razor index 64d40abc..f3cdfc74 100644 --- a/src/BlazorTable/Components/Column.razor +++ b/src/BlazorTable/Components/Column.razor @@ -10,7 +10,10 @@ - @*@this.CustomIFilters(this)*@ + @if (this.CustomIFilters != null) + { + this.CustomIFilters(this); + } diff --git a/src/BlazorTable/Components/Column.razor.cs b/src/BlazorTable/Components/Column.razor.cs index a9610122..cc175207 100644 --- a/src/BlazorTable/Components/Column.razor.cs +++ b/src/BlazorTable/Components/Column.razor.cs @@ -1,6 +1,5 @@ using Microsoft.AspNetCore.Components; using System; -using System.Linq; using System.Linq.Expressions; namespace BlazorTable @@ -50,7 +49,7 @@ public string Title public Type Type { get; private set; } - public IFilterManager FilterManager { get; set; } + public IFilter FilterControl { get; set; } public void Dispose() { diff --git a/src/BlazorTable/Components/FilterManager.razor b/src/BlazorTable/Components/FilterManager.razor index ffa83bff..5e161d5b 100644 --- a/src/BlazorTable/Components/FilterManager.razor +++ b/src/BlazorTable/Components/FilterManager.razor @@ -1,7 +1,7 @@ @namespace BlazorTable @typeparam TableItem - + @ChildContent
diff --git a/src/BlazorTable/Components/FilterManager.razor.cs b/src/BlazorTable/Components/FilterManager.razor.cs index 0f47abec..6fc0a02d 100644 --- a/src/BlazorTable/Components/FilterManager.razor.cs +++ b/src/BlazorTable/Components/FilterManager.razor.cs @@ -3,7 +3,7 @@ namespace BlazorTable { - public partial class FilterManager : IFilterManager + public partial class FilterManager { [CascadingParameter(Name = "Column")] public IColumn Column { get; set; } @@ -15,7 +15,6 @@ public partial class FilterManager : IFilterManager protected override void OnInitialized() { - Column.FilterManager = this; } private void ApplyFilter() @@ -23,7 +22,7 @@ private void ApplyFilter() Column.ToggleFilter(); if (Filter != null) { - Filter.ApplyFilter(); + Column.Filter = Filter.GetFilter(); Column.Table.Update(); Column.Table.FirstPage(); } diff --git a/src/BlazorTable/Filters/BooleanFilter.razor b/src/BlazorTable/Filters/BooleanFilter.razor index 96bd214d..d9ef07ae 100644 --- a/src/BlazorTable/Filters/BooleanFilter.razor +++ b/src/BlazorTable/Filters/BooleanFilter.razor @@ -1,7 +1,7 @@ @namespace BlazorTable @typeparam TableItem -@if (FilterTypes.Contains(FilterManager.Column.Type.GetNonNullableType())) +@if (FilterTypes.Contains(Column.Type.GetNonNullableType())) { @foreach (var option in (NumberCondition[])Enum.GetValues(typeof(NumberCondition))) diff --git a/src/BlazorTable/Filters/NumberFilter.razor.cs b/src/BlazorTable/Filters/NumberFilter.razor.cs index 0afdfa44..c5091287 100644 --- a/src/BlazorTable/Filters/NumberFilter.razor.cs +++ b/src/BlazorTable/Filters/NumberFilter.razor.cs @@ -2,13 +2,14 @@ using Microsoft.Extensions.Logging; using System; using System.ComponentModel; +using System.Globalization; using System.Linq.Expressions; namespace BlazorTable { public partial class NumberFilter : IFilter { - [CascadingParameter(Name = "FilterManager")] public IFilterManager FilterManager { get; set; } + [CascadingParameter(Name = "Column")] public IColumn Column { get; set; } [Inject] public ILogger> Logger { get; set; } @@ -18,13 +19,13 @@ public partial class NumberFilter : IFilter protected override void OnInitialized() { - if (FilterManager.Column.Type.IsNumeric()) + if (Column.Type.IsNumeric()) { - FilterManager.Filter = this; + Column.FilterControl = this; - if (FilterManager.Column.Filter != null) + if (Column.Filter != null) { - if (FilterManager.Column.Filter.Body is BinaryExpression binaryExpression) + if (Column.Filter.Body is BinaryExpression binaryExpression) { if (binaryExpression.NodeType == ExpressionType.AndAlso) { @@ -74,74 +75,73 @@ protected override void OnInitialized() } } - public void ApplyFilter() + public Expression> GetFilter() { switch (Condition) { case NumberCondition.IsEqualTo: - FilterManager.Column.Filter = Expression.Lambda>( + return Expression.Lambda>( Expression.AndAlso( - Expression.NotEqual(FilterManager.Column.Property.Body, Expression.Constant(null)), + Expression.NotEqual(Column.Property.Body, Expression.Constant(null)), Expression.Equal( - Expression.Convert(FilterManager.Column.Property.Body, FilterManager.Column.Type.GetNonNullableType()), - Expression.Constant(Convert.ChangeType(FilterValue, FilterManager.Column.Type.GetNonNullableType())))), - FilterManager.Column.Property.Parameters); - break; + Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()), + Expression.Constant(Convert.ChangeType(FilterValue, Column.Type.GetNonNullableType(), CultureInfo.InvariantCulture)))), + Column.Property.Parameters); + case NumberCondition.IsNotEqualTo: - FilterManager.Column.Filter = Expression.Lambda>( + return Expression.Lambda>( Expression.AndAlso( - Expression.NotEqual(FilterManager.Column.Property.Body, Expression.Constant(null)), + Expression.NotEqual(Column.Property.Body, Expression.Constant(null)), Expression.NotEqual( - Expression.Convert(FilterManager.Column.Property.Body, FilterManager.Column.Type.GetNonNullableType()), - Expression.Constant(Convert.ChangeType(FilterValue, FilterManager.Column.Type.GetNonNullableType())))), - FilterManager.Column.Property.Parameters); - break; + Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()), + Expression.Constant(Convert.ChangeType(FilterValue, Column.Type.GetNonNullableType(), CultureInfo.InvariantCulture)))), + Column.Property.Parameters); + case NumberCondition.IsGreaterThanOrEqualTo: - FilterManager.Column.Filter = Expression.Lambda>( + return Expression.Lambda>( Expression.AndAlso( - Expression.NotEqual(FilterManager.Column.Property.Body, Expression.Constant(null)), + Expression.NotEqual(Column.Property.Body, Expression.Constant(null)), Expression.GreaterThanOrEqual( - Expression.Convert(FilterManager.Column.Property.Body, FilterManager.Column.Type.GetNonNullableType()), - Expression.Constant(Convert.ChangeType(FilterValue, FilterManager.Column.Type.GetNonNullableType())))), - FilterManager.Column.Property.Parameters); - break; + Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()), + Expression.Constant(Convert.ChangeType(FilterValue, Column.Type.GetNonNullableType(), CultureInfo.InvariantCulture)))), + Column.Property.Parameters); + case NumberCondition.IsGreaterThan: - FilterManager.Column.Filter = Expression.Lambda>( + return Expression.Lambda>( Expression.AndAlso( - Expression.NotEqual(FilterManager.Column.Property.Body, Expression.Constant(null)), + Expression.NotEqual(Column.Property.Body, Expression.Constant(null)), Expression.GreaterThan( - Expression.Convert(FilterManager.Column.Property.Body, FilterManager.Column.Type.GetNonNullableType()), - Expression.Constant(Convert.ChangeType(FilterValue, FilterManager.Column.Type.GetNonNullableType())))), - FilterManager.Column.Property.Parameters); - break; + Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()), + Expression.Constant(Convert.ChangeType(FilterValue, Column.Type.GetNonNullableType(), CultureInfo.InvariantCulture)))), + Column.Property.Parameters); + case NumberCondition.IsLessThanOrEqualTo: - FilterManager.Column.Filter = Expression.Lambda>( + return Expression.Lambda>( Expression.AndAlso( - Expression.NotEqual(FilterManager.Column.Property.Body, Expression.Constant(null)), + Expression.NotEqual(Column.Property.Body, Expression.Constant(null)), Expression.LessThanOrEqual( - Expression.Convert(FilterManager.Column.Property.Body, FilterManager.Column.Type.GetNonNullableType()), - Expression.Constant(Convert.ChangeType(FilterValue, FilterManager.Column.Type.GetNonNullableType())))), - FilterManager.Column.Property.Parameters); - break; + Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()), + Expression.Constant(Convert.ChangeType(FilterValue, Column.Type.GetNonNullableType(), CultureInfo.InvariantCulture)))), + Column.Property.Parameters); + case NumberCondition.IsLessThan: - FilterManager.Column.Filter = Expression.Lambda>( + return Expression.Lambda>( Expression.AndAlso( - Expression.NotEqual(FilterManager.Column.Property.Body, Expression.Constant(null)), + Expression.NotEqual(Column.Property.Body, Expression.Constant(null)), Expression.LessThan( - Expression.Convert(FilterManager.Column.Property.Body, FilterManager.Column.Type.GetNonNullableType()), - Expression.Constant(Convert.ChangeType(FilterValue, FilterManager.Column.Type.GetNonNullableType())))), - FilterManager.Column.Property.Parameters); - break; + Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()), + Expression.Constant(Convert.ChangeType(FilterValue, Column.Type.GetNonNullableType(), CultureInfo.InvariantCulture)))), + Column.Property.Parameters); + case NumberCondition.IsNull: - FilterManager.Column.Filter = Expression.Lambda>( - Expression.Equal(FilterManager.Column.Property.Body, Expression.Constant(null)), - FilterManager.Column.Property.Parameters); - break; + return Expression.Lambda>( + Expression.Equal(Column.Property.Body, Expression.Constant(null)), + Column.Property.Parameters); + case NumberCondition.IsNotNull: - FilterManager.Column.Filter = Expression.Lambda>( - Expression.NotEqual(FilterManager.Column.Property.Body, Expression.Constant(null)), - FilterManager.Column.Property.Parameters); - break; + return Expression.Lambda>( + Expression.NotEqual(Column.Property.Body, Expression.Constant(null)), + Column.Property.Parameters); default: throw new ArgumentException(Condition + " is not defined!"); } diff --git a/src/BlazorTable/Filters/StringFilter.razor b/src/BlazorTable/Filters/StringFilter.razor index 1475c337..700f15e2 100644 --- a/src/BlazorTable/Filters/StringFilter.razor +++ b/src/BlazorTable/Filters/StringFilter.razor @@ -1,7 +1,7 @@ @namespace BlazorTable @typeparam TableItem -@if (FilterManager.Column.Type == FilterType) +@if (Column.Type == FilterType) { - + diff --git a/src/BlazorTable.Sample/Pages/Index.razor b/src/BlazorTable.Sample/Pages/Index.razor index d558a477..6e767def 100644 --- a/src/BlazorTable.Sample/Pages/Index.razor +++ b/src/BlazorTable.Sample/Pages/Index.razor @@ -41,7 +41,7 @@ @(context.fund.HasValue ? context.fund.Value.ToString("C") : string.Empty) - + diff --git a/src/BlazorTable/BlazorTable.csproj b/src/BlazorTable/BlazorTable.csproj index b08ca3fc..c5a811a4 100644 --- a/src/BlazorTable/BlazorTable.csproj +++ b/src/BlazorTable/BlazorTable.csproj @@ -9,7 +9,7 @@ Ivan Josipovic https://github.com/IvanJosipovic/BlazorTable Blazor;Table;Grid;DataTable;Data;Sort;Filter;AspNetCore;AspNet - 0.0.5-alpha + 0.0.6-alpha Experimental icon.png diff --git a/src/BlazorTable/Components/Column.razor b/src/BlazorTable/Components/Column.razor index f3cdfc74..ee1fafc3 100644 --- a/src/BlazorTable/Components/Column.razor +++ b/src/BlazorTable/Components/Column.razor @@ -10,10 +10,11 @@ - @if (this.CustomIFilters != null) + + @*@if (this.CustomIFilters != null) { this.CustomIFilters(this); - } + }*@ diff --git a/src/BlazorTable/Components/FilterManager.razor.cs b/src/BlazorTable/Components/FilterManager.razor.cs index 6fc0a02d..012b3037 100644 --- a/src/BlazorTable/Components/FilterManager.razor.cs +++ b/src/BlazorTable/Components/FilterManager.razor.cs @@ -11,8 +11,6 @@ public partial class FilterManager [Inject] public ILogger> Logger { get; set; } - public IFilter Filter { get; set; } - protected override void OnInitialized() { } @@ -20,11 +18,14 @@ protected override void OnInitialized() private void ApplyFilter() { Column.ToggleFilter(); - if (Filter != null) + if (Column.FilterControl != null) { - Column.Filter = Filter.GetFilter(); + Column.Filter = Column.FilterControl.GetFilter(); Column.Table.Update(); Column.Table.FirstPage(); + } else + { + Logger.LogInformation("Filter is null"); } } diff --git a/src/BlazorTable/Filters/DateFilter.razor b/src/BlazorTable/Filters/DateFilter.razor new file mode 100644 index 00000000..83da9aa1 --- /dev/null +++ b/src/BlazorTable/Filters/DateFilter.razor @@ -0,0 +1,16 @@ +@namespace BlazorTable +@typeparam TableItem + +@if (Column.Type.GetNonNullableType() == typeof(DateTime)) +{ + + @if (Condition != NumberCondition.IsNull && Condition != NumberCondition.IsNotNull) + { + + } +} \ No newline at end of file diff --git a/src/BlazorTable/Filters/DateFilter.razor.cs b/src/BlazorTable/Filters/DateFilter.razor.cs new file mode 100644 index 00000000..0f202ba0 --- /dev/null +++ b/src/BlazorTable/Filters/DateFilter.razor.cs @@ -0,0 +1,145 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Logging; +using System; +using System.Globalization; +using System.Linq.Expressions; + +namespace BlazorTable +{ + public partial class DateFilter : IFilter + { + [CascadingParameter(Name = "Column")] public IColumn Column { get; set; } + + [Inject] public ILogger> Logger { get; set; } + + private NumberCondition Condition { get; set; } + + private DateTime FilterValue { get; set; } = DateTime.Now; + + protected override void OnInitialized() + { + if (Column.Type.GetNonNullableType() == typeof(DateTime)) + { + Column.FilterControl = this; + + if (Column.Filter?.Body is BinaryExpression binaryExpression) + { + if (binaryExpression.NodeType == ExpressionType.AndAlso) + { + switch (binaryExpression.Right.NodeType) + { + case ExpressionType.Equal: + Condition = NumberCondition.IsEqualTo; + break; + case ExpressionType.NotEqual: + Condition = NumberCondition.IsNotEqualTo; + break; + case ExpressionType.GreaterThanOrEqual: + Condition = NumberCondition.IsGreaterThanOrEqualTo; + break; + case ExpressionType.GreaterThan: + Condition = NumberCondition.IsGreaterThan; + break; + case ExpressionType.LessThanOrEqual: + Condition = NumberCondition.IsLessThanOrEqualTo; + break; + case ExpressionType.LessThan: + Condition = NumberCondition.IsLessThan; + break; + } + } + else + { + if (binaryExpression.NodeType == ExpressionType.Equal) + { + Condition = NumberCondition.IsNull; + } + else if (binaryExpression.NodeType == ExpressionType.NotEqual) + { + Condition = NumberCondition.IsNotNull; + } + } + + if (binaryExpression.Right is BinaryExpression binaryExpression2 + && binaryExpression2.Right is ConstantExpression constantExpression) + { + FilterValue = DateTime.Parse(constantExpression.Value.ToString(), CultureInfo.InvariantCulture); + } + } + } + } + + public Expression> GetFilter() + { + switch (Condition) + { + case NumberCondition.IsEqualTo: + return Expression.Lambda>( + Expression.AndAlso( + Expression.NotEqual(Column.Property.Body, Expression.Constant(null)), + Expression.Equal( + Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()), + Expression.Constant(FilterValue))), + Column.Property.Parameters); + + case NumberCondition.IsNotEqualTo: + return Expression.Lambda>( + Expression.AndAlso( + Expression.NotEqual(Column.Property.Body, Expression.Constant(null)), + Expression.NotEqual( + Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()), + Expression.Constant(FilterValue))), + Column.Property.Parameters); + + case NumberCondition.IsGreaterThanOrEqualTo: + return Expression.Lambda>( + Expression.AndAlso( + Expression.NotEqual(Column.Property.Body, Expression.Constant(null)), + Expression.GreaterThanOrEqual( + Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()), + Expression.Constant(FilterValue))), + Column.Property.Parameters); + + case NumberCondition.IsGreaterThan: + return Expression.Lambda>( + Expression.AndAlso( + Expression.NotEqual(Column.Property.Body, Expression.Constant(null)), + Expression.GreaterThan( + Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()), + Expression.Constant(FilterValue))), + Column.Property.Parameters); + + case NumberCondition.IsLessThanOrEqualTo: + return Expression.Lambda>( + Expression.AndAlso( + Expression.NotEqual(Column.Property.Body, Expression.Constant(null)), + Expression.LessThanOrEqual( + Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()), + Expression.Constant(FilterValue))), + Column.Property.Parameters); + + case NumberCondition.IsLessThan: + return Expression.Lambda>( + Expression.AndAlso( + Expression.NotEqual(Column.Property.Body, Expression.Constant(null)), + Expression.LessThan( + Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()), + Expression.Constant(FilterValue))), + Column.Property.Parameters); + + case NumberCondition.IsNull: + return Expression.Lambda>( + Expression.Equal(Column.Property.Body, Expression.Constant(null)), + Column.Property.Parameters); + + case NumberCondition.IsNotNull: + return Expression.Lambda>( + Expression.NotEqual(Column.Property.Body, Expression.Constant(null)), + Column.Property.Parameters); + + default: + throw new ArgumentException(Condition + " is not defined!"); + } + } + } +} \ No newline at end of file diff --git a/src/BlazorTable/Filters/NumberFilter.razor b/src/BlazorTable/Filters/NumberFilter.razor index deae4170..96ec84f8 100644 --- a/src/BlazorTable/Filters/NumberFilter.razor +++ b/src/BlazorTable/Filters/NumberFilter.razor @@ -9,5 +9,8 @@ } - + @if (Condition != NumberCondition.IsNull && Condition != NumberCondition.IsNotNull) + { + + } } \ No newline at end of file diff --git a/src/BlazorTable/Filters/NumberFilter.razor.cs b/src/BlazorTable/Filters/NumberFilter.razor.cs index c5091287..820e7908 100644 --- a/src/BlazorTable/Filters/NumberFilter.razor.cs +++ b/src/BlazorTable/Filters/NumberFilter.razor.cs @@ -23,54 +23,49 @@ protected override void OnInitialized() { Column.FilterControl = this; - if (Column.Filter != null) + if (Column.Filter?.Body is BinaryExpression binaryExpression) { - if (Column.Filter.Body is BinaryExpression binaryExpression) + if (binaryExpression.NodeType == ExpressionType.AndAlso) { - if (binaryExpression.NodeType == ExpressionType.AndAlso) + switch (binaryExpression.Right.NodeType) { - switch (binaryExpression.Right.NodeType) - { - case ExpressionType.Equal: - Condition = NumberCondition.IsEqualTo; - break; - case ExpressionType.NotEqual: - Condition = NumberCondition.IsNotEqualTo; - break; - case ExpressionType.GreaterThanOrEqual: - Condition = NumberCondition.IsGreaterThanOrEqualTo; - break; - case ExpressionType.GreaterThan: - Condition = NumberCondition.IsGreaterThan; - break; - case ExpressionType.LessThanOrEqual: - Condition = NumberCondition.IsLessThanOrEqualTo; - break; - case ExpressionType.LessThan: - Condition = NumberCondition.IsLessThan; - break; - } + case ExpressionType.Equal: + Condition = NumberCondition.IsEqualTo; + break; + case ExpressionType.NotEqual: + Condition = NumberCondition.IsNotEqualTo; + break; + case ExpressionType.GreaterThanOrEqual: + Condition = NumberCondition.IsGreaterThanOrEqualTo; + break; + case ExpressionType.GreaterThan: + Condition = NumberCondition.IsGreaterThan; + break; + case ExpressionType.LessThanOrEqual: + Condition = NumberCondition.IsLessThanOrEqualTo; + break; + case ExpressionType.LessThan: + Condition = NumberCondition.IsLessThan; + break; } - else + } + else + { + if (binaryExpression.NodeType == ExpressionType.Equal) { - if (binaryExpression.NodeType == ExpressionType.Equal) - { - Condition = NumberCondition.IsNull; - } - else if (binaryExpression.NodeType == ExpressionType.NotEqual) - { - Condition = NumberCondition.IsNotNull; - } + Condition = NumberCondition.IsNull; } - - if (binaryExpression.Right is BinaryExpression binaryExpression2) + else if (binaryExpression.NodeType == ExpressionType.NotEqual) { - if (binaryExpression2.Right is ConstantExpression constantExpression) - { - FilterValue = constantExpression.Value.ToString(); - } + Condition = NumberCondition.IsNotNull; } } + + if (binaryExpression.Right is BinaryExpression binaryExpression2 + && binaryExpression2.Right is ConstantExpression constantExpression) + { + FilterValue = constantExpression.Value.ToString(); + } } } }