Skip to content

Commit

Permalink
Merge pull request #24 from Kusumoto/fixbug/check-dotnet6-pkg
Browse files Browse the repository at this point in the history
Fixbug/check dotnet6 pkg
  • Loading branch information
Kusumoto authored Mar 5, 2022
2 parents 3b4962d + 207ac4b commit 4bbef99
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 177 deletions.
4 changes: 2 additions & 2 deletions PrimeNG.TableFilter.Test/PrimeNG.TableFilter.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>

<TargetFramework>netcoreapp3.1</TargetFramework>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion PrimeNG.TableFilter/Core/ILinqOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PrimeNG.TableFilter.Core
{
public interface ILinqOperator<TEntity>
public interface ILinqOperator<out TEntity>
{
void AddFilterProperty(string propertyName, object propertyValue, string extensionMethod,
OperatorEnumeration operatorAction, bool isNegation = false);
Expand Down
2 changes: 1 addition & 1 deletion PrimeNG.TableFilter/Core/ITableFilterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PrimeNG.TableFilter.Core
{
public interface ITableFilterManager<TEntity>
public interface ITableFilterManager<out TEntity>
{
void MultipleOrderDataSet(TableFilterModel tableFilterPayload);
void SingleOrderDataSet(TableFilterModel tableFilterPayload);
Expand Down
179 changes: 91 additions & 88 deletions PrimeNG.TableFilter/Core/LinqOperator.cs

Large diffs are not rendered by default.

170 changes: 101 additions & 69 deletions PrimeNG.TableFilter/Core/TableFilterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,72 +5,82 @@

namespace PrimeNG.TableFilter.Core
{
/// <summary>
/// Class of PrimeNG table filter manager for Entity
/// </summary>
public class TableFilterManager<TEntity> : ITableFilterManager<TEntity>
{
private const string FilterTypeMatchModeStartsWith = "startsWith";
private const string FilterTypeMatchModeContains = "contains";
private const string FilterTypeMatchModeNotContains = "notContains";
private const string FilterTypeMatchModeEndsWith = "endsWith";
private const string FilterTypeMatchModeEquals = "equals";
private const string FilterTypeMatchModeNotEquals = "notEquals";
private const string FilterTypeMatchModeIn = "in";
private const string FilterTypeMatchModeLessThan = "lt";
private const string FilterTypeMatchModeLessOrEqualsThan = "lte";
private const string FilterTypeMatchModeGreaterThan = "gt";
private const string FilterTypeMatchModeGreaterOrEqualsThan = "gte";
private const string FilterTypeMatchModeBetween = "between";
private const string FilterTypeMatchModeIs = "is";
private const string FilterTypeMatchModeIsNot = "isNot";
private const string FilterTypeMatchModeBefore = "before";
private const string FilterTypeMatchModeAfter = "after";
private const string FilterTypeMatchModeDateIs = "dateIs";
private const string FilterTypeMatchModeDateIsNot = "dateIsNot";
private const string FilterTypeMatchModeDateBefore = "dateBefore";
private const string FilterTypeMatchModeDateAfter = "dateAfter";
private const string ConstantTypeMatchModeStartsWith = "startsWith";
private const string ConstantTypeMatchModeContains = "contains";
private const string ConstantTypeMatchModeNotContains = "notContains";
private const string ConstantTypeMatchModeEndsWith = "endsWith";
private const string ConstantTypeMatchModeEquals = "equals";
private const string ConstantTypeMatchModeNotEquals = "notEquals";
private const string ConstantTypeMatchModeIn = "in";
private const string ConstantTypeMatchModeLessThan = "lt";
private const string ConstantTypeMatchModeLessOrEqualsThan = "lte";
private const string ConstantTypeMatchModeGreaterThan = "gt";
private const string ConstantTypeMatchModeGreaterOrEqualsThan = "gte";
private const string ConstantTypeMatchModeBetween = "between";
private const string ConstantTypeMatchModeIs = "is";
private const string ConstantTypeMatchModeIsNot = "isNot";
private const string ConstantTypeMatchModeBefore = "before";
private const string ConstantTypeMatchModeAfter = "after";
private const string ConstantTypeMatchModeDateIs = "dateIs";
private const string ConstantTypeMatchModeDateIsNot = "dateIsNot";
private const string ConstantTypeMatchModeDateBefore = "dateBefore";
private const string ConstantTypeMatchModeDateAfter = "dateAfter";


private readonly ILinqOperator<TEntity> _linqOperator;

public TableFilterManager(IQueryable<TEntity> dataSet)
{
_linqOperator = new LinqOperator<TEntity>(dataSet);
}

public TableFilterManager(IQueryable<TEntity> dataSet) => _linqOperator = new LinqOperator<TEntity>(dataSet);

/// <summary>
/// Set multiple condition for ordering data set to LINQ Operation context
/// </summary>
/// <param name="tableFilterPayload">PrimeNG load lazy filter payload</param>
/// <exception cref="System.ArgumentException">Throws invalid ordering exception</exception>
public void MultipleOrderDataSet(TableFilterModel tableFilterPayload)
{
tableFilterPayload.MultiSortMeta.Select((value, i) => new {i, value}).ToList().ForEach(o =>
{
switch (o.value.Order)
{
case (int) SortingEnumeration.OrderByAsc:
if (o.i == 0)
_linqOperator.OrderBy(o.value.Field.FirstCharToUpper());
else
_linqOperator.ThenBy(o.value.Field.FirstCharToUpper());
break;
case (int) SortingEnumeration.OrderByDesc:
if (o.i == 0)
_linqOperator.OrderByDescending(o.value.Field.FirstCharToUpper());
else
_linqOperator.ThenByDescending(o.value.Field.FirstCharToUpper());
break;
default:
throw new System.ArgumentException("Invalid Sort Order!");
}
});
tableFilterPayload.MultiSortMeta.Select((value, i) => new { i, value }).ToList().ForEach(o =>
{
switch (o.value.Order)
{
case (int)SortingEnumeration.OrderByAsc:
if (o.i == 0)
_linqOperator.OrderBy(o.value.Field.FirstCharToUpper());
else
_linqOperator.ThenBy(o.value.Field.FirstCharToUpper());
break;
case (int)SortingEnumeration.OrderByDesc:
if (o.i == 0)
_linqOperator.OrderByDescending(o.value.Field.FirstCharToUpper());
else
_linqOperator.ThenByDescending(o.value.Field.FirstCharToUpper());
break;
default:
throw new System.ArgumentException("Invalid Sort Order!");
}
});
}

/// <summary>
/// Set single condition for ordering data set to LINQ Operation context
/// </summary>
/// <param name="tableFilterPayload">PrimeNG load lazy filter payload</param>
/// <exception cref="System.ArgumentException">Throws invalid ordering parameter exception</exception>
public void SingleOrderDataSet(TableFilterModel tableFilterPayload)
{
switch (tableFilterPayload.SortOrder)
{
case (int) SortingEnumeration.OrderByAsc:
case (int)SortingEnumeration.OrderByAsc:
_linqOperator.OrderBy(tableFilterPayload.SortField.FirstCharToUpper());
break;

case (int) SortingEnumeration.OrderByDesc:
case (int)SortingEnumeration.OrderByDesc:
_linqOperator.OrderByDescending(tableFilterPayload.SortField.FirstCharToUpper());
break;

Expand All @@ -79,94 +89,104 @@ public void SingleOrderDataSet(TableFilterModel tableFilterPayload)
}
}

/// <summary>
/// Set filter condition data to LINQ Operation context
/// </summary>
/// <param name="key">Name of property</param>
/// <param name="value">PrimeNG filter context</param>
public void FilterDataSet(string key, TableFilterContext value)
{
BaseFilterDataSet(key, value, OperatorEnumeration.None);
}

=> BaseFilterDataSet(key, value, OperatorEnumeration.None);

/// <summary>
/// The base method for set filter condition data to LINQ Operation context
/// </summary>
/// <param name="key">Name of property</param>
/// <param name="value">PrimeNG filter context</param>
/// <param name="operatorAction">Operation action condition</param>
/// <exception cref="System.ArgumentException">Throws invalid match mode exception</exception>
private void BaseFilterDataSet(string key, TableFilterContext value, OperatorEnumeration operatorAction)
{
if (value.Value == null)
return;

switch (value.MatchMode)
{
case FilterTypeMatchModeStartsWith:
case ConstantTypeMatchModeStartsWith:
_linqOperator.AddFilterProperty(key.FirstCharToUpper(), value.Value,
LinqOperatorConstants.ConstantStartsWith
, operatorAction);
break;

case FilterTypeMatchModeContains:
case ConstantTypeMatchModeContains:
_linqOperator.AddFilterProperty(key.FirstCharToUpper(), value.Value,
LinqOperatorConstants.ConstantContains
, operatorAction);
break;

case FilterTypeMatchModeIn:
case ConstantTypeMatchModeIn:
_linqOperator.AddFilterListProperty(key.FirstCharToUpper(), value.Value
, operatorAction);
break;

case FilterTypeMatchModeEndsWith:
case ConstantTypeMatchModeEndsWith:
_linqOperator.AddFilterProperty(key.FirstCharToUpper(), value.Value,
LinqOperatorConstants.ConstantEndsWith
, OperatorEnumeration.None);
break;

case FilterTypeMatchModeEquals:
case ConstantTypeMatchModeEquals:
_linqOperator.AddFilterProperty(key.FirstCharToUpper(), value.Value,
LinqOperatorConstants.ConstantEquals
, operatorAction);
break;

case FilterTypeMatchModeNotContains:
case ConstantTypeMatchModeNotContains:
_linqOperator.AddFilterProperty(key.FirstCharToUpper(), value.Value,
LinqOperatorConstants.ConstantContains
, OperatorEnumeration.None, true);
break;

case FilterTypeMatchModeNotEquals:
case ConstantTypeMatchModeNotEquals:
_linqOperator.AddFilterProperty(key.FirstCharToUpper(), value.Value,
LinqOperatorConstants.ConstantEquals
, operatorAction, true);
break;
case FilterTypeMatchModeDateIs:
case ConstantTypeMatchModeDateIs:
_linqOperator.AddFilterProperty(key.FirstCharToUpper(), value.Value,
LinqOperatorConstants.ConstantDateIs
, operatorAction);
break;
case FilterTypeMatchModeDateIsNot:
case ConstantTypeMatchModeDateIsNot:
_linqOperator.AddFilterProperty(key.FirstCharToUpper(), value.Value,
LinqOperatorConstants.ConstantDateIs
, operatorAction,true);
, operatorAction, true);
break;
case FilterTypeMatchModeDateBefore:
case ConstantTypeMatchModeDateBefore:
_linqOperator.AddFilterProperty(key.FirstCharToUpper(), value.Value,
LinqOperatorConstants.ConstantBefore
, operatorAction);
break;
case FilterTypeMatchModeDateAfter:
case ConstantTypeMatchModeDateAfter:
_linqOperator.AddFilterProperty(key.FirstCharToUpper(), value.Value,
LinqOperatorConstants.ConstantAfter
, operatorAction);
break;
case FilterTypeMatchModeLessThan:
case ConstantTypeMatchModeLessThan:
_linqOperator.AddFilterProperty(key.FirstCharToUpper(), value.Value,
LinqOperatorConstants.ConstantLessThan
, operatorAction);
break;
case FilterTypeMatchModeLessOrEqualsThan:
case ConstantTypeMatchModeLessOrEqualsThan:
_linqOperator.AddFilterProperty(key.FirstCharToUpper(), value.Value,
LinqOperatorConstants.ConstantLessThanOrEqual
, operatorAction);
break;
case FilterTypeMatchModeGreaterThan:
case ConstantTypeMatchModeGreaterThan:
_linqOperator.AddFilterProperty(key.FirstCharToUpper(), value.Value,
LinqOperatorConstants.ConstantGreaterThan
, operatorAction);
break;
case FilterTypeMatchModeGreaterOrEqualsThan:
case ConstantTypeMatchModeGreaterOrEqualsThan:
_linqOperator.AddFilterProperty(key.FirstCharToUpper(), value.Value,
LinqOperatorConstants.ConstantGreaterThanOrEqual
, operatorAction);
Expand All @@ -178,6 +198,11 @@ private void BaseFilterDataSet(string key, TableFilterContext value, OperatorEnu
}
}

/// <summary>
/// Set multiple filter condition data to LINQ Operation context
/// </summary>
/// <param name="key">Name of property</param>
/// <param name="values">PrimeNG filters context</param>
public void FiltersDataSet(string key, IEnumerable<TableFilterContext> values)
{
foreach (var filterContext in values)
Expand All @@ -187,8 +212,15 @@ public void FiltersDataSet(string key, IEnumerable<TableFilterContext> values)
}
}

/// <summary>
/// Invoke filter data set from filter context setting
/// </summary>
public void ExecuteFilter() => _linqOperator.WhereExecute();

/// <summary>
/// Get the filter result
/// </summary>
/// <returns>Filter result</returns>
public IQueryable<TEntity> GetResult() => _linqOperator.GetResult();
}
}
8 changes: 4 additions & 4 deletions PrimeNG.TableFilter/Enumerations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ public enum OperatorEnumeration

public static class OperatorConstant
{
private const string And = "and";
private const string Or = "or";
private const string ConstantAnd = "and";
private const string ConstantOr = "or";

public static OperatorEnumeration ConvertOperatorEnumeration(string value)
{
switch (value.ToLower())
{
case And:
case ConstantAnd:
return OperatorEnumeration.And;
case Or:
case ConstantOr:
return OperatorEnumeration.Or;
default:
return OperatorEnumeration.None;
Expand Down
13 changes: 7 additions & 6 deletions PrimeNG.TableFilter/PrimeNG.TableFilter.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand All @@ -7,12 +7,13 @@
<Company>Kusumoto Lab</Company>
<PackageProjectUrl>https://github.com/Kusumoto/PrimeNG.TableFilter</PackageProjectUrl>
<RepositoryUrl>https://github.com/Kusumoto/PrimeNG.TableFilter</RepositoryUrl>
<Version>1.0.4</Version>
<PackageVersion>2.0.0</PackageVersion>
<TargetFrameworks>net40;netstandard2.0</TargetFrameworks>
<Version>2.1.0</Version>
<PackageVersion>2.1.0</PackageVersion>
<TargetFrameworks>net462;netstandard2.1;net6.0</TargetFrameworks>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<AssemblyVersion>2.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
<AssemblyVersion>2.1.0</AssemblyVersion>
<FileVersion>2.1.0</FileVersion>
<Copyright>2021 Copyright by Weerayut Hongsa</Copyright>
</PropertyGroup>
<ItemGroup>
Expand Down
Loading

0 comments on commit 4bbef99

Please sign in to comment.