Added text area support and DI support for modifier functions

This commit is contained in:
2025-01-18 13:09:51 +01:00
parent 4f68fc578f
commit f8a3eb8ede
8 changed files with 128 additions and 89 deletions

View File

@@ -12,19 +12,11 @@
<list default="true" id="0648788e-7696-4e60-bf12-5d5601f33d8c" name="Changes" comment=""> <list default="true" id="0648788e-7696-4e60-bf12-5d5601f33d8c" name="Changes" comment="">
<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/ITableManager.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Core/Services/ITableManager.cs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/HopFrame.Core/Config/TableConfig.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Core/Config/TableConfig.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.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.Core/Services/Implementations/TableManager.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Core/Services/Implementations/TableManager.cs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/HopFrame.Core/Services/Implementations/TableManager.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Core/Services/Implementations/TableManager.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$/src/HopFrame.Web/Components/Dialogs/HopFrameRelationPicker.razor" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Web/Components/Dialogs/HopFrameRelationPicker.razor" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/HopFrame.Web/Components/Layout/HopFrameSideMenu.razor" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Web/Components/Layout/HopFrameSideMenu.razor" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/HopFrame.Web/Components/Pages/HopFrameTablePage.razor" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Web/Components/Pages/HopFrameTablePage.razor" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/HopFrame.Web/Components/Pages/HopFrameTablePage.razor" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Web/Components/Pages/HopFrameTablePage.razor" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/HopFrame.Web/Models/RelationPickerDialogData.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Web/Models/RelationPickerDialogData.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/HopFrame.Web/wwwroot/hopframe.css" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Web/wwwroot/hopframe.css" afterDir="false" />
<change beforePath="$PROJECT_DIR$/testing/HopFrame.Testing/Components/Pages/Home.razor" beforeDir="false" afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Components/Pages/Home.razor" afterDir="false" />
<change beforePath="$PROJECT_DIR$/testing/HopFrame.Testing/DatabaseContext.cs" beforeDir="false" afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/DatabaseContext.cs" 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" />
@@ -90,24 +82,24 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
".NET Launch Settings Profile.HopFrame.Testing.executor": "Run", &quot;.NET Launch Settings Profile.HopFrame.Testing.executor&quot;: &quot;Run&quot;,
".NET Launch Settings Profile.HopFrame.Testing: https.executor": "Run", &quot;.NET Launch Settings Profile.HopFrame.Testing: https.executor&quot;: &quot;Run&quot;,
".NET Project.HopFrame.Testing.executor": "Run", &quot;.NET Project.HopFrame.Testing.executor&quot;: &quot;Run&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.git.unshallow": "true", &quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
"git-widget-placeholder": "feature/setup", &quot;git-widget-placeholder&quot;: &quot;feature/setup&quot;,
"list.type.of.created.stylesheet": "CSS", &quot;list.type.of.created.stylesheet&quot;: &quot;CSS&quot;,
"node.js.detected.package.eslint": "true", &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
"node.js.detected.package.tslint": "true", &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
"node.js.selected.package.eslint": "(autodetect)", &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
"node.js.selected.package.tslint": "(autodetect)", &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
"nodejs_package_manager_path": "npm", &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
"settings.editor.selected.configurable": "preferences.environmentSetup", &quot;settings.editor.selected.configurable&quot;: &quot;preferences.environmentSetup&quot;,
"vue.rearranger.settings.migration": "true" &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
} }
}]]></component> }</component>
<component name="RunManager" selected=".NET Launch Settings Profile.HopFrame.Testing: https"> <component name="RunManager" selected=".NET Launch Settings Profile.HopFrame.Testing: https">
<configuration name="HopFrame.Testing: http" type="LaunchSettings" factoryName=".NET Launch Settings Profile"> <configuration name="HopFrame.Testing: http" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/testing/HopFrame.Testing/HopFrame.Testing.csproj" /> <option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/testing/HopFrame.Testing/HopFrame.Testing.csproj" />
@@ -163,7 +155,8 @@
<workItem from="1736962119221" duration="8119000" /> <workItem from="1736962119221" duration="8119000" />
<workItem from="1737021098746" duration="21112000" /> <workItem from="1737021098746" duration="21112000" />
<workItem from="1737047730756" duration="7678000" /> <workItem from="1737047730756" duration="7678000" />
<workItem from="1737120164342" duration="8932000" /> <workItem from="1737120164342" duration="9351000" />
<workItem from="1737199714142" duration="2295000" />
</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" />
@@ -261,7 +254,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1737055409535</updated> <updated>1737055409535</updated>
</task> </task>
<option name="localTasksCounter" value="13" /> <task id="LOCAL-00013" summary="Added n -&gt; m relation support">
<option name="closed" value="true" />
<created>1737129518866</created>
<option name="number" value="00013" />
<option name="presentableId" value="LOCAL-00013" />
<option name="project" value="LOCAL" />
<updated>1737129518866</updated>
</task>
<option name="localTasksCounter" value="14" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@@ -283,6 +284,7 @@
<MESSAGE value="Added creation/modification confirmation" /> <MESSAGE value="Added creation/modification confirmation" />
<MESSAGE value="Removed Template" /> <MESSAGE value="Removed Template" />
<MESSAGE value="Added policy validation, ordering and virtual listing properties" /> <MESSAGE value="Added policy validation, ordering and virtual listing properties" />
<option name="LAST_COMMIT_MESSAGE" value="Added policy validation, ordering and virtual listing properties" /> <MESSAGE value="Added n -&gt; m relation support" />
<option name="LAST_COMMIT_MESSAGE" value="Added n -&gt; m relation support" />
</component> </component>
</project> </project>

