This repository has been archived by the owner on Jul 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from IvanJosipovic/dev
v0.0.6-alpha
- Loading branch information
Showing
19 changed files
with
339 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@namespace BlazorTable | ||
@typeparam TableItem | ||
|
||
@if (Column.Type.GetNonNullableType() == typeof(DateTime)) | ||
{ | ||
<select class="form-control form-control-sm" value="@Condition" @onchange="@((x) => Condition = (NumberCondition)Enum.Parse(typeof(NumberCondition), x.Value.ToString()))"> | ||
@foreach (var option in (NumberCondition[])Enum.GetValues(typeof(NumberCondition))) | ||
{ | ||
<option value="@option">@option.GetDescription()</option> | ||
} | ||
</select> | ||
@if (Condition != NumberCondition.IsNull && Condition != NumberCondition.IsNotNull) | ||
{ | ||
<input type="date" class="form-control form-control-sm" @bind-value="FilterValue" /> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TableItem> : IFilter<TableItem> | ||
{ | ||
[CascadingParameter(Name = "Column")] public IColumn<TableItem> Column { get; set; } | ||
|
||
[Inject] public ILogger<NumberFilter<TableItem>> 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<Func<TableItem, bool>> GetFilter() | ||
{ | ||
switch (Condition) | ||
{ | ||
case NumberCondition.IsEqualTo: | ||
return Expression.Lambda<Func<TableItem, bool>>( | ||
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<Func<TableItem, bool>>( | ||
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<Func<TableItem, bool>>( | ||
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<Func<TableItem, bool>>( | ||
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<Func<TableItem, bool>>( | ||
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<Func<TableItem, bool>>( | ||
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<Func<TableItem, bool>>( | ||
Expression.Equal(Column.Property.Body, Expression.Constant(null)), | ||
Column.Property.Parameters); | ||
|
||
case NumberCondition.IsNotNull: | ||
return Expression.Lambda<Func<TableItem, bool>>( | ||
Expression.NotEqual(Column.Property.Body, Expression.Constant(null)), | ||
Column.Property.Parameters); | ||
|
||
default: | ||
throw new ArgumentException(Condition + " is not defined!"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
@namespace BlazorTable | ||
@typeparam TableItem | ||
|
||
@if (FilterManager.Column.Type.IsNumeric()) | ||
@if (Column.Type.IsNumeric()) | ||
{ | ||
<select class="form-control form-control-sm" value="@Condition" @onchange="@((x) => Condition = (NumberCondition)Enum.Parse(typeof(NumberCondition), x.Value.ToString()))"> | ||
@foreach (var option in (NumberCondition[])Enum.GetValues(typeof(NumberCondition))) | ||
{ | ||
<option value="@option">@option.GetDescription()</option> | ||
} | ||
</select> | ||
<input type="number" class="form-control form-control-sm" @bind-value="FilterValue" /> | ||
@if (Condition != NumberCondition.IsNull && Condition != NumberCondition.IsNotNull) | ||
{ | ||
<input type="number" class="form-control form-control-sm" @bind-value="FilterValue" /> | ||
} | ||
} |
Oops, something went wrong.