From eec13fa333d6cfb71abd0aac7b8cfcf833b70e88 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Mon, 12 Oct 2020 10:57:09 +0200 Subject: [PATCH 01/25] New extension method to reset an object properties --- .../System/AbpObjectExtensions.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/framework/src/Volo.Abp.Core/System/AbpObjectExtensions.cs b/framework/src/Volo.Abp.Core/System/AbpObjectExtensions.cs index 958398e0c5..9542383983 100644 --- a/framework/src/Volo.Abp.Core/System/AbpObjectExtensions.cs +++ b/framework/src/Volo.Abp.Core/System/AbpObjectExtensions.cs @@ -2,6 +2,7 @@ using System.ComponentModel; using System.Globalization; using System.Linq; +using System.Reflection; namespace System { @@ -105,5 +106,36 @@ namespace System return obj; } + + /// + /// Resets all fields of a given object to their default values. + /// + /// Type of the object + /// An object + /// Alternative custom method to reset the values. + /// Returns the original object. + public static T ResetState(this T obj, Action customReset = null) + { + if (customReset != null) + { + customReset(obj); + } + else + { + var properties = typeof(T).GetProperties(); + + foreach (var property in properties) + { + if (!property.CanWrite) + { + continue; + } + + property.SetValue(obj, null); + } + } + + return obj; + } } } From ed9f3f5c0a0d15f328d01dc05d63103bf455948d Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Mon, 12 Oct 2020 11:28:04 +0200 Subject: [PATCH 02/25] Reset model state when AbpCrudPageBase is opened --- framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs index 8723209c53..44fc2403f0 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs @@ -318,7 +318,8 @@ namespace Volo.Abp.BlazoriseUI { await CheckCreatePolicyAsync(); - NewEntity = new TCreateViewModel(); + NewEntity.ResetState(); + CreateModal.Show(); } From 56fce17d70733f23510b0435b2780272b5ab5141 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Mon, 12 Oct 2020 11:28:10 +0200 Subject: [PATCH 03/25] Blazorise client side validation for RoleManagementBase --- .../Pages/Identity/RoleManagement.razor | 28 +++++++++++-------- .../Pages/Identity/RoleManagement.razor.cs | 15 ++++++++++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor index 781756dd71..a45aafbe59 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor @@ -78,26 +78,32 @@ { - + @L["NewRole"] - + + + + @L["DisplayName:RoleName"] + + + + + + + - @L["DisplayName:RoleName"] - - - - @L["DisplayName:IsDefault"] - @L["DisplayName:IsPublic"] + @L["DisplayName:IsDefault"] + @L["DisplayName:IsPublic"] - + - + @@ -107,7 +113,7 @@ { - + @L["Edit"] diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs index bccf3ddbd8..591707355b 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using Blazorise; using Microsoft.AspNetCore.Authorization; using Volo.Abp.Application.Dtos; using Volo.Abp.BlazoriseUI; @@ -17,6 +18,8 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity protected bool ShouldShowEntityActions { get; set; } + protected Validations ValidationsRef { get; set; } + public RoleManagementBase() { ObjectMapperContext = typeof(AbpIdentityBlazorModule); @@ -38,5 +41,17 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity HasDeletePermission || HasManagePermissionsPermission; } + + protected virtual Task OnCreateEntityClicked() + { + if ( ValidationsRef.ValidateAll() ) + { + CreateModal.Hide(); + + return CreateEntityAsync(); + } + + return Task.CompletedTask; + } } } From 1a44a268f8787649ae32561ad83b2238468f8aaa Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Wed, 14 Oct 2020 12:11:39 +0200 Subject: [PATCH 04/25] Role and User client side Blazorise validations --- .../Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs | 2 +- .../System/AbpObjectExtensions.cs | 28 ++- .../Pages/Identity/RoleManagement.razor | 49 ++-- .../Pages/Identity/RoleManagement.razor.cs | 38 ++- .../Pages/Identity/UserManagement.razor | 219 ++++++++++++------ .../Pages/Identity/UserManagement.razor.cs | 47 +++- 6 files changed, 267 insertions(+), 116 deletions(-) diff --git a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs index 44fc2403f0..7616447552 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs @@ -335,7 +335,7 @@ namespace Volo.Abp.BlazoriseUI var entityDto = await AppService.GetAsync(id); EditingEntityId = id; - EditingEntity = MapToEditingEntity(entityDto); + EditingEntity.ApplyState(MapToEditingEntity(entityDto)); EditModal.Show(); } diff --git a/framework/src/Volo.Abp.Core/System/AbpObjectExtensions.cs b/framework/src/Volo.Abp.Core/System/AbpObjectExtensions.cs index 9542383983..a173c2a95d 100644 --- a/framework/src/Volo.Abp.Core/System/AbpObjectExtensions.cs +++ b/framework/src/Volo.Abp.Core/System/AbpObjectExtensions.cs @@ -110,7 +110,7 @@ namespace System /// /// Resets all fields of a given object to their default values. /// - /// Type of the object + /// Type of the object. /// An object /// Alternative custom method to reset the values. /// Returns the original object. @@ -137,5 +137,31 @@ namespace System return obj; } + + /// + /// Applies all fields of a given object from it's counterpart. + /// + /// Type of the object. + /// An object. + /// An object from which we copy the values. + /// Returns the original object. + public static T ApplyState(this T obj, T other) + { + // This code is not production ready and it should be removed once + // the proper validation in Blazorise is done! + var properties = typeof(T).GetProperties(); + + foreach (var property in properties) + { + if (!property.CanWrite) + { + continue; + } + + property.SetValue(obj, typeof(T).GetProperty(property.Name).GetValue(other)); + } + + return obj; + } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor index a45aafbe59..033a5293d8 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor @@ -1,5 +1,5 @@ @page "/identity/roles" -@attribute [Authorize(IdentityPermissions.Roles.Default)] +@attribute [Authorize( IdentityPermissions.Roles.Default )] @using Volo.Abp.Identity @using Microsoft.AspNetCore.Authorization @using Microsoft.Extensions.Localization @@ -7,14 +7,13 @@ @using Volo.Abp.PermissionManagement.Blazor.Components @inherits RoleManagementBase @inject IStringLocalizer L - @* ************************* PAGE HEADER ************************* *@

@L["Roles"]

