Created AdminContext handling
This commit is contained in:
9
src/HopFrame.Web.Admin/AdminPagesContext.cs
Normal file
9
src/HopFrame.Web.Admin/AdminPagesContext.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using HopFrame.Web.Admin.Generators;
|
||||
|
||||
namespace HopFrame.Web.Admin;
|
||||
|
||||
public abstract class AdminPagesContext {
|
||||
|
||||
public abstract void OnModelCreating(IAdminContextGenerator generator);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace HopFrame.Web.Admin.Attributes;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property)]
|
||||
public class AdminDescriptionAttribute(string description) : Attribute {
|
||||
public string Description { get; set; } = description;
|
||||
}
|
||||
6
src/HopFrame.Web.Admin/Attributes/AdminNameAttribute.cs
Normal file
6
src/HopFrame.Web.Admin/Attributes/AdminNameAttribute.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace HopFrame.Web.Admin.Attributes;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property)]
|
||||
public class AdminNameAttribute(string name) : Attribute {
|
||||
public string Name { get; set; } = name;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace HopFrame.Web.Admin.Attributes.Classes;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class AdminButtonConfigAttribute(bool showCreateButton = true, bool showDeleteButton = true, bool showUpdateButton = true) : Attribute {
|
||||
public bool ShowCreateButton { get; set; } = showCreateButton;
|
||||
public bool ShowDeleteButton { get; set; } = showDeleteButton;
|
||||
public bool ShowUpdateButton { get; set; } = showUpdateButton;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using HopFrame.Web.Admin.Models;
|
||||
|
||||
namespace HopFrame.Web.Admin.Attributes.Classes;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class AdminPermissionsAttribute(AdminPagePermissions permissions) : Attribute {
|
||||
public AdminPagePermissions Permissions { get; set; } = permissions;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace HopFrame.Web.Admin.Attributes.Members;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class AdminBoldAttribute : Attribute;
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace HopFrame.Web.Admin.Attributes.Members;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class AdminHideValueAttribute : Attribute;
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace HopFrame.Web.Admin.Attributes.Members;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class AdminIgnoreAttribute(bool onlyForListing = false) : Attribute {
|
||||
public bool OnlyForListing { get; set; } = onlyForListing;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace HopFrame.Web.Admin.Attributes.Members;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class AdminUneditableAttribute : Attribute;
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace HopFrame.Web.Admin.Attributes.Members;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class AdminUnsortableAttribute : Attribute;
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace HopFrame.Web.Admin.Generators;
|
||||
|
||||
public interface IAdminContextGenerator {
|
||||
|
||||
IAdminPageGenerator<TModel> Page<TModel>();
|
||||
|
||||
}
|
||||
26
src/HopFrame.Web.Admin/Generators/IAdminPageGenerator.cs
Normal file
26
src/HopFrame.Web.Admin/Generators/IAdminPageGenerator.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.ComponentModel;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace HopFrame.Web.Admin.Generators;
|
||||
|
||||
public interface IAdminPageGenerator<TModel> {
|
||||
|
||||
IAdminPageGenerator<TModel> Title(string title);
|
||||
IAdminPageGenerator<TModel> Description(string description);
|
||||
|
||||
IAdminPageGenerator<TModel> ViewPermission(string permission);
|
||||
IAdminPageGenerator<TModel> CreatePermission(string permission);
|
||||
IAdminPageGenerator<TModel> UpdatePermission(string permission);
|
||||
IAdminPageGenerator<TModel> DeletePermission(string permission);
|
||||
|
||||
IAdminPageGenerator<TModel> ShowCreateButton(bool show);
|
||||
IAdminPageGenerator<TModel> ShowDeleteButton(bool show);
|
||||
IAdminPageGenerator<TModel> ShowUpdateButton(bool show);
|
||||
|
||||
IAdminPageGenerator<TModel> DefaultSort<TProperty>(Expression<Func<TModel, TProperty>> propertyExpression, ListSortDirection direction);
|
||||
|
||||
IAdminPageGenerator<TModel> ConfigureRepository<TRepository>() where TRepository : IModelRepository<TModel>;
|
||||
|
||||
IAdminPropertyGenerator Property<TProperty>(Expression<Func<TModel, TProperty>> propertyExpression);
|
||||
|
||||
}
|
||||
14
src/HopFrame.Web.Admin/Generators/IAdminPropertyGenerator.cs
Normal file
14
src/HopFrame.Web.Admin/Generators/IAdminPropertyGenerator.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace HopFrame.Web.Admin.Generators;
|
||||
|
||||
public interface IAdminPropertyGenerator {
|
||||
|
||||
IAdminPropertyGenerator Sortable(bool sortable);
|
||||
IAdminPropertyGenerator Editable(bool editable);
|
||||
IAdminPropertyGenerator DisplayValueWhileEditing(bool display);
|
||||
IAdminPropertyGenerator DisplayInListing(bool display = true);
|
||||
IAdminPropertyGenerator Bold(bool isBold = true);
|
||||
|
||||
IAdminPropertyGenerator DisplayName(string displayName);
|
||||
IAdminPropertyGenerator Description(string description);
|
||||
|
||||
}
|
||||
7
src/HopFrame.Web.Admin/Generators/IGenerator.cs
Normal file
7
src/HopFrame.Web.Admin/Generators/IGenerator.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace HopFrame.Web.Admin.Generators;
|
||||
|
||||
public interface IGenerator<out TGeneratedType> {
|
||||
|
||||
TGeneratedType Compile();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System.Reflection;
|
||||
using HopFrame.Web.Admin.Attributes;
|
||||
using HopFrame.Web.Admin.Attributes.Classes;
|
||||
using HopFrame.Web.Admin.Models;
|
||||
|
||||
namespace HopFrame.Web.Admin.Generators.Implementation;
|
||||
|
||||
internal class AdminContextGenerator : IAdminContextGenerator {
|
||||
|
||||
private readonly IDictionary<Type, object> _adminPages = new Dictionary<Type, object>();
|
||||
|
||||
public IAdminPageGenerator<TModel> Page<TModel>() {
|
||||
if (_adminPages.TryGetValue(typeof(TModel), out var pageGenerator))
|
||||
return pageGenerator as IAdminPageGenerator<TModel>;
|
||||
|
||||
var generator = Activator.CreateInstance(typeof(IAdminPageGenerator<TModel>)) as IAdminPageGenerator<TModel>;
|
||||
|
||||
ApplyConfigurationFromAttributes(generator, typeof(TModel).GetCustomAttributes(false));
|
||||
|
||||
_adminPages.Add(typeof(TModel), generator);
|
||||
|
||||
return generator;
|
||||
}
|
||||
|
||||
public AdminPage<TModel> CompilePage<TModel>() {
|
||||
var generator = _adminPages[typeof(TModel)];
|
||||
if (generator is null) return null;
|
||||
|
||||
return (generator as AdminPageGenerator<TModel>)?.Compile();
|
||||
}
|
||||
|
||||
public TContext CompileContext<TContext>() where TContext : AdminPagesContext {
|
||||
var type = typeof(TContext);
|
||||
var compileMethod = typeof(AdminContextGenerator).GetMethod(nameof(CompilePage));
|
||||
|
||||
var properties = type.GetProperties();
|
||||
|
||||
var context = Activator.CreateInstance<TContext>();
|
||||
|
||||
foreach (var property in properties) {
|
||||
var propertyType = property.PropertyType.GenericTypeArguments[0];
|
||||
var pageGeneratorType = typeof(AdminPageGenerator<>).MakeGenericType(propertyType);
|
||||
var generatorInstance = Activator.CreateInstance(pageGeneratorType, [propertyType.Name]);
|
||||
|
||||
var populatorMethod = typeof(AdminContextGenerator)
|
||||
.GetMethod(nameof(ApplyConfigurationFromAttributes))?
|
||||
.MakeGenericMethod(propertyType);
|
||||
populatorMethod?.Invoke(this, [generatorInstance, propertyType.GetCustomAttributes()]);
|
||||
|
||||
_adminPages.Add(propertyType, generatorInstance);
|
||||
}
|
||||
|
||||
context.OnModelCreating(this);
|
||||
|
||||
foreach (var property in properties) {
|
||||
var modelType = property.PropertyType.GenericTypeArguments[0];
|
||||
var method = compileMethod?.MakeGenericMethod(modelType);
|
||||
property.SetValue(context, method?.Invoke(this, []));
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
public void ApplyConfigurationFromAttributes<TModel>(IAdminPageGenerator<TModel> generator, object[] attributes) {
|
||||
if (attributes.Any(a => a is AdminNameAttribute)) {
|
||||
var attribute = attributes.Single(a => a is AdminNameAttribute) as AdminNameAttribute;
|
||||
generator.Title(attribute?.Name);
|
||||
}
|
||||
|
||||
if (attributes.Any(a => a is AdminDescriptionAttribute)) {
|
||||
var attribute = attributes.Single(a => a is AdminDescriptionAttribute) as AdminDescriptionAttribute;
|
||||
generator.Description(attribute?.Description);
|
||||
}
|
||||
|
||||
if (attributes.Any(a => a is AdminPermissionsAttribute)) {
|
||||
var attribute = attributes.Single(a => a is AdminPermissionsAttribute) as AdminPermissionsAttribute;
|
||||
generator.CreatePermission(attribute?.Permissions.Create);
|
||||
generator.UpdatePermission(attribute?.Permissions.Update);
|
||||
generator.ViewPermission(attribute?.Permissions.View);
|
||||
generator.DeletePermission(attribute?.Permissions.Delete);
|
||||
}
|
||||
|
||||
if (attributes.Any(a => a is AdminButtonConfigAttribute)) {
|
||||
var attribute = attributes.Single(a => a is AdminButtonConfigAttribute) as AdminButtonConfigAttribute;
|
||||
generator.ShowCreateButton(attribute?.ShowCreateButton == true);
|
||||
generator.ShowUpdateButton(attribute?.ShowUpdateButton == true);
|
||||
generator.ShowDeleteButton(attribute?.ShowDeleteButton == true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using HopFrame.Web.Admin.Attributes;
|
||||
using HopFrame.Web.Admin.Attributes.Members;
|
||||
using HopFrame.Web.Admin.Models;
|
||||
|
||||
namespace HopFrame.Web.Admin.Generators.Implementation;
|
||||
|
||||
internal sealed class AdminPageGenerator<TModel> : IAdminPageGenerator<TModel>, IGenerator<AdminPage<TModel>> {
|
||||
|
||||
private readonly AdminPage<TModel> _page;
|
||||
private readonly IDictionary<string, AdminPropertyGenerator> _propertyGenerators;
|
||||
|
||||
public AdminPageGenerator() {
|
||||
_page = new AdminPage<TModel> {
|
||||
Permissions = new AdminPagePermissions()
|
||||
};
|
||||
_propertyGenerators = new Dictionary<string, AdminPropertyGenerator>();
|
||||
|
||||
var type = typeof(TModel);
|
||||
var properties = type.GetProperties();
|
||||
|
||||
foreach (var property in properties) {
|
||||
var attributes = property.GetCustomAttributes(false);
|
||||
var ignoreProperty = attributes
|
||||
.SingleOrDefault(a => a is AdminIgnoreAttribute) as AdminIgnoreAttribute;
|
||||
if (ignoreProperty?.OnlyForListing == false) continue;
|
||||
|
||||
var generator = Activator.CreateInstance(typeof(AdminPropertyGenerator), [property.Name, property.PropertyType]) as AdminPropertyGenerator;
|
||||
|
||||
ApplyConfigurationFromAttributes(generator, attributes, property);
|
||||
|
||||
_propertyGenerators.Add(property.Name, generator);
|
||||
}
|
||||
}
|
||||
|
||||
public AdminPageGenerator(string title) : this() {
|
||||
Title(title);
|
||||
}
|
||||
|
||||
public IAdminPageGenerator<TModel> Title(string title) {
|
||||
_page.Title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPageGenerator<TModel> Description(string description) {
|
||||
_page.Description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPageGenerator<TModel> ViewPermission(string permission) {
|
||||
_page.Permissions.View = permission;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPageGenerator<TModel> CreatePermission(string permission) {
|
||||
_page.Permissions.Create = permission;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPageGenerator<TModel> UpdatePermission(string permission) {
|
||||
_page.Permissions.Update = permission;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPageGenerator<TModel> DeletePermission(string permission) {
|
||||
_page.Permissions.Delete = permission;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPageGenerator<TModel> ShowCreateButton(bool show) {
|
||||
_page.ShowCreateButton = show;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPageGenerator<TModel> ShowDeleteButton(bool show) {
|
||||
_page.ShowDeleteButton = show;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPageGenerator<TModel> ShowUpdateButton(bool show) {
|
||||
_page.ShowUpdateButton = show;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPageGenerator<TModel> DefaultSort<TProperty>(Expression<Func<TModel, TProperty>> propertyExpression, ListSortDirection direction) {
|
||||
var property = GetPropertyInfo(propertyExpression);
|
||||
|
||||
_page.DefaultSortPropertyName = property.Name;
|
||||
_page.DefaultSortDirection = direction;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPageGenerator<TModel> ConfigureRepository<TRepository>() where TRepository : IModelRepository<TModel> {
|
||||
_page.RepositoryProvider = typeof(TRepository);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPropertyGenerator Property<TProperty>(Expression<Func<TModel, TProperty>> propertyExpression) {
|
||||
var property = GetPropertyInfo(propertyExpression);
|
||||
|
||||
if (_propertyGenerators.TryGetValue(property.Name, out var propertyGenerator))
|
||||
return propertyGenerator;
|
||||
|
||||
var generator = Activator.CreateInstance(typeof(AdminPropertyGenerator), new { property.Name, property.PropertyType }) as AdminPropertyGenerator;
|
||||
ApplyConfigurationFromAttributes(generator, property.GetCustomAttributes(false), property);
|
||||
_propertyGenerators.Add(property.Name, generator);
|
||||
|
||||
return generator;
|
||||
}
|
||||
|
||||
public AdminPage<TModel> Compile() {
|
||||
var properties = new List<AdminPageProperty>();
|
||||
|
||||
foreach (var generator in _propertyGenerators.Values){
|
||||
properties.Add(generator.Compile());
|
||||
}
|
||||
|
||||
_page.Properties = properties;
|
||||
|
||||
return _page;
|
||||
}
|
||||
|
||||
private void ApplyConfigurationFromAttributes(AdminPropertyGenerator generator, object[] attributes, PropertyInfo property) {
|
||||
if (attributes.Any(a => a is KeyAttribute)) {
|
||||
_page.DefaultSortPropertyName = property.Name;
|
||||
generator.Bold();
|
||||
generator.Editable(false);
|
||||
}
|
||||
|
||||
if (attributes.Any(a => a is AdminUnsortableAttribute))
|
||||
generator.Sortable(false);
|
||||
|
||||
if (attributes.Any(a => a is AdminUneditableAttribute))
|
||||
generator.Editable(false);
|
||||
|
||||
if (attributes.Any(a => a is AdminBoldAttribute))
|
||||
generator.Bold();
|
||||
|
||||
if (attributes.Any(a => a is AdminIgnoreAttribute))
|
||||
generator.DisplayInListing(false);
|
||||
|
||||
if (attributes.Any(a => a is AdminHideValueAttribute))
|
||||
generator.DisplayValueWhileEditing(false);
|
||||
|
||||
if (attributes.Any(a => a is AdminNameAttribute)) {
|
||||
var attribute = attributes.Single(a => a is AdminNameAttribute) as AdminNameAttribute;
|
||||
generator.DisplayName(attribute?.Name);
|
||||
}
|
||||
|
||||
if (attributes.Any(a => a is AdminDescriptionAttribute)) {
|
||||
var attribute = attributes.Single(a => a is AdminDescriptionAttribute) as AdminDescriptionAttribute;
|
||||
generator.Description(attribute?.Description);
|
||||
}
|
||||
}
|
||||
|
||||
private static PropertyInfo GetPropertyInfo<TSource, TProperty>(Expression<Func<TSource, TProperty>> propertyLambda) {
|
||||
if (propertyLambda.Body is not MemberExpression member) {
|
||||
throw new ArgumentException($"Expression '{propertyLambda}' refers to a method, not a property.");
|
||||
}
|
||||
|
||||
if (member.Member is not PropertyInfo propInfo) {
|
||||
throw new ArgumentException($"Expression '{propertyLambda}' refers to a field, not a property.");
|
||||
}
|
||||
|
||||
Type type = typeof(TSource);
|
||||
if (propInfo.ReflectedType != null && type != propInfo.ReflectedType &&
|
||||
!type.IsSubclassOf(propInfo.ReflectedType)) {
|
||||
throw new ArgumentException($"Expression '{propertyLambda}' refers to a property that is not from type {type}.");
|
||||
}
|
||||
|
||||
if (propInfo.Name is null)
|
||||
throw new ArgumentException($"Expression '{propertyLambda}' refers a not existing property.");
|
||||
|
||||
return propInfo;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using HopFrame.Web.Admin.Models;
|
||||
|
||||
namespace HopFrame.Web.Admin.Generators.Implementation;
|
||||
|
||||
internal sealed class AdminPropertyGenerator(string name, Type type) : IAdminPropertyGenerator, IGenerator<AdminPageProperty> {
|
||||
|
||||
private readonly AdminPageProperty _property = new() {
|
||||
Name = name,
|
||||
Type = type
|
||||
};
|
||||
|
||||
public IAdminPropertyGenerator Sortable(bool sortable) {
|
||||
_property.Sortable = sortable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPropertyGenerator Editable(bool editable) {
|
||||
_property.Editable = editable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPropertyGenerator DisplayValueWhileEditing(bool display) {
|
||||
_property.EditDisplayValue = display;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPropertyGenerator DisplayInListing(bool display = true) {
|
||||
_property.DisplayInListing = display;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPropertyGenerator Bold(bool isBold = true) {
|
||||
_property.Bold = isBold;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPropertyGenerator DisplayName(string displayName) {
|
||||
_property.DisplayName = displayName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPropertyGenerator Description(string description) {
|
||||
_property.Description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AdminPageProperty Compile() {
|
||||
_property.DisplayName ??= _property.Name;
|
||||
|
||||
return _property;
|
||||
}
|
||||
}
|
||||
13
src/HopFrame.Web.Admin/HopFrame.Web.Admin.csproj
Normal file
13
src/HopFrame.Web.Admin/HopFrame.Web.Admin.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
8
src/HopFrame.Web.Admin/IModelRepository.cs
Normal file
8
src/HopFrame.Web.Admin/IModelRepository.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace HopFrame.Web.Admin;
|
||||
|
||||
public interface IModelRepository<TModel> {
|
||||
Task<IEnumerable<TModel>> ReadAll();
|
||||
Task<TModel> Create(TModel model);
|
||||
Task<TModel> Update(TModel model);
|
||||
Task Delete(TModel model);
|
||||
}
|
||||
22
src/HopFrame.Web.Admin/Models/AdminPage.cs
Normal file
22
src/HopFrame.Web.Admin/Models/AdminPage.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace HopFrame.Web.Admin.Models;
|
||||
|
||||
public class AdminPage<TModel> : IAdminPageEntry {
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
public AdminPagePermissions Permissions { get; set; }
|
||||
public IList<AdminPageProperty> Properties { get; set; }
|
||||
[JsonIgnore]
|
||||
public Type RepositoryProvider { get; set; }
|
||||
|
||||
public string DefaultSortPropertyName { get; set; }
|
||||
public ListSortDirection DefaultSortDirection { get; set; }
|
||||
|
||||
public bool ShowCreateButton { get; set; } = true;
|
||||
public bool ShowDeleteButton { get; set; } = true;
|
||||
public bool ShowUpdateButton { get; set; } = true;
|
||||
}
|
||||
|
||||
public interface IAdminPageEntry;
|
||||
8
src/HopFrame.Web.Admin/Models/AdminPagePermissions.cs
Normal file
8
src/HopFrame.Web.Admin/Models/AdminPagePermissions.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace HopFrame.Web.Admin.Models;
|
||||
|
||||
public class AdminPagePermissions {
|
||||
public string View { get; set; }
|
||||
public string Create { get; set; }
|
||||
public string Update { get; set; }
|
||||
public string Delete { get; set; }
|
||||
}
|
||||
17
src/HopFrame.Web.Admin/Models/AdminPageProperty.cs
Normal file
17
src/HopFrame.Web.Admin/Models/AdminPageProperty.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace HopFrame.Web.Admin.Models;
|
||||
|
||||
public class AdminPageProperty {
|
||||
public string Name { get; set; }
|
||||
public string DisplayName { get; set; }
|
||||
public string Description { get; set; }
|
||||
|
||||
public bool DisplayInListing { get; set; } = true;
|
||||
public bool Sortable { get; set; } = true;
|
||||
public bool Editable { get; set; } = true;
|
||||
public bool EditDisplayValue { get; set; } = true;
|
||||
public bool Bold { get; set; }
|
||||
[JsonIgnore]
|
||||
public Type Type { get; set; }
|
||||
}
|
||||
17
src/HopFrame.Web.Admin/ServiceCollectionExtensions.cs
Normal file
17
src/HopFrame.Web.Admin/ServiceCollectionExtensions.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using HopFrame.Web.Admin.Generators.Implementation;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace HopFrame.Web.Admin;
|
||||
|
||||
public static class ServiceCollectionExtensions {
|
||||
|
||||
public static IServiceCollection AddAdminContext<TContext>(this IServiceCollection services) where TContext : AdminPagesContext {
|
||||
services.AddSingleton(_ => {
|
||||
var generator = new AdminContextGenerator();
|
||||
return generator.CompileContext<TContext>();
|
||||
});
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user