diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/CheckExtensionProperty.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/CheckExtensionProperty.razor index ed9f1664fe..eebff3970d 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/CheckExtensionProperty.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/CheckExtensionProperty.razor @@ -2,10 +2,20 @@ @typeparam TResourceType @using Volo.Abp.BlazoriseUI @using Volo.Abp.Localization +@inherits ExtensionPropertyComponentBase @if (PropertyInfo != null && Entity != null) { - - @PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory) - -} \ No newline at end of file + + + + + @PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory) + + + + + + + +} diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/CheckExtensionProperty.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/CheckExtensionProperty.razor.cs index 4f8a06a146..79662ab96c 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/CheckExtensionProperty.razor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/CheckExtensionProperty.razor.cs @@ -1,22 +1,10 @@ -using Microsoft.AspNetCore.Components; -using Microsoft.Extensions.Localization; -using Volo.Abp.Data; -using Volo.Abp.ObjectExtending; +using Volo.Abp.Data; namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending; -public partial class CheckExtensionProperty : ComponentBase +public partial class CheckExtensionProperty where TEntity : IHasExtraProperties { - [Inject] - public IStringLocalizerFactory StringLocalizerFactory { get; set; } - - [Parameter] - public TEntity Entity { get; set; } - - [Parameter] - public ObjectExtensionPropertyInfo PropertyInfo { get; set; } - protected bool Value { get { return PropertyInfo.GetInputValueOrDefault(Entity.GetProperty(PropertyInfo.Name)); diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/DateTimeExtensionProperty.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/DateTimeExtensionProperty.razor index a9847d8e33..8fa7f0d777 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/DateTimeExtensionProperty.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/DateTimeExtensionProperty.razor @@ -3,15 +3,21 @@ @using Volo.Abp.BlazoriseUI @using Volo.Abp.Localization @using Volo.Abp.ObjectExtending +@inherits ExtensionPropertyComponentBase @if (PropertyInfo != null && Entity != null) { - - @PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory) - - - + + + @PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory) + + + + + + + } diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/DateTimeExtensionProperty.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/DateTimeExtensionProperty.razor.cs index 30a8ecc1a1..9a39b7a02d 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/DateTimeExtensionProperty.razor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/DateTimeExtensionProperty.razor.cs @@ -5,23 +5,16 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Blazorise; +using Volo.Abp.AspNetCore.Components.Web; using Volo.Abp.Data; using Volo.Abp.ObjectExtending; namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending; -public partial class DateTimeExtensionProperty : ComponentBase +public partial class DateTimeExtensionProperty where TEntity : IHasExtraProperties { - [Inject] - public IStringLocalizerFactory StringLocalizerFactory { get; set; } - - [Parameter] - public TEntity Entity { get; set; } - - [Parameter] - public ObjectExtensionPropertyInfo PropertyInfo { get; set; } - protected DateTime? Value { get { return PropertyInfo.GetInputValueOrDefault(Entity.GetProperty(PropertyInfo.Name)); diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionProperties.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionProperties.razor index f8aad7b5cd..9fe96c7a20 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionProperties.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionProperties.razor @@ -1,7 +1,6 @@ @typeparam TEntityType @typeparam TResourceType @using Volo.Abp.ObjectExtending -@using Volo.Abp.Localization @using Volo.Abp.Data @{ @@ -13,11 +12,11 @@ { if (propertyInfo.Type.IsEnum) { - + } else if (!propertyInfo.Lookup.Url.IsNullOrEmpty()) { - + } else { @@ -25,6 +24,7 @@ __builder.OpenComponent(0, inputType.MakeGenericType(new[] { typeof(TEntityType), typeof(TResourceType) })); __builder.AddAttribute(1, "PropertyInfo", propertyInfo); __builder.AddAttribute(2, "Entity", Entity); + __builder.AddAttribute(3, "LH", LH); __builder.CloseComponent(); } } diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionPropertyComponentBase.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionPropertyComponentBase.cs new file mode 100644 index 0000000000..bb9657734d --- /dev/null +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionPropertyComponentBase.cs @@ -0,0 +1,39 @@ +using System.Linq; +using Blazorise; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Localization; +using Volo.Abp.AspNetCore.Components.Web; +using Volo.Abp.Data; +using Volo.Abp.ObjectExtending; + +namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending; + +public abstract class ExtensionPropertyComponentBase : OwningComponentBase + where TEntity : IHasExtraProperties +{ + [Inject] + public IStringLocalizerFactory StringLocalizerFactory { get; set; } + + [Parameter] + public TEntity Entity { get; set; } + + [Parameter] + public ObjectExtensionPropertyInfo PropertyInfo { get; set; } + + [Parameter] + public AbpBlazorMessageLocalizerHelper LH { get; set; } + + protected virtual void Validate(ValidatorEventArgs e) + { + e.Status = ValidationStatus.Success; + + var result = ExtensibleObjectValidator.GetValidationErrors(Entity, PropertyInfo.Name, e.Value); + if (!result.Any()) + { + return; + } + + e.Status = ValidationStatus.Error; + e.ErrorText = result.First().ErrorMessage; + } +} diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/LookupExtensionProperty.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/LookupExtensionProperty.razor index 4a305d606d..5a6a7c7c3e 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/LookupExtensionProperty.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/LookupExtensionProperty.razor @@ -2,18 +2,19 @@ @typeparam TResourceType @using Abp.Localization @using Blazorise.Components +@inherits ExtensionPropertyComponentBase @PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory) - \ No newline at end of file diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/LookupExtensionProperty.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/LookupExtensionProperty.razor.cs index 725edf8e99..608bd16d9e 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/LookupExtensionProperty.razor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/LookupExtensionProperty.razor.cs @@ -9,6 +9,8 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Text.Json; using System.Threading.Tasks; +using Blazorise; +using Volo.Abp.AspNetCore.Components.Web; using Volo.Abp.AspNetCore.Components.Web.Extensibility; using Volo.Abp.Data; using Volo.Abp.Http; @@ -18,18 +20,11 @@ using Volo.Abp.ObjectExtending; namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending; -public partial class LookupExtensionProperty : ComponentBase +public partial class LookupExtensionProperty where TEntity : IHasExtraProperties { protected List> lookupItems; - [Inject] public IStringLocalizerFactory StringLocalizerFactory { get; set; } - - [Parameter] public TEntity Entity { get; set; } - - [Parameter] public ObjectExtensionPropertyInfo PropertyInfo { get; set; } - - [Inject] public ILookupApiRequestService LookupApiService { get; set; } public string TextPropertyName => PropertyInfo.Name + "_Text"; @@ -63,7 +58,7 @@ public partial class LookupExtensionProperty : Component protected virtual void UpdateLookupTextProperty(object value) { - var selectedItemText = lookupItems.SingleOrDefault(t => t.Value.Equals(value)).Text; + var selectedItemText = lookupItems.SingleOrDefault(t => t.Value.Equals(value))?.Text; Entity.SetProperty(TextPropertyName, selectedItemText); } @@ -101,12 +96,12 @@ public partial class LookupExtensionProperty : Component return Task.CompletedTask; } - protected async Task SearchFilterChangedAsync(string filter) + protected virtual async Task SearchFilterChangedAsync(string filter) { lookupItems = await GetLookupItemsAsync(filter); } - protected override async Task OnAfterRenderAsync(bool firstRender) + protected async override Task OnAfterRenderAsync(bool firstRender) { await base.OnAfterRenderAsync(firstRender); diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/SelectExtensionProperty.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/SelectExtensionProperty.razor index c70dc11237..cc1735c26a 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/SelectExtensionProperty.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/SelectExtensionProperty.razor @@ -1,13 +1,21 @@ @typeparam TEntity @typeparam TResourceType @using Abp.Localization +@inherits ExtensionPropertyComponentBase - - @PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory) - - + + + @PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory) + + + diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/SelectExtensionProperty.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/SelectExtensionProperty.razor.cs index e873ec27d1..ddc00a4c8b 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/SelectExtensionProperty.razor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/SelectExtensionProperty.razor.cs @@ -2,23 +2,20 @@ using Microsoft.Extensions.Localization; using System; using System.Collections.Generic; +using System.Linq; +using Blazorise; +using Volo.Abp.AspNetCore.Components.Web; using Volo.Abp.Data; using Volo.Abp.Localization; using Volo.Abp.ObjectExtending; namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending; -public partial class SelectExtensionProperty : ComponentBase +public partial class SelectExtensionProperty where TEntity : IHasExtraProperties { protected List> SelectItems = new(); - [Inject] public IStringLocalizerFactory StringLocalizerFactory { get; set; } - - [Parameter] public TEntity Entity { get; set; } - - [Parameter] public ObjectExtensionPropertyInfo PropertyInfo { get; set; } - public int SelectedValue { get { return Entity.GetProperty(PropertyInfo.Name); } set { Entity.SetProperty(PropertyInfo.Name, value, false); } diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TextExtensionProperty.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TextExtensionProperty.razor index ade78ee6d2..fc8b7b5398 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TextExtensionProperty.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TextExtensionProperty.razor @@ -2,13 +2,18 @@ @typeparam TResourceType @using Volo.Abp.BlazoriseUI @using Volo.Abp.Localization +@inherits ExtensionPropertyComponentBase @if (PropertyInfo != null && Entity != null) { - - @PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory) - - - - -} \ No newline at end of file + + + @PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory) + + + + + + + +} diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TextExtensionProperty.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TextExtensionProperty.razor.cs index fd017d2472..6fe9c9fb71 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TextExtensionProperty.razor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TextExtensionProperty.razor.cs @@ -1,23 +1,10 @@ -using Microsoft.AspNetCore.Components; -using Microsoft.Extensions.Localization; -using Volo.Abp.Data; -using Volo.Abp.ObjectExtending; +using Volo.Abp.Data; namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending; -public partial class TextExtensionProperty : ComponentBase +public partial class TextExtensionProperty where TEntity : IHasExtraProperties { - [Inject] - public IStringLocalizerFactory StringLocalizerFactory { get; set; } - - [Parameter] - public TEntity Entity { get; set; } - - [Parameter] - public ObjectExtensionPropertyInfo PropertyInfo { get; set; } - - protected string Value { get { return PropertyInfo.GetTextInputValueOrNull(Entity.GetProperty(PropertyInfo.Name)); diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TimeExtensionProperty.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TimeExtensionProperty.razor index ce2215e621..6ad15b2cb5 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TimeExtensionProperty.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TimeExtensionProperty.razor @@ -2,12 +2,18 @@ @typeparam TResourceType @using Volo.Abp.BlazoriseUI @using Volo.Abp.Localization +@inherits ExtensionPropertyComponentBase @if (PropertyInfo != null && Entity != null) { - - @PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)--> - - - -} \ No newline at end of file + + + @PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)--> + + + + + + + +} diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TimeExtensionProperty.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TimeExtensionProperty.razor.cs index 6e582ef698..038283850c 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TimeExtensionProperty.razor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/TimeExtensionProperty.razor.cs @@ -5,23 +5,16 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Blazorise; +using Volo.Abp.AspNetCore.Components.Web; using Volo.Abp.Data; using Volo.Abp.ObjectExtending; namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending; -public partial class TimeExtensionProperty : ComponentBase +public partial class TimeExtensionProperty where TEntity : IHasExtraProperties { - [Inject] - public IStringLocalizerFactory StringLocalizerFactory { get; set; } - - [Parameter] - public TEntity Entity { get; set; } - - [Parameter] - public ObjectExtensionPropertyInfo PropertyInfo { get; set; } - protected TimeSpan? Value { get { return PropertyInfo.GetInputValueOrDefault(Entity.GetProperty(PropertyInfo.Name));