Merge pull request #16823 from abpframework/EngincanV/blazor-extension-property

Allow Setting Extended Property as ReadOnly on the UI for Blazor
pull/16985/head
liangshiwei 2 years ago committed by GitHub
commit 4ce1a735a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,7 +8,7 @@
{
<Validation Validator="@Validate" MessageLocalizer="@LH.Localize">
<Field>
<Check TValue="bool" @bind-Checked="@Value">
<Check TValue="bool" @bind-Checked="@Value" Disabled="IsReadonlyField">
<ChildContent>
@PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)
</ChildContent>

@ -13,6 +13,7 @@
<DateEdit TValue="DateTime?"
InputMode="@(PropertyInfo.IsDate() ? DateInputMode.Date : DateInputMode.DateTime)"
Pattern="@PropertyInfo.GetDateEditInputFormatOrNull()"
Disabled="IsReadonlyField"
@bind-Date="@Value">
<Feedback>
<ValidationError/>

@ -25,6 +25,7 @@
__builder.AddAttribute(1, "PropertyInfo", propertyInfo);
__builder.AddAttribute(2, "Entity", Entity);
__builder.AddAttribute(3, "LH", LH);
__builder.AddAttribute(4, "ModalType", ModalType);
__builder.CloseComponent();
}
}

@ -2,6 +2,7 @@
using Microsoft.Extensions.Localization;
using Volo.Abp.AspNetCore.Components.Web;
using Volo.Abp.Data;
using Volo.Abp.ObjectExtending;
namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending;
@ -16,4 +17,7 @@ public partial class ExtensionProperties<TEntityType, TResourceType> : Component
[Parameter]
public TEntityType Entity { get; set; }
[Parameter]
public ExtensionPropertyModalType? ModalType { get; set; }
}

@ -33,6 +33,9 @@ public abstract class ExtensionPropertyComponentBase<TEntity, TResourceType> : O
[Parameter]
public AbpBlazorMessageLocalizerHelper<TResourceType> LH { get; set; }
[Parameter]
public ExtensionPropertyModalType? ModalType { get; set; }
protected virtual void Validate(ValidatorEventArgs e)
{
e.Status = ValidationStatus.Success;
@ -65,12 +68,14 @@ public abstract class ExtensionPropertyComponentBase<TEntity, TResourceType> : O
}
e.MemberNames = result.MemberNames;
e.Status = ValidationStatus.Error;
e.Status = ValidationStatus.Error;
e.ErrorText = errorMessage;
break;
}
}
protected bool IsReadonlyField => ModalType is ExtensionPropertyModalType.EditModal && PropertyInfo.UI.EditModal.IsReadOnly;
private static string GetDefaultErrorMessage(ValidationAttribute validationAttribute)
{
if (validationAttribute is StringLengthAttribute stringLengthAttribute && stringLengthAttribute.MinimumLength != 0)

@ -0,0 +1,7 @@
namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending;
public enum ExtensionPropertyModalType : byte
{
CreateModal = 0,
EditModal = 1
}

@ -15,6 +15,7 @@
SelectedValueChanged="@SelectedValueChanged"
SearchChanged="@SearchFilterChangedAsync"
Validator="@Validate"
MinLength="0">
MinLength="0"
Disabled="IsReadonlyField">
</Autocomplete>
</Field>

@ -10,7 +10,7 @@
<ChildContent>
@foreach (var item in SelectItems)
{
<SelectItem Value="@item.Value">@item.Text</SelectItem>
<SelectItem Value="@item.Value" Disabled="IsReadonlyField">@item.Text</SelectItem>
}
</ChildContent>
<Feedback>

@ -9,7 +9,7 @@
<Validation Validator="@Validate" MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)</FieldLabel>
<TextEdit @bind-Text="@Value" Role="@PropertyInfo.GetTextRole()" InputMode="@PropertyInfo.GetTextInputMode()">
<TextEdit @bind-Text="@Value" Role="@PropertyInfo.GetTextRole()" InputMode="@PropertyInfo.GetTextInputMode()" Disabled="IsReadonlyField">
<Feedback>
<ValidationError/>
</Feedback>

@ -9,7 +9,7 @@
<Validation Validator="@Validate" MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)</FieldLabel>-->
<TimeEdit TValue="TimeSpan?" @bind-Time="@Value">
<TimeEdit TValue="TimeSpan?" @bind-Time="@Value" Disabled="IsReadonlyField">
<Feedback>
<ValidationError/>
</Feedback>

