Browse Source

Introduce BlazorisePageBase

pull/5399/head
Halil İbrahim Kalkan 6 years ago
parent
commit
904dd25bd0
  1. 1
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo.Abp.AspNetCore.Components.WebAssembly.csproj
  2. 4
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/AbpAspNetCoreComponentsWebAssemblyModule.cs
  3. 180
      framework/src/Volo.Abp.BlazoriseUI/Volo/Abp/BlazoriseUI/BlazorisePageBase.cs
  4. 4
      framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json
  5. 4
      framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json
  6. 131
      modules/identity/src/Volo.Abp.Identity.Blazor/Pages/AbpPageBase.cs
  7. 33
      modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor
  8. 122
      modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs

1
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo.Abp.AspNetCore.Components.WebAssembly.csproj

@ -16,6 +16,7 @@
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.AspNetCore.Mvc.Client.Common\Volo.Abp.AspNetCore.Mvc.Client.Common.csproj" />
<ProjectReference Include="..\Volo.Abp.UI\Volo.Abp.UI.csproj" />
</ItemGroup>
<ItemGroup>

4
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/AbpAspNetCoreComponentsWebAssemblyModule.cs

@ -1,10 +1,12 @@
using Volo.Abp.AspNetCore.Mvc.Client;
using Volo.Abp.Modularity;
using Volo.Abp.UI;
namespace Volo.Abp.AspNetCore.Components.WebAssembly
{
[DependsOn(
typeof(AbpAspNetCoreMvcClientCommonModule)
typeof(AbpAspNetCoreMvcClientCommonModule),
typeof(AbpUiModule)
)]
public class AbpAspNetCoreComponentsWebAssemblyModule : AbpModule
{

180
framework/src/Volo.Abp.BlazoriseUI/Volo/Abp/BlazoriseUI/BlazorisePageBase.cs

@ -0,0 +1,180 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Blazorise;
using Blazorise.DataGrid;
using Localization.Resources.AbpUi;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.AspNetCore.Components.WebAssembly;
using Volo.Abp.ObjectMapping;
namespace Volo.Abp.BlazoriseUI
{
public abstract class BlazorisePageBase<
TAppService,
TEntityDto,
TKey,
TGetListInput,
TCreateInput,
TUpdateInput>
: OwningComponentBase
where TAppService : ICrudAppService<TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
where TEntityDto : IEntityDto<TKey>
where TCreateInput : new()
where TUpdateInput : new()
where TGetListInput : PagedAndSortedResultRequestDto, new()
{
[Inject] protected TAppService AppService { get; set; }
[Inject] protected IUiMessageService UiMessageService { get; set; }
[Inject] protected IStringLocalizer<AbpUiResource> UiLocalizer { get; set; }
protected int CurrentPage;
protected string CurrentSorting;
protected int? TotalCount;
protected IReadOnlyList<TEntityDto> Entities;
protected TCreateInput NewEntity;
protected TKey EditingEntityId;
protected TUpdateInput EditingEntity;
protected Modal CreateModal;
protected Modal EditModal;
protected Type ObjectMapperContext { get; set; }
protected IObjectMapper ObjectMapper
{
get
{
if (_objectMapper != null)
{
return _objectMapper;
}
if (ObjectMapperContext == null)
{
return LazyGetRequiredService(ref _objectMapper);
}
return LazyGetRequiredService(
typeof(IObjectMapper<>).MakeGenericType(ObjectMapperContext),
ref _objectMapper
);
}
}
private IObjectMapper _objectMapper;
protected TService LazyGetRequiredService<TService>(ref TService reference)
=> LazyGetRequiredService(typeof(TService), ref reference);
protected TRef LazyGetRequiredService<TRef>(Type serviceType, ref TRef reference)
{
if (reference == null)
{
reference = (TRef) ScopedServices.GetRequiredService(serviceType);
}
return reference;
}
protected BlazorisePageBase()
{
NewEntity = new TCreateInput();
EditingEntity = new TUpdateInput();
}
protected override async Task OnInitializedAsync()
{
await GetEntitiesAsync();
}
protected virtual async Task GetEntitiesAsync()
{
var result = await AppService.GetListAsync(
new TGetListInput
{
SkipCount = CurrentPage * LimitedResultRequestDto.DefaultMaxResultCount,
MaxResultCount = LimitedResultRequestDto.DefaultMaxResultCount,
Sorting = CurrentSorting
});
Entities = result.Items;
TotalCount = (int?) result.TotalCount;
}
protected virtual async Task OnDataGridReadAsync(DataGridReadDataEventArgs<TEntityDto> e)
{
CurrentSorting = e.Columns
.Where(c => c.Direction != SortDirection.None)
.Select(c => c.Field + (c.Direction == SortDirection.Descending ? " DESC" : ""))
.JoinAsString(",");
CurrentPage = e.Page - 1;
await GetEntitiesAsync();
StateHasChanged();
}
protected virtual void OpenCreateModal()
{
NewEntity = new TCreateInput();
CreateModal.Show();
}
protected virtual void CloseCreateModal()
{
CreateModal.Hide();
}
protected virtual async Task OpenEditModalAsync(TKey id)
{
var entityDto = await AppService.GetAsync(id);
EditingEntityId = id;
EditingEntity = ObjectMapper.Map<TEntityDto, TUpdateInput>(entityDto);
EditModal.Show();
}
protected virtual void CloseEditModal()
{
EditModal.Hide();
}
protected virtual async Task CreateEntityAsync()
{
await AppService.CreateAsync(NewEntity);
await GetEntitiesAsync();
CreateModal.Hide();
}
protected virtual async Task UpdateEntityAsync()
{
await AppService.UpdateAsync(EditingEntityId, EditingEntity);
await GetEntitiesAsync();
EditModal.Hide();
}
protected virtual async Task DeleteEntityAsync(TEntityDto entity)
{
if (!await UiMessageService.ConfirmAsync(GetDeleteConfirmationMessage(entity)))
{
return;
}
await AppService.DeleteAsync(entity.Id);
await GetEntitiesAsync();
}
protected virtual string GetDeleteConfirmationMessage(TEntityDto entity)
{
return UiLocalizer["ItemWillBeDeletedMessage"];
}
}
}

4
framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json

@ -62,6 +62,8 @@
"500Message": "Internal Server Error",
"GoHomePage": "Go to the homepage",
"GoBack": "Go back",
"Search": "Search"
"Search": "Search",
"ItemWillBeDeletedMessageWithFormat": "{0} will be deleted!",
"ItemWillBeDeletedMessage": "This item will be deleted!"
}
}

