Skip to content

Commit

Permalink
Merge pull request #367 from personball/dev
Browse files Browse the repository at this point in the history
update sample code in vue template and add more localization text
  • Loading branch information
alirizaadiyahsi committed Dec 17, 2018
2 parents 1c63b77 + e8507a3 commit 671b97c
Show file tree
Hide file tree
Showing 14 changed files with 167 additions and 193 deletions.
@@ -0,0 +1,12 @@
using Abp.Application.Services.Dto;

namespace AbpCompanyName.AbpProjectName.MultiTenancy.Dto
{
public class PagedTenantResultRequestDto : PagedResultRequestDto
{
public string TenancyName { get; set; }
public string Name { get; set; }
public bool? IsActive { get; set; }
}
}

Expand Up @@ -4,7 +4,8 @@

namespace AbpCompanyName.AbpProjectName.MultiTenancy
{
public interface ITenantAppService : IAsyncCrudAppService<TenantDto, int, PagedResultRequestDto, CreateTenantDto, TenantDto>
public interface ITenantAppService : IAsyncCrudAppService<TenantDto, int, PagedTenantResultRequestDto, CreateTenantDto, TenantDto>
{
}
}

@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Abp.Application.Services;
Expand All @@ -14,11 +14,12 @@
using AbpCompanyName.AbpProjectName.Authorization.Users;
using AbpCompanyName.AbpProjectName.Editions;
using AbpCompanyName.AbpProjectName.MultiTenancy.Dto;
using Abp.Linq.Extensions;

namespace AbpCompanyName.AbpProjectName.MultiTenancy
{
[AbpAuthorize(PermissionNames.Pages_Tenants)]
public class TenantAppService : AsyncCrudAppService<Tenant, TenantDto, int, PagedResultRequestDto, CreateTenantDto, TenantDto>, ITenantAppService
public class TenantAppService : AsyncCrudAppService<Tenant, TenantDto, int, PagedTenantResultRequestDto, CreateTenantDto, TenantDto>, ITenantAppService
{
private readonly TenantManager _tenantManager;
private readonly EditionManager _editionManager;
Expand All @@ -28,23 +29,23 @@ public class TenantAppService : AsyncCrudAppService<Tenant, TenantDto, int, Page
private readonly IPasswordHasher<User> _passwordHasher;

public TenantAppService(
IRepository<Tenant, int> repository,
TenantManager tenantManager,
IRepository<Tenant, int> repository,
TenantManager tenantManager,
EditionManager editionManager,
UserManager userManager,
RoleManager roleManager,
IAbpZeroDbMigrator abpZeroDbMigrator,
IPasswordHasher<User> passwordHasher)
UserManager userManager,
RoleManager roleManager,
IAbpZeroDbMigrator abpZeroDbMigrator,
IPasswordHasher<User> passwordHasher)
: base(repository)
{
_tenantManager = tenantManager;
_tenantManager = tenantManager;
_editionManager = editionManager;
_userManager = userManager;
_roleManager = roleManager;
_abpZeroDbMigrator = abpZeroDbMigrator;
_passwordHasher = passwordHasher;
}

public override async Task<TenantDto> Create(CreateTenantDto input)
{
CheckCreatePermission();
Expand Down Expand Up @@ -93,6 +94,14 @@ public override async Task<TenantDto> Create(CreateTenantDto input)
return MapToEntityDto(tenant);
}

protected override IQueryable<Tenant> CreateFilteredQuery(PagedTenantResultRequestDto input)
{
return Repository.GetAll()
.WhereIf(!input.TenancyName.IsNullOrWhiteSpace(), x => x.TenancyName.Contains(input.TenancyName))
.WhereIf(!input.Name.IsNullOrWhiteSpace(), x => x.Name.Contains(input.Name))
.WhereIf(input.IsActive.HasValue, x => x.IsActive == input.IsActive);
}

protected override void MapToEntity(TenantDto updateInput, Tenant entity)
{
// Manually mapped since TenantDto contains non-editable properties too.
Expand All @@ -115,3 +124,4 @@ private void CheckErrors(IdentityResult identityResult)
}
}
}

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
using Abp.Application.Services.Dto;

