This commit is contained in:
Adam 2023-12-13 22:38:23 +01:00
parent 231119963e
commit bb2b6af3ab
9 changed files with 341 additions and 27 deletions

View File

@ -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}))$");
}
}
}

View File

@ -3,29 +3,42 @@
<h2>Edit Form</h2>
<div class="wrapper">
<div class="card cw-480">
<EditForm Model="@Data"
OnValidSubmit="@HandleValidSubmit"
OnInvalidSubmit="@HandleInvalidSubmit"
Context="EditFormContext">
<DataAnnotationsValidator />
<div class="card-header text-center py-3">
<h4>Register with DevExpress</h4>
<p class="tm-8 mb-0 fw-normal fs-825">
Create a new account to see it in action
</p>
</div>
<div class="card-body">
@CreateEditFormFields()
</div>
</EditForm>
</div>
<div class="card cw-480">
<EditForm Model="@Data"
OnValidSubmit="@HandleValidSubmit"
OnInvalidSubmit="@HandleInvalidSubmit"
Context="EditFormContext">
<DataAnnotationsValidator />
<div class="card-header text-center py-3">
<h4>Register with DevExpress</h4>
<p class="tm-8 mb-0 fw-normal fs-825">
Create a new account to see it in action
</p>
</div>
<div class="card-body">
@CreateEditFormFields()
</div>
</EditForm>
</div>
<div class="card cw-480">
<div class="card-header text-center py-3">
<h4>Register with DevExpress</h4>
<p class="tm-8 mb-0 fw-normal fs-825">
Create a new account to see it in action
</p>
</div>
<div class="card-body">
@CreateDynamicTest()
</div>
</div>
</div>
<p class="tm-8 cw-480 mt-2">
@FormSubmitResult
</p>
@code {
}

View File

@ -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<DxFormLayout>(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<DxFormLayoutItem>(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<Object>)((context) => ((editor) =>
{
var j = 0;
switch (attrList.DataType)
{
case DataType.Text:
{
editor.OpenComponent<DxTextBox>(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<DxComboBox<String, String>>(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<System.String>(this, str => { property.SetValue(Data, str); }));
editor.CloseComponent();
break;
if(property.PropertyType == typeof(double))
{
editor.OpenComponent<DxTextBox>(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<Func<double>>(Expression.Convert(access, typeof(string)));
editor.AddAttribute(j++, "TextExpression", lambda2);
editor.AddAttribute(j++, "CssClass", "form-field");
editor.AddAttribute(j++, "TextChanged", EventCallback.Factory.Create<System.String>(this, str => { property.SetValue(Data, str); }));
editor.CloseComponent();
break;
}
else
{
editor.OpenComponent<DxComboBox<String, String>>(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<System.String>(this, str => { property.SetValue(Data, str); }));
editor.CloseComponent();
break;
}
}
case DataType.MultilineText:
@ -112,6 +149,7 @@ namespace TIAMSharedUI.Pages.Components
editor.OpenComponent<DxMemo>(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<System.String>(this, str => { property.SetValue(Data, str); }));
editor.CloseComponent();
break;
@ -136,7 +174,126 @@ namespace TIAMSharedUI.Pages.Components
editor.OpenComponent<DxButton>(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<StepComponent>(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<DxFormLayoutItem>(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<Object>)((context) => ((editor) =>
{
var j = 0;
switch (attrList.DataType)
{
case DataType.Text:
{
editor.OpenComponent<DxTextBox>(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<System.String>(this, str => { property.SetValue(Data, str); }));
editor.CloseComponent();
break;
}
case DataType.Password:
{
editor.OpenComponent<DxTextBox>(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<System.String>(this, str => { property.SetValue(Data, str); }));
editor.CloseComponent();
break;
}
case DataType.PhoneNumber:
{
editor.OpenComponent<DxMaskedInput<String>>(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<System.String>(this, str => { property.SetValue(Data, str); }));
editor.CloseComponent();
break;
}
case DataType.Date:
{
editor.OpenComponent<DxDateEdit<DateTime>>(j);
editor.AddAttribute(j++, "Date", property.GetValue(Data));
editor.AddAttribute(j++, "DateExpression", lambda);
editor.AddAttribute(j++, "DateChanged", EventCallback.Factory.Create<System.DateTime>(this, str => { property.SetValue(Data, str); }));
editor.CloseComponent();
break;
}
case DataType.Custom:
{
editor.OpenComponent<DxComboBox<String, String>>(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<System.String>(this, str => { property.SetValue(Data, str); }));
editor.CloseComponent();
break;
}
case DataType.MultilineText:
{
editor.OpenComponent<DxMemo>(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<System.String>(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<DxFormLayoutItem>(i++);
layoutItemBuilder.AddAttribute(i++, "Template", (RenderFragment<Object>)((context) => ((editor) =>
{
editor.OpenComponent<DxButton>(i++);
editor.AddAttribute(i++, "SubmitFormOnClick", true);
editor.AddAttribute(i++, "Text", "Bleh");
editor.CloseComponent();
})));

View File

@ -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; }
}
}

View File

@ -0,0 +1,5 @@
<h3>StepComponent</h3>
@code {
}

View File

@ -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
{
}
}

View File

@ -0,0 +1,5 @@
<h3>StepComponentBase</h3>
@code {
}

View File

@ -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<Func<string>> TextExpression {
get
{
return Model.TextExpression;
}
set
{
Model.TextExpression = value;
}
}
}
}

View File

@ -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;
}
}
}