Skip to content

Commit c4b6df9

Browse files
committed
#79: Tenant page is aligned with Angular UI
1 parent 8ae27e3 commit c4b6df9

File tree

10 files changed

+178
-12
lines changed

10 files changed

+178
-12
lines changed

aspnet-core/src/AbpCompanyName.AbpProjectName.Application/MultiTenancy/TenantAppService.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
namespace AbpCompanyName.AbpProjectName.MultiTenancy
1919
{
20-
[AbpAuthorize(PermissionNames.Pages_Tenants)]
2120
public class TenantAppService : AsyncCrudAppService<Tenant, TenantDto, int, PagedResultRequestDto, CreateTenantDto, TenantDto>, ITenantAppService
2221
{
2322
private readonly TenantManager _tenantManager;
@@ -45,6 +44,14 @@ IPasswordHasher<User> passwordHasher
4544
_abpZeroDbMigrator = abpZeroDbMigrator;
4645
_passwordHasher = passwordHasher;
4746
_userManager = userManager;
47+
48+
//todo@ismail: move to AbpAuthorize attribute when this is resolved https://github.com/aspnetboilerplate/aspnetboilerplate/issues/2253
49+
CreatePermissionName
50+
= GetAllPermissionName
51+
= GetPermissionName
52+
= UpdatePermissionName
53+
= DeletePermissionName
54+
= PermissionNames.Pages_Tenants;
4855
}
4956

5057
public override async Task<TenantDto> Create(CreateTenantDto input)

aspnet-core/src/AbpCompanyName.AbpProjectName.Application/Roles/RoleAppService.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
namespace AbpCompanyName.AbpProjectName.Roles
1818
{
19-
[AbpAuthorize(PermissionNames.Pages_Roles)]
2019
public class RoleAppService : AsyncCrudAppService<Role, RoleDto, int, PagedResultRequestDto, CreateRoleDto, RoleDto>, IRoleAppService
2120
{
2221
private readonly RoleManager _roleManager;
@@ -25,6 +24,13 @@ public class RoleAppService : AsyncCrudAppService<Role, RoleDto, int, PagedResul
2524
public RoleAppService(IRepository<Role> repository, RoleManager roleManager, UserManager userManager)
2625
: base(repository)
2726
{
27+
//todo@ismail: move to AbpAuthorize attribute when this is resolved https://github.com/aspnetboilerplate/aspnetboilerplate/issues/2253
28+
CreatePermissionName
29+
= GetAllPermissionName
30+
= GetPermissionName
31+
= UpdatePermissionName
32+
= DeletePermissionName = PermissionNames.Pages_Roles;
33+
2834
_roleManager = roleManager;
2935
_userManager = userManager;
3036
}

aspnet-core/src/AbpCompanyName.AbpProjectName.Application/Users/UserAppService.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
using AbpCompanyName.AbpProjectName.Users.Dto;
99
using Microsoft.AspNetCore.Identity;
1010
using System.Linq;
11-
using Abp.Authorization;
1211
using Microsoft.EntityFrameworkCore;
1312
using Abp.IdentityFramework;
1413
using AbpCompanyName.AbpProjectName.Authorization.Roles;
1514
using AbpCompanyName.AbpProjectName.Roles.Dto;
1615

1716
namespace AbpCompanyName.AbpProjectName.Users
1817
{
19-
[AbpAuthorize(PermissionNames.Pages_Users)]
2018
public class UserAppService : AsyncCrudAppService<User, UserDto, long, PagedResultRequestDto, CreateUserDto, UserDto>, IUserAppService
2119
{
2220
private readonly UserManager _userManager;
@@ -26,6 +24,13 @@ public class UserAppService : AsyncCrudAppService<User, UserDto, long, PagedResu
2624
public UserAppService(IRepository<User, long> repository, UserManager userManager, IPasswordHasher<User> passwordHasher, IRepository<Role> roleRepository)
2725
: base(repository)
2826
{
27+
//todo@ismail: move to AbpAuthorize attribute when this is resolved https://github.com/aspnetboilerplate/aspnetboilerplate/issues/2253
28+
CreatePermissionName
29+
= GetAllPermissionName
30+
= GetPermissionName
31+
= UpdatePermissionName
32+
= DeletePermissionName = PermissionNames.Pages_Users;
33+
2934
_userManager = userManager;
3035
_passwordHasher = passwordHasher;
3136
_roleRepository = roleRepository;

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Mvc/AbpCompanyName.AbpProjectName.Web.Mvc.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
<ItemGroup>
1919
<Content Include="wwwroot\view-resources\Views\Shared\_Layout.js" />
20+
<Content Include="wwwroot\view-resources\Views\Tenants\_EditTenantModal.js" />
2021
</ItemGroup>
2122

2223
<ItemGroup>

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Mvc/Controllers/TenantsController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,11 @@ public async Task<ActionResult> Index()
2323
var output = await _tenantAppService.GetAll(new PagedResultRequestDto { MaxResultCount = int.MaxValue }); //Paging not implemented yet
2424
return View(output);
2525
}
26+
27+
public async Task<ActionResult> EditTenantModal(int tenantId)
28+
{
29+
var tenantDto = await _tenantAppService.Get(new EntityDto(tenantId));
30+
return View("_EditTenantModal", tenantDto);
31+
}
2632
}
2733
}

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Mvc/Views/Tenants/Index.cshtml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
<i class="material-icons">more_vert</i>
3030
</a>
3131
<ul class="dropdown-menu pull-right">
32-
<li><a href="javascript:void(0);" class=" waves-effect waves-block">Action</a></li>
33-
<li><a href="javascript:void(0);" class=" waves-effect waves-block">Another action</a></li>
34-
<li><a href="javascript:void(0);" class=" waves-effect waves-block">Something else here</a></li>
32+
<li><a id="RefreshButton" href="javascript:void(0);" class="waves-effect waves-block"><i class="material-icons">refresh</i>Refresh</a></li>
3533
</ul>
3634
</li>
3735
</ul>
@@ -42,6 +40,7 @@
4240
<tr>
4341
<th>@L("TenancyName")</th>
4442
<th>@L("Name")</th>
43+
<th>@L("IsActive")</th>
4544
</tr>
4645
</thead>
4746
<tbody>
@@ -50,6 +49,16 @@
5049
<tr>
5150
<td>@tenant.TenancyName</td>
5251
<td>@tenant.Name</td>
52+
<td><i class="material-icons" style="color:@(tenant.IsActive ? "green":"red");">@(tenant.IsActive ? "check_box" : "indeterminate_check_box")</i></td>
53+
<td class="dropdown">
54+
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
55+
<i class="material-icons">menu</i>
56+
</a>
57+
<ul class="dropdown-menu pull-right">
58+
<li><a href="#" class="waves-effect waves-block edit-tenant" data-tenant-id="@tenant.Id" data-toggle="modal" data-target="#TenantEditModal"><i class="material-icons">edit</i>@L("Edit")</a></li>
59+
<li><a href="#" class="waves-effect waves-block delete-tenant" data-tenant-id="@tenant.Id" data-tenancy-name="@tenant.TenancyName"><i class="material-icons">delete_sweep</i>@L("Delete")</a></li>
60+
</ul>
61+
</td>
5362
</tr>
5463
}
5564
</tbody>
@@ -110,3 +119,11 @@
110119
</div>
111120
</div>
112121
</div>
122+
123+
<div class="modal fade" id="TenantEditModal" tabindex="-1" role="dialog" aria-labelledby="TenantEditModalLabel" data-backdrop="static">
124+
<div class="modal-dialog" role="document">
125+
<div class="modal-content">
126+
127+
</div>
128+
</div>
129+
</div>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@using Abp.MultiTenancy
2+
@using AbpCompanyName.AbpProjectName.MultiTenancy.Dto
3+
@using AbpCompanyName.AbpProjectName.Web.Models.Common.Modals
4+
@model TenantDto
5+
@{
6+
Layout = null;
7+
}
8+
@Html.Partial("~/Views/Shared/Modals/_ModalHeader.cshtml", new ModalHeaderViewModel(L("ChangeTenant")))
9+
10+
<div class="modal-body">
11+
<form name="TenantEditForm" role="form" novalidate class="form-validation">
12+
<input type="hidden" name="Id" value="@Model.Id"/>
13+
<div class="form-group form-float">
14+
<div class="form-line">
15+
<input class="form-control" type="text" name="TenancyName" value="@Model.TenancyName" required maxlength="64" minlength="2">
16+
<label class="form-label">@L("TenancyName")</label>
17+
</div>
18+
</div>
19+
<div class="form-group form-float">
20+
<div class="form-line">
21+
<input type="text" name="Name" class="form-control" value="@Model.Name" required maxlength="128">
22+
<label class="form-label">@L("Name")</label>
23+
</div>
24+
</div>
25+
<div class="form-group form-float">
26+
<div class="">
27+
<input id="isactive" type="checkbox" name="IsActive" value="true" @(Model.IsActive ? "checked" : "") class="form-control"/>
28+
<label for="isactive" class="form-label">@L("IsActive")</label>
29+
</div>
30+
</div>
31+
</form>
32+
</div>
33+
34+
@Html.Partial("~/Views/Shared/Modals/_ModalFooterWithSaveAndCancel.cshtml")
35+
36+
<script src="~/view-resources/Views/Tenants/_EditTenantModal.js" asp-append-version="true"></script>

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Mvc/wwwroot/view-resources/Views/Tenants/Index.js

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,38 @@
1-
(function() {
2-
$(function() {
1+
(function () {
2+
$(function () {
33

44
var _tenantService = abp.services.app.tenant;
55
var _$modal = $('#TenantCreateModal');
66
var _$form = _$modal.find('form');
77

88
_$form.validate();
99

10+
$('#RefreshButton').click(function () {
11+
document.location.reload();
12+
});
13+
14+
$('.delete-tenant').click(function () {
15+
var tenantId = $(this).attr("data-tenant-id");
16+
var tenancyName = $(this).attr('data-tenancy-name');
17+
18+
deleteTenant(tenantId, tenancyName);
19+
});
20+
21+
$('.edit-tenant').click(function (e) {
22+
var tenantId = $(this).attr("data-tenant-id");
23+
24+
e.preventDefault();
25+
$.ajax({
26+
url: abp.appPath + 'Tenants/EditTenantModal?tenantId=' + tenantId,
27+
type: 'POST',
28+
contentType: 'application/html',
29+
success: function (content) {
30+
$('#TenantEditModal div.modal-content').html(content);
31+
},
32+
error: function (e) { }
33+
});
34+
});
35+
1036
_$form.find('button[type="submit"]').click(function (e) {
1137
e.preventDefault();
1238

@@ -20,13 +46,32 @@
2046
_tenantService.create(tenant).done(function () {
2147
_$modal.modal('hide');
2248
location.reload(true); //reload page to see new tenant!
23-
}).always(function() {
49+
}).always(function () {
2450
abp.ui.clearBusy(_$modal);
2551
});
2652
});
27-
53+
2854
_$modal.on('shown.bs.modal', function () {
2955
_$modal.find('input:not([type=hidden]):first').focus();
3056
});
57+
58+
function refreshTenantsList() {
59+
location.reload(true); //reload page to see new tenant!
60+
}
61+
62+
function deleteTenant(tenantId, tenancyName) {
63+
abp.message.confirm(
64+
"Delete tenant '" + tenancyName + "'?",
65+
function (isConfirmed) {
66+
if (isConfirmed) {
67+
_tenantService.delete({
68+
id: tenantId
69+
}).done(function () {
70+
refreshTenantsList();
71+
});
72+
}
73+
}
74+
);
75+
}
3176
});
3277
})();

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Mvc/wwwroot/view-resources/Views/Tenants/Index.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
(function ($) {
2+
3+
var _tenantService = abp.services.app.tenant;
4+
var _$modal = $('#TenantEditModal');
5+
var _$form = $('form[name=TenantEditForm]');
6+
7+
function save() {
8+
9+
if (!_$form.valid()) {
10+
return;
11+
}
12+
13+
var tenant = _$form.serializeFormToObject(); //serializeFormToObject is defined in main.js
14+
15+
abp.ui.setBusy(_$form);
16+
_tenantService.update(tenant).done(function () {
17+
_$modal.modal('hide');
18+
location.reload(true); //reload page to see edited tenant!
19+
}).always(function () {
20+
abp.ui.clearBusy(_$modal);
21+
});
22+
}
23+
24+
//Handle save button click
25+
_$form.closest('div.modal-content').find(".save-button").click(function (e) {
26+
e.preventDefault();
27+
save();
28+
});
29+
30+
//Handle enter key
31+
_$form.find('input').on('keypress', function (e) {
32+
if (e.which === 13) {
33+
e.preventDefault();
34+
save();
35+
}
36+
});
37+
38+
$.AdminBSB.input.activate(_$form);
39+
40+
$('#TenantChangeModal').on('shown.bs.modal', function () {
41+
_$form.find('input[type=text]:first').focus();
42+
});
43+
})(jQuery);

0 commit comments

Comments
 (0)