From 73d86bc5d10b5f6befe7b42f312c7a63be0f319e Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 19 Aug 2022 11:53:00 +0800 Subject: [PATCH] Module extensions for the Profile UI --- .../AbpAccountBlazorAutoMapperProfile.cs | 3 +- .../AbpAccountBlazorModule.cs | 19 +++++++ .../Pages/Account/AccountManage.razor | 5 ++ .../Pages/Account/AccountManage.razor.cs | 5 +- .../AbpAccountWebAutomapperProfile.cs | 3 +- .../AbpAccountWebModule.cs | 19 +++++++ ...ersonalInfoManagementGroupViewComponent.cs | 8 +-- .../PersonalInfo/Default.cshtml | 51 +++++++++++++++++-- .../PersonalInfo/Default.js | 2 +- 9 files changed, 103 insertions(+), 12 deletions(-) diff --git a/modules/account/src/Volo.Abp.Account.Blazor/AbpAccountBlazorAutoMapperProfile.cs b/modules/account/src/Volo.Abp.Account.Blazor/AbpAccountBlazorAutoMapperProfile.cs index 8838cee634..af59d75321 100644 --- a/modules/account/src/Volo.Abp.Account.Blazor/AbpAccountBlazorAutoMapperProfile.cs +++ b/modules/account/src/Volo.Abp.Account.Blazor/AbpAccountBlazorAutoMapperProfile.cs @@ -10,10 +10,11 @@ public class AbpAccountBlazorAutoMapperProfile : Profile public AbpAccountBlazorAutoMapperProfile() { CreateMap() + .MapExtraProperties() .Ignore(x => x.PhoneNumberConfirmed) .Ignore(x => x.EmailConfirmed); CreateMap() - .Ignore(x => x.ExtraProperties); + .MapExtraProperties(); } } diff --git a/modules/account/src/Volo.Abp.Account.Blazor/AbpAccountBlazorModule.cs b/modules/account/src/Volo.Abp.Account.Blazor/AbpAccountBlazorModule.cs index c1e52e9b5f..61b42e1807 100644 --- a/modules/account/src/Volo.Abp.Account.Blazor/AbpAccountBlazorModule.cs +++ b/modules/account/src/Volo.Abp.Account.Blazor/AbpAccountBlazorModule.cs @@ -1,8 +1,12 @@ using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Account.Blazor.Pages.Account; using Volo.Abp.AspNetCore.Components.Web.Theming; using Volo.Abp.AspNetCore.Components.Web.Theming.Routing; using Volo.Abp.AutoMapper; using Volo.Abp.Modularity; +using Volo.Abp.ObjectExtending; +using Volo.Abp.ObjectExtending.Modularity; +using Volo.Abp.Threading; using Volo.Abp.UI.Navigation; namespace Volo.Abp.Account.Blazor; @@ -14,6 +18,8 @@ namespace Volo.Abp.Account.Blazor; )] public class AbpAccountBlazorModule : AbpModule { + private readonly static OneTimeRunner OneTimeRunner = new OneTimeRunner(); + public override void ConfigureServices(ServiceConfigurationContext context) { context.Services.AddAutoMapperObjectMapper(); @@ -33,4 +39,17 @@ public class AbpAccountBlazorModule : AbpModule options.AdditionalAssemblies.Add(typeof(AbpAccountBlazorModule).Assembly); }); } + + public override void PostConfigureServices(ServiceConfigurationContext context) + { + OneTimeRunner.Run(() => + { + ModuleExtensionConfigurationHelper + .ApplyEntityConfigurationToUi( + IdentityModuleExtensionConsts.ModuleName, + IdentityModuleExtensionConsts.EntityNames.User, + editFormTypes: new[] { typeof(PersonalInfoModel) } + ); + }); + } } diff --git a/modules/account/src/Volo.Abp.Account.Blazor/Pages/Account/AccountManage.razor b/modules/account/src/Volo.Abp.Account.Blazor/Pages/Account/AccountManage.razor index a3a4e76b58..2a625f3e35 100644 --- a/modules/account/src/Volo.Abp.Account.Blazor/Pages/Account/AccountManage.razor +++ b/modules/account/src/Volo.Abp.Account.Blazor/Pages/Account/AccountManage.razor @@ -1,5 +1,9 @@ @page "/account/manage-profile" @using Microsoft.AspNetCore.Components.Forms +@using Volo.Abp.Account.Localization +@using Volo.Abp.AspNetCore.Components.Web +@using Volo.Abp.BlazoriseUI.Components.ObjectExtending +@inject AbpBlazorMessageLocalizerHelper LH @inherits AbpAccountComponentBase @@ -58,6 +62,7 @@ @L["DisplayName:PhoneNumber"] + diff --git a/modules/account/src/Volo.Abp.Account.Blazor/Pages/Account/AccountManage.razor.cs b/modules/account/src/Volo.Abp.Account.Blazor/Pages/Account/AccountManage.razor.cs index 3a0aff243b..567363843b 100644 --- a/modules/account/src/Volo.Abp.Account.Blazor/Pages/Account/AccountManage.razor.cs +++ b/modules/account/src/Volo.Abp.Account.Blazor/Pages/Account/AccountManage.razor.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Components; using Volo.Abp.AspNetCore.Components.Messages; using Volo.Abp.Identity; +using Volo.Abp.ObjectExtending; namespace Volo.Abp.Account.Blazor.Pages.Account; @@ -58,7 +59,7 @@ public partial class AccountManage await UiMessageService.Success(L["PasswordChanged"]); } - protected async Task UpdatePersonalInfoAsync() + protected virtual async Task UpdatePersonalInfoAsync() { await ProfileAppService.UpdateAsync( ObjectMapper.Map(PersonalInfoModel) @@ -86,7 +87,7 @@ public class ChangePasswordModel } } -public class PersonalInfoModel +public class PersonalInfoModel : ExtensibleObject { public string UserName { get; set; } diff --git a/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebAutomapperProfile.cs b/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebAutomapperProfile.cs index 329f8f7ac1..cdc92e8b19 100644 --- a/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebAutomapperProfile.cs +++ b/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebAutomapperProfile.cs @@ -9,6 +9,7 @@ public class AbpAccountWebAutoMapperProfile : Profile { public AbpAccountWebAutoMapperProfile() { - CreateMap(); + CreateMap() + .MapExtraProperties(); } } diff --git a/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs b/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs index 0dc4f2fc48..9f670ffc82 100644 --- a/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs +++ b/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Account.Localization; using Volo.Abp.Account.Web.Pages.Account; +using Volo.Abp.Account.Web.Pages.Account.Components.ProfileManagementGroup.PersonalInfo; using Volo.Abp.Account.Web.ProfileManagement; using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.UI.Bundling; @@ -12,6 +13,9 @@ using Volo.Abp.ExceptionHandling; using Volo.Abp.Http.ProxyScripting.Generators.JQuery; using Volo.Abp.Identity.AspNetCore; using Volo.Abp.Modularity; +using Volo.Abp.ObjectExtending; +using Volo.Abp.ObjectExtending.Modularity; +using Volo.Abp.Threading; using Volo.Abp.UI.Navigation; using Volo.Abp.VirtualFileSystem; @@ -26,6 +30,8 @@ namespace Volo.Abp.Account.Web; )] public class AbpAccountWebModule : AbpModule { + private readonly static OneTimeRunner OneTimeRunner = new OneTimeRunner(); + public override void PreConfigureServices(ServiceConfigurationContext context) { context.Services.PreConfigure(options => @@ -95,4 +101,17 @@ public class AbpAccountWebModule : AbpModule }); } + + public override void PostConfigureServices(ServiceConfigurationContext context) + { + OneTimeRunner.Run(() => + { + ModuleExtensionConfigurationHelper + .ApplyEntityConfigurationToUi( + IdentityModuleExtensionConsts.ModuleName, + IdentityModuleExtensionConsts.EntityNames.User, + editFormTypes: new[] { typeof(AccountProfilePersonalInfoManagementGroupViewComponent.PersonalInfoModel) } + ); + }); + } } diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/AccountProfilePersonalInfoManagementGroupViewComponent.cs b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/AccountProfilePersonalInfoManagementGroupViewComponent.cs index 45705eb7f5..0dea3bc6eb 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/AccountProfilePersonalInfoManagementGroupViewComponent.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/AccountProfilePersonalInfoManagementGroupViewComponent.cs @@ -5,6 +5,7 @@ using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.Widgets; using Volo.Abp.Domain.Entities; using Volo.Abp.Identity; +using Volo.Abp.ObjectExtending; using Volo.Abp.Validation; namespace Volo.Abp.Account.Web.Pages.Account.Components.ProfileManagementGroup.PersonalInfo; @@ -30,7 +31,7 @@ public class AccountProfilePersonalInfoManagementGroupViewComponent : AbpViewCom return View("~/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.cshtml", model); } - public class PersonalInfoModel : IHasConcurrencyStamp + public class PersonalInfoModel : ExtensibleObject, IHasConcurrencyStamp { [Required] [DynamicStringLength(typeof(IdentityUserConsts), nameof(IdentityUserConsts.MaxUserNameLength))] @@ -54,7 +55,6 @@ public class AccountProfilePersonalInfoManagementGroupViewComponent : AbpViewCom [Display(Name = "DisplayName:PhoneNumber")] public string PhoneNumber { get; set; } - [HiddenInput] - public string ConcurrencyStamp { get; set; } + [HiddenInput] public string ConcurrencyStamp { get; set; } } -} +} \ No newline at end of file diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.cshtml b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.cshtml index ba695a8557..b9b0783ab9 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.cshtml +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.cshtml @@ -1,13 +1,24 @@ @using Volo.Abp.Account.Localization @using Volo.Abp.Users @using Microsoft.AspNetCore.Mvc.Localization +@using Microsoft.AspNetCore.Mvc.TagHelpers +@using Microsoft.Extensions.Localization +@using Volo.Abp.Account.Web.Pages.Account.Components.ProfileManagementGroup.PersonalInfo +@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Alert +@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Button +@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form +@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Grid @using Volo.Abp.AspNetCore.Mvc.UI.Theming +@using Volo.Abp.Data @using Volo.Abp.Identity.Settings +@using Volo.Abp.Localization +@using Volo.Abp.ObjectExtending @using Volo.Abp.Settings @inject IHtmlLocalizer L @inject ICurrentUser CurrentUser @inject ISettingProvider SettingManager @inject IThemeManager ThemeManager +@inject IStringLocalizerFactory StringLocalizerFactory @model Volo.Abp.Account.Web.Pages.Account.Components.ProfileManagementGroup.PersonalInfo.AccountProfilePersonalInfoManagementGroupViewComponent.PersonalInfoModel @{ var isUserNameUpdateEnabled = string.Equals(await SettingManager.GetOrNullAsync(IdentitySettingNames.User.IsUserNameUpdateEnabled), "true", @@ -19,8 +30,8 @@

@L["PersonalSettings"]


- - + + @@ -37,5 +48,39 @@ + @foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties()) + { + if (!propertyInfo.Name.EndsWith("_Text")) + { + if (propertyInfo.Type.IsEnum || !propertyInfo.Lookup.Url.IsNullOrEmpty()) + { + if (propertyInfo.Type.IsEnum) + { + Model.ExtraProperties.ToEnum(propertyInfo.Name, propertyInfo.Type); + } + + + } + else + { + + } + } + } + - + \ No newline at end of file diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.js b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.js index 55a88e52e3..c8ff17ec67 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.js +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.js @@ -9,7 +9,7 @@ return false; } - var input = $('#PersonalSettingsForm').serializeFormToObject(); + var input = $('#PersonalSettingsForm').serializeFormToObject(false); volo.abp.account.profile.update(input).then(function (result) { abp.notify.success(l('PersonalSettingsSaved'));