namespace AbpCompanyName.AbpProjectName.Roles.Dto
{
public class PagedRoleResultRequestDto : PagedResultRequestDto
{
public string RoleName { get; set; }
public string DisplayName { get; set; }
public string Description { get; set; }
}
}

Expand Up @@ -5,12 +5,12 @@

namespace AbpCompanyName.AbpProjectName.Roles
{
public interface IRoleAppService : IAsyncCrudAppService<RoleDto, int, PagedResultRequestDto, CreateRoleDto, RoleDto>
public interface IRoleAppService : IAsyncCrudAppService<RoleDto, int, PagedRoleResultRequestDto, CreateRoleDto, RoleDto>
{
Task<ListResultDto<PermissionDto>> GetAllPermissions();

Task<GetRoleForEditOutput> GetRoleForEdit(EntityDto input);

Task<ListResultDto<RoleListDto>> GetRolesAsync(GetRolesInput input);
}
}
}
Expand Up @@ -18,7 +18,7 @@
namespace AbpCompanyName.AbpProjectName.Roles
{
[AbpAuthorize(PermissionNames.Pages_Roles)]
public class RoleAppService : AsyncCrudAppService<Role, RoleDto, int, PagedResultRequestDto, CreateRoleDto, RoleDto>, IRoleAppService
public class RoleAppService : AsyncCrudAppService<Role, RoleDto, int, PagedRoleResultRequestDto, CreateRoleDto, RoleDto>, IRoleAppService
{
private readonly RoleManager _roleManager;
private readonly UserManager _userManager;
Expand Down Expand Up @@ -106,17 +106,20 @@ public Task<ListResultDto<PermissionDto>> GetAllPermissions()
));
}

protected override IQueryable<Role> CreateFilteredQuery(PagedResultRequestDto input)
protected override IQueryable<Role> CreateFilteredQuery(PagedRoleResultRequestDto input)
{
return Repository.GetAllIncluding(x => x.Permissions);
return Repository.GetAllIncluding(x => x.Permissions)
.WhereIf(!input.RoleName.IsNullOrWhiteSpace(), x => x.Name.Contains(input.RoleName))
.WhereIf(!input.DisplayName.IsNullOrWhiteSpace(), x => x.DisplayName.Contains(input.DisplayName))
.WhereIf(!input.Description.IsNullOrWhiteSpace(), x => x.Description.Contains(input.Description));
}

protected override async Task<Role> GetEntityByIdAsync(int id)
{
return await Repository.GetAllIncluding(x => x.Permissions).FirstOrDefaultAsync(x => x.Id == id);
}

protected override IQueryable<Role> ApplySorting(IQueryable<Role> query, PagedResultRequestDto input)
protected override IQueryable<Role> ApplySorting(IQueryable<Role> query, PagedRoleResultRequestDto input)
{
return query.OrderBy(r => r.DisplayName);
}
Expand All @@ -142,3 +145,4 @@ public async Task<GetRoleForEditOutput> GetRoleForEdit(EntityDto input)
}
}
}

@@ -1,23 +1,23 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Authorization;
using Abp.Domain.Entities;
using Abp.Domain.Repositories;
using Abp.Extensions;
using Abp.IdentityFramework;
using Abp.Linq.Extensions;
using Abp.Localization;
using Abp.Runtime.Session;
using AbpCompanyName.AbpProjectName.Authorization;
using AbpCompanyName.AbpProjectName.Authorization.Roles;
using AbpCompanyName.AbpProjectName.Authorization.Users;
using AbpCompanyName.AbpProjectName.Roles.Dto;
using AbpCompanyName.AbpProjectName.Users.Dto;
using Abp.Linq.Extensions;
using Abp.Extensions;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;

