Removed Template

This commit is contained in:
2025-01-16 16:43:46 +01:00
parent 3dde278955
commit 4908947217
6 changed files with 33 additions and 32 deletions

View File

@@ -9,11 +9,12 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="0648788e-7696-4e60-bf12-5d5601f33d8c" name="Changes" comment="Added automatic relation mapping"> <list default="true" id="0648788e-7696-4e60-bf12-5d5601f33d8c" name="Changes" comment="Added creation/modification confirmation">
<change beforePath="$PROJECT_DIR$/.idea/.idea.HopFrame/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.HopFrame/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/.idea.HopFrame/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.HopFrame/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/HopFrame.Core/Config/PropertyConfig.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Core/Config/PropertyConfig.cs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/HopFrame.Core/Config/PropertyConfig.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Core/Config/PropertyConfig.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/HopFrame.Core/Services/Implementations/ContextExplorer.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Core/Services/Implementations/ContextExplorer.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/HopFrame.Web/Components/Dialogs/HopFrameEditor.razor" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Web/Components/Dialogs/HopFrameEditor.razor" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/HopFrame.Web/Components/Dialogs/HopFrameEditor.razor" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Web/Components/Dialogs/HopFrameEditor.razor" afterDir="false" />
<change beforePath="$PROJECT_DIR$/testing/HopFrame.Testing/Models/Post.cs" beforeDir="false" afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Models/Post.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/testing/HopFrame.Testing/Models/User.cs" beforeDir="false" afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Models/User.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/testing/HopFrame.Testing/Program.cs" beforeDir="false" afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Program.cs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/testing/HopFrame.Testing/Program.cs" beforeDir="false" afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Program.cs" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@@ -148,7 +149,7 @@
<workItem from="1736875984621" duration="8464000" /> <workItem from="1736875984621" duration="8464000" />
<workItem from="1736884461354" duration="1075000" /> <workItem from="1736884461354" duration="1075000" />
<workItem from="1736962119221" duration="8119000" /> <workItem from="1736962119221" duration="8119000" />
<workItem from="1737021098746" duration="19408000" /> <workItem from="1737021098746" duration="21001000" />
</task> </task>
<task id="LOCAL-00001" summary="Added basic configuration"> <task id="LOCAL-00001" summary="Added basic configuration">
<option name="closed" value="true" /> <option name="closed" value="true" />
@@ -214,7 +215,23 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1737037853482</updated> <updated>1737037853482</updated>
</task> </task>
<option name="localTasksCounter" value="9" /> <task id="LOCAL-00009" summary="Added property validation">
<option name="closed" value="true" />
<created>1737040612038</created>
<option name="number" value="00009" />
<option name="presentableId" value="LOCAL-00009" />
<option name="project" value="LOCAL" />
<updated>1737040612038</updated>
</task>
<task id="LOCAL-00010" summary="Added creation/modification confirmation">
<option name="closed" value="true" />
<created>1737040946489</created>
<option name="number" value="00010" />
<option name="presentableId" value="LOCAL-00010" />
<option name="project" value="LOCAL" />
<updated>1737040946489</updated>
</task>
<option name="localTasksCounter" value="11" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@@ -232,6 +249,8 @@
<MESSAGE value="Added reload button and animation" /> <MESSAGE value="Added reload button and animation" />
<MESSAGE value="Added relation picker dialog" /> <MESSAGE value="Added relation picker dialog" />
<MESSAGE value="Added automatic relation mapping" /> <MESSAGE value="Added automatic relation mapping" />
<option name="LAST_COMMIT_MESSAGE" value="Added automatic relation mapping" /> <MESSAGE value="Added property validation" />
<MESSAGE value="Added creation/modification confirmation" />
<option name="LAST_COMMIT_MESSAGE" value="Added creation/modification confirmation" />
</component> </component>
</project> </project>

View File

