Merge pull request #5883 from abpframework/dev-client-validation

Blazor client-side validation
pull/5994/head^2
Halil İbrahim Kalkan 5 years ago committed by GitHub
commit 6fe15952f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -186,6 +186,8 @@ namespace Volo.Abp.BlazoriseUI
protected TUpdateViewModel EditingEntity;
protected Modal CreateModal;
protected Modal EditModal;
protected Validations CreateValidationsRef;
protected Validations EditValidationsRef;
protected List<BreadcrumbItem> BreadcrumbItems = new List<BreadcrumbItem>(2);
protected string CreatePolicyName { get; set; }
@ -279,12 +281,26 @@ namespace Volo.Abp.BlazoriseUI
protected virtual async Task OpenCreateModalAsync()
{
await OnOpeningCreateModalAsync();
CreateValidationsRef.ClearAll();
await CheckCreatePolicyAsync();
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();
}
protected virtual Task OnOpeningCreateModalAsync()
{
return Task.CompletedTask;
}
protected virtual Task CloseCreateModalAsync()
{
CreateModal.Hide();
@ -293,14 +309,27 @@ 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;
EditingEntity = MapToEditingEntity(entityDto);
await InvokeAsync(() => StateHasChanged());
EditModal.Show();
}
protected virtual Task OnOpeningEditModalAsync(TKey id)
{
return Task.CompletedTask;
}
protected virtual TUpdateViewModel MapToEditingEntity(TGetOutputDto entityDto)
{
return ObjectMapper.Map<TGetOutputDto, TUpdateViewModel>(entityDto);
@ -334,20 +363,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)

@ -12,8 +12,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Blazorise" Version="0.9.2-preview9" />
<PackageReference Include="Blazorise.DataGrid" Version="0.9.2-preview9" />
<PackageReference Include="Blazorise" Version="0.9.2-rc1" />
<PackageReference Include="Blazorise.DataGrid" Version="0.9.2-rc1" />
</ItemGroup>
</Project>

@ -2,6 +2,7 @@
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Reflection;
namespace System
{

@ -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

@ -0,0 +1,41 @@
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Microsoft.Extensions.Localization;
namespace Volo.Abp.Identity.Blazor
{
public class AbpIdentityBlazorMessageLocalizerHelper<T>
{
private readonly IStringLocalizer<T> stringLocalizer;
public AbpIdentityBlazorMessageLocalizerHelper(IStringLocalizer<T> stringLocalizer)
{
this.stringLocalizer = stringLocalizer;
}
public string Localize(string message, [CanBeNull] IEnumerable<string> arguments)
{
try
{
return arguments?.Count() > 0
? stringLocalizer[message, LocalizeMessageArguments(arguments)?.ToArray()]
: stringLocalizer[message];
}
catch
{
return stringLocalizer[message];
}
}
private IEnumerable<string> LocalizeMessageArguments(IEnumerable<string> arguments)
{
foreach (var argument in arguments)
{
yield return stringLocalizer[$"DisplayName:{argument}"]
?? stringLocalizer[argument]
?? argument;
}
}
}
}

@ -32,6 +32,8 @@ namespace Volo.Abp.Identity.Blazor
{
options.AdditionalAssemblies.Add(typeof(AbpIdentityBlazorModule).Assembly);
});
context.Services.AddSingleton(typeof(AbpIdentityBlazorMessageLocalizerHelper<>));
}
}
}

