diff --git a/Enigmatry.Entry.CodeGeneration.Configuration/Form/Controls/Group/FormControlGroupBuilder.cs b/Enigmatry.Entry.CodeGeneration.Configuration/Form/Controls/Group/FormControlGroupBuilder.cs index 3923585..13d8fc5 100644 --- a/Enigmatry.Entry.CodeGeneration.Configuration/Form/Controls/Group/FormControlGroupBuilder.cs +++ b/Enigmatry.Entry.CodeGeneration.Configuration/Form/Controls/Group/FormControlGroupBuilder.cs @@ -64,6 +64,11 @@ public PasswordFormControlBuilder PasswordFormControl(Expression new PasswordFormControlBuilder(propertyInfo)); } + public NumberFormControlBuilder NumberFormControl(Expression> propertyExpression) + { + return GetOrCreateBuilder(propertyExpression.GetPropertyInfo(), propertyInfo => new NumberFormControlBuilder(propertyInfo)); + } + public CheckboxFormControlBuilder CheckboxFormControl(Expression> propertyExpression) { return GetOrCreateBuilder(propertyExpression.GetPropertyInfo(), propertyInfo => new CheckboxFormControlBuilder(propertyInfo)); diff --git a/Enigmatry.Entry.CodeGeneration.Configuration/Form/Controls/Input/NumberFormControl.cs b/Enigmatry.Entry.CodeGeneration.Configuration/Form/Controls/Input/NumberFormControl.cs new file mode 100644 index 0000000..3e31c84 --- /dev/null +++ b/Enigmatry.Entry.CodeGeneration.Configuration/Form/Controls/Input/NumberFormControl.cs @@ -0,0 +1,6 @@ +namespace Enigmatry.Entry.CodeGeneration.Configuration.Form.Controls; + +public class NumberFormControl : InputControlBase +{ + public override string Type => "number"; +} diff --git a/Enigmatry.Entry.CodeGeneration.Configuration/Form/Controls/Input/NumberFormControlBuilder.cs b/Enigmatry.Entry.CodeGeneration.Configuration/Form/Controls/Input/NumberFormControlBuilder.cs new file mode 100644 index 0000000..9bca250 --- /dev/null +++ b/Enigmatry.Entry.CodeGeneration.Configuration/Form/Controls/Input/NumberFormControlBuilder.cs @@ -0,0 +1,14 @@ +using System.Reflection; + +namespace Enigmatry.Entry.CodeGeneration.Configuration.Form.Controls; + +public class NumberFormControlBuilder : InputControlBuilderBase +{ + public NumberFormControlBuilder(PropertyInfo propertyInfo) : base(propertyInfo) + { + } + + public NumberFormControlBuilder(string propertyName) : base(propertyName) + { + } +} diff --git a/Enigmatry.Entry.CodeGeneration.Configuration/Form/FormComponentBuilder.cs b/Enigmatry.Entry.CodeGeneration.Configuration/Form/FormComponentBuilder.cs index a58b747..4546748 100644 --- a/Enigmatry.Entry.CodeGeneration.Configuration/Form/FormComponentBuilder.cs +++ b/Enigmatry.Entry.CodeGeneration.Configuration/Form/FormComponentBuilder.cs @@ -69,6 +69,11 @@ public PasswordFormControlBuilder PasswordFormControl(Expression(Expression> propertyExpression) + { + return _formGroup.NumberFormControl(propertyExpression); + } + public CheckboxFormControlBuilder CheckboxFormControl(Expression> propertyExpression) { return _formGroup.CheckboxFormControl(propertyExpression); diff --git a/Enigmatry.Entry.CodeGeneration.Tests/Angular/FilesToBeGenerated/mock-edit-generated.component.ts.txt b/Enigmatry.Entry.CodeGeneration.Tests/Angular/FilesToBeGenerated/mock-edit-generated.component.ts.txt index 5ae827a..a054251 100644 --- a/Enigmatry.Entry.CodeGeneration.Tests/Angular/FilesToBeGenerated/mock-edit-generated.component.ts.txt +++ b/Enigmatry.Entry.CodeGeneration.Tests/Angular/FilesToBeGenerated/mock-edit-generated.component.ts.txt @@ -165,7 +165,7 @@ pattern: /[A-Z]/, validation: { messages: { required: (err, field) => $localize `:@@CUSTOM_VALIDATION_MESSAGE_TRANSLATION_ID:CUSTOM_VALIDATION_MESSAGE`, -maxlength: (err, field) => $localize `:@@CUSTOM_VALIDATION_MESSAGE_TRANSLATION_ID:CUSTOM_VALIDATION_MESSAGE` +maxLength: (err, field) => $localize `:@@CUSTOM_VALIDATION_MESSAGE_TRANSLATION_ID:CUSTOM_VALIDATION_MESSAGE` } }, asyncValidators: { validation: [ 'uniqueName', 'isEnsured' ] }, @@ -233,9 +233,6 @@ className: `entry-money-field entry-input`, description: ``, attributes: { }, hidden: !true, - type: 'number', -max: 999.99 - 0.1, - typeFormatDef: { name: 'number' } }, }, @@ -255,10 +252,10 @@ className: `entry-amount-field entry-input`, label: $localize `:@@test.mock-edit.amount.label:Amount`, placeholder: $localize `:@@test.mock-edit.amount.placeholder:Amount`, description: $localize `:@@test.mock-edit.amount.hint:Don't panic if it is 0`, + type: 'number', attributes: { }, hidden: !true, required: true, -type: 'number', min: 0 + 1, max: 100, @@ -700,4 +697,3 @@ pattern: (err, field) => $localize `:@@validators.pattern.emailAddress:Invalid e } } - diff --git a/Enigmatry.Entry.CodeGeneration.Tests/Angular/FilesToBeGenerated/test-generated.module.ts.txt b/Enigmatry.Entry.CodeGeneration.Tests/Angular/FilesToBeGenerated/test-generated.module.ts.txt index 091a01c..714758a 100644 --- a/Enigmatry.Entry.CodeGeneration.Tests/Angular/FilesToBeGenerated/test-generated.module.ts.txt +++ b/Enigmatry.Entry.CodeGeneration.Tests/Angular/FilesToBeGenerated/test-generated.module.ts.txt @@ -31,9 +31,8 @@ import { CustomValidatorsService, customValidatorsFactory } from 'src/app/shared FormlyModule.forChild( { validationMessages: [ -{ name: 'maxlength', message: (err, field) => $localize `:@@validators.maxLength:${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.maxLength}:max-value: characters` }, +{ name: 'maxLength', message: (err, field) => $localize `:@@validators.maxLength:${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.maxLength}:max-value: characters` }, { name: 'pattern', message: (err, field) => $localize `:@@validators.pattern:${field?.templateOptions?.label}:property-name: is not in valid format` }, -{ name: 'max', message: (err, field) => $localize `:@@validators.max:${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.max}:max-value:` }, { name: 'required', message: (err, field) => $localize `:@@validators.required:${field?.templateOptions?.label}:property-name: is required` } ] } diff --git a/Enigmatry.Entry.CodeGeneration.Tests/Angular/HtmlHelperExtensions/AngularFormlyValidationHtmlHelperExtensionsFixture.cs b/Enigmatry.Entry.CodeGeneration.Tests/Angular/HtmlHelperExtensions/AngularFormlyValidationHtmlHelperExtensionsFixture.cs index e518842..aef2614 100644 --- a/Enigmatry.Entry.CodeGeneration.Tests/Angular/HtmlHelperExtensions/AngularFormlyValidationHtmlHelperExtensionsFixture.cs +++ b/Enigmatry.Entry.CodeGeneration.Tests/Angular/HtmlHelperExtensions/AngularFormlyValidationHtmlHelperExtensionsFixture.cs @@ -31,14 +31,13 @@ public void SetUp() } [TestCase(nameof(FormMock.Name), ExpectedResult = "required: true,maxLength: 50,pattern: /[A-Z]/,")] - [TestCase(nameof(FormMock.Money), ExpectedResult = "type: 'number',max: 999.99 - 0.1,")] - [TestCase(nameof(FormMock.Amount), ExpectedResult = "required: true,type: 'number',min: 0 + 1,max: 100,")] + [TestCase(nameof(FormMock.Amount), ExpectedResult = "required: true,min: 0 + 1,max: 100,")] [TestCase(nameof(FormMock.Email1), ExpectedResult = "pattern: /^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$/,maxLength: 50,")] [TestCase(nameof(FormMock.Email2), ExpectedResult = "pattern: /^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$/,maxLength: 50,")] public string AddValidationTemplateOptions(string propertyName) { var formControl = _formComponent.FormControlsOfType().Single(x => x.PropertyName == propertyName.Camelize()); - return _htmlHelper.AddValidationTemplateOptions(formControl)?.ToString()?.Replace("\r\n", "") ?? ""; + return _htmlHelper.AddValidationTemplateOptions(formControl).ToString()?.Replace("\r\n", "") ?? ""; } [TestCase(nameof(FormMock.Name), ExpectedResult = "modelOptions: { updateOn: 'blur' },")] @@ -48,7 +47,7 @@ public string AddValidationTemplateOptions(string propertyName) public string AddModelOptions(string propertyName) { var formControl = _formComponent.FormControlsOfType().Single(x => x.PropertyName == propertyName.Camelize()); - return _htmlHelper.AddModelOptions(formControl)?.ToString()?.Replace("\r\n", "") ?? ""; + return _htmlHelper.AddModelOptions(formControl).ToString()?.Replace("\r\n", "") ?? ""; } [TestCase(nameof(FormMock.Name), ExpectedResult = "asyncValidators: { validation: [ 'nameValidator' ] },")] @@ -59,7 +58,7 @@ public string AddModelOptions(string propertyName) public string AddAsyncValidators(string propertyName) { var formControl = _formComponent.FormControlsOfType().Single(x => x.PropertyName == propertyName.Camelize()); - return _htmlHelper.AddAsyncValidators(formControl)?.ToString()?.Replace("\r\n", "") ?? ""; + return _htmlHelper.AddAsyncValidators(formControl).ToString()?.Replace("\r\n", "") ?? ""; } [TestCase(nameof(FormMock.Name), ExpectedResult = @@ -73,22 +72,21 @@ public string AddAsyncValidators(string propertyName) public string AddCustomValidationMessages(string propertyName) { var formControl = _formComponent.FormControlsOfType().Single(x => x.PropertyName == propertyName.Camelize()); - return _htmlHelper.AddCustomValidationMessages(formControl, true)?.ToString()?.Replace("\r\n", "") ?? ""; + return _htmlHelper.AddCustomValidationMessages(formControl, true).ToString()?.Replace("\r\n", "") ?? ""; } [TestCase(ExpectedResult = "{ name: 'maxLength', message: (err, field) => $localize `:@@validators.maxLength:${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.maxLength}:max-value: characters` }," + "{ name: 'pattern', message: (err, field) => $localize `:@@validators.pattern:${field?.templateOptions?.label}:property-name: is not in valid format` }," + - "{ name: 'max', message: (err, field) => $localize `:@@validators.max:${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.max}:max-value:` }," + "{ name: 'required', message: (err, field) => $localize `:@@validators.required:${field?.templateOptions?.label}:property-name: is required` }")] public string AddCommonValidationMessages() => - _htmlHelper.AddCommonValidationMessages(_featureModule, true)?.ToString()?.Replace("\r\n", "") ?? ""; + _htmlHelper.AddCommonValidationMessages(_featureModule, true).ToString()?.Replace("\r\n", "") ?? ""; [TestCase("src/app/custom-path", ExpectedResult = "import { CustomValidatorsService, customValidatorsFactory } from 'src/app/custom-path';")] public string ImportValidators(string path) => - _htmlHelper.ImportValidators(_featureModule, path)?.ToString()?.Replace("\r\n", "") ?? ""; + _htmlHelper.ImportValidators(_featureModule, path).ToString()?.Replace("\r\n", "") ?? ""; [TestCase(ExpectedResult = "CustomValidatorsService,{ provide: FORMLY_CONFIG, multi: true, useFactory: customValidatorsFactory, deps: [ CustomValidatorsService ] }")] public string AddFromValidationProvider() => - _htmlHelper.AddFromValidationProvider(_featureModule)?.ToString()?.Replace("\r\n", "") ?? ""; + _htmlHelper.AddFromValidationProvider(_featureModule).ToString()?.Replace("\r\n", "") ?? ""; } diff --git a/Enigmatry.Entry.CodeGeneration.Tests/Angular/Mocks/FormMockConfiguration.cs b/Enigmatry.Entry.CodeGeneration.Tests/Angular/Mocks/FormMockConfiguration.cs index 38fc7cb..eae6fc8 100644 --- a/Enigmatry.Entry.CodeGeneration.Tests/Angular/Mocks/FormMockConfiguration.cs +++ b/Enigmatry.Entry.CodeGeneration.Tests/Angular/Mocks/FormMockConfiguration.cs @@ -64,7 +64,7 @@ public void Configure(FormComponentBuilder builder) .WithPlaceholder("Money"); formGroup - .FormControl(x => x.Amount) + .NumberFormControl(x => x.Amount) .WithLabel("Amount") .WithPlaceholder("Amount") .WithHint("Don't panic if it is 0"); diff --git a/Enigmatry.Entry.CodeGeneration.Tests/Angular/Mocks/FormMockValidationConfiguration.cs b/Enigmatry.Entry.CodeGeneration.Tests/Angular/Mocks/FormMockValidationConfiguration.cs index 5cbd260..58d9546 100644 --- a/Enigmatry.Entry.CodeGeneration.Tests/Angular/Mocks/FormMockValidationConfiguration.cs +++ b/Enigmatry.Entry.CodeGeneration.Tests/Angular/Mocks/FormMockValidationConfiguration.cs @@ -14,9 +14,6 @@ public FormMockValidationConfiguration() .WithMessage(Constants.CustomValidationMessage, Constants.CustomValidationMessageTranslationId) .Match(new Regex("/[A-Z]/")); - RuleFor(x => x.Money) - .LessThen(999.99M); - RuleFor(x => x.Amount) .IsRequired() .GreaterThen(0) @@ -33,4 +30,4 @@ public FormMockValidationConfiguration() .EmailAddress() .MaxLength(50); } -} \ No newline at end of file +} diff --git a/Enigmatry.Entry.CodeGeneration.Validation.Tests/InitialPropertyValidationBuilderExtensionsFixtures.cs b/Enigmatry.Entry.CodeGeneration.Validation.Tests/InitialPropertyValidationBuilderExtensionsFixtures.cs index 420c586..46f96c3 100644 --- a/Enigmatry.Entry.CodeGeneration.Validation.Tests/InitialPropertyValidationBuilderExtensionsFixtures.cs +++ b/Enigmatry.Entry.CodeGeneration.Validation.Tests/InitialPropertyValidationBuilderExtensionsFixtures.cs @@ -166,9 +166,9 @@ public void GreaterThen() _validationConfiguration.ValidationRules.Should().HaveCount(3); - AssertNumbercMinValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.IntField)), MinIntField, false); - AssertNumbercMinValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.DoubleField)), MinDoubleField, false); - AssertNumbercMinValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.ByteField)), MinByteField, false); + AssertNumericMinValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.IntField)), MinIntField, false); + AssertNumericMinValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.DoubleField)), MinDoubleField, false); + AssertNumericMinValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.ByteField)), MinByteField, false); } [Test] @@ -186,9 +186,9 @@ public void GreaterOrEqualTo() _validationConfiguration.ValidationRules.Should().HaveCount(3); - AssertNumbercMinValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.IntField)), MinIntField, true); - AssertNumbercMinValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.DoubleField)), MinDoubleField, true); - AssertNumbercMinValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.ByteField)), MinByteField, true); + AssertNumericMinValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.IntField)), MinIntField, true); + AssertNumericMinValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.DoubleField)), MinDoubleField, true); + AssertNumericMinValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.ByteField)), MinByteField, true); } [Test] @@ -206,9 +206,9 @@ public void LessThen() _validationConfiguration.ValidationRules.Should().HaveCount(3); - AssertNumbercMaxValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.IntField)), MaxIntField, false); - AssertNumbercMaxValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.DoubleField)), MaxDoubleField, false); - AssertNumbercMaxValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.ByteField)), MaxByteField, false); + AssertNumericMaxValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.IntField)), MaxIntField, false); + AssertNumericMaxValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.DoubleField)), MaxDoubleField, false); + AssertNumericMaxValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.ByteField)), MaxByteField, false); } [Test] @@ -226,9 +226,9 @@ public void LessOrEqualTo() _validationConfiguration.ValidationRules.Should().HaveCount(3); - AssertNumbercMaxValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.IntField)), MaxIntField, true); - AssertNumbercMaxValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.DoubleField)), MaxDoubleField, true); - AssertNumbercMaxValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.ByteField)), MaxByteField, true); + AssertNumericMaxValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.IntField)), MaxIntField, true); + AssertNumericMaxValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.DoubleField)), MaxDoubleField, true); + AssertNumericMaxValidationRule(GetRuleByPropertyName(nameof(ValidationMockModel.ByteField)), MaxByteField, true); } [Test] @@ -240,8 +240,8 @@ public void EqualToInt() _validationConfiguration.ValidationRules.Should().HaveCount(2); - AssertNumbercMinValidationRule(GetRuleByFormlyRuleName("min"), MinIntField, true); - AssertNumbercMaxValidationRule(GetRuleByFormlyRuleName("max"), MinIntField, true); + AssertNumericMinValidationRule(GetRuleByFormlyRuleName("min"), MinIntField, true); + AssertNumericMaxValidationRule(GetRuleByFormlyRuleName("max"), MinIntField, true); } [Test] @@ -253,8 +253,8 @@ public void EqualToDouble() _validationConfiguration.ValidationRules.Should().HaveCount(2); - AssertNumbercMinValidationRule(GetRuleByFormlyRuleName("min"), MinDoubleField, true); - AssertNumbercMaxValidationRule(GetRuleByFormlyRuleName("max"), MinDoubleField, true); + AssertNumericMinValidationRule(GetRuleByFormlyRuleName("min"), MinDoubleField, true); + AssertNumericMaxValidationRule(GetRuleByFormlyRuleName("max"), MinDoubleField, true); } [TestCase("MESSAGE", "")] @@ -286,7 +286,7 @@ public void InvalidWithMessage() .WithMessage($"{nameof(ValidationMockModel.IntField)} validation message cannot be empty."); } - private static void AssertNumbercMinValidationRule(IFormlyValidationRule rule, T value, bool isEqual) + private static void AssertNumericMinValidationRule(IFormlyValidationRule rule, T value, bool isEqual) { rule.FormlyRuleName .Should().Be("min"); @@ -295,12 +295,12 @@ private static void AssertNumbercMinValidationRule(IFormlyValidationRule rule rule.MessageTranslationId .Should().Be("validators.min"); rule.FormlyTemplateOptions - .Should().BeEquivalentTo("type: 'number'", $"min: {String.Format(CultureInfo.InvariantCulture, "{0}", value)}{(isEqual ? "" : $" + {GetIncrement()}")}"); + .Should().BeEquivalentTo($"min: {String.Format(CultureInfo.InvariantCulture, "{0}", value)}{(isEqual ? "" : $" + {GetIncrement()}")}"); rule.FormlyValidationMessage .Should().Be("${field?.templateOptions?.label}:property-name: value should be more than ${field?.templateOptions?.min}:min-value:"); } - private static void AssertNumbercMaxValidationRule(IFormlyValidationRule rule, T value, bool isEqual) + private static void AssertNumericMaxValidationRule(IFormlyValidationRule rule, T value, bool isEqual) { rule.FormlyRuleName .Should().Be("max"); @@ -309,7 +309,7 @@ private static void AssertNumbercMaxValidationRule(IFormlyValidationRule rule rule.MessageTranslationId .Should().Be("validators.max"); rule.FormlyTemplateOptions - .Should().BeEquivalentTo("type: 'number'", $"max: {String.Format(CultureInfo.InvariantCulture, "{0}", value)}{(isEqual ? "" : $" - {GetIncrement()}")}"); + .Should().BeEquivalentTo($"max: {String.Format(CultureInfo.InvariantCulture, "{0}", value)}{(isEqual ? "" : $" - {GetIncrement()}")}"); rule.FormlyValidationMessage .Should().Be("${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.max}:max-value:"); } diff --git a/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/GreaterOrEqualToValidationRule.cs b/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/GreaterOrEqualToValidationRule.cs index 369a934..40c6a2c 100644 --- a/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/GreaterOrEqualToValidationRule.cs +++ b/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/GreaterOrEqualToValidationRule.cs @@ -4,7 +4,7 @@ namespace Enigmatry.Entry.CodeGeneration.Validation.ValidationRules; -public class GreaterOrEqualToValidationRule : NumbericValidationRule +public class GreaterOrEqualToValidationRule : NumericValidationRule where T : struct, IComparable, IComparable, IConvertible, IEquatable, IFormattable { public GreaterOrEqualToValidationRule(T value, PropertyInfo propertyInfo, LambdaExpression expression) @@ -14,13 +14,11 @@ public GreaterOrEqualToValidationRule(T value, PropertyInfo propertyInfo, Lambda public override string FormlyRuleName => "min"; public override string[] FormlyTemplateOptions => - new[] - { - "type: 'number'", - $"{FormlyRuleName}: {RuleAsString}" - }; + [ + $"{FormlyRuleName}: {RuleAsString}" + ]; public override string FormlyValidationMessage => HasCustomMessage ? CustomMessage : "${field?.templateOptions?.label}:property-name: value should be more than ${field?.templateOptions?.min}:min-value:"; -} \ No newline at end of file +} diff --git a/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/GreaterThenValidationRule.cs b/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/GreaterThenValidationRule.cs index 20e6b64..d9a7910 100644 --- a/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/GreaterThenValidationRule.cs +++ b/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/GreaterThenValidationRule.cs @@ -4,7 +4,7 @@ namespace Enigmatry.Entry.CodeGeneration.Validation.ValidationRules; -public class GreaterThenValidationRule : NumbericValidationRule +public class GreaterThenValidationRule : NumericValidationRule where T : struct, IComparable, IComparable, IConvertible, IEquatable, IFormattable { public GreaterThenValidationRule(T value, PropertyInfo propertyInfo, LambdaExpression expression) @@ -14,13 +14,11 @@ public GreaterThenValidationRule(T value, PropertyInfo propertyInfo, LambdaExpre public override string FormlyRuleName => "min"; public override string[] FormlyTemplateOptions => - new[] - { - "type: 'number'", - $"{FormlyRuleName}: {RuleAsString} + {Increment}" - }; + [ + $"{FormlyRuleName}: {RuleAsString} + {Increment}" + ]; public override string FormlyValidationMessage => HasCustomMessage ? CustomMessage : "${field?.templateOptions?.label}:property-name: value should be more than ${field?.templateOptions?.min}:min-value:"; -} \ No newline at end of file +} diff --git a/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/LessOrEqualToValidationRule.cs b/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/LessOrEqualToValidationRule.cs index 1fde8df..1a13dea 100644 --- a/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/LessOrEqualToValidationRule.cs +++ b/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/LessOrEqualToValidationRule.cs @@ -4,7 +4,7 @@ namespace Enigmatry.Entry.CodeGeneration.Validation.ValidationRules; -public class LessOrEqualToValidationRule : NumbericValidationRule +public class LessOrEqualToValidationRule : NumericValidationRule where T : struct, IComparable, IComparable, IConvertible, IEquatable, IFormattable { public LessOrEqualToValidationRule(T value, PropertyInfo propertyInfo, LambdaExpression expression) @@ -14,13 +14,11 @@ public LessOrEqualToValidationRule(T value, PropertyInfo propertyInfo, LambdaExp public override string FormlyRuleName => "max"; public override string[] FormlyTemplateOptions => - new[] - { - "type: 'number'", - $"{FormlyRuleName}: {RuleAsString}" - }; + [ + $"{FormlyRuleName}: {RuleAsString}" + ]; public override string FormlyValidationMessage => HasCustomMessage ? CustomMessage : "${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.max}:max-value:"; -} \ No newline at end of file +} diff --git a/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/LessThenValidationRule.cs b/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/LessThenValidationRule.cs index 50ecc11..214cf2f 100644 --- a/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/LessThenValidationRule.cs +++ b/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/LessThenValidationRule.cs @@ -4,7 +4,7 @@ namespace Enigmatry.Entry.CodeGeneration.Validation.ValidationRules; -public class LessThenValidationRule : NumbericValidationRule +public class LessThenValidationRule : NumericValidationRule where T : struct, IComparable, IComparable, IConvertible, IEquatable, IFormattable { public LessThenValidationRule(T value, PropertyInfo propertyInfo, LambdaExpression expression) @@ -14,13 +14,11 @@ public LessThenValidationRule(T value, PropertyInfo propertyInfo, LambdaExpressi public override string FormlyRuleName => "max"; public override string[] FormlyTemplateOptions => - new[] - { - "type: 'number'", - $"{FormlyRuleName}: {RuleAsString} - {Increment}" - }; + [ + $"{FormlyRuleName}: {RuleAsString} - {Increment}" + ]; public override string FormlyValidationMessage => HasCustomMessage ? CustomMessage : "${field?.templateOptions?.label}:property-name: value should be less than ${field?.templateOptions?.max}:max-value:"; -} \ No newline at end of file +} diff --git a/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/NumbericValidationRule.cs b/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/NumericValidationRule.cs similarity index 73% rename from Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/NumbericValidationRule.cs rename to Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/NumericValidationRule.cs index 3238713..7579f33 100644 --- a/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/NumbericValidationRule.cs +++ b/Enigmatry.Entry.CodeGeneration.Validation/ValidationRules/NumericValidationRule.cs @@ -6,14 +6,14 @@ namespace Enigmatry.Entry.CodeGeneration.Validation.ValidationRules; -public abstract class NumbericValidationRule : ValidationRule +public abstract class NumericValidationRule : ValidationRule where T : struct, IComparable, IComparable, IConvertible, IEquatable, IFormattable { - protected NumbericValidationRule(T rule, PropertyInfo propertyInfo, LambdaExpression expression, string message, string messageTranslationId) + protected NumericValidationRule(T rule, PropertyInfo propertyInfo, LambdaExpression expression, string message, string messageTranslationId) : base(rule, propertyInfo, expression, message, messageTranslationId) { } public string Increment => typeof(T).IsFloatingPointNumber() ? "0.1" : "1"; public string RuleAsString => String.Format(CultureInfo.InvariantCulture, "{0}", Rule); -} \ No newline at end of file +}