diff --git a/TIAM.Entities/TransferDestinations/TransferDestination.cs b/TIAM.Entities/TransferDestinations/TransferDestination.cs index 739531a1..d51da3dc 100644 --- a/TIAM.Entities/TransferDestinations/TransferDestination.cs +++ b/TIAM.Entities/TransferDestinations/TransferDestination.cs @@ -2,13 +2,21 @@ using AyCode.Interfaces.Entities; using AyCode.Entities.Locations; using AyCode.Interfaces.TimeStampInfo; +using System.ComponentModel.DataAnnotations; +using System.Text.RegularExpressions; namespace TIAM.Entities.TransferDestinations { [Table("TransferDestination")] public class TransferDestination : LocationBase, ITimeStampInfo { + //[Required(ErrorMessage = "The Username value should be specified.")] + [DataType(DataType.Text)] + [Display(Name = "Destination name")] public string? Name { get; set; } + + [DataType(DataType.MultilineText)] + [Display(Name = "Destination info")] public string? Description { get; set; } public DateTime Created { get; set; } @@ -20,5 +28,31 @@ namespace TIAM.Entities.TransferDestinations public TransferDestination(Guid id, string name, double latitude, double longitude, string address) : base(id, latitude,longitude, address) { } public TransferDestination(Guid id, string name, string description, double latitude, double longitude, string address) : base(id, latitude,longitude, address) { } } + + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)] + public class MinPasswordLengthAttribute : ValidationAttribute + { + int MinLength { get; } + public MinPasswordLengthAttribute(int minLength, string errorMsg) : base(errorMsg) + { + MinLength = minLength; + } + + public override bool IsValid(object value) + { + return ((string)value).Length >= MinLength; + } + } + + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)] + public class EmailAttribute : ValidationAttribute + { + public override bool IsValid(object value) + { + return Regex.IsMatch((string)value, @"^[\w!#$%&'*+\-/=?\^_`{|}~]+(\.[\w!#$%&'*+\-/=?\^_`{|}~]+)*" + + "@" + + @"((([\-\w]+\.)+[a-zA-Z]{2,4})|(([0-9]{1,3}\.){3}[0-9]{1,3}))$"); + } + } } diff --git a/TIAMSharedUI/Pages/Components/InputWizard.razor b/TIAMSharedUI/Pages/Components/InputWizard.razor index 95a7a868..2b51e392 100644 --- a/TIAMSharedUI/Pages/Components/InputWizard.razor +++ b/TIAMSharedUI/Pages/Components/InputWizard.razor @@ -3,29 +3,42 @@

Edit Form

-
- - -
-

Register with DevExpress

-

- Create a new account to see it in action -

-
-
- @CreateEditFormFields() -
-
-
+
+ + +
+

Register with DevExpress

+

+ Create a new account to see it in action +

+
+
+ @CreateEditFormFields() +
+
+
+
+ +
+

Register with DevExpress

+

+ Create a new account to see it in action +

+
+
+ @CreateDynamicTest() +
+ +

@FormSubmitResult

@code { - + } \ No newline at end of file diff --git a/TIAMSharedUI/Pages/Components/InputWizard.razor.cs b/TIAMSharedUI/Pages/Components/InputWizard.razor.cs index 3004a9e7..c0b503b1 100644 --- a/TIAMSharedUI/Pages/Components/InputWizard.razor.cs +++ b/TIAMSharedUI/Pages/Components/InputWizard.razor.cs @@ -7,14 +7,19 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Linq.Expressions; +using System.Reflection; using System.Text; using System.Threading.Tasks; using TIAM.Entities.TransferDestinations; +using TIAMWebApp.Shared.Application.Utility; + namespace TIAMSharedUI.Pages.Components { public partial class InputWizard : ComponentBase { + [Inject] + LogToBrowserConsole logToBrowserConsole { get; set; } string FormSubmitResult = ""; //TestUserData Data { get; set; } = new TestUserData(); @@ -33,15 +38,23 @@ namespace TIAMSharedUI.Pages.Components public RenderFragment CreateEditFormFields() => formLayoutBuilder => { + logToBrowserConsole.LogToBC("Hellooooo"); + var propertyList = typeof(TransferDestination).GetProperties(); + //var propertyList = typeof(TestUserData).GetProperties(); formLayoutBuilder.OpenComponent(0); formLayoutBuilder.AddAttribute(1, "ChildContent", (RenderFragment)((layoutItemBuilder) => { int i = 0; foreach (var property in propertyList) { + //if(property.Name == "Id" || property.Name == "Latitude" || property.Name == "Longitude" || property.Name == "Created" || property.Name == "Modified") + if(property.Name == "Id" || property.Name == "Created" || property.Name == "Modified") + { + continue; + } - var attrList = (DataTypeAttribute)property.GetCustomAttributes(typeof(DataTypeAttribute), false).First(); + DataTypeAttribute attrList = (DataTypeAttribute)property.GetCustomAttributes(typeof(DataTypeAttribute), false).First(); DisplayAttribute displayLabel = (DisplayAttribute)property.GetCustomAttributes(typeof(DisplayAttribute), false).First(); layoutItemBuilder.OpenComponent(i++); layoutItemBuilder.AddAttribute(i++, "Caption", displayLabel.Name); @@ -49,14 +62,18 @@ namespace TIAMSharedUI.Pages.Components //layoutItemBuilder.AddAttribute(i++, "CssClass", "form-field"); var access = Expression.Property(Expression.Constant(Data), property.Name); var lambda = Expression.Lambda(typeof(Func<>).MakeGenericType(property.PropertyType), access); + var lambda2 = Expression.Lambda(typeof(Func<>).MakeGenericType(property.PropertyType), access); + layoutItemBuilder.AddAttribute(i++, "Template", (RenderFragment)((context) => ((editor) => { var j = 0; switch (attrList.DataType) { + case DataType.Text: { editor.OpenComponent(j++); + logToBrowserConsole.LogToBC($"{property.Name}, {property.PropertyType}"); editor.AddAttribute(j++, "Text", property.GetValue(Data)); editor.AddAttribute(j++, "TextExpression", lambda); editor.AddAttribute(j++, "CssClass", "form-field"); @@ -98,13 +115,33 @@ namespace TIAMSharedUI.Pages.Components } case DataType.Custom: { - editor.OpenComponent>(j); - editor.AddAttribute(j++, "Data", AdditionalData.Occupations); - editor.AddAttribute(j++, "Value", property.GetValue(Data)); - editor.AddAttribute(j++, "ValueExpression", lambda); - editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); - editor.CloseComponent(); - break; + if(property.PropertyType == typeof(double)) + { + + editor.OpenComponent(j); + object _value = property.GetValue(Data); + string _valueString = _value == null ? "" : _value.ToString(); + logToBrowserConsole.LogToBC($"Bleh: {_value.GetType()}, {_valueString}"); + editor.AddAttribute(j++, "Text", _valueString); + //editor.AddAttribute(j++, "Text", property.GetValue(Data)); + var lambda2 = Expression.Lambda>(Expression.Convert(access, typeof(string))); + editor.AddAttribute(j++, "TextExpression", lambda2); + editor.AddAttribute(j++, "CssClass", "form-field"); + editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.CloseComponent(); + break; + } + else + { + + editor.OpenComponent>(j); + editor.AddAttribute(j++, "Data", AdditionalData.Occupations); + editor.AddAttribute(j++, "Value", property.GetValue(Data)); + editor.AddAttribute(j++, "ValueExpression", lambda); + editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.CloseComponent(); + break; + } } case DataType.MultilineText: @@ -112,6 +149,7 @@ namespace TIAMSharedUI.Pages.Components editor.OpenComponent(j); editor.AddAttribute(j++, "Text", property.GetValue(Data)); editor.AddAttribute(j++, "TextExpression", lambda); + editor.AddAttribute(j++, "CssClass", "form-field"); editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); editor.CloseComponent(); break; @@ -136,7 +174,126 @@ namespace TIAMSharedUI.Pages.Components editor.OpenComponent(i++); editor.AddAttribute(i++, "SubmitFormOnClick", true); - editor.AddAttribute(i++, "Text", "Register"); + editor.AddAttribute(i++, "Text", "Bleh"); + editor.CloseComponent(); + }))); + + layoutItemBuilder.CloseComponent(); + })); + formLayoutBuilder.CloseComponent(); + }; + + public RenderFragment CreateDynamicTest() => formLayoutBuilder => + { + logToBrowserConsole.LogToBC("Hellooooo"); + + var propertyList = typeof(TransferDestination).GetProperties(); + //var propertyList = typeof(TestUserData).GetProperties(); + formLayoutBuilder.OpenComponent(0); + formLayoutBuilder.AddAttribute(1, "ChildContent", (RenderFragment)((layoutItemBuilder) => + { + int i = 0; + + /*DataTypeAttribute attrList = (DataTypeAttribute)property.GetCustomAttributes(typeof(DataTypeAttribute), false).First(); + DisplayAttribute displayLabel = (DisplayAttribute)property.GetCustomAttributes(typeof(DisplayAttribute), false).First(); + layoutItemBuilder.OpenComponent(i++); + layoutItemBuilder.AddAttribute(i++, "Caption", displayLabel.Name); + layoutItemBuilder.AddAttribute(i++, "ColSpanMd", 12); + //layoutItemBuilder.AddAttribute(i++, "CssClass", "form-field"); + var access = Expression.Property(Expression.Constant(Data), property.Name); + var lambda = Expression.Lambda(typeof(Func<>).MakeGenericType(property.PropertyType), access); + layoutItemBuilder.AddAttribute(i++, "Template", (RenderFragment)((context) => ((editor) => + { + var j = 0; + switch (attrList.DataType) + { + + case DataType.Text: + { + editor.OpenComponent(j++); + logToBrowserConsole.LogToBC($"{property.Name}, {property.PropertyType}, {property.GetValue(Data).ToString()}"); + editor.AddAttribute(j++, "Text", property.GetValue(Data)); + editor.AddAttribute(j++, "TextExpression", lambda); + editor.AddAttribute(j++, "CssClass", "form-field"); + editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.CloseComponent(); + break; + } + case DataType.Password: + { + + editor.OpenComponent(j++); + editor.AddAttribute(j++, "Password", true); + editor.AddAttribute(j++, "NullText", "Password"); + editor.AddAttribute(j++, "Text", property.GetValue(Data)); + editor.AddAttribute(j++, "TextExpression", lambda); + editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.CloseComponent(); + break; + } + case DataType.PhoneNumber: + { + editor.OpenComponent>(j++); + editor.AddAttribute(j++, "Value", property.GetValue(Data)); + editor.AddAttribute(j++, "Mask", PhoneMask); + editor.AddAttribute(j++, "ValueExpression", lambda); + editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.CloseComponent(); + break; + } + case DataType.Date: + { + editor.OpenComponent>(j); + editor.AddAttribute(j++, "Date", property.GetValue(Data)); + editor.AddAttribute(j++, "DateExpression", lambda); + editor.AddAttribute(j++, "DateChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.CloseComponent(); + break; + + } + case DataType.Custom: + { + editor.OpenComponent>(j); + editor.AddAttribute(j++, "Data", AdditionalData.Occupations); + editor.AddAttribute(j++, "Value", property.GetValue(Data)); + editor.AddAttribute(j++, "ValueExpression", lambda); + editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.CloseComponent(); + break; + + } + case DataType.MultilineText: + { + editor.OpenComponent(j); + editor.AddAttribute(j++, "Text", property.GetValue(Data)); + editor.AddAttribute(j++, "TextExpression", lambda); + editor.AddAttribute(j++, "CssClass", "form-field"); + editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create(this, str => { property.SetValue(Data, str); })); + editor.CloseComponent(); + break; + + } + default: + break; + } + }))); + + layoutItemBuilder.CloseComponent(); + layoutItemBuilder.OpenElement(i++, "div"); + layoutItemBuilder.AddAttribute(i++, "class", "text-danger"); + layoutItemBuilder.OpenComponent(i++, typeof(ValidationMessage<>).MakeGenericType(property.PropertyType)); + layoutItemBuilder.AddAttribute(i++, "For", lambda); + layoutItemBuilder.CloseComponent(); + layoutItemBuilder.CloseElement();*/ + + + layoutItemBuilder.OpenComponent(i++); + layoutItemBuilder.AddAttribute(i++, "Template", (RenderFragment)((context) => ((editor) => + { + + editor.OpenComponent(i++); + editor.AddAttribute(i++, "SubmitFormOnClick", true); + editor.AddAttribute(i++, "Text", "Bleh"); editor.CloseComponent(); }))); diff --git a/TIAMSharedUI/Pages/Components/StepComponent.Razor.cs b/TIAMSharedUI/Pages/Components/StepComponent.Razor.cs new file mode 100644 index 00000000..8784dfa0 --- /dev/null +++ b/TIAMSharedUI/Pages/Components/StepComponent.Razor.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Components; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TIAMWebApp.Shared.Application.Models.ClientSide.UI; + +namespace TIAMSharedUI.Pages.Components +{ + public partial class StepComponent : ComponentBase + { + + [Parameter] + public RenderFragment ChildContent { get; set; } + + [Parameter] + public ACStepModelBase StepModel { get; set; } + + + [Parameter] + public EventCallback OnNext { get; set; } + + + } +} diff --git a/TIAMSharedUI/Pages/Components/StepComponent.razor b/TIAMSharedUI/Pages/Components/StepComponent.razor new file mode 100644 index 00000000..6ab7f06d --- /dev/null +++ b/TIAMSharedUI/Pages/Components/StepComponent.razor @@ -0,0 +1,5 @@ +

StepComponent

+ +@code { + +} diff --git a/TIAMSharedUI/Pages/Components/StepComponentBase.Razor.cs b/TIAMSharedUI/Pages/Components/StepComponentBase.Razor.cs new file mode 100644 index 00000000..74fddd70 --- /dev/null +++ b/TIAMSharedUI/Pages/Components/StepComponentBase.Razor.cs @@ -0,0 +1,18 @@ +using Microsoft.AspNetCore.Components; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TIAMSharedUI.Pages.Components +{ + public partial class StepComponentBase : ComponentBase + { + + + + + + } +} diff --git a/TIAMSharedUI/Pages/Components/StepComponentBase.razor b/TIAMSharedUI/Pages/Components/StepComponentBase.razor new file mode 100644 index 00000000..0f7b5209 --- /dev/null +++ b/TIAMSharedUI/Pages/Components/StepComponentBase.razor @@ -0,0 +1,5 @@ +

StepComponentBase

+ +@code { + +} diff --git a/TIAMSharedUI/Pages/Components/TiamDXTextBox.cs b/TIAMSharedUI/Pages/Components/TiamDXTextBox.cs new file mode 100644 index 00000000..411db714 --- /dev/null +++ b/TIAMSharedUI/Pages/Components/TiamDXTextBox.cs @@ -0,0 +1,30 @@ +using DevExpress.Blazor; +using Microsoft.AspNetCore.Components; +using System.Linq.Expressions; + +namespace TIAMSharedUI.Pages.Components +{ + public class TiamDXTextBox : DxTextBox + { + protected override void OnInitialized() + { + base.OnInitialized(); + this.CssClass = "dx-textbox tiam-textbox"; + + } + + //need a textexpression that works with double? and string + [Parameter] + public new Expression> TextExpression { + get + { + return Model.TextExpression; + } + set + { + Model.TextExpression = value; + } + } + } +} + diff --git a/TIAMWebApp/Shared/Models/ClientSide/UI/ACStepModelBase.cs b/TIAMWebApp/Shared/Models/ClientSide/UI/ACStepModelBase.cs new file mode 100644 index 00000000..c9d97445 --- /dev/null +++ b/TIAMWebApp/Shared/Models/ClientSide/UI/ACStepModelBase.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace TIAMWebApp.Shared.Application.Models.ClientSide.UI +{ + public class ACStepModelBase + { + public PropertyInfo PropertyInfo { get; set; } + + public bool IsLastStep { get; set; } + + public bool IsFirstStep { get; set; } + + public ACStepModelBase(PropertyInfo propertyInfo, bool isLastStep, bool isFirstStep) + { + PropertyInfo = propertyInfo; + IsLastStep = isLastStep; + IsFirstStep = isFirstStep; + } + + } +}