diff --git a/.idea/.idea.HopFrame/.idea/workspace.xml b/.idea/.idea.HopFrame/.idea/workspace.xml
index 8e2ccaf..cafd9ca 100644
--- a/.idea/.idea.HopFrame/.idea/workspace.xml
+++ b/.idea/.idea.HopFrame/.idea/workspace.xml
@@ -9,17 +9,14 @@
-
-
-
+
-
-
-
-
-
+
+
+
+
@@ -154,7 +151,7 @@
-
+
@@ -204,7 +201,15 @@
1737023058093
-
+
+
+ 1737035288104
+
+
+
+ 1737035288104
+
+
@@ -220,6 +225,7 @@
-
+
+
\ No newline at end of file
diff --git a/src/HopFrame.Core/Config/PropertyConfig.cs b/src/HopFrame.Core/Config/PropertyConfig.cs
index 242b4ff..f477bf2 100644
--- a/src/HopFrame.Core/Config/PropertyConfig.cs
+++ b/src/HopFrame.Core/Config/PropertyConfig.cs
@@ -79,10 +79,4 @@ public class PropertyConfig(PropertyConfig config) {
InnerConfig.DisplayValue = display;
return this;
}
-
- public PropertyConfig IsRelation(bool isRelation) {
- InnerConfig.IsRelation = isRelation;
- return this;
- }
-
}
diff --git a/src/HopFrame.Core/Config/TableConfig.cs b/src/HopFrame.Core/Config/TableConfig.cs
index e2a6199..20d5822 100644
--- a/src/HopFrame.Core/Config/TableConfig.cs
+++ b/src/HopFrame.Core/Config/TableConfig.cs
@@ -8,8 +8,10 @@ namespace HopFrame.Core.Config;
public class TableConfig {
public Type TableType { get; }
public string PropertyName { get; }
+ public string DisplayName { get; set; }
public DbContextConfig ContextConfig { get; }
public bool Ignored { get; set; }
+ internal bool Seeded { get; set; }
public List Properties { get; } = new();
@@ -17,6 +19,7 @@ public class TableConfig {
TableType = tableType;
PropertyName = propertyName;
ContextConfig = config;
+ DisplayName = PropertyName;
foreach (var info in tableType.GetProperties()) {
var propConfig = new PropertyConfig(info, this);
@@ -55,6 +58,11 @@ public class TableConfig(TableConfig config) {
configurator.Invoke(prop);
return this;
}
+
+ public TableConfig SetDisplayName(string name) {
+ InnerConfig.DisplayName = name;
+ return this;
+ }
internal static PropertyInfo GetPropertyInfo(Expression> propertyLambda) {
if (propertyLambda.Body is not MemberExpression member) {
diff --git a/src/HopFrame.Core/Services/IContextExplorer.cs b/src/HopFrame.Core/Services/IContextExplorer.cs
index 272d4aa..db60554 100644
--- a/src/HopFrame.Core/Services/IContextExplorer.cs
+++ b/src/HopFrame.Core/Services/IContextExplorer.cs
@@ -4,7 +4,7 @@ namespace HopFrame.Core.Services;
public interface IContextExplorer {
public IEnumerable GetTableNames();
- public TableConfig? GetTable(string tableName);
+ public TableConfig? GetTable(string tableDisplayName);
public TableConfig? GetTable(Type tableEntity);
- public ITableManager? GetTableManager(string tableName);
+ public ITableManager? GetTableManager(string tablePropertyName);
}
\ No newline at end of file
diff --git a/src/HopFrame.Core/Services/Implementations/ContextExplorer.cs b/src/HopFrame.Core/Services/Implementations/ContextExplorer.cs
index 92126c9..895aad2 100644
--- a/src/HopFrame.Core/Services/Implementations/ContextExplorer.cs
+++ b/src/HopFrame.Core/Services/Implementations/ContextExplorer.cs
@@ -1,23 +1,26 @@
using HopFrame.Core.Config;
using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Logging;
namespace HopFrame.Core.Services.Implementations;
-internal sealed class ContextExplorer(HopFrameConfig config, IServiceProvider provider) : IContextExplorer {
+internal sealed class ContextExplorer(HopFrameConfig config, IServiceProvider provider, ILogger logger) : IContextExplorer {
public IEnumerable GetTableNames() {
foreach (var context in config.Contexts) {
foreach (var table in context.Tables) {
if (table.Ignored) continue;
- yield return table.PropertyName;
+ yield return table.DisplayName;
}
}
}
- public TableConfig? GetTable(string tableName) {
+ public TableConfig? GetTable(string tableDisplayName) {
foreach (var context in config.Contexts) {
- var table = context.Tables.FirstOrDefault(table => table.PropertyName.Equals(tableName, StringComparison.CurrentCultureIgnoreCase));
- if (table is not null)
- return table;
+ var table = context.Tables.FirstOrDefault(table => table.DisplayName.Equals(tableDisplayName, StringComparison.CurrentCultureIgnoreCase));
+ if (table is null) continue;
+
+ SeedTableData(table);
+ return table;
}
return null;
@@ -26,16 +29,18 @@ internal sealed class ContextExplorer(HopFrameConfig config, IServiceProvider pr
public TableConfig? GetTable(Type tableEntity) {
foreach (var context in config.Contexts) {
var table = context.Tables.FirstOrDefault(table => table.TableType == tableEntity);
- if (table is not null)
- return table;
+ if (table is null) continue;
+
+ SeedTableData(table);
+ return table;
}
return null;
}
- public ITableManager? GetTableManager(string tableName) {
+ public ITableManager? GetTableManager(string tablePropertyName) {
foreach (var context in config.Contexts) {
- var table = context.Tables.FirstOrDefault(table => table.PropertyName == tableName);
+ var table = context.Tables.FirstOrDefault(table => table.PropertyName == tablePropertyName);
if (table is null) continue;
var dbContext = provider.GetService(context.ContextType) as DbContext;
@@ -48,4 +53,20 @@ internal sealed class ContextExplorer(HopFrameConfig config, IServiceProvider pr
return null;
}
+ private void SeedTableData(TableConfig table) {
+ if (table.Seeded) return;
+ var dbContext = (provider.GetService(table.ContextConfig.ContextType) as DbContext)!;
+ var entity = dbContext.Model.FindEntityType(table.TableType)!;
+
+ foreach (var key in entity.GetForeignKeys()) {
+ var propConfig = table.Properties
+ .SingleOrDefault(prop => prop.Info == key.DependentToPrincipal?.PropertyInfo);
+ if (propConfig is null) continue;
+ propConfig.IsRelation = true;
+ }
+
+ logger.LogInformation("Extracted information for table '" + table.PropertyName + "'");
+ table.Seeded = true;
+ }
+
}
\ No newline at end of file
diff --git a/src/HopFrame.Web/Components/Dialogs/HopFrameRelationPicker.razor b/src/HopFrame.Web/Components/Dialogs/HopFrameRelationPicker.razor
index 1c8480f..3ca46a5 100644
--- a/src/HopFrame.Web/Components/Dialogs/HopFrameRelationPicker.razor
+++ b/src/HopFrame.Web/Components/Dialogs/HopFrameRelationPicker.razor
@@ -5,7 +5,7 @@
@using HopFrame.Web.Components.Pages
-
+
@code {
diff --git a/src/HopFrame.Web/Components/Pages/HopFrameTablePage.razor b/src/HopFrame.Web/Components/Pages/HopFrameTablePage.razor
index 939668b..8af32a8 100644
--- a/src/HopFrame.Web/Components/Pages/HopFrameTablePage.razor
+++ b/src/HopFrame.Web/Components/Pages/HopFrameTablePage.razor
@@ -1,4 +1,4 @@
-@page "/admin/{TableName}"
+@page "/admin/{TableDisplayName}"
@layout HopFrameLayout
@rendermode InteractiveServer
@implements IDisposable
@@ -13,7 +13,7 @@
- @_config?.PropertyName
+ @_config?.DisplayName
{
options.AddDbContext(context => {
context.Table(table => {
table.Property(u => u.Password)
- .List(false)
- .DisplayValue(false);
+ .ValueParser(pwd => pwd + "-edited");
table.Property(u => u.FirstName)
.SetDisplayName("First Name");
@@ -35,6 +34,8 @@ builder.Services.AddHopFrame(options => {
table.Property(u => u.Id)
.Sortable(false)
.ValueTemplate(Guid.CreateVersion7);
+
+ table.SetDisplayName("Benutzer");
});
context.Table()
@@ -46,8 +47,8 @@ builder.Services.AddHopFrame(options => {
.SetDisplayName("ID");
context.Table()
- .Property(p => p.Author)
- .IsRelation(true);
+ .Property(p => p.CreatedAt)
+ .ValueTemplate(() => DateTime.UtcNow);
});
});