@@ -13,7 +13,6 @@ public class PropertyConfig(PropertyInfo info, TableConfig table) {
public PropertyInfo? DisplayedProperty { get; set; } public PropertyInfo? DisplayedProperty { get; set; }
public Func<object, string>? Formatter { get; set; } public Func<object, string>? Formatter { get; set; }
public Func<string, object>? Parser { get; set; } public Func<string, object>? Parser { get; set; }
public Func<object>? Template { get; set; }
public Func<object?, Task<IEnumerable<string>>>? Validator { get; set; } public Func<object?, Task<IEnumerable<string>>>? Validator { get; set; }
public bool Editable { get; set; } = true; public bool Editable { get; set; } = true;
public bool Creatable { get; set; } = true; public bool Creatable { get; set; } = true;
@@ -61,11 +60,6 @@ public class PropertyConfig<TProp>(PropertyConfig config) {
return this; return this;
} }
public PropertyConfig<TProp> ValueTemplate(Func<TProp> template) {
InnerConfig.Template = () => template.Invoke()!;
return this;
}
public PropertyConfig<TProp> Editable(bool editable) { public PropertyConfig<TProp> Editable(bool editable) {
InnerConfig.Editable = editable; InnerConfig.Editable = editable;
return this; return this;

View File

@@ -129,7 +129,7 @@
private bool _currentlyEditing; private bool _currentlyEditing;
private ITableManager? _manager; private ITableManager? _manager;
private Dictionary<string, List<string>> _validationErrors = new(); private readonly Dictionary<string, List<string>> _validationErrors = new();
protected override void OnInitialized() { protected override void OnInitialized() {
_currentlyEditing = Content.CurrentObject is not null; _currentlyEditing = Content.CurrentObject is not null;
@@ -150,25 +150,15 @@
if (Content.CurrentObject is null) return default; if (Content.CurrentObject is null) return default;
var value = config.Info.GetValue(Content.CurrentObject); var value = config.Info.GetValue(Content.CurrentObject);
var newlyGenerated = false;
if (config.Info.PropertyType.IsDefaultValue(value) && config.Template is not null && !_currentlyEditing) {
value = config.Template.Invoke();
newlyGenerated = true;
}
if (value is null) if (value is null)
return default; return default;
if (config.Info.PropertyType == typeof(TValue)) if (config.Info.PropertyType == typeof(TValue))
return (TValue)value; return (TValue)value;
if (typeof(TValue) == typeof(string)) { if (typeof(TValue) == typeof(string))
if (!newlyGenerated)
return (TValue)(object)_manager!.DisplayProperty(Content.CurrentObject, config.Info, Content.Config); return (TValue)(object)_manager!.DisplayProperty(Content.CurrentObject, config.Info, Content.Config);
return (TValue)(object)value.ToString()!;
}
return (TValue)Convert.ChangeType(value, typeof(TValue)); return (TValue)Convert.ChangeType(value, typeof(TValue));
} }

View File

@@ -14,11 +14,11 @@ public class Post {
public required string Content { get; set; } public required string Content { get; set; }
[ForeignKey("author")] [ForeignKey("author")]
public User? Author { get; set; } public virtual required User Author { get; set; }
public bool Published { get; set; } public bool Published { get; set; }
public DateTime CreatedAt { get; set; } public DateTime CreatedAt { get; set; } = DateTime.Now;
public DateOnly Created { get; set; } public DateOnly Created { get; set; }

View File

@@ -4,7 +4,7 @@ namespace HopFrame.Testing.Models;
public class User { public class User {
[Key] [Key]
public required Guid Id { get; init; } public required Guid Id { get; init; } = Guid.CreateVersion7();
public required string Email { get; init; } public required string Email { get; init; }
public string? Username { get; set; } public string? Username { get; set; }
public string? Password { get; set; } public string? Password { get; set; }

View File

@@ -32,8 +32,7 @@ builder.Services.AddHopFrame(options => {
.SetDisplayName("Last Name"); .SetDisplayName("Last Name");
table.Property(u => u.Id) table.Property(u => u.Id)
.Sortable(false) .Sortable(false);
.ValueTemplate(Guid.CreateVersion7);
table.SetDisplayName("Benutzer"); table.SetDisplayName("Benutzer");
}); });
@@ -47,8 +46,7 @@ builder.Services.AddHopFrame(options => {
.SetDisplayName("ID"); .SetDisplayName("ID");
context.Table<Post>() context.Table<Post>()
.Property(p => p.CreatedAt) .Property(p => p.CreatedAt);
.ValueTemplate(() => DateTime.UtcNow);
context.Table<Post>() context.Table<Post>()
.Property(p => p.Caption) .Property(p => p.Caption)