View File

@@ -12,13 +12,15 @@ public class PropertyConfig(PropertyInfo info, TableConfig table, int nthPropert
public bool Sortable { get; set; } = true; public bool Sortable { get; set; } = true;
public bool Searchable { get; set; } = true; public bool Searchable { get; set; } = true;
public PropertyInfo? DisplayedProperty { get; set; } public PropertyInfo? DisplayedProperty { get; set; }
public Func<object, string>? Formatter { get; set; } public Func<object, IServiceProvider, string>? Formatter { get; set; }
public Func<object, string>? EnumerableFormatter { get; set; } public Func<object, IServiceProvider, string>? EnumerableFormatter { get; set; }
public Func<string, object>? Parser { get; set; } public Func<string, IServiceProvider, object>? Parser { get; set; }
public Func<object?, Task<IEnumerable<string>>>? Validator { get; set; } public Func<object?, IServiceProvider, 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;
public bool DisplayValue { get; set; } = true; public bool DisplayValue { get; set; } = true;
public bool TextArea { get; set; }
public int TextAreaRows { get; set; } = 16;
public bool IsRelation { get; set; } public bool IsRelation { get; set; }
public bool IsRequired { get; set; } public bool IsRequired { get; set; }
public bool IsEnumerable { get; set; } public bool IsEnumerable { get; set; }
@@ -36,46 +38,46 @@ public class PropertyConfig<TProp>(PropertyConfig config) {
public PropertyConfig<TProp> List(bool list) { public PropertyConfig<TProp> List(bool list) {
InnerConfig.List = list; InnerConfig.List = list;
InnerConfig.Searchable = false; InnerConfig.Searchable = !list;
return this; return this;
} }
public PropertyConfig<TProp> Sortable(bool sortable) { public PropertyConfig<TProp> IsSortable(bool sortable) {
InnerConfig.Sortable = sortable; InnerConfig.Sortable = sortable;
return this; return this;
} }
public PropertyConfig<TProp> Searchable(bool searchable) { public PropertyConfig<TProp> IsSearchable(bool searchable) {
InnerConfig.Searchable = searchable; InnerConfig.Searchable = searchable;
return this; return this;
} }
public PropertyConfig<TProp> DisplayedProperty<TInnerProp>(Expression<Func<TProp, TInnerProp>> propertyExpression) { public PropertyConfig<TProp> SetDisplayedProperty<TInnerProp>(Expression<Func<TProp, TInnerProp>> propertyExpression) {
InnerConfig.DisplayedProperty = TableConfig<TProp>.GetPropertyInfo(propertyExpression); InnerConfig.DisplayedProperty = TableConfig<TProp>.GetPropertyInfo(propertyExpression);
return this; return this;
} }
public PropertyConfig<TProp> Format(Func<TProp, string> formatter) { public PropertyConfig<TProp> Format(Func<TProp, IServiceProvider, string> formatter) {
InnerConfig.Formatter = obj => formatter.Invoke((TProp)obj); InnerConfig.Formatter = (obj, provider) => formatter.Invoke((TProp)obj, provider);
return this; return this;
} }
public PropertyConfig<TProp> FormatEach<TInnerProp>(Func<TInnerProp, string> formatter) { public PropertyConfig<TProp> FormatEach<TInnerProp>(Func<TInnerProp, IServiceProvider, string> formatter) {
InnerConfig.EnumerableFormatter = obj => formatter.Invoke((TInnerProp)obj); InnerConfig.EnumerableFormatter = (obj, provider) => formatter.Invoke((TInnerProp)obj, provider);
return this; return this;
} }
public PropertyConfig<TProp> ValueParser(Func<string, TProp> parser) { public PropertyConfig<TProp> SetParser(Func<string, IServiceProvider, TProp> parser) {
InnerConfig.Parser = str => parser.Invoke(str)!; InnerConfig.Parser = (str, provider) => parser.Invoke(str, provider)!;
return this; return this;
} }
public PropertyConfig<TProp> Editable(bool editable) { public PropertyConfig<TProp> SetEditable(bool editable) {
InnerConfig.Editable = editable; InnerConfig.Editable = editable;
return this; return this;
} }
public PropertyConfig<TProp> Creatable(bool creatable) { public PropertyConfig<TProp> SetCreatable(bool creatable) {
InnerConfig.Creatable = creatable; InnerConfig.Creatable = creatable;
return this; return this;
} }
@@ -85,17 +87,27 @@ public class PropertyConfig<TProp>(PropertyConfig config) {
return this; return this;
} }
public PropertyConfig<TProp> Validator(Func<TProp?, IEnumerable<string>> validator) { public PropertyConfig<TProp> IsTextArea(bool textField) {
InnerConfig.Validator = obj => Task.FromResult(validator.Invoke((TProp?)obj)); InnerConfig.TextArea = textField;
return this; return this;
} }
public PropertyConfig<TProp> Validator(Func<TProp?, Task<IEnumerable<string>>> validator) { public PropertyConfig<TProp> SetTextAreaRows(int rows) {
InnerConfig.Validator = obj => validator.Invoke((TProp?)obj); InnerConfig.TextAreaRows = rows;
return this; return this;
} }
public PropertyConfig<TProp> OrderIndex(int index) { public PropertyConfig<TProp> SetValidator(Func<TProp?, IServiceProvider, IEnumerable<string>> validator) {
InnerConfig.Validator = (obj, provider) => Task.FromResult(validator.Invoke((TProp?)obj, provider));
return this;
}
public PropertyConfig<TProp> SetValidator(Func<TProp?, IServiceProvider, Task<IEnumerable<string>>> validator) {
InnerConfig.Validator = (obj, provider) => validator.Invoke((TProp?)obj, provider);
return this;
}
public PropertyConfig<TProp> SetOrderIndex(int index) {
InnerConfig.Order = index; InnerConfig.Order = index;
return this; return this;
} }

View File

@@ -69,16 +69,16 @@ public class TableConfig<TModel>(TableConfig config) {
return this; return this;
} }
public PropertyConfig<string> AddListingProperty(string name, Func<TModel, string> template) { public PropertyConfig<string> AddListingProperty(string name, Func<TModel, IServiceProvider, string> template) {
var prop = new PropertyConfig(InnerConfig.Properties.First().Info, InnerConfig, InnerConfig.Properties.Count); var prop = new PropertyConfig(InnerConfig.Properties.First().Info, InnerConfig, InnerConfig.Properties.Count);
prop.Name = name; prop.Name = name;
prop.IsListingProperty = true; prop.IsListingProperty = true;
prop.Formatter = obj => template.Invoke((TModel)obj); prop.Formatter = (obj, provider) => template.Invoke((TModel)obj, provider);
InnerConfig.Properties.Add(prop); InnerConfig.Properties.Add(prop);
return new PropertyConfig<string>(prop); return new PropertyConfig<string>(prop);
} }
public TableConfig<TModel> AddListingProperty(string name, Func<TModel, string> template, Action<PropertyConfig<string>> configurator) { public TableConfig<TModel> AddListingProperty(string name, Func<TModel, IServiceProvider, string> template, Action<PropertyConfig<string>> configurator) {
var prop = AddListingProperty(name, template); var prop = AddListingProperty(name, template);
configurator.Invoke(prop); configurator.Invoke(prop);
return this; return this;
@@ -94,7 +94,7 @@ public class TableConfig<TModel>(TableConfig config) {
return this; return this;
} }
public TableConfig<TModel> OrderIndex(int index) { public TableConfig<TModel> SetOrderIndex(int index) {
InnerConfig.Order = index; InnerConfig.Order = index;
return this; return this;
} }

View File

@@ -48,7 +48,7 @@ internal sealed class ContextExplorer(HopFrameConfig config, IServiceProvider pr
if (dbContext is null) return null; if (dbContext is null) return null;
var type = typeof(TableManager<>).MakeGenericType(table.TableType); var type = typeof(TableManager<>).MakeGenericType(table.TableType);
return Activator.CreateInstance(type, dbContext, table, this) as ITableManager; return Activator.CreateInstance(type, dbContext, table, this, provider) as ITableManager;
} }
return null; return null;