@ -65,6 +65,8 @@ public class ObjectExtensionPropertyInfo : IHasNameWithLocalizableDisplayName, I
/// </summary>
public int Order { get; set; }
public ExtensionPropertyUI UI { get; set; }
public ObjectExtensionPropertyInfo(
[NotNull] ObjectExtensionInfo objectExtension,
[NotNull] Type type,
@ -81,10 +83,26 @@ public class ObjectExtensionPropertyInfo : IHasNameWithLocalizableDisplayName, I
Attributes.AddRange(ExtensionPropertyHelper.GetDefaultAttributes(Type));
DefaultValue = TypeHelper.GetDefaultValue(Type);
Lookup = new ExtensionPropertyLookupConfiguration();
UI = new ExtensionPropertyUI();
}
public object GetDefaultValue()
{
return ExtensionPropertyHelper.GetDefaultValue(Type, DefaultValueFactory, DefaultValue);
}
public class ExtensionPropertyUI
{
public ExtensionPropertyUIEditModal EditModal { get; set; }
public ExtensionPropertyUI()
{
EditModal = new ExtensionPropertyUIEditModal();
}
}
public class ExtensionPropertyUIEditModal
{
public bool IsReadOnly { get; set; }
}
}

@ -54,7 +54,7 @@
</Feedback>
</TextEdit>
</Field>
<ExtensionProperties TEntityType="IdentityRoleCreateDto" TResourceType="IdentityResource" Entity="@NewEntity" LH="@LH"/>
<ExtensionProperties TEntityType="IdentityRoleCreateDto" TResourceType="IdentityResource" Entity="@NewEntity" LH="@LH" ModalType="ExtensionPropertyModalType.CreateModal" />
</Validation>
<Field>
<Check TValue="bool" @bind-Checked="@NewEntity.IsDefault">@L["DisplayName:IsDefault"]</Check>
@ -92,7 +92,7 @@
</Feedback>
</TextEdit>
</Field>
<ExtensionProperties TEntityType="IdentityRoleUpdateDto" TResourceType="IdentityResource" Entity="@EditingEntity" LH="@LH"/>
<ExtensionProperties TEntityType="IdentityRoleUpdateDto" TResourceType="IdentityResource" Entity="@EditingEntity" LH="@LH" ModalType="ExtensionPropertyModalType.EditModal" />
</Validation>
<Field>
<Check TValue="bool" @bind-Checked="@EditingEntity.IsDefault">@L["DisplayName:IsDefault"]</Check>
@ -112,4 +112,4 @@
@if (HasManagePermissionsPermission)
{
<PermissionManagementModal @ref="PermissionManagementModal"/>
}
}

@ -132,7 +132,7 @@
<Field>
<Check TValue="bool" @bind-Checked="@NewEntity.LockoutEnabled">@L["DisplayName:LockoutEnabled"]</Check>
</Field>
<ExtensionProperties TEntityType="IdentityUserCreateDto" TResourceType="IdentityResource" Entity="@NewEntity" LH="@LH" />
<ExtensionProperties TEntityType="IdentityUserCreateDto" TResourceType="IdentityResource" Entity="@NewEntity" LH="@LH" ModalType="ExtensionPropertyModalType.CreateModal" />
</TabPanel>
<TabPanel Name="Roles">
@if (NewUserRoles != null)
@ -253,7 +253,7 @@
<Field>
<Check TValue="bool" @bind-Checked="EditingEntity.LockoutEnabled">@L["DisplayName:LockoutEnabled"]</Check>
</Field>
<ExtensionProperties TEntityType="IdentityUserUpdateDto" TResourceType="IdentityResource" Entity="@EditingEntity" LH="@LH" />
<ExtensionProperties TEntityType="IdentityUserUpdateDto" TResourceType="IdentityResource" Entity="@EditingEntity" LH="@LH" ModalType="ExtensionPropertyModalType.EditModal" />
</TabPanel>
<TabPanel Name="Roles">
@if (EditUserRoles != null)

@ -81,7 +81,7 @@
<ValidationError Style="display: block" />
</Field>
</Validation>
<ExtensionProperties TEntityType="TenantCreateDto" TResourceType="AbpTenantManagementResource" Entity="@NewEntity" LH="@LH"/>
<ExtensionProperties TEntityType="TenantCreateDto" TResourceType="AbpTenantManagementResource" Entity="@NewEntity" LH="@LH" ModalType="ExtensionPropertyModalType.CreateModal" />
</Validations>
</ModalBody>
<ModalFooter>
@ -116,7 +116,7 @@
</Field>
</Validation>
</Validations>
<ExtensionProperties TEntityType="TenantUpdateDto" TResourceType="AbpTenantManagementResource" Entity="@EditingEntity" LH="@LH"/>
<ExtensionProperties TEntityType="TenantUpdateDto" TResourceType="AbpTenantManagementResource" Entity="@EditingEntity" LH="@LH" ModalType="ExtensionPropertyModalType.EditModal" />
</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseEditModalAsync">@L["Cancel"]</Button>

Loading…
Cancel
Save