- @if (HasCreatePermission) + @if ( HasCreatePermission ) { @@ -31,7 +30,7 @@ ShowPager="true" PageSize="PageSize"> - @if (ShouldShowEntityActions) + @if ( ShouldShowEntityActions ) { @@ -40,15 +39,15 @@ @L["Actions"] - @if (HasUpdatePermission) + @if ( HasUpdatePermission ) { @L["Edit"] } - @if (HasManagePermissionsPermission) + @if ( HasManagePermissionsPermission ) { @L["Permissions"] } - @if (HasDeletePermission) + @if ( HasDeletePermission ) { @L["Delete"] } @@ -60,11 +59,11 @@ @(context.As().Name) - @if (context.As().IsDefault) + @if ( context.As().IsDefault ) { @L["DisplayName:IsDefault"] } - @if (context.As().IsPublic) + @if ( context.As().IsPublic ) { @L["DisplayName:IsPublic"] } @@ -74,7 +73,7 @@ @* ************************* CREATE MODAL ************************* *@ -@if (HasCreatePermission) +@if ( HasCreatePermission ) { @@ -84,7 +83,7 @@
- + @L["DisplayName:RoleName"] @@ -103,13 +102,13 @@ - +
} @* ************************* EDIT MODAL ************************* *@ -@if (HasUpdatePermission) +@if ( HasUpdatePermission ) { @@ -119,17 +118,23 @@ - + + + + @L["DisplayName:RoleName"] + + + + + + + - @L["DisplayName:RoleName"] - - - - @L["DisplayName:IsDefault"] - @L["DisplayName:IsPublic"] + @L["DisplayName:IsDefault"] + @L["DisplayName:IsPublic"] - + @@ -139,4 +144,4 @@ } - + diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs index 591707355b..1645f1f2a3 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs @@ -8,7 +8,7 @@ using Volo.Abp.PermissionManagement.Blazor.Components; namespace Volo.Abp.Identity.Blazor.Pages.Identity { - public abstract class RoleManagementBase : AbpCrudPageBase + public abstract class RoleManagementBase : AbpCrudPageBase { protected const string PermissionProviderName = "R"; @@ -18,7 +18,9 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity protected bool ShouldShowEntityActions { get; set; } - protected Validations ValidationsRef { get; set; } + protected Validations CreateValidationsRef { get; set; } + + protected Validations EditValidationsRef { get; set; } public RoleManagementBase() { @@ -42,13 +44,39 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity HasManagePermissionsPermission; } - protected virtual Task OnCreateEntityClicked() + protected override Task OpenCreateModalAsync() + { + CreateValidationsRef.ClearAll(); + + return base.OpenCreateModalAsync(); + } + + protected override Task OpenEditModalAsync(Guid id) + { + EditValidationsRef.ClearAll(); + + return base.OpenEditModalAsync(id); + } + + protected override Task CreateEntityAsync() { - if ( ValidationsRef.ValidateAll() ) + if (CreateValidationsRef.ValidateAll()) { CreateModal.Hide(); - return CreateEntityAsync(); + return base.CreateEntityAsync(); + } + + return Task.CompletedTask; + } + + protected override Task UpdateEntityAsync() + { + if (EditValidationsRef.ValidateAll()) + { + EditModal.Hide(); + + return base.UpdateEntityAsync(); } return Task.CompletedTask; diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor index bfbd2150c6..e3a24323e8 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor @@ -1,19 +1,18 @@ @page "/identity/users" -@attribute [Authorize(IdentityPermissions.Users.Default)] +@attribute [Authorize( IdentityPermissions.Users.Default )] @using Microsoft.AspNetCore.Authorization @using Microsoft.Extensions.Localization @using Volo.Abp.Identity.Localization @using Volo.Abp.PermissionManagement.Blazor.Components @inherits UserManagementBase @inject IStringLocalizer L - @* ************************* PAGE HEADER ************************* *@

@L["Users"]

- @if (HasCreatePermission) + @if ( HasCreatePermission ) { @@ -30,7 +29,7 @@ ShowPager="true" PageSize="PageSize"> - @if (ShouldShowEntityActions) + @if ( ShouldShowEntityActions ) { @@ -39,17 +38,17 @@ @L["Actions"] - @if (HasUpdatePermission) + @if ( HasUpdatePermission ) { @L["Edit"] } - @if (HasManagePermissionsPermission) + @if ( HasManagePermissionsPermission ) { @L["Permissions"] } - @if (HasDeletePermission) + @if ( HasDeletePermission ) { - + @L["Delete"] } @@ -76,17 +75,17 @@ @* ************************* CREATE MODAL ************************* *@ -@if (HasCreatePermission) +@if ( HasCreatePermission ) { - + @L["NewUser"] - + - + @L["UserInformations"] @@ -94,71 +93,107 @@ + + + @L["DisplayName:UserName"] + + + + + + + + + + @L["DisplayName:Name"] + + + + + + + + + + @L["DisplayName:Surname"] + + + + + + + + + + @L["DisplayName:Password"] + + + + + + + + + + @L["DisplayName:Email"] + + + + + + + + + + @L["DisplayName:PhoneNumber"] + + + + + + + - @L["DisplayName:UserName"] - - - - @L["DisplayName:Name"] - - - - @L["DisplayName:Surname"] - - - - @L["DisplayName:Password"] - - - - @L["DisplayName:Email"] - - - - @L["DisplayName:PhoneNumber"] - - - - @L["DisplayName:LockoutEnabled"] + @L["DisplayName:LockoutEnabled"] - @if (NewUserRoles != null) + @if ( NewUserRoles != null ) { - @foreach (var role in NewUserRoles) + @foreach ( var role in NewUserRoles ) { - - @role.Name + + @role.Name } } - + - + } @* ************************* EDIT MODAL ************************* *@ -@if (HasUpdatePermission) +@if ( HasUpdatePermission ) { - + @L["Edit"] - + - - + + @@ -168,55 +203,89 @@ - @L["DisplayName:UserName"] - - - - @L["DisplayName:Name"] - + + @L["DisplayName:UserName"] + + + + + + + + + @L["DisplayName:Name"] + + + + + + + @L["DisplayName:Surname"] - - - - @L["DisplayName:Password"] - - - - @L["DisplayName:Email"] - - - - @L["DisplayName:PhoneNumber"] - + + + + + + + + @L["DisplayName:Password"] + + + + + + + + + + @L["DisplayName:Email"] + + + + + + + + + + @L["DisplayName:PhoneNumber"] + + + + + + + - @L["DisplayName:LockoutEnabled"] + @L["DisplayName:LockoutEnabled"] - @if (EditUserRoles != null) + @if ( EditUserRoles != null ) { - @foreach (var role in EditUserRoles) + @foreach ( var role in EditUserRoles ) { - - @role.Name + + @role.Name } } - + - + } - \ No newline at end of file + \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs index a488cbd358..dc51f59dc1 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Blazorise; using Microsoft.AspNetCore.Authorization; using Volo.Abp.BlazoriseUI; using Volo.Abp.PermissionManagement.Blazor.Components; @@ -29,6 +30,10 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity protected string EditModalSelectedTab = DefaultSelectedTab; + protected Validations CreateValidationsRef { get; set; } + + protected Validations EditValidationsRef { get; set; } + public UserManagementBase() { ObjectMapperContext = typeof(AbpIdentityBlazorModule); @@ -60,44 +65,62 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity protected override Task OpenCreateModalAsync() { + CreateValidationsRef.ClearAll(); + CreateModalSelectedTab = DefaultSelectedTab; NewUserRoles = Roles.Select(x => new AssignedRoleViewModel - { - Name = x.Name, - IsAssigned = x.IsDefault - }).ToArray(); + { + Name = x.Name, + IsAssigned = x.IsDefault + }).ToArray(); return base.OpenCreateModalAsync(); } protected override Task CreateEntityAsync() { - NewEntity.RoleNames = NewUserRoles.Where(x => x.IsAssigned).Select(x => x.Name).ToArray(); + if (CreateValidationsRef.ValidateAll()) + { + CreateModal.Hide(); + + NewEntity.RoleNames = NewUserRoles.Where(x => x.IsAssigned).Select(x => x.Name).ToArray(); - return base.CreateEntityAsync(); + return base.CreateEntityAsync(); + } + + return Task.CompletedTask; } protected override async Task OpenEditModalAsync(Guid id) { + EditValidationsRef.ClearAll(); + EditModalSelectedTab = DefaultSelectedTab; var userRoleNames = (await AppService.GetRolesAsync(id)).Items.Select(r => r.Name).ToList(); EditUserRoles = Roles.Select(x => new AssignedRoleViewModel - { - Name = x.Name, - IsAssigned = userRoleNames.Contains(x.Name) - }).ToArray(); + { + Name = x.Name, + IsAssigned = userRoleNames.Contains(x.Name) + }).ToArray(); await base.OpenEditModalAsync(id); } protected override Task UpdateEntityAsync() { - EditingEntity.RoleNames = EditUserRoles.Where(x => x.IsAssigned).Select(x => x.Name).ToArray(); + if (EditValidationsRef.ValidateAll()) + { + EditModal.Hide(); + + EditingEntity.RoleNames = EditUserRoles.Where(x => x.IsAssigned).Select(x => x.Name).ToArray(); + + return base.UpdateEntityAsync(); + } - return base.UpdateEntityAsync(); + return Task.CompletedTask; } } From f4e568befe16efbf99123e558d24e0c11638a0e8 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Wed, 21 Oct 2020 12:11:11 +0200 Subject: [PATCH 05/25] WIP message arguments localization --- ...dentityBlazorMessageLocalizerExtensions.cs | 15 ++++++ .../Pages/Identity/RoleManagement.razor | 5 +- .../Identity/AbpIdentityDomainSharedModule.cs | 5 +- .../Identity/AbpIdentityMessageLocalizer.cs | 46 +++++++++++++++++++ 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs create mode 100644 modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityMessageLocalizer.cs diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs new file mode 100644 index 0000000000..480b17ac14 --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using System.Linq; +using Blazorise; + +namespace Volo.Abp.Identity.Blazor +{ + public static class AbpIdentityBlazorMessageLocalizerExtensions + { + public static IEnumerable Localize(this AbpIdentityMessageLocalizer abpIdentityMessageLocalizer, + ValidationMessageLocalizerEventArgs eventArgs) + { + return abpIdentityMessageLocalizer.Localize(eventArgs.Messages?.Select(m => (m.Message, m.MessageArguments)))?.ToArray(); + } + } +} diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor index 033a5293d8..e850e5c87a 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor @@ -7,6 +7,7 @@ @using Volo.Abp.PermissionManagement.Blazor.Components @inherits RoleManagementBase @inject IStringLocalizer L +@inject AbpIdentityMessageLocalizer ML @* ************************* PAGE HEADER ************************* *@ @@ -84,7 +85,7 @@ - + @L["DisplayName:RoleName"] @@ -120,7 +121,7 @@ - + @L["DisplayName:RoleName"] diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityDomainSharedModule.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityDomainSharedModule.cs index e14ce5e3f4..5a63d52b24 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityDomainSharedModule.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityDomainSharedModule.cs @@ -1,4 +1,5 @@ -using Volo.Abp.Features; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Features; using Volo.Abp.Identity.Localization; using Volo.Abp.Localization; using Volo.Abp.Localization.ExceptionHandling; @@ -37,6 +38,8 @@ namespace Volo.Abp.Identity { options.MapCodeNamespace("Volo.Abp.Identity", typeof(IdentityResource)); }); + + context.Services.AddSingleton(typeof(AbpIdentityMessageLocalizer<>), typeof(AbpIdentityMessageLocalizer<>)); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityMessageLocalizer.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityMessageLocalizer.cs new file mode 100644 index 0000000000..ff2c50ee83 --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityMessageLocalizer.cs @@ -0,0 +1,46 @@ +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Extensions.Localization; + +namespace Volo.Abp.Identity +{ + public class AbpIdentityMessageLocalizer + { + private readonly IStringLocalizer stringLocalizer; + + public AbpIdentityMessageLocalizer(IStringLocalizer stringLocalizer) + { + this.stringLocalizer = stringLocalizer; + } + + public virtual string Localize(string format, params string[] arguments) + { + try + { + return arguments?.Length > 0 + ? string.Format(stringLocalizer[format], LocalizeArguments(arguments)?.ToArray()) + : stringLocalizer[format]; + } + catch + { + return stringLocalizer[format]; + } + } + + public virtual IEnumerable Localize(IEnumerable<(string format, string[] arguments)> messages) + { + return messages?.Select(m => Localize(m.format, m.arguments)); + } + + protected virtual IEnumerable LocalizeArguments(IEnumerable arguments) + { + foreach (var argument in arguments) + { + yield return stringLocalizer[$"DisplayName:{argument}"] + ?? stringLocalizer[argument] + ?? argument; + } + } + } +} From eb2be1d672335f188ffac94f2a715c2588cddc49 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Thu, 22 Oct 2020 11:25:57 +0200 Subject: [PATCH 06/25] Optimized usage of Localize method --- .../Pages/Identity/RoleManagement.razor | 4 +- .../Pages/Identity/UserManagement.razor | 47 ++++++++++--------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor index e850e5c87a..daba629c3e 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor @@ -85,7 +85,7 @@ - + @L["DisplayName:RoleName"] @@ -121,7 +121,7 @@ - + @L["DisplayName:RoleName"] diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor index e3a24323e8..f0fe98c61c 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor @@ -6,6 +6,7 @@ @using Volo.Abp.PermissionManagement.Blazor.Components @inherits UserManagementBase @inject IStringLocalizer L +@inject AbpIdentityMessageLocalizer ML @* ************************* PAGE HEADER ************************* *@ @@ -79,7 +80,7 @@ { - + @L["NewUser"] @@ -93,7 +94,7 @@ - + @L["DisplayName:UserName"] @@ -103,7 +104,7 @@ - + @L["DisplayName:Name"] @@ -113,7 +114,7 @@ - + @L["DisplayName:Surname"] @@ -133,7 +134,7 @@ - + @L["DisplayName:Email"] @@ -143,7 +144,7 @@ - + @L["DisplayName:PhoneNumber"] @@ -186,7 +187,7 @@ { - + @L["Edit"] @@ -202,17 +203,17 @@ - - + + @L["DisplayName:UserName"] - - - + + + @L["DisplayName:Name"] @@ -222,14 +223,16 @@ - - @L["DisplayName:Surname"] - - - - - - + + + @L["DisplayName:Surname"] + + + + + + + @L["DisplayName:Password"] @@ -240,7 +243,7 @@ - + @L["DisplayName:Email"] @@ -250,7 +253,7 @@ - + @L["DisplayName:PhoneNumber"] From f24a7d18e18a35cc7ccf1a7e7ebae4d6b0700c5f Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Thu, 22 Oct 2020 11:26:33 +0200 Subject: [PATCH 07/25] Fixed blazor app element for .Net 5 --- .../MyProjectNameBlazorModule.cs | 2 +- .../src/MyCompanyName.MyProjectName.Blazor/wwwroot/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBlazorModule.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBlazorModule.cs index 7554ae8aca..279fe57114 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBlazorModule.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBlazorModule.cs @@ -77,7 +77,7 @@ namespace MyCompanyName.MyProjectName.Blazor private static void ConfigureUI(WebAssemblyHostBuilder builder) { - builder.RootComponents.Add("app"); + builder.RootComponents.Add("#app"); } private static void ConfigureHttpClient(ServiceConfigurationContext context, IWebAssemblyHostEnvironment environment) diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/wwwroot/index.html b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/wwwroot/index.html index 4566bec3c1..576e00f716 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/wwwroot/index.html +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/wwwroot/index.html @@ -17,7 +17,7 @@ - Loading... +
Loading...
From 38495de1812f66d0151d12f20e97e51961a5ddca Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Thu, 22 Oct 2020 11:27:55 +0200 Subject: [PATCH 08/25] Added editorconfig for identity/module solution --- modules/identity/.editorconfig | 131 +++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 modules/identity/.editorconfig diff --git a/modules/identity/.editorconfig b/modules/identity/.editorconfig new file mode 100644 index 0000000000..9f20b90112 --- /dev/null +++ b/modules/identity/.editorconfig @@ -0,0 +1,131 @@ +# Rules in this file were initially inferred by Visual Studio IntelliCode from the D:\Projects\Volosoft\abp\framework codebase based on best match to current usage at 2.10.2020. +# You can modify the rules from these initially generated values to suit your own policies +# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference +[*.cs] + + +#Core editorconfig formatting - indentation + +#use soft tabs (spaces) for indentation +indent_style = space + +#Formatting - indentation options + +#indent switch case contents. +csharp_indent_case_contents = true +#indent switch labels +csharp_indent_switch_labels = true + +#Formatting - new line options + +#place catch statements on a new line +csharp_new_line_before_catch = true +#place else statements on a new line +csharp_new_line_before_else = true +#require members of object intializers to be on separate lines +csharp_new_line_before_members_in_object_initializers = true +#require braces to be on a new line for accessors, methods, lambdas, object_collection_array_initializers, control_blocks, types, and properties (also known as "Allman" style) +csharp_new_line_before_open_brace = accessors, methods, lambdas, object_collection_array_initializers, control_blocks, types, properties + +#Formatting - organize using options + +#sort System.* using directives alphabetically, and place them before other usings +dotnet_sort_system_directives_first = true + +#Formatting - spacing options + +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +#Formatting - wrapping options + +#leave code block on single line +csharp_preserve_single_line_blocks = true + +#Style - Code block preferences + +#prefer curly braces even for one line of code +csharp_prefer_braces = true:suggestion + +#Style - expression bodied member options + +#prefer block bodies for constructors +csharp_style_expression_bodied_constructors = false:suggestion +#prefer block bodies for methods +csharp_style_expression_bodied_methods = false:suggestion +#prefer expression-bodied members for properties +csharp_style_expression_bodied_properties = true:suggestion + +#Style - expression level options + +#prefer out variables to be declared inline in the argument list of a method call when possible +csharp_style_inlined_variable_declaration = true:suggestion +#prefer the language keyword for member access expressions, instead of the type name, for types that have a keyword to represent them +dotnet_style_predefined_type_for_member_access = true:suggestion + +#Style - Expression-level preferences + +#prefer default over default(T) +csharp_prefer_simple_default_expression = true:suggestion +#prefer objects to be initialized using object initializers when possible +dotnet_style_object_initializer = true:suggestion +#prefer inferred tuple element names +dotnet_style_prefer_inferred_tuple_names = true:suggestion + +#Style - implicit and explicit types + +#prefer var over explicit type in all cases, unless overridden by another code style rule +csharp_style_var_elsewhere = true:suggestion +#prefer var is used to declare variables with built-in system types such as int +csharp_style_var_for_built_in_types = true:suggestion +#prefer var when the type is already mentioned on the right-hand side of a declaration expression +csharp_style_var_when_type_is_apparent = true:suggestion + +#Style - language keyword and framework type options + +#prefer the language keyword for local variables, method parameters, and class members, instead of the type name, for types that have a keyword to represent them +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion + +#Style - modifier options + +#prefer accessibility modifiers to be declared except for public interface members. This will currently not differ from always and will act as future proofing for if C# adds default interface methods. +dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion + +#Style - Modifier preferences + +#when this rule is set to a list of modifiers, prefer the specified ordering. +csharp_preferred_modifier_order = public,protected,private,virtual,async,static,override,readonly,abstract:suggestion + +#Style - Pattern matching + +#prefer pattern matching instead of is expression with type casts +csharp_style_pattern_matching_over_as_with_null_check = true:suggestion + +#Style - qualification options + +#prefer fields not to be prefaced with this. or Me. in Visual Basic +dotnet_style_qualification_for_field = false:suggestion +#prefer methods not to be prefaced with this. or Me. in Visual Basic +dotnet_style_qualification_for_method = false:suggestion +#prefer properties not to be prefaced with this. or Me. in Visual Basic +dotnet_style_qualification_for_property = false:suggestion From d6fce9d9d65e474d0412174cabd113667f5fbdb4 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Thu, 22 Oct 2020 11:36:53 +0200 Subject: [PATCH 09/25] Update Blazorise 0.9.2-preview12 --- .../src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj | 4 ++-- .../MyCompanyName.MyProjectName.Blazor.csproj | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj b/framework/src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj index e696a2f915..2e67a2b182 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj +++ b/framework/src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj index d1bec5d5d3..31f9899115 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj @@ -6,8 +6,8 @@ - - + + From 1d84ce4f8af7b13c9bf80005bbacf3a1adb94de4 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Thu, 22 Oct 2020 11:43:21 +0200 Subject: [PATCH 10/25] Fix Password localization --- .../Pages/Identity/UserManagement.razor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor index f0fe98c61c..03a8b68fa7 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor @@ -124,7 +124,7 @@
- + @L["DisplayName:Password"] @@ -233,7 +233,7 @@ - + @L["DisplayName:Password"] From 167aae0ec520d2e1bae76fd025f4476ab9e8415e Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Fri, 23 Oct 2020 10:05:34 +0200 Subject: [PATCH 11/25] Fixed formating --- .../Pages/Identity/RoleManagement.razor | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor index daba629c3e..4246d2dd76 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor @@ -11,10 +11,10 @@ @* ************************* PAGE HEADER ************************* *@ -

@L["Roles"]

+ @L["Roles"]
- @if ( HasCreatePermission ) + @if (HasCreatePermission) { @@ -31,7 +31,7 @@ ShowPager="true" PageSize="PageSize"> - @if ( ShouldShowEntityActions ) + @if (ShouldShowEntityActions) { @@ -40,15 +40,15 @@ @L["Actions"] - @if ( HasUpdatePermission ) + @if (HasUpdatePermission) { @L["Edit"] } - @if ( HasManagePermissionsPermission ) + @if (HasManagePermissionsPermission) { @L["Permissions"] } - @if ( HasDeletePermission ) + @if (HasDeletePermission) { @L["Delete"] } @@ -60,11 +60,11 @@ @(context.As().Name) - @if ( context.As().IsDefault ) + @if (context.As().IsDefault) { @L["DisplayName:IsDefault"] } - @if ( context.As().IsPublic ) + @if (context.As().IsPublic) { @L["DisplayName:IsPublic"] } @@ -74,7 +74,7 @@ @* ************************* CREATE MODAL ************************* *@ -@if ( HasCreatePermission ) +@if (HasCreatePermission) { @@ -109,7 +109,7 @@ } @* ************************* EDIT MODAL ************************* *@ -@if ( HasUpdatePermission ) +@if (HasUpdatePermission) { From 157d7b1d6e732bd4f6beb2b8ba2485c3e85b7f37 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Fri, 23 Oct 2020 11:06:07 +0200 Subject: [PATCH 12/25] Use ObjectMapper for NewEntity and EditingEntity --- .../src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs index 7616447552..c6491f1ec1 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs @@ -318,7 +318,11 @@ namespace Volo.Abp.BlazoriseUI { await CheckCreatePolicyAsync(); - NewEntity.ResetState(); + ObjectMapper.Map(new TCreateViewModel(), NewEntity); + + // Mapper will not notify Blazor that binded values are changed + // so we need to notify it manually by calling StateHasChanged + await InvokeAsync(() => StateHasChanged()); CreateModal.Show(); } @@ -334,8 +338,12 @@ namespace Volo.Abp.BlazoriseUI await CheckUpdatePolicyAsync(); var entityDto = await AppService.GetAsync(id); + EditingEntityId = id; - EditingEntity.ApplyState(MapToEditingEntity(entityDto)); + ObjectMapper.Map(entityDto, EditingEntity); + + await InvokeAsync(() => StateHasChanged()); + EditModal.Show(); } @@ -379,8 +387,6 @@ namespace Volo.Abp.BlazoriseUI CreateModal.Hide(); } - - protected virtual async Task UpdateEntityAsync() { await CheckUpdatePolicyAsync(); From b5986115a2ac737ce7bcc90ef9839d5585a639d2 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Fri, 23 Oct 2020 11:13:20 +0200 Subject: [PATCH 13/25] Remove explicit Auto validation mode --- .../Pages/Identity/RoleManagement.razor | 22 +++++++++---------- .../Pages/Identity/UserManagement.razor | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor index 4246d2dd76..ef59e969fd 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor @@ -14,7 +14,7 @@ @L["Roles"] - @if (HasCreatePermission) + @if ( HasCreatePermission ) { @@ -31,7 +31,7 @@ ShowPager="true" PageSize="PageSize"> - @if (ShouldShowEntityActions) + @if ( ShouldShowEntityActions ) { @@ -40,15 +40,15 @@ @L["Actions"] - @if (HasUpdatePermission) + @if ( HasUpdatePermission ) { @L["Edit"] } - @if (HasManagePermissionsPermission) + @if ( HasManagePermissionsPermission ) { @L["Permissions"] } - @if (HasDeletePermission) + @if ( HasDeletePermission ) { @L["Delete"] } @@ -60,11 +60,11 @@ @(context.As().Name) - @if (context.As().IsDefault) + @if ( context.As().IsDefault ) { @L["DisplayName:IsDefault"] } - @if (context.As().IsPublic) + @if ( context.As().IsPublic ) { @L["DisplayName:IsPublic"] } @@ -74,7 +74,7 @@ @* ************************* CREATE MODAL ************************* *@ -@if (HasCreatePermission) +@if ( HasCreatePermission ) { @@ -84,7 +84,7 @@ - + @L["DisplayName:RoleName"] @@ -109,7 +109,7 @@ } @* ************************* EDIT MODAL ************************* *@ -@if (HasUpdatePermission) +@if ( HasUpdatePermission ) { @@ -119,7 +119,7 @@ - + diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor index 03a8b68fa7..0ed1fd3d5a 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor @@ -86,7 +86,7 @@ - + @L["UserInformations"] @@ -193,7 +193,7 @@ - + From e6b9253614c883ae19be2039804d5622e372214b Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Fri, 23 Oct 2020 11:25:09 +0200 Subject: [PATCH 14/25] Removed AbpIdentityMessageLocalizer --- ...dentityBlazorMessageLocalizerExtensions.cs | 35 ++++++++++++-- .../Pages/Identity/RoleManagement.razor | 5 +- .../Pages/Identity/UserManagement.razor | 25 +++++----- .../Identity/AbpIdentityDomainSharedModule.cs | 2 - .../Identity/AbpIdentityMessageLocalizer.cs | 46 ------------------- 5 files changed, 46 insertions(+), 67 deletions(-) delete mode 100644 modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityMessageLocalizer.cs diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs index 480b17ac14..bb5214ac63 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs @@ -1,15 +1,44 @@ using System.Collections.Generic; using System.Linq; using Blazorise; +using Microsoft.Extensions.Localization; namespace Volo.Abp.Identity.Blazor { public static class AbpIdentityBlazorMessageLocalizerExtensions { - public static IEnumerable Localize(this AbpIdentityMessageLocalizer abpIdentityMessageLocalizer, - ValidationMessageLocalizerEventArgs eventArgs) + public static IEnumerable Localize(this IStringLocalizer stringLocalizer, ValidationMessageLocalizerEventArgs eventArgs) { - return abpIdentityMessageLocalizer.Localize(eventArgs.Messages?.Select(m => (m.Message, m.MessageArguments)))?.ToArray(); + return LocalizeMessages(stringLocalizer, eventArgs.Messages?.Select(m => (m.Message, m.MessageArguments)))?.ToArray(); + } + + private static IEnumerable LocalizeMessages(IStringLocalizer stringLocalizer, IEnumerable<(string format, string[] arguments)> messages) + { + return messages?.Select(m => LocalizeMessage(stringLocalizer, m.format, m.arguments)); + } + + private static string LocalizeMessage(IStringLocalizer stringLocalizer, string format, params string[] arguments) + { + try + { + return arguments?.Length > 0 + ? string.Format(stringLocalizer[format], LocalizeMessageArguments(stringLocalizer, arguments)?.ToArray()) + : stringLocalizer[format]; + } + catch + { + return stringLocalizer[format]; + } + } + + private static IEnumerable LocalizeMessageArguments(IStringLocalizer stringLocalizer, IEnumerable arguments) + { + foreach (var argument in arguments) + { + yield return stringLocalizer[$"DisplayName:{argument}"] + ?? stringLocalizer[argument] + ?? argument; + } } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor index ef59e969fd..ac40aca83d 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor @@ -7,7 +7,6 @@ @using Volo.Abp.PermissionManagement.Blazor.Components @inherits RoleManagementBase @inject IStringLocalizer L -@inject AbpIdentityMessageLocalizer ML @* ************************* PAGE HEADER ************************* *@ @@ -85,7 +84,7 @@ - + @L["DisplayName:RoleName"] @@ -121,7 +120,7 @@ - + @L["DisplayName:RoleName"] diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor index 0ed1fd3d5a..6f33181f8a 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor @@ -6,7 +6,6 @@ @using Volo.Abp.PermissionManagement.Blazor.Components @inherits UserManagementBase @inject IStringLocalizer L -@inject AbpIdentityMessageLocalizer ML @* ************************* PAGE HEADER ************************* *@ @@ -94,7 +93,7 @@ - + @L["DisplayName:UserName"] @@ -104,7 +103,7 @@ - + @L["DisplayName:Name"] @@ -114,7 +113,7 @@ - + @L["DisplayName:Surname"] @@ -124,7 +123,7 @@ - + @L["DisplayName:Password"] @@ -134,7 +133,7 @@ - + @L["DisplayName:Email"] @@ -144,7 +143,7 @@ - + @L["DisplayName:PhoneNumber"] @@ -203,7 +202,7 @@ - + @L["DisplayName:UserName"] @@ -213,7 +212,7 @@ - + @L["DisplayName:Name"] @@ -223,7 +222,7 @@ - + @L["DisplayName:Surname"] @@ -233,7 +232,7 @@ - + @L["DisplayName:Password"] @@ -243,7 +242,7 @@ - + @L["DisplayName:Email"] @@ -253,7 +252,7 @@ - + @L["DisplayName:PhoneNumber"] diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityDomainSharedModule.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityDomainSharedModule.cs index 5a63d52b24..80d039b7d7 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityDomainSharedModule.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityDomainSharedModule.cs @@ -38,8 +38,6 @@ namespace Volo.Abp.Identity { options.MapCodeNamespace("Volo.Abp.Identity", typeof(IdentityResource)); }); - - context.Services.AddSingleton(typeof(AbpIdentityMessageLocalizer<>), typeof(AbpIdentityMessageLocalizer<>)); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityMessageLocalizer.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityMessageLocalizer.cs deleted file mode 100644 index ff2c50ee83..0000000000 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/AbpIdentityMessageLocalizer.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Extensions.Localization; - -namespace Volo.Abp.Identity -{ - public class AbpIdentityMessageLocalizer - { - private readonly IStringLocalizer stringLocalizer; - - public AbpIdentityMessageLocalizer(IStringLocalizer stringLocalizer) - { - this.stringLocalizer = stringLocalizer; - } - - public virtual string Localize(string format, params string[] arguments) - { - try - { - return arguments?.Length > 0 - ? string.Format(stringLocalizer[format], LocalizeArguments(arguments)?.ToArray()) - : stringLocalizer[format]; - } - catch - { - return stringLocalizer[format]; - } - } - - public virtual IEnumerable Localize(IEnumerable<(string format, string[] arguments)> messages) - { - return messages?.Select(m => Localize(m.format, m.arguments)); - } - - protected virtual IEnumerable LocalizeArguments(IEnumerable arguments) - { - foreach (var argument in arguments) - { - yield return stringLocalizer[$"DisplayName:{argument}"] - ?? stringLocalizer[argument] - ?? argument; - } - } - } -} From 429e62d06384b274f6887957b5546c4f908b1219 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Tue, 27 Oct 2020 11:34:27 +0100 Subject: [PATCH 15/25] Added more Before and After methods for AbpCrudPageBase --- .../Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs | 94 ++++++++++++++++--- 1 file changed, 82 insertions(+), 12 deletions(-) diff --git a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs index c6491f1ec1..fae7e136ba 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs @@ -184,6 +184,8 @@ namespace Volo.Abp.BlazoriseUI protected TUpdateViewModel EditingEntity; protected Modal CreateModal; protected Modal EditModal; + protected Validations CreateValidationsRef; + protected Validations EditValidationsRef; protected string CreatePolicyName { get; set; } protected string UpdatePolicyName { get; set; } @@ -316,15 +318,31 @@ namespace Volo.Abp.BlazoriseUI protected virtual async Task OpenCreateModalAsync() { + await OnOpeningCreateModalAsync(); + + CreateValidationsRef.ClearAll(); + await CheckCreatePolicyAsync(); - ObjectMapper.Map(new TCreateViewModel(), NewEntity); + NewEntity = new TCreateViewModel(); // Mapper will not notify Blazor that binded values are changed // so we need to notify it manually by calling StateHasChanged await InvokeAsync(() => StateHasChanged()); CreateModal.Show(); + + await OnOpeningCreateModalAsync(); + } + + protected virtual Task OnOpeningCreateModalAsync() + { + return Task.CompletedTask; + } + + protected virtual Task OnOpenedCreateModalAsync() + { + return Task.CompletedTask; } protected virtual Task CloseCreateModalAsync() @@ -335,16 +353,32 @@ namespace Volo.Abp.BlazoriseUI protected virtual async Task OpenEditModalAsync(TKey id) { + await OnOpeningEditModalAsync(id); + + EditValidationsRef.ClearAll(); + await CheckUpdatePolicyAsync(); var entityDto = await AppService.GetAsync(id); EditingEntityId = id; - ObjectMapper.Map(entityDto, EditingEntity); + EditingEntity = MapToEditingEntity(entityDto); await InvokeAsync(() => StateHasChanged()); EditModal.Show(); + + await OnOpenedEditModalAsync(id); + } + + protected virtual Task OnOpeningEditModalAsync(TKey id) + { + return Task.CompletedTask; + } + + protected virtual Task OnOpenedEditModalAsync(TKey id) + { + return Task.CompletedTask; } protected virtual TUpdateViewModel MapToEditingEntity(TGetOutputDto entityDto) @@ -380,20 +414,56 @@ namespace Volo.Abp.BlazoriseUI protected virtual async Task CreateEntityAsync() { - await CheckCreatePolicyAsync(); - var createInput = MapToCreateInput(NewEntity); - await AppService.CreateAsync(createInput); - await GetEntitiesAsync(); - CreateModal.Hide(); + if (CreateValidationsRef.ValidateAll()) + { + await OnCreatingEntityAsync(); + + await CheckCreatePolicyAsync(); + var createInput = MapToCreateInput(NewEntity); + await AppService.CreateAsync(createInput); + await GetEntitiesAsync(); + + await OnCreatedEntityAsync(); + + CreateModal.Hide(); + } + } + + protected virtual Task OnCreatingEntityAsync() + { + return Task.CompletedTask; + } + + protected virtual Task OnCreatedEntityAsync() + { + return Task.CompletedTask; } protected virtual async Task UpdateEntityAsync() { - await CheckUpdatePolicyAsync(); - var updateInput = MapToUpdateInput(EditingEntity); - await AppService.UpdateAsync(EditingEntityId, updateInput); - await GetEntitiesAsync(); - EditModal.Hide(); + if (EditValidationsRef.ValidateAll()) + { + await OnUpdatingEntityAsync(); + + await CheckUpdatePolicyAsync(); + var updateInput = MapToUpdateInput(EditingEntity); + await AppService.UpdateAsync(EditingEntityId, updateInput); + await GetEntitiesAsync(); + + await OnUpdatedEntityAsync(); + + EditModal.Hide(); + } + } + + protected virtual Task OnUpdatingEntityAsync() + { + return Task.CompletedTask; + } + + protected virtual Task OnUpdatedEntityAsync() + { + return Task.CompletedTask; } protected virtual async Task DeleteEntityAsync(TListViewModel entity) From 0aaa5b8c4617af17cfdf44fecff6fcc1740c7443 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Tue, 27 Oct 2020 11:35:00 +0100 Subject: [PATCH 16/25] Updated to Blazorise 0.9.2-preview14 --- .../src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj | 4 ++-- .../MyCompanyName.MyProjectName.Blazor.csproj | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj b/framework/src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj index 2e67a2b182..1134821b78 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj +++ b/framework/src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj index 31f9899115..c9abf32119 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj @@ -6,8 +6,8 @@ - - + + From 6ee17e04c631e2258279bfdf32306c1c95edd058 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Tue, 27 Oct 2020 11:35:57 +0100 Subject: [PATCH 17/25] Most of crud operations moved to base class --- .../Pages/Identity/RoleManagement.razor.cs | 42 ------------------ .../Pages/Identity/UserManagement.razor.cs | 44 +++++-------------- 2 files changed, 12 insertions(+), 74 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs index 1645f1f2a3..a2cb77478f 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs @@ -18,10 +18,6 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity protected bool ShouldShowEntityActions { get; set; } - protected Validations CreateValidationsRef { get; set; } - - protected Validations EditValidationsRef { get; set; } - public RoleManagementBase() { ObjectMapperContext = typeof(AbpIdentityBlazorModule); @@ -43,43 +39,5 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity HasDeletePermission || HasManagePermissionsPermission; } - - protected override Task OpenCreateModalAsync() - { - CreateValidationsRef.ClearAll(); - - return base.OpenCreateModalAsync(); - } - - protected override Task OpenEditModalAsync(Guid id) - { - EditValidationsRef.ClearAll(); - - return base.OpenEditModalAsync(id); - } - - protected override Task CreateEntityAsync() - { - if (CreateValidationsRef.ValidateAll()) - { - CreateModal.Hide(); - - return base.CreateEntityAsync(); - } - - return Task.CompletedTask; - } - - protected override Task UpdateEntityAsync() - { - if (EditValidationsRef.ValidateAll()) - { - EditModal.Hide(); - - return base.UpdateEntityAsync(); - } - - return Task.CompletedTask; - } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs index dc51f59dc1..e2773e8334 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs @@ -30,10 +30,6 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity protected string EditModalSelectedTab = DefaultSelectedTab; - protected Validations CreateValidationsRef { get; set; } - - protected Validations EditValidationsRef { get; set; } - public UserManagementBase() { ObjectMapperContext = typeof(AbpIdentityBlazorModule); @@ -63,10 +59,8 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity HasManagePermissionsPermission; } - protected override Task OpenCreateModalAsync() + protected override async Task OnOpeningCreateModalAsync() { - CreateValidationsRef.ClearAll(); - CreateModalSelectedTab = DefaultSelectedTab; NewUserRoles = Roles.Select(x => new AssignedRoleViewModel @@ -75,27 +69,19 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity IsAssigned = x.IsDefault }).ToArray(); - return base.OpenCreateModalAsync(); + await base.OnOpeningCreateModalAsync(); } - protected override Task CreateEntityAsync() + protected override Task OnCreatingEntityAsync() { - if (CreateValidationsRef.ValidateAll()) - { - CreateModal.Hide(); - - NewEntity.RoleNames = NewUserRoles.Where(x => x.IsAssigned).Select(x => x.Name).ToArray(); + // apply roles before saving + NewEntity.RoleNames = NewUserRoles.Where(x => x.IsAssigned).Select(x => x.Name).ToArray(); - return base.CreateEntityAsync(); - } - - return Task.CompletedTask; + return base.OnCreatingEntityAsync(); } - protected override async Task OpenEditModalAsync(Guid id) + protected override async Task OnOpeningEditModalAsync(Guid id) { - EditValidationsRef.ClearAll(); - EditModalSelectedTab = DefaultSelectedTab; var userRoleNames = (await AppService.GetRolesAsync(id)).Items.Select(r => r.Name).ToList(); @@ -106,21 +92,15 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity IsAssigned = userRoleNames.Contains(x.Name) }).ToArray(); - await base.OpenEditModalAsync(id); + await base.OnOpeningEditModalAsync(id); } - protected override Task UpdateEntityAsync() + protected override Task OnUpdatingEntityAsync() { - if (EditValidationsRef.ValidateAll()) - { - EditModal.Hide(); - - EditingEntity.RoleNames = EditUserRoles.Where(x => x.IsAssigned).Select(x => x.Name).ToArray(); - - return base.UpdateEntityAsync(); - } + // apply roles before saving + EditingEntity.RoleNames = EditUserRoles.Where(x => x.IsAssigned).Select(x => x.Name).ToArray(); - return Task.CompletedTask; + return base.OnUpdatingEntityAsync(); } } From 31e39c1ce36cfdd276fde0ae20b52ab212c0b7e3 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Tue, 27 Oct 2020 11:37:05 +0100 Subject: [PATCH 18/25] Updated Blazorise MessageLocalizer according to latest changes --- .../AbpIdentityBlazorMessageLocalizerExtensions.cs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs index bb5214ac63..18a6242bab 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs @@ -7,21 +7,11 @@ namespace Volo.Abp.Identity.Blazor { public static class AbpIdentityBlazorMessageLocalizerExtensions { - public static IEnumerable Localize(this IStringLocalizer stringLocalizer, ValidationMessageLocalizerEventArgs eventArgs) - { - return LocalizeMessages(stringLocalizer, eventArgs.Messages?.Select(m => (m.Message, m.MessageArguments)))?.ToArray(); - } - - private static IEnumerable LocalizeMessages(IStringLocalizer stringLocalizer, IEnumerable<(string format, string[] arguments)> messages) - { - return messages?.Select(m => LocalizeMessage(stringLocalizer, m.format, m.arguments)); - } - - private static string LocalizeMessage(IStringLocalizer stringLocalizer, string format, params string[] arguments) + public static string Localize(this IStringLocalizer stringLocalizer, string format, IEnumerable arguments) { try { - return arguments?.Length > 0 + return arguments?.Count() > 0 ? string.Format(stringLocalizer[format], LocalizeMessageArguments(stringLocalizer, arguments)?.ToArray()) : stringLocalizer[format]; } From 1c0baa6ca64ac6db9686a13964f71e4edc5332df Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Wed, 28 Oct 2020 15:23:58 +0100 Subject: [PATCH 19/25] Remove OnOpenedCreateModalAsync --- .../src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs index f1563947c0..35b436565d 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs @@ -294,8 +294,6 @@ namespace Volo.Abp.BlazoriseUI await InvokeAsync(() => StateHasChanged()); CreateModal.Show(); - - await OnOpeningCreateModalAsync(); } protected virtual Task OnOpeningCreateModalAsync() @@ -303,11 +301,6 @@ namespace Volo.Abp.BlazoriseUI return Task.CompletedTask; } - protected virtual Task OnOpenedCreateModalAsync() - { - return Task.CompletedTask; - } - protected virtual Task CloseCreateModalAsync() { CreateModal.Hide(); @@ -330,8 +323,6 @@ namespace Volo.Abp.BlazoriseUI await InvokeAsync(() => StateHasChanged()); EditModal.Show(); - - await OnOpenedEditModalAsync(id); } protected virtual Task OnOpeningEditModalAsync(TKey id) @@ -339,11 +330,6 @@ namespace Volo.Abp.BlazoriseUI return Task.CompletedTask; } - protected virtual Task OnOpenedEditModalAsync(TKey id) - { - return Task.CompletedTask; - } - protected virtual TUpdateViewModel MapToEditingEntity(TGetOutputDto entityDto) { return ObjectMapper.Map(entityDto); From 66d60024ed8bd597c134a0e4f5a90dea3eed7b5c Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Wed, 28 Oct 2020 15:26:20 +0100 Subject: [PATCH 20/25] Remove ResetState and ApplyState temporary helpers --- .../System/AbpObjectExtensions.cs | 57 ------------------- 1 file changed, 57 deletions(-) diff --git a/framework/src/Volo.Abp.Core/System/AbpObjectExtensions.cs b/framework/src/Volo.Abp.Core/System/AbpObjectExtensions.cs index a173c2a95d..a3fd87188f 100644 --- a/framework/src/Volo.Abp.Core/System/AbpObjectExtensions.cs +++ b/framework/src/Volo.Abp.Core/System/AbpObjectExtensions.cs @@ -106,62 +106,5 @@ namespace System return obj; } - - /// - /// Resets all fields of a given object to their default values. - /// - /// Type of the object. - /// An object - /// Alternative custom method to reset the values. - /// Returns the original object. - public static T ResetState(this T obj, Action customReset = null) - { - if (customReset != null) - { - customReset(obj); - } - else - { - var properties = typeof(T).GetProperties(); - - foreach (var property in properties) - { - if (!property.CanWrite) - { - continue; - } - - property.SetValue(obj, null); - } - } - - return obj; - } - - /// - /// Applies all fields of a given object from it's counterpart. - /// - /// Type of the object. - /// An object. - /// An object from which we copy the values. - /// Returns the original object. - public static T ApplyState(this T obj, T other) - { - // This code is not production ready and it should be removed once - // the proper validation in Blazorise is done! - var properties = typeof(T).GetProperties(); - - foreach (var property in properties) - { - if (!property.CanWrite) - { - continue; - } - - property.SetValue(obj, typeof(T).GetProperty(property.Name).GetValue(other)); - } - - return obj; - } } } From 18a3c6271675713cd99af64247a7b9034029ca84 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Wed, 28 Oct 2020 15:34:33 +0100 Subject: [PATCH 21/25] Use stringLocalizer default formater --- .../AbpIdentityBlazorMessageLocalizerExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs index 18a6242bab..a8aa779151 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs @@ -12,7 +12,7 @@ namespace Volo.Abp.Identity.Blazor try { return arguments?.Count() > 0 - ? string.Format(stringLocalizer[format], LocalizeMessageArguments(stringLocalizer, arguments)?.ToArray()) + ? stringLocalizer[format, LocalizeMessageArguments(stringLocalizer, arguments)?.ToArray()] : stringLocalizer[format]; } catch From 26d54f693283f31f44c0ec664bc68196f19ad6c0 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Wed, 28 Oct 2020 15:35:38 +0100 Subject: [PATCH 22/25] Rename format parameter to message --- .../AbpIdentityBlazorMessageLocalizerExtensions.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs index a8aa779151..72328eb86d 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs @@ -7,17 +7,17 @@ namespace Volo.Abp.Identity.Blazor { public static class AbpIdentityBlazorMessageLocalizerExtensions { - public static string Localize(this IStringLocalizer stringLocalizer, string format, IEnumerable arguments) + public static string Localize(this IStringLocalizer stringLocalizer, string message, IEnumerable arguments) { try { return arguments?.Count() > 0 - ? stringLocalizer[format, LocalizeMessageArguments(stringLocalizer, arguments)?.ToArray()] - : stringLocalizer[format]; + ? stringLocalizer[message, LocalizeMessageArguments(stringLocalizer, arguments)?.ToArray()] + : stringLocalizer[message]; } catch { - return stringLocalizer[format]; + return stringLocalizer[message]; } } From 11c9daf11a0f0af8e9d8315bc6bc72e5a490ca9f Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Wed, 28 Oct 2020 15:37:01 +0100 Subject: [PATCH 23/25] Fix formating --- .../Pages/Identity/RoleManagement.razor | 2 +- .../Pages/Identity/UserManagement.razor | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor index ac40aca83d..97001ee6ec 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor @@ -1,5 +1,5 @@ @page "/identity/roles" -@attribute [Authorize( IdentityPermissions.Roles.Default )] +@attribute [Authorize(IdentityPermissions.Roles.Default)] @using Volo.Abp.Identity @using Microsoft.AspNetCore.Authorization @using Microsoft.Extensions.Localization diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor index 6f33181f8a..0a61fc70ab 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor @@ -1,5 +1,5 @@ @page "/identity/users" -@attribute [Authorize( IdentityPermissions.Users.Default )] +@attribute [Authorize(IdentityPermissions.Users.Default)] @using Microsoft.AspNetCore.Authorization @using Microsoft.Extensions.Localization @using Volo.Abp.Identity.Localization From 2ecee7e148648b3220d3de8d123f77efa09cb909 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Fri, 30 Oct 2020 11:38:31 +0100 Subject: [PATCH 24/25] Updated Blazorise version to 0.9.2-rc1 --- .../src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj b/framework/src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj index 1134821b78..47e8b32f00 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj +++ b/framework/src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj @@ -12,8 +12,8 @@ - - + + From c4cc529f39ddaca7f7d76fa9222e0c05b1103d24 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Fri, 30 Oct 2020 11:39:22 +0100 Subject: [PATCH 25/25] Created AbpIdentityBlazorMessageLocalizerHelper instead of extension methods --- ...bpIdentityBlazorMessageLocalizerHelper.cs} | 17 ++++++++---- .../AbpIdentityBlazorModule.cs | 2 ++ .../Pages/Identity/RoleManagement.razor | 7 ++--- .../Pages/Identity/UserManagement.razor | 27 ++++++++++--------- 4 files changed, 32 insertions(+), 21 deletions(-) rename modules/identity/src/Volo.Abp.Identity.Blazor/{AbpIdentityBlazorMessageLocalizerExtensions.cs => AbpIdentityBlazorMessageLocalizerHelper.cs} (57%) diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerHelper.cs similarity index 57% rename from modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs rename to modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerHelper.cs index 72328eb86d..5d858843b8 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerExtensions.cs +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorMessageLocalizerHelper.cs @@ -1,18 +1,25 @@ using System.Collections.Generic; using System.Linq; -using Blazorise; +using JetBrains.Annotations; using Microsoft.Extensions.Localization; namespace Volo.Abp.Identity.Blazor { - public static class AbpIdentityBlazorMessageLocalizerExtensions + public class AbpIdentityBlazorMessageLocalizerHelper { - public static string Localize(this IStringLocalizer stringLocalizer, string message, IEnumerable arguments) + private readonly IStringLocalizer stringLocalizer; + + public AbpIdentityBlazorMessageLocalizerHelper(IStringLocalizer stringLocalizer) + { + this.stringLocalizer = stringLocalizer; + } + + public string Localize(string message, [CanBeNull] IEnumerable arguments) { try { return arguments?.Count() > 0 - ? stringLocalizer[message, LocalizeMessageArguments(stringLocalizer, arguments)?.ToArray()] + ? stringLocalizer[message, LocalizeMessageArguments(arguments)?.ToArray()] : stringLocalizer[message]; } catch @@ -21,7 +28,7 @@ namespace Volo.Abp.Identity.Blazor } } - private static IEnumerable LocalizeMessageArguments(IStringLocalizer stringLocalizer, IEnumerable arguments) + private IEnumerable LocalizeMessageArguments(IEnumerable arguments) { foreach (var argument in arguments) { diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorModule.cs b/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorModule.cs index cebde068c3..7f11267132 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorModule.cs +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/AbpIdentityBlazorModule.cs @@ -32,6 +32,8 @@ namespace Volo.Abp.Identity.Blazor { options.AdditionalAssemblies.Add(typeof(AbpIdentityBlazorModule).Assembly); }); + + context.Services.AddSingleton(typeof(AbpIdentityBlazorMessageLocalizerHelper<>)); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor index 97001ee6ec..4639f81be2 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor @@ -1,5 +1,5 @@ @page "/identity/roles" -@attribute [Authorize(IdentityPermissions.Roles.Default)] +@attribute [Authorize( IdentityPermissions.Roles.Default )] @using Volo.Abp.Identity @using Microsoft.AspNetCore.Authorization @using Microsoft.Extensions.Localization @@ -7,6 +7,7 @@ @using Volo.Abp.PermissionManagement.Blazor.Components @inherits RoleManagementBase @inject IStringLocalizer L +@inject AbpIdentityBlazorMessageLocalizerHelper LH @* ************************* PAGE HEADER ************************* *@ @@ -84,7 +85,7 @@ - + @L["DisplayName:RoleName"] @@ -120,7 +121,7 @@ - + @L["DisplayName:RoleName"] diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor index 0a61fc70ab..93e0ccaa85 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor @@ -1,11 +1,12 @@ @page "/identity/users" -@attribute [Authorize(IdentityPermissions.Users.Default)] +@attribute [Authorize( IdentityPermissions.Users.Default )] @using Microsoft.AspNetCore.Authorization @using Microsoft.Extensions.Localization @using Volo.Abp.Identity.Localization @using Volo.Abp.PermissionManagement.Blazor.Components @inherits UserManagementBase @inject IStringLocalizer L +@inject AbpIdentityBlazorMessageLocalizerHelper LH @* ************************* PAGE HEADER ************************* *@ @@ -93,7 +94,7 @@ - + @L["DisplayName:UserName"] @@ -103,7 +104,7 @@ - + @L["DisplayName:Name"] @@ -113,7 +114,7 @@ - + @L["DisplayName:Surname"] @@ -123,7 +124,7 @@ - + @L["DisplayName:Password"] @@ -133,7 +134,7 @@ - + @L["DisplayName:Email"] @@ -143,7 +144,7 @@ - + @L["DisplayName:PhoneNumber"] @@ -202,7 +203,7 @@ - + @L["DisplayName:UserName"] @@ -212,7 +213,7 @@ - + @L["DisplayName:Name"] @@ -222,7 +223,7 @@ - + @L["DisplayName:Surname"] @@ -232,7 +233,7 @@ - + @L["DisplayName:Password"] @@ -242,7 +243,7 @@ - + @L["DisplayName:Email"] @@ -252,7 +253,7 @@ - + @L["DisplayName:PhoneNumber"]