View File

@@ -1,13 +1,11 @@
using System.Collections; using System.Collections;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Reflection;
using HopFrame.Core.Config; using HopFrame.Core.Config;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace HopFrame.Core.Services.Implementations; namespace HopFrame.Core.Services.Implementations;
internal sealed class TableManager<TModel>(DbContext context, TableConfig config, IContextExplorer explorer) : ITableManager where TModel : class { internal sealed class TableManager<TModel>(DbContext context, TableConfig config, IContextExplorer explorer, IServiceProvider provider) : ITableManager where TModel : class {
public IQueryable<object> LoadPage(int page, int perPage = 20) { public IQueryable<object> LoadPage(int page, int perPage = 20) {
var table = context.Set<TModel>(); var table = context.Set<TModel>();
@@ -72,20 +70,20 @@ internal sealed class TableManager<TModel>(DbContext context, TableConfig config
if (item is null) return string.Empty; if (item is null) return string.Empty;
if (prop.IsListingProperty) if (prop.IsListingProperty)
return prop.Formatter!.Invoke(item); return prop.Formatter!.Invoke(item, provider);
var propValue = value ?? prop.Info.GetValue(item); var propValue = value ?? prop.Info.GetValue(item);
if (propValue is null) if (propValue is null)
return string.Empty; return string.Empty;
if (prop.Formatter is not null) { if (prop.Formatter is not null) {
return prop.Formatter.Invoke(propValue); return prop.Formatter.Invoke(propValue, provider);
} }
if (prop.IsEnumerable) { if (prop.IsEnumerable) {
if (value is not null) { if (value is not null) {
if (prop.EnumerableFormatter is not null) { if (prop.EnumerableFormatter is not null) {
return prop.EnumerableFormatter.Invoke(value); return prop.EnumerableFormatter.Invoke(value, provider);
} }
return value.ToString() ?? string.Empty; return value.ToString() ?? string.Empty;

View File

@@ -36,11 +36,11 @@
</div> </div>
<div style="display: flex; gap: 5px; margin-bottom: 4px"> <div style="display: flex; gap: 5px; margin-bottom: 4px">
@if (!property.IsRequired) { @if (!property.IsRequired) {
<FluentButton OnClick="async () => await SetPropertyValue(property, null, InputType.Relation)" Disabled="@(!property.Editable)"> <FluentButton OnClick="async () => await SetPropertyValue(property, null, InputType.Relation)" Disabled="@(_currentlyEditing && !property.Editable)">
<FluentIcon Value="@(new Icons.Regular.Size20.Dismiss())" Color="Color.Neutral" /> <FluentIcon Value="@(new Icons.Regular.Size20.Dismiss())" Color="Color.Neutral" />
</FluentButton> </FluentButton>
} }
<FluentButton OnClick="async () => await OpenRelationalPicker(property)" Disabled="@(!property.Editable)"> <FluentButton OnClick="async () => await OpenRelationalPicker(property)" Disabled="@(_currentlyEditing && !property.Editable)">
<FluentIcon Value="@(new Icons.Regular.Size20.Open())" Color="Color.Neutral" /> <FluentIcon Value="@(new Icons.Regular.Size20.Open())" Color="Color.Neutral" />
</FluentButton> </FluentButton>
</div> </div>
@@ -52,7 +52,7 @@
Label="@property.Name" Label="@property.Name"
Value="GetPropertyValue<double>(property)" Value="GetPropertyValue<double>(property)"
Style="width: 100%;" Style="width: 100%;"
Disabled="@(!property.Editable)" Disabled="@(_currentlyEditing && !property.Editable)"
Required="@property.IsRequired" Required="@property.IsRequired"
ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Number))" /> ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Number))" />
} }
@@ -60,7 +60,7 @@
<FluentSwitch <FluentSwitch
Label="@property.Name" Label="@property.Name"
Value="GetPropertyValue<bool>(property)" Value="GetPropertyValue<bool>(property)"
Disabled="@(!property.Editable)" Disabled="@(_currentlyEditing && !property.Editable)"
Required="@property.IsRequired" Required="@property.IsRequired"
ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Switch))" /> ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Switch))" />
} }
@@ -70,14 +70,14 @@
<FluentDatePicker <FluentDatePicker
Label="@property.Name" Label="@property.Name"
Value="GetPropertyValue<DateTime>(property)" Value="GetPropertyValue<DateTime>(property)"
Disabled="@(!property.Editable)" Disabled="@(_currentlyEditing && !property.Editable)"
Required="@property.IsRequired" Required="@property.IsRequired"
ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Date))" /> ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Date))" />
</div> </div>
<div style="display: flex; flex-direction: column; justify-content: flex-end"> <div style="display: flex; flex-direction: column; justify-content: flex-end">
<FluentTimePicker <FluentTimePicker
Value="GetPropertyValue<DateTime>(property)" Value="GetPropertyValue<DateTime>(property)"
Disabled="@(!property.Editable)" Disabled="@(_currentlyEditing && !property.Editable)"
Required="@property.IsRequired" Required="@property.IsRequired"
ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Time))" /> ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Time))" />
</div> </div>
@@ -88,7 +88,7 @@
Label="@property.Name" Label="@property.Name"
Value="GetPropertyValue<DateOnly>(property).ToDateTime(TimeOnly.MinValue)" Value="GetPropertyValue<DateOnly>(property).ToDateTime(TimeOnly.MinValue)"
Style="width: 100%" Style="width: 100%"
Disabled="@(!property.Editable)" Disabled="@(_currentlyEditing && !property.Editable)"
Required="@property.IsRequired" Required="@property.IsRequired"
ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Date))" /> ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Date))" />
} }
@@ -97,7 +97,7 @@
Label="@property.Name" Label="@property.Name"
Value="GetPropertyValue<TimeOnly>(property).ToDateTime()" Value="GetPropertyValue<TimeOnly>(property).ToDateTime()"
Style="width: 100%" Style="width: 100%"
Disabled="@(!property.Editable)" Disabled="@(_currentlyEditing && !property.Editable)"
Required="@property.IsRequired" Required="@property.IsRequired"
ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Time))" /> ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Time))" />
} }
@@ -109,7 +109,7 @@
Value="@(GetPropertyValue<string>(property))" Value="@(GetPropertyValue<string>(property))"
Style="width: 100%" Style="width: 100%"
Height="250px" Height="250px"
Disabled="@(!property.Editable)" Disabled="@(_currentlyEditing && !property.Editable)"
Required="@property.IsRequired" Required="@property.IsRequired"
ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Enum))" /> ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Enum))" />
} }
@@ -123,23 +123,33 @@
Value="@(GetPropertyValue<string>(property))" Value="@(GetPropertyValue<string>(property))"
Style="width: 100%" Style="width: 100%"
Height="250px" Height="250px"
Disabled="@(!property.Editable)" Disabled="@(_currentlyEditing && !property.Editable)"
Required="@property.IsRequired" Required="@property.IsRequired"
ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Enum))" /> ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Enum))" />
</div> </div>
<div style="display: flex; gap: 5px"> <div style="display: flex; gap: 5px">
<FluentButton OnClick="async () => await SetPropertyValue(property, null, InputType.Enum)" Disabled="@(!property.Editable)"> <FluentButton OnClick="async () => await SetPropertyValue(property, null, InputType.Enum)" Disabled="@(_currentlyEditing && !property.Editable)">
<FluentIcon Value="@(new Icons.Regular.Size20.Dismiss())" Color="Color.Neutral" /> <FluentIcon Value="@(new Icons.Regular.Size20.Dismiss())" Color="Color.Neutral" />
</FluentButton> </FluentButton>
</div> </div>
</div> </div>
} }
else if (property.TextArea) {
<FluentTextArea
Label="@property.Name"
Value="@(GetPropertyValue<string>(property))"
Style="width: 100%;"
Rows="@property.TextAreaRows"
Disabled="@(_currentlyEditing && !property.Editable)"
Required="@property.IsRequired"
ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Text))" />
}
else { else {
<FluentTextField <FluentTextField
Label="@property.Name" Label="@property.Name"
Value="@(GetPropertyValue<string>(property))" Value="@(GetPropertyValue<string>(property))"
Style="width: 100%;" Style="width: 100%;"
Disabled="@(!property.Editable)" Disabled="@(_currentlyEditing && !property.Editable)"
Required="@property.IsRequired" Required="@property.IsRequired"
ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Text))" /> ValueChanged="@(async v => await SetPropertyValue(property, v, InputType.Text))" />
} }
@@ -151,9 +161,13 @@
} }
</FluentDialogBody> </FluentDialogBody>
<FluentToastProvider MaxToastCount="10" />
@inject IContextExplorer Explorer @inject IContextExplorer Explorer
@inject IDialogService Dialogs @inject IDialogService Dialogs
@inject IHopFrameAuthHandler Handler @inject IHopFrameAuthHandler Handler
@inject IToastService Toasts
@inject IServiceProvider Provider
@code { @code {
[Parameter] [Parameter]
@@ -217,6 +231,13 @@
break; break;
case InputType.Text: case InputType.Text:
if (config.Info.PropertyType == typeof(Guid)) {
var success = Guid.TryParse((string)value, out var guid);
if (success) result = guid;
else Toasts.ShowError($"'{value}' is not a valid guid");
break;
}
result = Convert.ToString(value); result = Convert.ToString(value);
break; break;
@@ -254,6 +275,11 @@
result = ((IEnumerable)value).OfType<object>().FirstOrDefault(); result = ((IEnumerable)value).OfType<object>().FirstOrDefault();
else { else {
needsOverride = false; needsOverride = false;
if (!typeof(IList).IsAssignableFrom(config.Info.PropertyType)) {
throw new ArgumentException($"Invalid type of '{config.Name}' property in '{config.Table.DisplayName}' table, only list types are supported on enumerable relations.");
}
var asList = (IList)config.Info.GetValue(Content.CurrentObject)!; var asList = (IList)config.Info.GetValue(Content.CurrentObject)!;
asList.Clear(); asList.Clear();
foreach (var element in (IEnumerable)value) { foreach (var element in (IEnumerable)value) {
@@ -268,7 +294,7 @@
} }
if (config.Parser is not null && result is not null) { if (config.Parser is not null && result is not null) {
result = config.Parser(result.ToString()!); result = config.Parser(result.ToString()!, Provider);
} }
if (needsOverride) if (needsOverride)
@@ -319,7 +345,7 @@
var value = property.Info.GetValue(Content.CurrentObject); var value = property.Info.GetValue(Content.CurrentObject);
if (property.Validator is not null) { if (property.Validator is not null) {
errorList.AddRange(await property.Validator.Invoke(value)); errorList.AddRange(await property.Validator.Invoke(value, Provider));
continue; continue;
} }

View File

@@ -273,8 +273,8 @@
else DialogData?.SelectedObjects.Add(item); else DialogData?.SelectedObjects.Add(item);
} }
private void SelectAll(bool? selected) { private void SelectAll() {
selected = _currentlyDisplayedModels.Any(obj => DialogData?.SelectedObjects.Contains(obj) != true); var selected = _currentlyDisplayedModels.Any(obj => DialogData?.SelectedObjects.Contains(obj) != true);
foreach (var displayedModel in _currentlyDisplayedModels) { foreach (var displayedModel in _currentlyDisplayedModels) {
SelectItem(displayedModel, selected == true); SelectItem(displayedModel, selected == true);
} }

View File

@@ -23,7 +23,7 @@ builder.Services.AddHopFrame(options => {
options.AddDbContext<DatabaseContext>(context => { options.AddDbContext<DatabaseContext>(context => {
context.Table<User>(table => { context.Table<User>(table => {
table.Property(u => u.Password) table.Property(u => u.Password)
.ValueParser(pwd => pwd + "-edited"); .SetParser((pwd, _) => pwd + "-edited");
table.Property(u => u.FirstName) table.Property(u => u.FirstName)
.List(false); .List(false);
@@ -32,11 +32,11 @@ builder.Services.AddHopFrame(options => {
.List(false); .List(false);
table.Property(u => u.Id) table.Property(u => u.Id)
.Sortable(false) .IsSortable(false)
.OrderIndex(3); .SetOrderIndex(3);
table.AddListingProperty("Name", user => $"{user.FirstName} {user.LastName}") table.AddListingProperty("Name", (user, _) => $"{user.FirstName} {user.LastName}")
.OrderIndex(2); .SetOrderIndex(2);
table.SetDisplayName("Benutzer"); table.SetDisplayName("Benutzer");
table.SetDescription("This table is used for user data store and user authentication"); table.SetDescription("This table is used for user data store and user authentication");
@@ -44,12 +44,12 @@ builder.Services.AddHopFrame(options => {
table.SetViewPolicy("policy"); table.SetViewPolicy("policy");
table.Property(u => u.Posts) table.Property(u => u.Posts)
.FormatEach<Post>(post => post.Caption); .FormatEach<Post>((post, _) => post.Caption);
}); });
context.Table<Post>() context.Table<Post>()
.Property(p => p.Author) .Property(p => p.Author)
.Format(user => $"{user?.FirstName} {user?.LastName}"); .Format((user, _) => $"{user.FirstName} {user.LastName}");
context.Table<Post>() context.Table<Post>()
.Property(p => p.Id) .Property(p => p.Id)
@@ -59,7 +59,8 @@ builder.Services.AddHopFrame(options => {
.Property(p => p.CreatedAt); .Property(p => p.CreatedAt);
context.Table<Post>() context.Table<Post>()
.Property(p => p.Caption) .Property(p => p.Content)
.IsTextArea(true)
/*.Validator(input => { /*.Validator(input => {
var errors = new List<string>(); var errors = new List<string>();
@@ -73,7 +74,7 @@ builder.Services.AddHopFrame(options => {
})*/; })*/;
context.Table<Post>() context.Table<Post>()
.OrderIndex(-1); .SetOrderIndex(-1);
}); });
}); });