Skip to content

Commit b2b2256

Browse files
authored
fix: fixed the web ui filter rules by value (content) (#121)
* fix: fixed the web ui filter rules by value (content)
1 parent cdc0c50 commit b2b2256

5 files changed

Lines changed: 132 additions & 72 deletions

File tree

samples/Rules.Framework.WebUI.Sample/Engine/RulesEngineProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public RulesEngineProvider(RulesBuilder rulesBuilder)
1919
.WithContentType<ContentTypes>()
2020
.WithConditionType<ConditionTypes>()
2121
.SetInMemoryDataSource()
22-
.Configure(c => c.PriotityCriteria = PriorityCriterias.BottommostRuleWins)
22+
.Configure(c => c.PriotityCriteria = PriorityCriterias.TopmostRuleWins)
2323
.Build();
2424

2525
await rulesBuilder.BuildAsync(rulesEngine).ConfigureAwait(false);

samples/Rules.Framework.WebUI.Sample/Rules/RulesRandomFactory.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private static RuleBuilderResult<ContentTypes, ConditionTypes> CreateMultipleRul
4343
RuleBuilder
4444
.NewRule<ContentTypes, ConditionTypes>()
4545
.WithName($"Multi rule for test {contentTypes} {value}")
46-
.WithContent(contentTypes, $"Value {contentTypes} {value}")
46+
.WithContent(contentTypes, new { Value = value })
4747
.WithDatesInterval(dateBegin, dateEnd)
4848
.WithCondition(cnb => cnb.AsComposed()
4949
.WithLogicalOperator(LogicalOperators.Or)
@@ -52,6 +52,11 @@ private static RuleBuilderResult<ContentTypes, ConditionTypes> CreateMultipleRul
5252
.WithComparisonOperator(Operators.Equal)
5353
.SetOperand(7)
5454
.Build())
55+
.AddCondition(condition => condition
56+
.AsValued(ConditionTypes.SumAll).OfDataType<int>()
57+
.WithComparisonOperator(Operators.Equal)
58+
.SetOperand(9)
59+
.Build())
5560
.AddCondition(condition => condition.AsComposed()
5661
.WithLogicalOperator(LogicalOperators.And)
5762
.AddCondition(sub => sub
@@ -73,8 +78,8 @@ private static RuleBuilderResult<ContentTypes, ConditionTypes> CreateMultipleRul
7378
.Build())
7479
.AddCondition(sub => sub
7580
.AsValued(ConditionTypes.SumAll).OfDataType<string>()
76-
.WithComparisonOperator(Operators.EndsWith)
77-
.SetOperand("150")
81+
.WithComparisonOperator(Operators.NotEqual)
82+
.SetOperand(string.Empty)
7883
.Build())
7984
.Build())
8085
.Build())

src/Rules.Framework.WebUI/Dto/ContentTypeDto.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace Rules.Framework.WebUI.Dto
22
{
33
internal sealed class ContentTypeDto
44
{
5+
public int Index { get; internal set; }
56
public int ActiveRulesCount { get; internal set; }
67
public string Name { get; internal set; }
78
public int RulesCount { get; internal set; }

src/Rules.Framework.WebUI/Handlers/GetContentTypeHandler.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected override async Task HandleRequestAsync(HttpRequest httpRequest, HttpRe
3333
var contents = this.genericRulesEngineAdapter.GetContentTypes();
3434

3535
var contentTypes = new List<ContentTypeDto>();
36-
36+
var index = 0;
3737
foreach (var identifier in contents.Select(c => c.Identifier))
3838
{
3939
var genericContentType = new GenericContentType { Identifier = identifier };
@@ -46,10 +46,12 @@ protected override async Task HandleRequestAsync(HttpRequest httpRequest, HttpRe
4646

4747
contentTypes.Add(new ContentTypeDto
4848
{
49+
Index = index,
4950
Name = identifier,
5051
ActiveRulesCount = genericRules.Count(IsActive),
5152
RulesCount = genericRules.Count()
5253
});
54+
index++;
5355
}
5456

5557
await this.WriteResponseAsync(httpResponse, contentTypes, (int)HttpStatusCode.OK).ConfigureAwait(false);

0 commit comments

Comments
 (0)