Skip to content

Commit 20cb7c2

Browse files
authored
feat: able to update rules date end and disable (#117)
feat: able to update rules date end and disable
1 parent 4cb9309 commit 20cb7c2

37 files changed

Lines changed: 1019 additions & 63 deletions

File tree

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,25 @@ public IEnumerable<RuleSpecification> GetRulesSpecifications()
3333
RuleAddPriorityOption.ByPriorityNumber(i),
3434
rulesSpecifications);
3535
}
36+
37+
var deactiveDateBegin = CreateRandomDateBegin(currentYear);
38+
39+
Add(CreateMultipleRule((ContentTypes)contentType, finalNumber, deactiveDateBegin, CreateRandomDateEnd(deactiveDateBegin), isActive: false),
40+
RuleAddPriorityOption.ByPriorityNumber(finalNumber),
41+
rulesSpecifications);
3642
}
3743

3844
return rulesSpecifications;
3945
}
4046

4147
private static RuleBuilderResult<ContentTypes, ConditionTypes> CreateMultipleRule(ContentTypes contentTypes, int value, DateTime dateBegin,
42-
DateTime? dateEnd) =>
48+
DateTime? dateEnd, bool isActive = true) =>
4349
RuleBuilder
4450
.NewRule<ContentTypes, ConditionTypes>()
4551
.WithName($"Multi rule for test {contentTypes} {value}")
4652
.WithContent(contentTypes, new { Value = value })
4753
.WithDatesInterval(dateBegin, dateEnd)
54+
.WithActive(isActive)
4855
.WithCondition(cnb => cnb.AsComposed()
4956
.WithLogicalOperator(LogicalOperators.Or)
5057
.AddCondition(condition => condition
@@ -53,9 +60,9 @@ private static RuleBuilderResult<ContentTypes, ConditionTypes> CreateMultipleRul
5360
.SetOperand(7)
5461
.Build())
5562
.AddCondition(condition => condition
56-
.AsValued(ConditionTypes.SumAll).OfDataType<int>()
57-
.WithComparisonOperator(Operators.Equal)
58-
.SetOperand(9)
63+
.AsValued(ConditionTypes.SumAll).OfDataType<IEnumerable<int>>()
64+
.WithComparisonOperator(Operators.In)
65+
.SetOperand(new int[] { 9, 8, 6 })
5966
.Build())
6067
.AddCondition(condition => condition.AsComposed()
6168
.WithLogicalOperator(LogicalOperators.And)
@@ -127,4 +134,4 @@ private DateTime CreateRandomDateBegin(int year)
127134
return dateBegin.AddMonths(months).AddDays(1);
128135
}
129136
}
130-
}
137+
}

src/Rules.Framework.Providers.MongoDb/DataModel/RuleDataModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace Rules.Framework.Providers.MongoDb.DataModel
55

66
internal sealed class RuleDataModel
77
{
8+
public bool? Active { get; set; }
89
public dynamic Content { get; set; }
910

1011
public string ContentType { get; set; }

src/Rules.Framework.Providers.MongoDb/MongoDbProviderRulesDataSource.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public async Task UpdateRuleAsync(Rule<TContentType, TConditionType> rule)
102102
Builders<RuleDataModel>.Update.Set(r => r.DateEnd, ruleDataModel.DateEnd),
103103
Builders<RuleDataModel>.Update.Set(r => r.Name, ruleDataModel.Name),
104104
Builders<RuleDataModel>.Update.Set(r => r.Priority, ruleDataModel.Priority),
105+
Builders<RuleDataModel>.Update.Set(r => r.Active, ruleDataModel.Active),
105106
Builders<RuleDataModel>.Update.Set(r => r.RootCondition, ruleDataModel.RootCondition),
106107
};
107108

@@ -157,4 +158,4 @@ private async Task<IEnumerable<Rule<TContentType, TConditionType>>> GetRulesAsyn
157158
return fetchedRules.Select(r => this.ruleFactory.CreateRule(r));
158159
}
159160
}
160-
}
161+
}

