Added validation to admin pages
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
namespace HopFrame.Web.Admin.Attributes.Members;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class AdminUniqueAttribute : Attribute;
|
||||
@@ -11,11 +11,12 @@ public interface IAdminPropertyGenerator<TProperty> {
|
||||
IAdminPropertyGenerator<TProperty> Ignore(bool ignore = true);
|
||||
IAdminPropertyGenerator<TProperty> Generated(bool generated = true);
|
||||
IAdminPropertyGenerator<TProperty> Bold(bool bold = true);
|
||||
IAdminPropertyGenerator<TProperty> Unique(bool unique = true);
|
||||
|
||||
IAdminPropertyGenerator<TProperty> DisplayName(string displayName);
|
||||
IAdminPropertyGenerator<TProperty> Description(string description);
|
||||
IAdminPropertyGenerator<TProperty> Prefix(string prefix);
|
||||
IAdminPropertyGenerator<TProperty> Validator(Func<object, bool> validator);
|
||||
IAdminPropertyGenerator<TProperty> Validator(Func<TProperty, string> validator);
|
||||
IAdminPropertyGenerator<TProperty> IsSelector<TSelector>();
|
||||
IAdminPropertyGenerator<TProperty> Parser<TModel>(Func<TModel, string, TProperty> parser);
|
||||
IAdminPropertyGenerator<TProperty> ParserForListType<TModel, TInnerProperty>(Func<TModel, string, TInnerProperty> parser);
|
||||
|
||||
@@ -51,6 +51,11 @@ internal sealed class AdminPropertyGenerator<TProperty>(string name, Type type)
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPropertyGenerator<TProperty> Unique(bool unique = true) {
|
||||
_property.Unique = unique;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPropertyGenerator<TProperty> DisplayName(string displayName) {
|
||||
_property.DisplayName = displayName;
|
||||
return this;
|
||||
@@ -66,8 +71,8 @@ internal sealed class AdminPropertyGenerator<TProperty>(string name, Type type)
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPropertyGenerator<TProperty> Validator(Func<object, bool> validator) {
|
||||
_property.Validator = validator;
|
||||
public IAdminPropertyGenerator<TProperty> Validator(Func<TProperty, string> validator) {
|
||||
_property.Validator = o => validator.Invoke((TProperty)o);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -115,6 +120,9 @@ internal sealed class AdminPropertyGenerator<TProperty>(string name, Type type)
|
||||
|
||||
if (attributes.Any(a => a is AdminUneditableAttribute))
|
||||
Editable(false);
|
||||
|
||||
if (attributes.Any(a => a is AdminUniqueAttribute))
|
||||
Unique();
|
||||
|
||||
if (attributes.Any(a => a is AdminIgnoreAttribute)) {
|
||||
var attribute = attributes.Single(a => a is AdminIgnoreAttribute) as AdminIgnoreAttribute;
|
||||
|
||||
@@ -17,12 +17,14 @@ public sealed class AdminPageProperty {
|
||||
public bool Bold { get; set; }
|
||||
public bool Required { get; set; }
|
||||
public bool Ignore { get; set; }
|
||||
public bool Unique { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public Type Type { get; set; }
|
||||
|
||||
public Type SelectorType { get; set; }
|
||||
|
||||
public Func<object, bool> Validator { get; set; }
|
||||
public Func<object, string> Validator { get; set; }
|
||||
public Func<object, string, object> Parser { get; set; }
|
||||
|
||||
public object GetValue(object entry) {
|
||||
|
||||
Reference in New Issue
Block a user