4
framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json

@ -62,6 +62,8 @@
"500Message": "Sunucu tarafında hata",
"GoHomePage": "Ana sayfaya git",
"GoBack": "Geri dön",
"Search": "Arama"
"Search": "Arama",
"ItemWillBeDeletedMessageWithFormat": "{0} silinecektir!",
"ItemWillBeDeletedMessage": "Bu nesne silinecektir!"
}
}

131
modules/identity/src/Volo.Abp.Identity.Blazor/Pages/AbpPageBase.cs

@ -1,131 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Blazorise;
using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.ObjectMapping;
namespace Volo.Abp.Identity.Blazor.Pages
{
public abstract class AbpPageBase<
TAppService,
TEntityDto,
TKey,
TGetListInput,
TCreateInput,
TUpdateInput>
: ComponentBase
where TAppService : ICrudAppService<TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
where TEntityDto : IEntityDto<TKey>
where TCreateInput : new()
where TUpdateInput : new()
where TGetListInput : PagedAndSortedResultRequestDto, new()
{
[Inject] protected TAppService AppService { get; set; }
[Inject] protected IObjectMapper<AbpIdentityBlazorModule> ObjectMapper { get; set; }
protected int _currentPage;
protected string _currentSorting;
protected int? _totalCount;
protected IReadOnlyList<TEntityDto> _roles;
protected TCreateInput _newRole;
protected TKey _editingRoleId;
protected TUpdateInput _editingRole;
protected Modal _createModal;
protected Modal _editModal;
protected AbpPageBase()
{
_newRole = new TCreateInput();
_editingRole = new TUpdateInput();
}
protected override async Task OnInitializedAsync()
{
await GetRolesAsync();
}
protected async Task GetRolesAsync()
{
var result = await AppService.GetListAsync(
new TGetListInput
{
SkipCount = _currentPage * LimitedResultRequestDto.DefaultMaxResultCount,
MaxResultCount = LimitedResultRequestDto.DefaultMaxResultCount,
Sorting = _currentSorting
});
_roles = result.Items;
_totalCount = (int?)result.TotalCount;
}
protected async Task OnDataGridReadAsync(DataGridReadDataEventArgs<TEntityDto> e)
{
_currentSorting = e.Columns
.Where(c => c.Direction != SortDirection.None)
.Select(c => c.Field + (c.Direction == SortDirection.Descending ? " DESC" : ""))
.JoinAsString(",");
_currentPage = e.Page - 1;
await GetRolesAsync();
StateHasChanged();
}
protected void OpenCreateModal()
{
_newRole = new TCreateInput();
_createModal.Show();
}
protected void CloseCreateModal()
{
_createModal.Hide();
}
protected async Task OpenEditModalAsync(TKey id)
{
var role = await AppService.GetAsync(id);
_editingRoleId = id;
_editingRole = ObjectMapper.Map<TEntityDto, TUpdateInput>(role);
_editModal.Show();
}
protected void CloseEditModal()
{
_editModal.Hide();
}
protected async Task CreateRoleAsync()
{
await AppService.CreateAsync(_newRole);
await GetRolesAsync();
_createModal.Hide();
}
protected async Task UpdateRoleAsync()
{
await AppService.UpdateAsync(_editingRoleId, _editingRole);
await GetRolesAsync();
_editModal.Hide();
}
protected async Task DeleteRoleAsync(TEntityDto role)
{
//if (!await UiMessageService.ConfirmAsync(L["RoleDeletionConfirmationMessage", role.Name]))
//{
// return;
//}
await AppService.DeleteAsync(role.Id);
await GetRolesAsync();
}
}
}