src/Rules.Framework.Providers.MongoDb/RuleFactory.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public Rule<TContentType, TConditionType> CreateRule(RuleDataModel ruleDataModel
3131
var ruleBuilderResult = RuleBuilder.NewRule<TContentType, TConditionType>()
3232
.WithName(ruleDataModel.Name)
3333
.WithDatesInterval(ruleDataModel.DateBegin, ruleDataModel.DateEnd)
34+
.WithActive(ruleDataModel.Active ?? true)
3435
.WithCondition(cnb => ruleDataModel.RootCondition is { } ? ConvertConditionNode(cnb, ruleDataModel.RootCondition) : null)
3536
.WithSerializedContent(contentType, (object)ruleDataModel.Content, this.contentSerializationProvider)
3637
.Build();
@@ -69,6 +70,7 @@ public RuleDataModel CreateRule(Rule<TContentType, TConditionType> rule)
6970
DateEnd = rule.DateEnd,
7071
Name = rule.Name,
7172
Priority = rule.Priority,
73+
Active = rule.Active,
7274
RootCondition = rule.RootCondition is { } ? ConvertConditionNode(rule.RootCondition) : null,
7375
};
7476

@@ -202,4 +204,4 @@ private ConditionNodeDataModel ConvertConditionNode(IConditionNode<TConditionTyp
202204
return ConvertComposedConditionNode(conditionNode as ComposedConditionNode<TConditionType>);
203205
}
204206
}
205-
}
207+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ internal enum RuleStatusDto : short
44
{
55
Inactive,
66
Active,
7-
Pending
7+
Pending,
8+
Deactivated
89
}
9-
}
10+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ internal sealed class ValueConditionNodeDto : ConditionNodeDto
66

77
public string DataType { get; internal set; }
88

9-
public string Operand { get; internal set; }
9+
public dynamic Operand { get; internal set; }
1010

1111
public string Operator { get; internal set; }
1212
}
13-
}
13+
}

src/Rules.Framework.WebUI/Extensions/RuleDtoExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public static ConditionNodeDto ToConditionNodeDto(this GenericConditionNode root
2020
{
2121
ConditionTypeName = condition.ConditionTypeName,
2222
DataType = condition.DataType.ToString(),
23-
Operand = condition.Operand.ToString(),
24-
Operator = condition.Operator.ToString()
23+
Operand = condition.Operand,
24+
Operator = condition.Operator.ToString(),
2525
};
2626
}
2727

@@ -51,8 +51,8 @@ public static RuleDto ToRuleDto(this GenericRule rule, IRuleStatusDtoAnalyzer ru
5151
Value = rule.Content,
5252
DateEnd = !rule.DateEnd.HasValue ? null : rule.DateEnd.Value.ToString(dateFormat),
5353
DateBegin = rule.DateBegin.ToString(dateFormat),
54-
Status = ruleStatusDtoAnalyzer.Analyze(rule.DateBegin, rule.DateEnd).ToString(),
54+
Status = !rule.Active ? RuleStatusDto.Deactivated.ToString() : ruleStatusDtoAnalyzer.Analyze(rule.DateBegin, rule.DateEnd).ToString(),
5555
};
5656
}
5757
}
58-
}
58+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ private bool IsActive(GenericRule genericRule)
6767
return this.ruleStatusDtoAnalyzer.Analyze(genericRule.DateBegin, genericRule.DateEnd) == RuleStatusDto.Active;
6868
}
6969
}
70-
}
70+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ protected override async Task HandleRequestAsync(HttpRequest httpRequest, HttpRe
6868
}
6969
}
7070
}
71-
}
71+
}

src/Rules.Framework.WebUI/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ <h5 class="mb-3">Content Types</h5>
185185
<option value="active">Active</option>
186186
<option value="inactive">Inactive</option>
187187
<option value="pending">Pending</option>
188+
<option value="deactivated">Deactivated</option>
188189
</select>
189190
</div>
190191
</form>
@@ -316,6 +317,11 @@ <h5 class="mb-3">Rules</h5>
316317
style = 'color: #bc3803 !important;background-color: #ffefca !important;'
317318
icon = 'glyphicon glyphicon-time';
318319
break;
320+
case 'deactivated':
321+
labelColor = 'badge text-bg-info';
322+
style = 'color: #494141 !important;background-color: #bdbbbb !important;'
323+
icon = 'glyphicon glyphicon-minus-sign';
324+
break;
319325
default:
320326
labelColor = 'badge text-bg-danger';
321327
style = 'color: #AF0000 !important;background-color: #FFC8C8 !important;'

0 commit comments

Comments
 (0)