Made AdminPageProperty generic + added dynamic display property selecting

This commit is contained in:
2024-10-26 11:54:02 +02:00
parent 599ce2bf43
commit ce15717c7d
16 changed files with 97 additions and 68 deletions

View File

@@ -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();