Started working on admin page modal

This commit is contained in:
2024-10-08 21:34:00 +02:00
parent bc0651cb75
commit d2729870e3
7 changed files with 180 additions and 29 deletions

View File

@@ -13,5 +13,6 @@ public interface IAdminPropertyGenerator {
IAdminPropertyGenerator DisplayName(string displayName);
IAdminPropertyGenerator Description(string description);
IAdminPropertyGenerator Prefix(string prefix);
IAdminPropertyGenerator Validator(Func<object, bool> validator);
}

View File

@@ -14,7 +14,8 @@ internal sealed class AdminPageGenerator<TModel> : IAdminPageGenerator<TModel>,
public AdminPageGenerator() {
Page = new AdminPage<TModel> {
Permissions = new AdminPagePermissions()
Permissions = new AdminPagePermissions(),
ModelType = typeof(TModel)
};
_propertyGenerators = new Dictionary<string, AdminPropertyGenerator>();

View File

@@ -65,6 +65,11 @@ internal sealed class AdminPropertyGenerator(string name, Type type) : IAdminPro
return this;
}
public IAdminPropertyGenerator Validator(Func<object, bool> validator) {
_property.Validator = validator;
return this;
}
public AdminPageProperty Compile() {
_property.DisplayName ??= _property.Name;
return _property;
@@ -111,6 +116,10 @@ internal sealed class AdminPropertyGenerator(string name, Type type) : IAdminPro
Bold(attribute?.Bold == true);
}
if (attributes.Any(a => a is RequiredAttribute)) {
_property.Required = true;
}
if (attributes.Any(a => a is AdminPrefixAttribute)) {
var attribute = attributes.Single(a => a is AdminPrefixAttribute) as AdminPrefixAttribute;
Prefix(attribute?.Prefix);

View File

@@ -14,6 +14,8 @@ public class AdminPage {
[JsonIgnore]
public Type RepositoryProvider { get; set; }
public Type ModelType { get; set; }
public string DefaultSortPropertyName { get; set; }
public ListSortDirection DefaultSortDirection { get; set; }

View File

@@ -13,8 +13,23 @@ public sealed class AdminPageProperty {
public bool Editable { get; set; } = true;
public bool EditDisplayValue { get; set; } = true;
public bool Generated { get; set; }
public bool Bold { get; set; } = false;
public bool Bold { get; set; }
public bool Required { get; set; }
public bool Ignore { get; set; }
[JsonIgnore]
public Type Type { get; set; }
public Func<object, bool> Validator { get; set; }
public object GetValue(object entry) {
return entry.GetType().GetProperty(Name)?.GetValue(entry);
}
public T GetValue<T>(object entry) {
return (T)entry.GetType().GetProperty(Name)?.GetValue(entry);
}
public void SetValue(object entry, object value) {
entry.GetType().GetProperty(Name)?.SetValue(entry, value);
}
}