namespace AbpCompanyName.AbpProjectName.Users
{
Expand Down Expand Up @@ -128,11 +128,10 @@ protected override UserDto MapToEntityDto(User user)

protected override IQueryable<User> CreateFilteredQuery(PagedUserResultRequestDto input)
{
return
Repository.GetAllIncluding(x => x.Roles)
return Repository.GetAllIncluding(x => x.Roles)
.WhereIf(!input.UserName.IsNullOrWhiteSpace(), x => x.UserName.Contains(input.UserName))
.WhereIf(!input.Name.IsNullOrWhiteSpace(), x => x.Name.Contains(input.Name))
.WhereIf(input.IsActive.HasValue, x => x.IsActive)
.WhereIf(input.IsActive.HasValue, x => x.IsActive == input.IsActive)
.WhereIf(input.From.HasValue, x => x.CreationTime >= input.From.Value.LocalDateTime)
.WhereIf(input.To.HasValue, x => x.CreationTime <= input.To.Value.LocalDateTime);
}
Expand Down Expand Up @@ -160,3 +159,4 @@ protected virtual void CheckErrors(IdentityResult identityResult)
}
}
}

Expand Up @@ -4,35 +4,29 @@
<text name="HomePage" value="主页" />
<text name="About" value="关于我们" />
<text name="WelcomeMessage" value="欢迎使用 AbpProjectName!" />

<text name="FormIsNotValidMessage" value="部分输入信息不符合要求,请检查并改正.." />
<text name="TenantNameCanNotBeEmpty" value="租户名不能为空" />

<text name="InvalidUserNameOrPassword" value="用户名或密码无效" />
<text name="ThereIsNoTenantDefinedWithName{0}" value="租户 {0}不存在" />
<text name="TenantIsNotActive" value="租户 {0} 未激活." />
<text name="UserIsNotActiveAndCanNotLogin" value="用户 {0} 未激活,不能登录." />
<text name="PleaseEnterLoginInformation" value="请输入登录信息" />
<text name="TenancyName" value="租户名称" />
<text name="TenancyName" value="租户标识" />
<text name="UserNameOrEmail" value="用户名或邮箱地址" />
<text name="Password" value="密码" />
<text name="RememberMe" value="记住我" />
<text name="LogIn" value="登录" />

<text name="LoginFailed" value="登录失败!" />

<text name="AppName" >AbpProjectName</text>
<text name="UserNamePlaceholder" >请输入账户</text>
<text name="PasswordPlaceholder" >请输入密码</text>
<text name="CopyRight" >© 2018 AbpProjectName</text>
<text name="LoginPrompt" >正在登陆,请稍候!</text>

<text name="UserProfile" >用户资料</text>
<text name="Users" >用户</text>
<text name="Roles" >角色</text>
<text name="Tenants" >租户</text>
<text name="Logout" >注销</text>

<text name="ManageMenu" >菜单</text>
<text name="LabelOptions" >页签操作</text>
<text name="ClearAll" >关闭所有</text>
Expand All @@ -52,17 +46,14 @@
<text name="DeleteConfirm">确定删除?</text>
<text name="Title" >标题</text>
<text name="Content" >内容</text>

<text name="ChangePassword" >修改密码</text>

<text name="PasswordComplexityNotSatisfied">密码复杂度要求不符.</text>
<text name="PasswordRequireDigit">密码至少需要一位是0到9的数字.</text>
<text name="PasswordRequireLowercase">密码至少需要一位是a到z的小写字母.</text>
<text name="PasswordRequireNonAlphanumeric">密码至少需要包含一个特殊字符(非字母或数字的字符).</text>
<text name="PasswordRequireUppercase">密码至少需要一位是A到Z的大写字母.</text>
<text name="PasswordTooShort">密码长度太短</text>

<text name="UserName">用户名</text>
<text name="UserName">用户名</text>
<text name="Name">名称</text>
<text name="IsActive">是否启用</text>
<text name="LastLoginTime">最近登陆时间</text>
Expand All @@ -77,5 +68,33 @@

<text name="Yes">是</text>
<text name="No">否</text>

<text name="Cancel">取消</text>
<text name="OK">确定</text>
<text name="CreateNewRole">创建新角色</text>
<text name="RoleDetails">角色详情</text>
<text name="RolePermission">角色权限</text>
<text name="EditRole">编辑角色</text>
<text name="DeleteRolesConfirm">确认删除该角色?</text>