33
modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor

@ -6,6 +6,7 @@
@using Volo.Abp.Application.Dtos
@using Volo.Abp.Identity.Localization
@using Volo.Abp.PermissionManagement.Blazor.Components
@inherits BlazorisePageBase<IIdentityRoleAppService,IdentityRoleDto, Guid, PagedAndSortedResultRequestDto, IdentityRoleCreateDto, IdentityRoleUpdateDto>
@inject IStringLocalizer<IdentityResource> L
@* ************************* PAGE HEADER ************************* *@
<Row>
@ -21,9 +22,9 @@
@* ************************* DATA GRID ************************* *@
<DataGrid TItem="IdentityRoleDto"
Data="_roles"
Data="Entities"
ReadData="OnDataGridReadAsync"
TotalItems="_totalCount"
TotalItems="TotalCount"
ShowPager="true"
PageSize="@LimitedResultRequestDto.DefaultMaxResultCount">
<DataGridColumns>
@ -35,9 +36,9 @@
</DropdownToggle>
<DropdownMenu>
<DropdownItem Clicked="() => OpenEditModalAsync(context.As<IdentityRoleDto>().Id)">@L["Edit"]</DropdownItem>
<DropdownItem Clicked="() => _permissionManagementModal.OpenAsync(PermissionProviderName,context.As<IdentityRoleDto>().Name)">@L["Permissions"]</DropdownItem>
<DropdownItem Clicked="() => PermissionManagementModal.OpenAsync(PermissionProviderName,context.As<IdentityRoleDto>().Name)">@L["Permissions"]</DropdownItem>
<DropdownDivider/>
<DropdownItem Clicked="() => DeleteRoleAsync(context.As<IdentityRoleDto>())">@L["Delete"]</DropdownItem>
<DropdownItem Clicked="() => DeleteEntityAsync(context.As<IdentityRoleDto>())">@L["Delete"]</DropdownItem>
</DropdownMenu>
</Dropdown>
</DisplayTemplate>
@ -59,7 +60,7 @@
</DataGrid>
@* ************************* CREATE MODAL ************************* *@
<Modal @ref="_createModal">
<Modal @ref="CreateModal">
<ModalBackdrop />
<ModalContent IsCentered="true">
<ModalHeader>
@ -69,22 +70,22 @@
<ModalBody>
<Field>
<FieldLabel>@L["DisplayName:RoleName"]</FieldLabel>
<TextEdit @bind-text="_newRole.Name" />
<TextEdit @bind-text="NewEntity.Name" />
</Field>
<Field>
<Check TValue="bool" @bind-checked="_newRole.IsDefault">@L["DisplayName:IsDefault"]</Check>
<Check TValue="bool" @bind-checked="_newRole.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>
</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseCreateModal">@L["Cancel"]</Button>
<Button Color="Color.Primary" Clicked="CreateRoleAsync">@L["Save"]</Button>
<Button Color="Color.Primary" Clicked="CreateEntityAsync">@L["Save"]</Button>
</ModalFooter>
</ModalContent>
</Modal>
@* ************************* EDIT MODAL ************************* *@
<Modal @ref="_editModal">
<Modal @ref="EditModal">
<ModalBackdrop />
<ModalContent IsCentered="true">
<ModalHeader>
@ -92,21 +93,21 @@
<CloseButton Clicked="CloseEditModal" />
</ModalHeader>
<ModalBody>
<input type="hidden" name="ConcurrencyStamp" @bind-value="_editingRole.ConcurrencyStamp" />
<input type="hidden" name="ConcurrencyStamp" @bind-value="EditingEntity.ConcurrencyStamp" />
<Field>
<FieldLabel>@L["DisplayName:RoleName"]</FieldLabel>
<TextEdit @bind-text="_editingRole.Name" />
<TextEdit @bind-text="EditingEntity.Name" />
</Field>
<Field>
<Check TValue="bool" @bind-checked="_editingRole.IsDefault">@L["DisplayName:IsDefault"]</Check>
<Check TValue="bool" @bind-checked="_editingRole.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>
</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" Clicked="CloseEditModal">@L["Cancel"]</Button>
<Button Color="Color.Primary" Clicked="UpdateRoleAsync">@L["Save"]</Button>
<Button Color="Color.Primary" Clicked="UpdateEntityAsync">@L["Save"]</Button>
</ModalFooter>
</ModalContent>
</Modal>
<PermissionManagementModal @ref="_permissionManagementModal"/>
<PermissionManagementModal @ref="PermissionManagementModal"/>