@ -1,17 +1,20 @@
@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
@using Volo.Abp.Identity.Localization
@using Volo.Abp.PermissionManagement.Blazor.Components
@inherits RoleManagementBase
@inject IStringLocalizer<IdentityResource> L
@inject AbpIdentityBlazorMessageLocalizerHelper<IdentityResource> LH
@* ************************* PAGE HEADER ************************* *@
<Row>
<Column ColumnSize="ColumnSize.Is6">
<h1>@L["Roles"]</h1>
<Heading Size="HeadingSize.Is1">@L["Roles"]</Heading>
</Column>
<Column ColumnSize="ColumnSize.Is6">
@if (HasCreatePermission)
@if ( HasCreatePermission )
{
<Paragraph Alignment="TextAlignment.Right">
<Button Color="Color.Primary" Clicked="OpenCreateModalAsync">@L["NewRole"]</Button>
@ -28,7 +31,7 @@
ShowPager="true"
PageSize="PageSize">
<DataGridColumns>
@if (ShouldShowEntityActions)
@if ( ShouldShowEntityActions )
{
<DataGridColumn Width="150px" TItem="IdentityRoleDto" Field="@nameof(IdentityRoleDto.Name)" Sortable="false" Caption="@L["Actions"].Value">
<DisplayTemplate>
@ -37,15 +40,15 @@
@L["Actions"]
</DropdownToggle>
<DropdownMenu>
@if (HasUpdatePermission)
@if ( HasUpdatePermission )
{
<DropdownItem Clicked="() => OpenEditModalAsync(context.As<IdentityRoleDto>().Id)">@L["Edit"]</DropdownItem>
}
@if (HasManagePermissionsPermission)
@if ( HasManagePermissionsPermission )
{
<DropdownItem Clicked="() => PermissionManagementModal.OpenAsync(PermissionProviderName, context.As<IdentityRoleDto>().Name)">@L["Permissions"]</DropdownItem>
}
@if (HasDeletePermission)
@if ( HasDeletePermission )
{
<DropdownItem Clicked="() => DeleteEntityAsync(context.As<IdentityRoleDto>())">@L["Delete"]</DropdownItem>
}
@ -57,11 +60,11 @@
<DataGridColumn TItem="IdentityRoleDto" Field="@nameof(IdentityRoleDto.Name)" Caption="@L["RoleName"].Value">
<DisplayTemplate>
@(context.As<IdentityRoleDto>().Name)
@if (context.As<IdentityRoleDto>().IsDefault)
@if ( context.As<IdentityRoleDto>().IsDefault )
{
<Badge Color="Color.Primary">@L["DisplayName:IsDefault"]</Badge>
}
@if (context.As<IdentityRoleDto>().IsPublic)
@if ( context.As<IdentityRoleDto>().IsPublic )
{
<Badge Color="Color.Light">@L["DisplayName:IsPublic"]</Badge>
}
@ -71,56 +74,68 @@
</DataGrid>
@* ************************* CREATE MODAL ************************* *@
@if (HasCreatePermission)
@if ( HasCreatePermission )
{
<Modal @ref="CreateModal">
<ModalBackdrop />
<ModalContent IsCentered="true">
<ModalContent Centered="true">
<ModalHeader>
<ModalTitle>@L["NewRole"]</ModalTitle>
<CloseButton Clicked="CloseCreateModalAsync" />
</ModalHeader>
<ModalBody>
<EditForm id="IdentityRoleCreateForm" Model="@NewEntity" OnValidSubmit="CreateEntityAsync">
<Field>
<FieldLabel>@L["DisplayName:RoleName"]</FieldLabel>
<TextEdit @bind-text="@NewEntity.Name"/>
</Field>
<Validations @ref="@CreateValidationsRef" Model="@NewEntity" ValidateOnLoad="false">
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:RoleName"]</FieldLabel>
<TextEdit @bind-Text="@NewEntity.Name">
<Feedback>
<ValidationError />
</Feedback>
</TextEdit>
</Field>
</Validation>
<Field>
<Check TValue="bool" @bind-checked="@NewEntity.IsDefault">@L["DisplayName:IsDefault"]</Check>
<Check TValue="bool" @bind-checked="@NewEntity.IsPublic">@L["DisplayName:IsPublic"]</Check>
<Check TValue="bool" @bind-Checked="@NewEntity.IsDefault">@L["DisplayName:IsDefault"]</Check>
<Check TValue="bool" @bind-Checked="@NewEntity.IsPublic">@L["DisplayName:IsPublic"]</Check>
</Field>
</EditForm>
</Validations>
</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseCreateModalAsync">@L["Cancel"]</Button>
<Button form="IdentityRoleCreateForm" Color="Color.Primary" Clicked="CreateEntityAsync">@L["Save"]</Button>
<Button Color="Color.Primary" Clicked="CreateEntityAsync">@L["Save"]</Button>
</ModalFooter>
</ModalContent>
</Modal>
}
@* ************************* EDIT MODAL ************************* *@
@if (HasUpdatePermission)
@if ( HasUpdatePermission )
{
<Modal @ref="EditModal">
<ModalBackdrop />
<ModalContent IsCentered="true">
<ModalContent Centered="true">
<ModalHeader>
<ModalTitle>@L["Edit"]</ModalTitle>
<CloseButton Clicked="CloseEditModalAsync" />
</ModalHeader>
<ModalBody>
<EditForm id="IdentityRoleEditForm" Model="@EditingEntity" OnValidSubmit="UpdateEntityAsync">
<Validations @ref="@EditValidationsRef" Model="@EditingEntity" ValidateOnLoad="false">
<input type="hidden" name="ConcurrencyStamp" @bind-value="EditingEntity.ConcurrencyStamp" />
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:RoleName"]</FieldLabel>
<TextEdit @bind-Text="EditingEntity.Name">
<Feedback>
<ValidationError />
</Feedback>
</TextEdit>
</Field>
</Validation>
<Field>
<FieldLabel>@L["DisplayName:RoleName"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.Name" />
</Field>
<Field>
<Check TValue="bool" @bind-checked="@EditingEntity.IsDefault">@L["DisplayName:IsDefault"]</Check>
<Check TValue="bool" @bind-checked="@EditingEntity.IsPublic">@L["DisplayName:IsPublic"]</Check>
<Check TValue="bool" @bind-Checked="@EditingEntity.IsDefault">@L["DisplayName:IsDefault"]</Check>
<Check TValue="bool" @bind-Checked="@EditingEntity.IsPublic">@L["DisplayName:IsPublic"]</Check>
</Field>
</EditForm>
</Validations>
</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseEditModalAsync">@L["Cancel"]</Button>
@ -130,4 +145,4 @@
</Modal>
}
<PermissionManagementModal @ref="PermissionManagementModal"/>
<PermissionManagementModal @ref="PermissionManagementModal" />

@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using Blazorise;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.BlazoriseUI;
using Volo.Abp.Identity.Localization;

@ -1,16 +1,19 @@
@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<IdentityResource> L
@inject AbpIdentityBlazorMessageLocalizerHelper<IdentityResource> LH
@* ************************* PAGE HEADER ************************* *@
<Row>
<Column ColumnSize="ColumnSize.Is6">
<h1>@L["Users"]</h1>
</Column>
<Column ColumnSize="ColumnSize.Is6">
@if (HasCreatePermission)
@if ( HasCreatePermission )
{
<Paragraph Alignment="TextAlignment.Right">
<Button Color="Color.Primary" Clicked="OpenCreateModalAsync">@L["NewUser"]</Button>
@ -27,7 +30,7 @@
ShowPager="true"
PageSize="PageSize">
<DataGridColumns>
@if (ShouldShowEntityActions)
@if ( ShouldShowEntityActions )
{
<DataGridColumn Width="150px" TItem="IdentityUserDto" Field="@nameof(IdentityUserDto.UserName)" Sortable="false" Caption="@L["Actions"].Value">
<DisplayTemplate>
@ -36,17 +39,17 @@
@L["Actions"]
</DropdownToggle>
<DropdownMenu>
@if (HasUpdatePermission)
@if ( HasUpdatePermission )
{
<DropdownItem Clicked="() => OpenEditModalAsync(context.As<IdentityUserDto>().Id)">@L["Edit"]</DropdownItem>
}
@if (HasManagePermissionsPermission)
@if ( HasManagePermissionsPermission )
{
<DropdownItem Clicked="() => PermissionManagementModal.OpenAsync(PermissionProviderName, context.As<IdentityUserDto>().Id.ToString())">@L["Permissions"]</DropdownItem>
}
@if (HasDeletePermission)
@if ( HasDeletePermission )
{
<DropdownDivider/>
<DropdownDivider />
<DropdownItem Clicked="() => DeleteEntityAsync(context.As<IdentityUserDto>())">@L["Delete"]</DropdownItem>
}
</DropdownMenu>
@ -73,17 +76,17 @@
</DataGrid>
@* ************************* CREATE MODAL ************************* *@
@if (HasCreatePermission)
@if ( HasCreatePermission )
{
<Modal @ref="CreateModal">
<ModalBackdrop/>
<ModalContent IsCentered="true">
<ModalBackdrop />
<ModalContent Centered="true">
<ModalHeader>
<ModalTitle>@L["NewUser"]</ModalTitle>
<CloseButton Clicked="CloseCreateModalAsync"/>
<CloseButton Clicked="CloseCreateModalAsync" />
</ModalHeader>
<ModalBody>
<EditForm id="IdentityUserCreateForm" Model="@NewEntity" OnValidSubmit="CreateEntityAsync">
<Validations @ref="@CreateValidationsRef" Model="@NewEntity" ValidateOnLoad="false">
<Tabs @bind-SelectedTab="@CreateModalSelectedTab">
<Items>
<Tab Name="UserInformations">@L["UserInformations"]</Tab>
@ -91,71 +94,107 @@
</Items>
<Content>
<TabPanel Name="UserInformations">
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:UserName"]</FieldLabel>
<TextEdit @bind-Text="NewEntity.UserName">
<Feedback>
<ValidationError />
</Feedback>
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:Name"]</FieldLabel>
<TextEdit @bind-Text="NewEntity.Name">
<Feedback>
<ValidationError />
</Feedback>
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:Surname"]</FieldLabel>
<TextEdit @bind-Text="NewEntity.Surname">
<Feedback>
<ValidationError />
</Feedback>
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:Password"]</FieldLabel>
<TextEdit Role="TextRole.Password" @bind-Text="NewEntity.Password">
<Feedback>
<ValidationError />
</Feedback>
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:Email"]</FieldLabel>
<TextEdit @bind-Text="NewEntity.Email">
<Feedback>
<ValidationError />
</Feedback>
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:PhoneNumber"]</FieldLabel>
<TextEdit @bind-Text="NewEntity.PhoneNumber">
<Feedback>
<ValidationError />
</Feedback>
</TextEdit>
</Field>
</Validation>
<Field>
<FieldLabel>@L["DisplayName:UserName"]</FieldLabel>
<TextEdit @bind-text="NewEntity.UserName"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:Name"]</FieldLabel>
<TextEdit @bind-text="NewEntity.Name"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:Surname"]</FieldLabel>
<TextEdit @bind-text="NewEntity.Surname"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:Password"]</FieldLabel>
<TextEdit Role="TextRole.Password" @bind-text="NewEntity.Password"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:Email"]</FieldLabel>
<TextEdit @bind-text="NewEntity.Email"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:PhoneNumber"]</FieldLabel>
<TextEdit @bind-text="NewEntity.PhoneNumber"/>
</Field>
<Field>
<Check TValue="bool" @bind-checked="@NewEntity.LockoutEnabled">@L["DisplayName:LockoutEnabled"]</Check>
<Check TValue="bool" @bind-Checked="@NewEntity.LockoutEnabled">@L["DisplayName:LockoutEnabled"]</Check>
</Field>
</TabPanel>
<TabPanel Name="Roles">
@if (NewUserRoles != null)
@if ( NewUserRoles != null )
{
@foreach (var role in NewUserRoles)
@foreach ( var role in NewUserRoles )
{
<Field>
<input type="hidden" @bind-value="@role.Name"/>
<Check TValue="bool" @bind-checked="@role.IsAssigned">@role.Name</Check>
<input type="hidden" @bind-value="@role.Name" />
<Check TValue="bool" @bind-Checked="@role.IsAssigned">@role.Name</Check>
</Field>
}
}
</TabPanel>
</Content>
</Tabs>
</EditForm>
</Validations>
</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseCreateModalAsync">@L["Cancel"]</Button>
<Button form="IdentityUserCreateForm" Color="Color.Primary" Clicked="CreateEntityAsync">@L["Save"]</Button>
<Button Color="Color.Primary" Clicked="CreateEntityAsync">@L["Save"]</Button>
</ModalFooter>
</ModalContent>
</Modal>
}
@* ************************* EDIT MODAL ************************* *@
@if (HasUpdatePermission)
@if ( HasUpdatePermission )
{
<Modal @ref="EditModal">
<ModalBackdrop/>
<ModalContent IsCentered="true">
<ModalBackdrop />
<ModalContent Centered="true">
<ModalHeader>
<ModalTitle>@L["Edit"]</ModalTitle>
<CloseButton Clicked="CloseEditModalAsync"/>
<CloseButton Clicked="CloseEditModalAsync" />
</ModalHeader>
<ModalBody>
<EditForm id="IdentityUserEditForm" Model="@EditingEntity" OnValidSubmit="UpdateEntityAsync">
<input type="hidden" name="ConcurrencyStamp" @bind-value="EditingEntity.ConcurrencyStamp"/>
<Validations @ref="@EditValidationsRef" Model="@NewEntity" ValidateOnLoad="false">
<input type="hidden" name="ConcurrencyStamp" @bind-value="EditingEntity.ConcurrencyStamp" />
<Tabs @bind-SelectedTab="@EditModalSelectedTab">
<Items>
@ -164,56 +203,92 @@
</Items>
<Content>
<TabPanel Name="UserInformations">
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:UserName"]</FieldLabel>
<TextEdit @bind-Text="EditingEntity.UserName">
<Feedback>
<ValidationError />
</Feedback>
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:Name"]</FieldLabel>
<TextEdit @bind-Text="EditingEntity.Name">
<Feedback>
<ValidationError />
</Feedback>
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:Surname"]</FieldLabel>
<TextEdit @bind-Text="EditingEntity.Surname">
<Feedback>
<ValidationError />
</Feedback>
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:Password"]</FieldLabel>
<TextEdit Role="TextRole.Password" @bind-Text="EditingEntity.Password">
<Feedback>
<ValidationError />
</Feedback>
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:Email"]</FieldLabel>
<TextEdit @bind-Text="EditingEntity.Email">
<Feedback>
<ValidationError />
</Feedback>
</TextEdit>
</Field>
</Validation>
<Validation MessageLocalizer="@LH.Localize">
<Field>
<FieldLabel>@L["DisplayName:PhoneNumber"]</FieldLabel>
<TextEdit @bind-Text="EditingEntity.PhoneNumber">
<Feedback>
<ValidationError />
</Feedback>
</TextEdit>
</Field>
</Validation>
<Field>
<FieldLabel>@L["DisplayName:UserName"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.UserName"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:Name"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.Name"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:Surname"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.Surname"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:Password"]</FieldLabel>
<TextEdit Role="TextRole.Password" @bind-text="EditingEntity.Password"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:Email"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.Email"/>
</Field>
<Field>
<FieldLabel>@L["DisplayName:PhoneNumber"]</FieldLabel>
<TextEdit @bind-text="EditingEntity.PhoneNumber"/>
</Field>
<Field>
<Check TValue="bool" @bind-checked="EditingEntity.LockoutEnabled">@L["DisplayName:LockoutEnabled"]</Check>
<Check TValue="bool" @bind-Checked="EditingEntity.LockoutEnabled">@L["DisplayName:LockoutEnabled"]</Check>
</Field>
</TabPanel>
<TabPanel Name="Roles">
@if (EditUserRoles != null)
@if ( EditUserRoles != null )
{
@foreach (var role in EditUserRoles)
@foreach ( var role in EditUserRoles )
{
<Field>
<input type="hidden" @bind-value="@role.Name"/>
<Check TValue="bool" @bind-checked="@role.IsAssigned">@role.Name</Check>
<input type="hidden" @bind-value="@role.Name" />
<Check TValue="bool" @bind-Checked="@role.IsAssigned">@role.Name</Check>
</Field>
}
}
</TabPanel>
</Content>
</Tabs>
</EditForm>
</Validations>
</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseEditModalAsync">@L["Cancel"]</Button>
<Button form="IdentityUserEditForm" Color="Color.Primary" Clicked="UpdateEntityAsync">@L["Save"]</Button>
<Button Color="Color.Primary" Clicked="UpdateEntityAsync">@L["Save"]</Button>
</ModalFooter>
</ModalContent>
</Modal>
}
<PermissionManagementModal @ref="PermissionManagementModal"/>
<PermissionManagementModal @ref="PermissionManagementModal" />

@ -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.Identity.Localization;
@ -60,46 +61,48 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
HasManagePermissionsPermission;
}
protected override Task OpenCreateModalAsync()
protected override async Task OnOpeningCreateModalAsync()
{
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();
await base.OnOpeningCreateModalAsync();
}
protected override Task CreateEntityAsync()
protected override Task OnCreatingEntityAsync()
{
// apply roles before saving
NewEntity.RoleNames = NewUserRoles.Where(x => x.IsAssigned).Select(x => x.Name).ToArray();
return base.CreateEntityAsync();
return base.OnCreatingEntityAsync();
}
protected override async Task OpenEditModalAsync(Guid id)
protected override async Task OnOpeningEditModalAsync(Guid id)
{
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);
await base.OnOpeningEditModalAsync(id);
}
protected override Task UpdateEntityAsync()
protected override Task OnUpdatingEntityAsync()
{
// apply roles before saving
EditingEntity.RoleNames = EditUserRoles.Where(x => x.IsAssigned).Select(x => x.Name).ToArray();
return base.UpdateEntityAsync();
return base.OnUpdatingEntityAsync();
}
}

@ -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;

Loading…
Cancel
Save