Open Closed

Can I overwrite component ExtensionProperties? #6925


User avatar
0
lan.dang created
  • ABP Framework version: v8.0.0
  • UI Type: Blazor Server
  • Database System: EF Core (SQL Server, Oracle, MySQL, PostgreSQL, etc..)
  • Tiered (for MVC) or Auth Server Separated (for Angular): no
  • Exception message and full stack trace:
  • Steps to reproduce the issue: In UserManagement page I want to hide some extra property, can I overwrite ExtensionProperties component? I tried to hide field but it does not work user.AddOrUpdateProperty<string>( //property type: string UserConsts.TokenPropertyName, //property name property => { //validation rules property.Attributes.Add(new StringLengthAttribute(UserConsts.TokenMaxLength)); property.UI.OnEditForm.IsVisible = false; property.UI.OnCreateForm.IsVisible = false; property.Configuration["AllowUserToEdit"] = false; } );

16 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Yes, you can override this component.

    https://docs.abp.io/en/abp/latest/UI/Blazor/Customization-Overriding-Components?UI=BlazorServer

    The source code: https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionProperties.razor.cs#L9 https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionProperties.razor

  • User Avatar
    0
    lan.dang created

    Can you give me snipper code to overwrite this component? I just manually hide some specific field eg if (!propertyInfo.Name.EndsWith("_Text")) => if (!propertyInfo.Name.EndsWith("_Text") && !propertyInfo.Name.Equals("Token"))

    OR alternative solution is give me source code of UserManagement page in Pro module so I disable ExtraProperties

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    sure, what's your email?

    I will share the source code of UserManagement component.

  • User Avatar
    0
    lan.dang created

    Can you share me to lan.dang@kwork.fi ? Thank you

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Hi

    I have sent the mail.

  • User Avatar
    0
    lan.dang created

    I still get this error with page

    It related to Blazorise.TreeView, what is version of Blazorise you are uing?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Add below namespaces to your _Imports.razor file:

    @using Microsoft.AspNetCore.Components.Web
    @using Microsoft.AspNetCore.Components.Forms
    @using Volo.Abp.AspNetCore.Components.Web
    @using Volo.Abp.BlazoriseUI
    @using Volo.Abp.BlazoriseUI.Components
    @using Blazorise
    @using Blazorise.DataGrid
    @using Excubo.Blazor.TreeViews
    @using Volo.Abp.Identity.Pro.Blazor.Pages.Identity.Components;
    
    
  • User Avatar
    0
    lan.dang created

    I just sent you email, could you help me check what I was wrong

    Thank you

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share a minimal project so I can debug it.

    Thanks.

  • User Avatar
    0
    lan.dang created

    I get hard to make a minimal project. I try to solve the problem with some modify, As per this document : https://docs.abp.io/en/abp/latest/UI/Blazor/Customization-Overriding-Components?UI=BlazorServer Could we modify in both razor and code behind?

    I want to update UI and overwrite some method in code behind as well Where do I put this code line? [ExposeServices(typeof(UserManagement))] [Dependency(ReplaceServices = true)]

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Could we modify in both razor and code behind?

    Yes.

    Where do I put this code line?

    In your blazor project, eg the Component folder.

  • User Avatar
    0
    lan.dang created

    I mean, if i put this code in razor page it will not hit razor.cs (code behind) @inherits UserManagement @attribute [ExposeServices(typeof(UserManagement))] @attribute [Dependency(ReplaceServices = true)]

    But if i put this code in razor.cs it does not update UI from razor page [ExposeServices(typeof(UserManagement))] [Dependency(ReplaceServices = true)]

    I want to update both razor and razor.cs file. How can I do that?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I will share the code. wait a monent.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can add your code to MyExtensionProperties.razor

    MyExtensionProperties.razor

    @typeparam TEntityType
    @typeparam TResourceType
    @using Volo.Abp.Data
    @using Volo.Abp.ObjectExtending
    @inherits Volo.Abp.BlazoriseUI.Components.ObjectExtending.ExtensionProperties<TEntityType, TResourceType>
    
    @{
        Entity.SetDefaultsForExtraProperties();
    
        foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties<TEntityType>())
        {
            if (!propertyInfo.Name.EndsWith("_Text"))
            {
                if (propertyInfo.Type.IsEnum)
                {
                    <SelectExtensionProperty PropertyInfo="@propertyInfo" Entity="@Entity" TEntity="TEntityType" TResourceType="TResourceType" LH="@LH" />
                }
                else if (!propertyInfo.Lookup.Url.IsNullOrEmpty())
                {
                    <LookupExtensionProperty PropertyInfo="@propertyInfo" Entity="@Entity" TEntity="TEntityType" TResourceType="TResourceType" LH="@LH" />
                }
                else
                {
                    var inputType = BlazoriseUiObjectExtensionPropertyInfoExtensions.GetInputType(propertyInfo);
                    __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.AddAttribute(4, "ModalType", ModalType);
                    __builder.CloseComponent();
                }
            }
        }
    }
    
    

    MyExtensionProperties.razor.cs

    using Volo.Abp.BlazoriseUI.Components.ObjectExtending;
    using Volo.Abp.Data;
    
    namespace BookStore.Blazor.Components;
    
    public partial class MyExtensionProperties<TEntityType, TResourceType> : ExtensionProperties<TEntityType, TResourceType>
        where TEntityType : IHasExtraProperties
    {
    
    }
    
    

    Replace the ExtensionProperties in DI.

    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        context.Services.Replace(ServiceDescriptor.Transient(
            typeof(ExtensionProperties<IdentityUserCreateDto, IdentityResource>),
            typeof(MyExtensionProperties<IdentityUserCreateDto, IdentityResource>)));
    
        context.Services.Replace(ServiceDescriptor.Transient(
            typeof(ExtensionProperties<IdentityUserUpdateDto, IdentityResource>),
            typeof(MyExtensionProperties<IdentityUserUpdateDto, IdentityResource>)));
    }
    
  • User Avatar
    0
    lan.dang created

    Thank a lot , it solves my requirement

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Good news.

Made with ❤️ on ABP v9.0.0-preview. Updated on October 07, 2024, 08:52