122
modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs

@ -1,15 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Blazorise;
using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Components.WebAssembly;
using Volo.Abp.ObjectMapping;
using Volo.Abp.PermissionManagement.Blazor.Components;
using Volo.Abp.PermissionManagement.Blazor.Components;
namespace Volo.Abp.Identity.Blazor.Pages.Identity
{
@ -17,114 +6,11 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
{
private const string PermissionProviderName = "R";
[Inject] private IIdentityRoleAppService RoleAppService { get; set; }
[Inject] private IUiMessageService UiMessageService { get; set; }
[Inject] private IObjectMapper<AbpIdentityBlazorModule> ObjectMapper { get; set; }
private int _currentPage;
private string _currentSorting;
private int? _totalCount;
private IReadOnlyList<IdentityRoleDto> _roles;
private IdentityRoleCreateDto _newRole; //TODO: Would be better to create a UI model class
private Guid _editingRoleId;
private IdentityRoleUpdateDto _editingRole; //TODO: Would be better to create a UI model class
private Modal _createModal;
private Modal _editModal;
private PermissionManagementModal _permissionManagementModal;
private PermissionManagementModal PermissionManagementModal;
public RoleManagement()
{
_newRole = new IdentityRoleCreateDto(); //TODO: Can we discard this (create on modal opening)?
_editingRole = new IdentityRoleUpdateDto(); //TODO: Can we discard this (create on modal opening)?
}
protected override async Task OnInitializedAsync()
{
await GetRolesAsync();
}
private async Task GetRolesAsync()
{
var result = await RoleAppService.GetListAsync(
new PagedAndSortedResultRequestDto
{
SkipCount = _currentPage * LimitedResultRequestDto.DefaultMaxResultCount,
MaxResultCount = LimitedResultRequestDto.DefaultMaxResultCount,
Sorting = _currentSorting
});
_roles = result.Items;
_totalCount = (int?)result.TotalCount;
}
private async Task OnDataGridReadAsync(DataGridReadDataEventArgs<IdentityRoleDto> e)
{
_currentSorting = e.Columns
.Where(c => c.Direction != SortDirection.None)
.Select(c => c.Field + (c.Direction == SortDirection.Descending ? " DESC" : ""))
.JoinAsString(",");
_currentPage = e.Page - 1;
await GetRolesAsync();
StateHasChanged();
}
private void OpenCreateModal()
{
_newRole = new IdentityRoleCreateDto();
_createModal.Show();
}
private void CloseCreateModal()
{
_createModal.Hide();
}
private async Task OpenEditModalAsync(Guid id)
{
var role = await RoleAppService.GetAsync(id);
_editingRoleId = id;
_editingRole = ObjectMapper.Map<IdentityRoleDto, IdentityRoleUpdateDto>(role);
_editModal.Show();
}
private void CloseEditModal()
{
_editModal.Hide();
}
private async Task CreateRoleAsync()
{
await RoleAppService.CreateAsync(_newRole);
await GetRolesAsync();
_createModal.Hide();
}
private async Task UpdateRoleAsync()
{
await RoleAppService.UpdateAsync(_editingRoleId, _editingRole);
await GetRolesAsync();
_editModal.Hide();
}
private async Task DeleteRoleAsync(IdentityRoleDto role)
{
if (!await UiMessageService.ConfirmAsync(L["RoleDeletionConfirmationMessage", role.Name]))
{
return;
}
await RoleAppService.DeleteAsync(role.Id);
await GetRolesAsync();
}
ObjectMapperContext = typeof(AbpIdentityBlazorModule);
}
}
}

Loading…
Cancel
Save