chore: update pages

This commit is contained in:
Wendell Muntslag 2024-05-28 10:23:17 +02:00
parent a866237dea
commit 49a069cef0
10 changed files with 248 additions and 14 deletions

View File

@ -19,7 +19,9 @@
<RadzenLabel Text="Property" Component="Property" style="width: 100%" />
</RadzenColumn>
<RadzenColumn SizeMD="9">
<RadzenTextBox style="display: block; width: 100%" @bind-Value="@coreRuleCriterion.Property" Name="Property" />
<RadzenAutoComplete Data="@Properties" @bind-Value="@coreRuleCriterion.Property"
Placeholder="Choose property or type your own" style="display: block; width: 100%" Name="Property"
/>
</RadzenColumn>
</RadzenRow>
<RadzenRow style="margin-bottom: 1rem">
@ -27,7 +29,8 @@
<RadzenLabel Text="Comparison" Component="Comparison" style="width: 100%" />
</RadzenColumn>
<RadzenColumn SizeMD="9">
<RadzenTextBox style="display: block; width: 100%" @bind-Value="@coreRuleCriterion.Comparison" Name="Comparison" />
<RadzenDropDown TValue="string" Data="@Comparisons" @bind-Value="@coreRuleCriterion.Comparison" AllowClear=true
Placeholder="Choose comparer" style="display: block; width: 100%" Name="Comparison" />
</RadzenColumn>
</RadzenRow>
<RadzenRow style="margin-bottom: 1rem">

View File

@ -2,11 +2,13 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DocumentFormat.OpenXml.CustomProperties;
using Microsoft.JSInterop;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Radzen;
using Radzen.Blazor;
using Microsoft.EntityFrameworkCore;
namespace ILoan.Rules.Web.Components.Pages
{
@ -32,8 +34,13 @@ namespace ILoan.Rules.Web.Components.Pages
[Inject]
public RulesService RulesService { get; set; }
public List<string> Properties { get; set; }
public List<string> Comparisons { get; set; }
protected override async Task OnInitializedAsync()
{
Properties = RulesService.GetProperties();
Comparisons = RulesService.GetComparisons();
coreRulesForRuleID = await RulesService.GetCoreRules();
}
@ -80,5 +87,10 @@ namespace ILoan.Rules.Web.Components.Pages
}
await base.SetParametersAsync(parameters);
}
void OnChange(dynamic args)
{
coreRuleCriterion.Property = args;
}
}
}

View File

