Made AdminPageProperty generic + added dynamic display property selecting
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
@rendermode InteractiveServer
|
||||
|
||||
@using System.Collections
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using BlazorStrap
|
||||
@using BlazorStrap.Shared.Components.Modal
|
||||
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
||||
@using BlazorStrap.V5
|
||||
@using HopFrame.Database.Attributes
|
||||
@using HopFrame.Web.Admin
|
||||
@using HopFrame.Web.Admin.Models
|
||||
@using HopFrame.Web.Admin.Providers
|
||||
@@ -166,7 +164,7 @@
|
||||
return MapPropertyValue(property.GetValue(_entry), property);
|
||||
}
|
||||
|
||||
public string MapPropertyValue(object value, AdminPageProperty property) {
|
||||
public string MapPropertyValue(object value, AdminPageProperty property, bool isSubProperty = false) {
|
||||
if (value is null) return string.Empty;
|
||||
var type = value.GetType();
|
||||
|
||||
@@ -180,11 +178,18 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (type.GetProperties().Any(p => p.GetCustomAttributes(false).Any(a => a is ListingPropertyAttribute))) {
|
||||
/*if (type.GetProperties().Any(p => p.GetCustomAttributes(false).Any(a => a is ListingPropertyAttribute))) {
|
||||
var prop = type.GetProperties()
|
||||
.SingleOrDefault(p => p.GetCustomAttributes(false).Any(a => a is ListingPropertyAttribute));
|
||||
|
||||
return MapPropertyValue(prop?.GetValue(value), property);
|
||||
}*/
|
||||
|
||||
if (!string.IsNullOrEmpty(property.DisplayPropertyName) && !isSubProperty) {
|
||||
var prop = type.GetProperties()
|
||||
.SingleOrDefault(p => p.Name == property.DisplayPropertyName);
|
||||
|
||||
return MapPropertyValue(prop?.GetValue(value), property, true);
|
||||
}
|
||||
|
||||
var stringValue = value.ToString();
|
||||
|
||||
@@ -30,7 +30,8 @@ public class HopAdminContext : AdminPagesContext {
|
||||
|
||||
generator.Page<User>().Property(u => u.Permissions)
|
||||
.DisplayInListing(false)
|
||||
.IsSelector<PermissionGroup>();
|
||||
.IsSelector<PermissionGroup>()
|
||||
.DisplayPropertyForListType<Permission>(p => p.PermissionName);
|
||||
|
||||
generator.Page<User>().Property(u => u.Tokens)
|
||||
.Ignore();
|
||||
@@ -54,6 +55,7 @@ public class HopAdminContext : AdminPagesContext {
|
||||
.Editable(false);
|
||||
|
||||
generator.Page<PermissionGroup>().Property(g => g.Permissions)
|
||||
.DisplayInListing(false);
|
||||
.DisplayInListing(false)
|
||||
.DisplayPropertyForListType<Permission>(p => p.PermissionName);
|
||||
}
|
||||
}
|
||||
@@ -178,12 +178,7 @@
|
||||
return String.CompareOrdinal(propX, propY);
|
||||
});
|
||||
|
||||
if (_currentSortDirection == ListSortDirection.Ascending) {
|
||||
_displayedModels = _displayedModels.Order(comparer).ToList();
|
||||
}
|
||||
else {
|
||||
_displayedModels = _displayedModels.OrderDescending(comparer).ToList();
|
||||
}
|
||||
_displayedModels = _currentSortDirection == ListSortDirection.Ascending ? _displayedModels.Order(comparer).ToList() : _displayedModels.OrderDescending(comparer).ToList();
|
||||
|
||||
_currentSortProperty = property;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user