<text name="CreateNewUser">创建新用户</text>
<text name="UserDetails">用户详情</text>
<text name="UserRoles">用户角色</text>
<text name="ConfirmPassword">确认密码</text>
<text name="EmailAddress">邮箱地址</text>
<text name="Surname">姓</text>
<text name="DeleteUserConfirm">确认删除该用户?</text>
<text name="EditUser">编辑用户</text>

<text name="CreateNewTenant">创建新租户</text>
<text name="DatabaseConnectionString">数据库连接</text>
<text name="AdminEmailAddress">管理员邮箱地址</text>
<text name="DefaultPasswordIs">默认密码为:{0}</text>
<text name="DeleteTenantConfirm">确认删除该租户?</text>
<text name="EditTenant">编辑租户</text>


</texts>
</localizationDictionary>


88 changes: 0 additions & 88 deletions vue/src/lib/util.ts
Expand Up @@ -9,94 +9,6 @@ class Util{
script.src=url;
document.body.appendChild(script);
}
buildFilters(filters:Filter[]){
console.warn('SQL Injection warning.');
let fileswhere:string[]=[];
filters.forEach(f=>{
let where='';
if(f.Type===FieldType.Number){
where=this.buildNumber(f);
}else if(f.Type===FieldType.String){
where=this.buildString(f);
}else if(f.Type===FieldType.Boolean){
where=this.buildBoolean(f);
}else if(f.Type===FieldType.DataRange||f.Type===FieldType.Date){
where=this.buildDate(f);
}else if(f.Type===FieldType.Enum){
where=this.buildEnum(f);
}
if(where){
fileswhere.push(where);
}

})
return fileswhere.join(' AND ');
}
private buildDate(filter:Filter){
if(filter.Type===FieldType.Date){
if(!!filter.Value){
let compare=this.caseCompare(filter.CompareType);
let date=new Date(filter.Value);
return `${filter.FieldName}${compare} DateTime(${date.getFullYear()},${date.getMonth()+1},${date.getDate()})`;
}else{
return ''
}
}else if(filter.Type===FieldType.DataRange){
if(!!filter.Value){
let dates=filter.Value as Array<Date>;
if(dates.length!==2){
throw 'Dates format is error';
}else if(dates[0]&&dates[1]){
return `(${filter.FieldName}>= DateTime(${dates[0].getFullYear()},${dates[0].getMonth()+1},${dates[0].getDate()}) AND ${filter.FieldName}<= DateTime(${dates[1].getFullYear()},${dates[1].getMonth()+1},${dates[1].getDate()}))`;
}else{
return ''
}
}else{
return ''
}
}else{
return ''
}
}
private buildEnum(filter:Filter){
let compare=this.caseCompare(filter.CompareType);
return `${filter.FieldName}${compare}"${filter.Value}"`;
}
private buildBoolean(filter:Filter){
if(filter.Value==null){
return ''
}else if(filter.Value){
return `${filter.FieldName}=true`
}else if(!filter.Value){
return `${filter.FieldName}=false`
}else{
return ''
}
}
private buildString(filter:Filter){
if(!filter.Value){
return ''
}
let compare=this.caseCompare(filter.CompareType);
return `${filter.FieldName}${compare}("${filter.Value}")`
}
private buildNumber(filter:Filter){
let compare=this.caseCompare(filter.CompareType);
return `${filter.FieldName}${compare}${filter.Value}`
}
private caseCompare(compareType:CompareType){
switch(compareType){
case CompareType.Greater:return '>';
case CompareType.Less:return '<';
case CompareType.Equal:return '=';
case CompareType.GreaterOrEqual:return '>=';
case CompareType.LessOrEqual:return '<=';
case CompareType.Contains:return '.Contains';
case CompareType.StartWith:return '.StartWith';
case CompareType.EndWith:return '.EndWith';
case CompareType.NotEqual:return '!=';
}
}
title(title:string){
let appname=this.abp.localization.localize('AppName',appconst.localization.defaultLocalizationSourceName);
let page=this.abp.localization.localize(title,appconst.localization.defaultLocalizationSourceName);
Expand Down

0 comments on commit 671b97c

Please sign in to comment.