@ -122,7 +122,11 @@ namespace ILoan.Rules.Web.Components.Pages
protected async Task CoreRuleCriteriaAddButtonClick(MouseEventArgs args, ILoan.Rules.Web.Models.Rules.CoreRule data)
{
var dialogResult = await DialogService.OpenAsync<AddCoreRuleCriterion>("Add CoreRuleCriteria", new Dictionary<string, object> { {"RuleID" , data.ID} });
var dialogResult = await DialogService.OpenAsync<AddCoreRuleCriterion>("Add CoreRuleCriteria", new Dictionary<string, object> { {"RuleID" , data.ID} }, new DialogOptions
{
Width = "70%"
});
await GetChildData(data);
await CoreRuleCriteriaDataGrid.Reload();

View File

@ -20,7 +20,8 @@
<RadzenLabel Text="Property" Component="Property" style="width: 100%" />
</RadzenColumn>
<RadzenColumn SizeMD="9">
<RadzenTextBox style="display: block; width: 100%" @bind-Value="@coreRuleCriterion.Property" Name="Property" />
<RadzenDropDown TValue="string" Data="@Properties" @bind-Value="@coreRuleCriterion.Property" AllowClear=true
Placeholder="Choose property" style="display: block; width: 100%" Name="Property" />
</RadzenColumn>
</RadzenRow>
<RadzenRow style="margin-bottom: 1rem">
@ -28,7 +29,8 @@
<RadzenLabel Text="Comparison" Component="Comparison" style="width: 100%" />
</RadzenColumn>
<RadzenColumn SizeMD="9">
<RadzenTextBox style="display: block; width: 100%" @bind-Value="@coreRuleCriterion.Comparison" Name="Comparison" />
<RadzenDropDown TValue="string" Data="@Comparisons" @bind-Value="@coreRuleCriterion.Comparison" AllowClear=true
Placeholder="Choose comparer" style="display: block; width: 100%" Name="Comparison" />
</RadzenColumn>
</RadzenRow>
<RadzenRow style="margin-bottom: 1rem">

View File

@ -36,8 +36,14 @@ namespace ILoan.Rules.Web.Components.Pages
[Parameter]
public int ID { get; set; }
public List<string> Properties { get; set; }
public List<string> Comparisons { get; set; }
protected override async Task OnInitializedAsync()
{
Properties = RulesService.GetProperties();
Comparisons = RulesService.GetComparisons();
coreRuleCriterion = await RulesService.GetCoreRuleCriterionById(ID);
coreRulesForRuleID = await RulesService.GetCoreRules();

View File

@ -0,0 +1,16 @@
namespace ILoan.Rules.Web.Extensions;
public static class EnumExtensions
{
public static List<string> ToList<T>() where T : Enum
{
var names = new List<string>();
foreach (var name in Enum.GetNames(typeof(T)))
{
names.Add(name);
}
return names;
}
}

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<NoWarn>CS0168,CS1998,BL9993,CS0649,CS0436,0436</NoWarn>
<TargetFramework>net8.0</TargetFramework>

View File

@ -0,0 +1,78 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
namespace ILoan.Rules.Web.Models.Enums;
/// <summary>
/// The comparison to apply to the rule value.
/// </summary>
[Description("The comparison to apply to the rule value")]
public enum RuleComparison
{
/// <summary>
/// The rule should contain a value.
/// </summary>
[Display(Name = "contains")]
Contains,
/// <summary>
/// The rule should not contain a value.
/// </summary>
[Display(Name = "does not contain")]
DoesNotContain,
/// <summary>
/// The rule should start with a value.
/// </summary>
[Display(Name = "starts with")]
StartsWith,
/// <summary>
/// The rule should not start with a value.
/// </summary>
[Display(Name = "does not start with")]
DoesNotStartWith,
/// <summary>
/// The rule should be lower than a value.
/// </summary>
[Display(Name = "lower than")]
LowerThan,
/// <summary>
/// The rule should be lower than or equal to a value.
/// </summary>
[Display(Name = "lower than or equal to")]
LowerThanOrEqualTo,
/// <summary>
/// The rule should be greater than a value.
/// </summary>
[Display(Name = "greater than")]
GreaterThan,
/// <summary>
/// The rule should be greater than or equal to a value.
/// </summary>
[Display(Name = "greater than or equal to")]
GreaterThanOrEqualTo,
/// <summary>
/// The rule should be equal to a value.
/// </summary>
[Display(Name = "is")]
Is,
/// <summary>
/// The rule should not be equal to a value.
/// </summary>
[Display(Name = "is not")]
IsNot,
/// <summary>
/// The rule value should be similar to a value.
/// </summary>
[Display(Name = "similar to")]
SimilarTo
}

View File

@ -28,9 +28,13 @@ public class RuleFileGeneratorService
if (!Directory.Exists(_root)) Directory.CreateDirectory(_root);
}
var rules = await _context.CoreRules.Where(rule => rule.ID >= _startRuleId).ToListAsync();
var rules = await _context.CoreRules
.Include(r => r.CoreRuleCriteria)
.Include(r => r.CoreRuleCriteriaOperators)
.Where(rule => rule.ID >= _startRuleId)
.ToListAsync();
foreach (var rule in rules.OrderBy(x =>x.ID))
foreach (var rule in rules.OrderBy(x => x.ID))
{
var fileName = $"V2.{_startSeq:000}__{rule.WorkItemId}_Rules_{rule.ID}_{rule.Title}.sql";
@ -40,7 +44,6 @@ public class RuleFileGeneratorService
}
var sql = GenerateSqlStatement(rule);
// Simulate writing to a file (you can replace this with actual file writing)
Console.WriteLine($"Generating file: {fileName}");
await File.WriteAllTextAsync(Path.Combine(_root, fileName), sql, Encoding.UTF8);
_startSeq++;
@ -49,8 +52,12 @@ public class RuleFileGeneratorService
private string GenerateSqlStatement(CoreRule rule)
{
return $@"
-- SQL statement to insert or update the rule
var sqlBuilder = new StringBuilder();
if (rule.Update == 0)
{
// SQL for inserting CoreRule
sqlBuilder.AppendLine($@"
INSERT INTO core.""Core_Rules"" (
""ID"", ""RuleName"", ""Source"", ""DefaultThreshold"", ""Blocked"", ""TriggersManualReview"",
""SuggestedResolution"", ""TriggerReason"", ""UseLastRecord"", ""ApplicantType"", ""FilterOnClickthrough"",
@ -65,11 +72,99 @@ INSERT INTO core.""Core_Rules"" (
'{EscapeSingleQuote(rule.DutchSuggestedResolution)}', '{EscapeSingleQuote(rule.DutchFilterOnClickthrough)}',
'{EscapeSingleQuote(rule.RuleExplanation)}', '{EscapeSingleQuote(rule.DutchRuleExplanation)}'
);
";
");
// SQL for inserting CoreRuleCriteria
foreach (var criterion in rule.CoreRuleCriteria)
{
sqlBuilder.AppendLine($@"
INSERT INTO core.""Core_RuleCriteria"" (
""ID"", ""RuleID"", ""Property"", ""Comparison"", ""Value"", ""ValueIsProperty"", ""ReturnCount"", ""IsThresholdCriterium""
) VALUES (
{criterion.ID}, {criterion.RuleID}, '{EscapeSingleQuote(criterion.Property)}', '{EscapeSingleQuote(criterion.Comparison)}', '{EscapeSingleQuote(criterion.Value)}',
{criterion.ValueIsProperty?.ToString().ToUpper() ?? "NULL"}, {criterion.ReturnCount?.ToString().ToUpper() ?? "NULL"}, {criterion.IsThresholdCriterium?.ToString().ToUpper() ?? "NULL"}
);
");
}
private static string? EscapeSingleQuote(string value)
// SQL for inserting CoreRuleCriteriaOperator
foreach (var coreRuleCriteriaOperator in rule.CoreRuleCriteriaOperators)
{
sqlBuilder.AppendLine($@"
INSERT INTO core.""Core_RuleCriteriaOperator"" (
""ID"", ""RuleID"", ""Operator""
) VALUES (
{coreRuleCriteriaOperator.ID}, {coreRuleCriteriaOperator.RuleID}, '{EscapeSingleQuote(coreRuleCriteriaOperator.Operator1)}'
);
");
}
}
else
{
// SQL for updating CoreRule
sqlBuilder.AppendLine($@"
UPDATE core.""Core_Rules""
SET
""RuleName"" = '{EscapeSingleQuote(rule.RuleName)}',
""Source"" = '{EscapeSingleQuote(rule.Source)}',
""DefaultThreshold"" = {rule.DefaultThreshold?.ToString() ?? "NULL"},
""Blocked"" = {rule.Blocked.ToString().ToUpper()},
""TriggersManualReview"" = {rule.TriggersManualReview.ToString().ToUpper()},
""SuggestedResolution"" = '{EscapeSingleQuote(rule.SuggestedResolution)}',
""TriggerReason"" = '{EscapeSingleQuote(rule.TriggerReason)}',
""UseLastRecord"" = {rule.UseLastRecord?.ToString().ToUpper() ?? "NULL"},
""ApplicantType"" = '{EscapeSingleQuote(rule.ApplicantType)}',
""FilterOnClickthrough"" = '{EscapeSingleQuote(rule.FilterOnClickthrough)}',
""RunBeforeStatus"" = '{EscapeSingleQuote(rule.RunBeforeStatus)}',
""DisplaySection"" = '{EscapeSingleQuote(rule.DisplaySection)}',
""WarningField"" = '{EscapeSingleQuote(rule.WarningField)}',
""DutchRuleName"" = '{EscapeSingleQuote(rule.DutchRuleName)}',
""DutchTriggerReason"" = '{EscapeSingleQuote(rule.DutchTriggerReason)}',
""DutchSuggestedResolution"" = '{EscapeSingleQuote(rule.DutchSuggestedResolution)}',
""DutchFilterOnClickthrough"" = '{EscapeSingleQuote(rule.DutchFilterOnClickthrough)}',
""RuleExplanation"" = '{EscapeSingleQuote(rule.RuleExplanation)}',
""DutchRuleExplanation"" = '{EscapeSingleQuote(rule.DutchRuleExplanation)}'
WHERE ""ID"" = {rule.ID};
");
// SQL for updating CoreRuleCriteria
foreach (var criterion in rule.CoreRuleCriteria)
{
sqlBuilder.AppendLine($@"
UPDATE core.""Core_RuleCriteria""
SET
""Property"" = '{EscapeSingleQuote(criterion.Property)}',
""Comparison"" = '{EscapeSingleQuote(criterion.Comparison)}',
""Value"" = '{EscapeSingleQuote(criterion.Value)}',
""ValueIsProperty"" = {criterion.ValueIsProperty?.ToString().ToUpper() ?? "NULL"},
""ReturnCount"" = {criterion.ReturnCount?.ToString().ToUpper() ?? "NULL"},
""IsThresholdCriterium"" = {criterion.IsThresholdCriterium?.ToString().ToUpper() ?? "NULL"}
WHERE ""ID"" = {criterion.ID};
");
}
// SQL for updating CoreRuleCriteriaOperator
foreach (var coreRuleCriteriaOperator in rule.CoreRuleCriteriaOperators)
{
sqlBuilder.AppendLine($@"
UPDATE core.""Core_RuleCriteriaOperator""
SET
""Operator"" = '{EscapeSingleQuote(coreRuleCriteriaOperator.Operator1)}'
WHERE ""ID"" = {coreRuleCriteriaOperator.ID};
");
}
}
return sqlBuilder.ToString();
}
private static string EscapeSingleQuote(string value)
{
return value?.Replace("'", "''");
}
}
// Usage example:
// var context = new RulesContext();
// var generator = new RuleFileGeneratorService(context, configuration);
// await generator.GenerateRuleFilesAsync();

View File

@ -10,6 +10,9 @@ using Microsoft.EntityFrameworkCore;
using Radzen;
using ILoan.Rules.Web.Data;
using DocumentFormat.OpenXml.InkML;
using ILoan.Rules.Web.Models.Enums;
using ILoan.Rules.Web.Extensions;
namespace ILoan.Rules.Web
{
@ -556,5 +559,20 @@ namespace ILoan.Rules.Web
return itemToDelete;
}
// get properties from CoreRuleCriterion as a disctinct list for type ahead
public List<string> GetProperties()
{
var properties = context.CoreRuleCriteria.Select(c => c.Property).Distinct().OrderBy(x => x).ToList();
return properties;
}
public List<string> GetComparisons()
{
return EnumExtensions.ToList<RuleComparison>();
}
}
}