diff --git a/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Layout/PageHeader.razor.cs b/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Layout/PageHeader.razor.cs index 594909cd52..fd6bd50942 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Layout/PageHeader.razor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Layout/PageHeader.razor.cs @@ -37,7 +37,7 @@ public partial class PageHeader : ComponentBase ToolbarItemRenders = new List(); } - protected override async Task OnParametersSetAsync() + protected async override Task OnParametersSetAsync() { await base.OnParametersSetAsync(); if (Toolbar != null) @@ -65,7 +65,7 @@ public partial class PageHeader : ComponentBase } } - protected override async Task OnInitializedAsync() + protected async override Task OnInitializedAsync() { await base.OnInitializedAsync(); } diff --git a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs index e2b188eec3..f5d06f5ba1 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs @@ -212,7 +212,7 @@ public abstract class AbpCrudPageBase< EntityActions = new EntityActionDictionary(); } - protected override async Task OnInitializedAsync() + protected async override Task OnInitializedAsync() { await SetPermissionsAsync(); await SetEntityActionsAsync(); @@ -220,7 +220,7 @@ public abstract class AbpCrudPageBase< await InvokeAsync(StateHasChanged); } - protected override async Task OnAfterRenderAsync(bool firstRender) + protected async override Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { @@ -350,6 +350,7 @@ public abstract class AbpCrudPageBase< protected virtual Task CloseCreateModalAsync() { + NewEntity = new TCreateViewModel(); return InvokeAsync(CreateModal.Hide); } @@ -464,6 +465,7 @@ public abstract class AbpCrudPageBase< protected virtual async Task OnCreatedEntityAsync() { + NewEntity = new TCreateViewModel(); await GetEntitiesAsync(); await InvokeAsync(CreateModal.Hide); 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..4408741fef --- /dev/null +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionPropertyComponentBase.cs @@ -0,0 +1,83 @@ +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using Blazorise; +using Blazorise.Utilities; +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; } + + [Inject] + public IValidationMessageLocalizerAttributeFinder ValidationMessageLocalizerAttributeFinder { 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 validationAttributes = PropertyInfo.GetValidationAttributes(); + var validationContext = new ValidationContext(Entity) + { + DisplayName = PropertyInfo.Name, + MemberName = PropertyInfo.Name + }; + + foreach (var validationAttribute in validationAttributes) + { + var result = validationAttribute.GetValidationResult(e.Value, validationContext); + if (result == ValidationResult.Success || result == null) + { + continue; + } + + var errorMessage = result.ErrorMessage; + if (LH != null) + { + var formattedErrorMessage = GetDefaultErrorMessage(validationAttribute); + var errorMessageString = ValidationAttributeHelper.RevertErrorMessagePlaceholders(formattedErrorMessage); + var errorMessageArguments = ValidationMessageLocalizerAttributeFinder.FindAll(errorMessage, errorMessageString) + ?.OrderBy(x => x.Index) + ?.Select(x => x.Argument); + + errorMessage = LH.Localize(errorMessageString, errorMessageArguments); + } + + e.MemberNames = result.MemberNames; + e.Status = ValidationStatus.Error; + e.ErrorText = errorMessage; + break; + } + } + + private static string GetDefaultErrorMessage(ValidationAttribute validationAttribute) + { + if (validationAttribute is StringLengthAttribute stringLengthAttribute && stringLengthAttribute.MinimumLength != 0) + { + var nullable = ValidationAttributeHelper.ValidationAttributeCustomErrorMessageSetProperty.GetValue((object) validationAttribute) as bool?; + var flag = true; + if (!(nullable.GetValueOrDefault() == flag & nullable.HasValue)) + { + return ValidationAttributeHelper.SetErrorMessagePlaceholders("The field {0} must be a string with a minimum length of {2} and a maximum length of {1}."); + } + } + return ValidationAttributeHelper.SetErrorMessagePlaceholders(ValidationAttributeHelper.ValidationAttributeErrorMessageStringProperty.GetValue((object) validationAttribute) as string); + } +} diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/LookupExtensionProperty.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/LookupExtensionProperty.razor index 4a305d606d..52369d6b46 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/LookupExtensionProperty.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/LookupExtensionProperty.razor @@ -2,18 +2,20 @@ @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..c21db1352d 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"; @@ -42,28 +37,22 @@ public partial class LookupExtensionProperty : Component } } + public string SelectedText => Entity.GetProperty(TextPropertyName); + public LookupExtensionProperty() { lookupItems = new List>(); } - protected override void OnParametersSet() + protected async override Task OnInitializedAsync() { - var value = Entity.GetProperty(PropertyInfo.Name); - var text = Entity.GetProperty(TextPropertyName); - if (value != null && text != null) - { - lookupItems.Add(new SelectItem - { - Text = Entity.GetProperty(TextPropertyName).ToString(), - Value = value - }); - } + await base.OnInitializedAsync(); + await SearchFilterChangedAsync(string.Empty); } 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); } @@ -86,8 +75,7 @@ public partial class LookupExtensionProperty : Component selectItems.Add(new SelectItem { Text = item.GetProperty(PropertyInfo.Lookup.DisplayPropertyName).GetString(), - Value = JsonSerializer.Deserialize( - item.GetProperty(PropertyInfo.Lookup.ValuePropertyName).GetRawText(), PropertyInfo.Type) + Value = JsonSerializer.Deserialize(item.GetProperty(PropertyInfo.Lookup.ValuePropertyName).GetRawText(), PropertyInfo.Type) }); } @@ -97,22 +85,11 @@ public partial class LookupExtensionProperty : Component protected virtual Task SelectedValueChanged(object selectedItem) { SelectedValue = selectedItem; - 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) - { - await base.OnAfterRenderAsync(firstRender); - - if (firstRender) - { - await SearchFilterChangedAsync(string.Empty); - } - } } 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));