mirror of https://github.com/abpframework/abp.git
24 changed files with 96 additions and 465 deletions
@ -1 +0,0 @@ |
|||
export * from './rest.actions'; |
|||
@ -1,6 +0,0 @@ |
|||
import { HttpErrorResponse } from '@angular/common/http'; |
|||
|
|||
export class RestOccurError { |
|||
static readonly type = '[Rest] Error'; |
|||
constructor(public payload: HttpErrorResponse | any) {} |
|||
} |
|||
@ -1,64 +0,0 @@ |
|||
import { Identity } from '../models/identity'; |
|||
import { ABP, PagedAndSortedResultRequestDto } from '@abp/ng.core'; |
|||
import { |
|||
GetIdentityUsersInput, |
|||
IdentityRoleCreateDto, |
|||
IdentityRoleUpdateDto, |
|||
IdentityUserCreateDto, |
|||
IdentityUserUpdateDto, |
|||
} from '../proxy/identity/models'; |
|||
|
|||
export class GetRoles { |
|||
static readonly type = '[Identity] Get Roles'; |
|||
constructor(public payload?: PagedAndSortedResultRequestDto) {} |
|||
} |
|||
|
|||
export class GetRoleById { |
|||
static readonly type = '[Identity] Get Role By Id'; |
|||
constructor(public payload: string) {} |
|||
} |
|||
|
|||
export class DeleteRole { |
|||
static readonly type = '[Identity] Delete Role'; |
|||
constructor(public payload: string) {} |
|||
} |
|||
|
|||
export class CreateRole { |
|||
static readonly type = '[Identity] Create Role'; |
|||
constructor(public payload: IdentityRoleCreateDto) {} |
|||
} |
|||
|
|||
export class UpdateRole { |
|||
static readonly type = '[Identity] Update Role'; |
|||
constructor(public payload: IdentityRoleUpdateDto & { id: string }) {} |
|||
} |
|||
|
|||
export class GetUsers { |
|||
static readonly type = '[Identity] Get Users'; |
|||
constructor(public payload?: GetIdentityUsersInput) {} |
|||
} |
|||
|
|||
export class GetUserById { |
|||
static readonly type = '[Identity] Get User By Id'; |
|||
constructor(public payload: string) {} |
|||
} |
|||
|
|||
export class DeleteUser { |
|||
static readonly type = '[Identity] Delete User'; |
|||
constructor(public payload: string) {} |
|||
} |
|||
|
|||
export class CreateUser { |
|||
static readonly type = '[Identity] Create User'; |
|||
constructor(public payload: IdentityUserCreateDto) {} |
|||
} |
|||
|
|||
export class UpdateUser { |
|||
static readonly type = '[Identity] Update User'; |
|||
constructor(public payload: IdentityUserUpdateDto & { id: string }) {} |
|||
} |
|||
|
|||
export class GetUserRoles { |
|||
static readonly type = '[Identity] Get User Roles'; |
|||
constructor(public payload: string) {} |
|||
} |
|||
@ -1 +0,0 @@ |
|||
export * from './identity.actions'; |
|||
@ -1,12 +0,0 @@ |
|||
import { PagedResultDto } from '@abp/ng.core'; |
|||
import { IdentityRoleDto, IdentityUserDto } from '../proxy/identity/models'; |
|||
|
|||
export namespace Identity { |
|||
export interface State { |
|||
roles: PagedResultDto<IdentityRoleDto>; |
|||
users: PagedResultDto<IdentityUserDto>; |
|||
selectedRole: IdentityRoleDto; |
|||
selectedUser: IdentityUserDto; |
|||
selectedUserRoles: IdentityRoleDto[]; |
|||
} |
|||
} |
|||
@ -1,82 +0,0 @@ |
|||
import { ABP } from '@abp/ng.core'; |
|||
import { Injectable } from '@angular/core'; |
|||
import { Store } from '@ngxs/store'; |
|||
import { |
|||
CreateRole, |
|||
CreateUser, |
|||
DeleteRole, |
|||
DeleteUser, |
|||
GetRoleById, |
|||
GetRoles, |
|||
GetUserById, |
|||
GetUsers, |
|||
UpdateRole, |
|||
UpdateUser, |
|||
GetUserRoles, |
|||
} from '../actions/identity.actions'; |
|||
import { Identity } from '../models/identity'; |
|||
import { IdentityState } from '../states/identity.state'; |
|||
|
|||
@Injectable({ |
|||
providedIn: 'root', |
|||
}) |
|||
export class IdentityStateService { |
|||
constructor(private store: Store) {} |
|||
|
|||
getRoles() { |
|||
return this.store.selectSnapshot(IdentityState.getRoles); |
|||
} |
|||
getRolesTotalCount() { |
|||
return this.store.selectSnapshot(IdentityState.getRolesTotalCount); |
|||
} |
|||
getUsers() { |
|||
return this.store.selectSnapshot(IdentityState.getUsers); |
|||
} |
|||
getUsersTotalCount() { |
|||
return this.store.selectSnapshot(IdentityState.getUsersTotalCount); |
|||
} |
|||
|
|||
dispatchGetRoles(...args: ConstructorParameters<typeof GetRoles>) { |
|||
return this.store.dispatch(new GetRoles(...args)); |
|||
} |
|||
|
|||
dispatchGetRoleById(...args: ConstructorParameters<typeof GetRoleById>) { |
|||
return this.store.dispatch(new GetRoleById(...args)); |
|||
} |
|||
|
|||
dispatchDeleteRole(...args: ConstructorParameters<typeof DeleteRole>) { |
|||
return this.store.dispatch(new DeleteRole(...args)); |
|||
} |
|||
|
|||
dispatchCreateRole(...args: ConstructorParameters<typeof CreateRole>) { |
|||
return this.store.dispatch(new CreateRole(...args)); |
|||
} |
|||
|
|||
dispatchUpdateRole(...args: ConstructorParameters<typeof UpdateRole>) { |
|||
return this.store.dispatch(new UpdateRole(...args)); |
|||
} |
|||
|
|||
dispatchGetUsers(...args: ConstructorParameters<typeof GetUsers>) { |
|||
return this.store.dispatch(new GetUsers(...args)); |
|||
} |
|||
|
|||
dispatchGetUserById(...args: ConstructorParameters<typeof GetUserById>) { |
|||
return this.store.dispatch(new GetUserById(...args)); |
|||
} |
|||
|
|||
dispatchDeleteUser(...args: ConstructorParameters<typeof DeleteUser>) { |
|||
return this.store.dispatch(new DeleteUser(...args)); |
|||
} |
|||
|
|||
dispatchCreateUser(...args: ConstructorParameters<typeof CreateUser>) { |
|||
return this.store.dispatch(new CreateUser(...args)); |
|||
} |
|||
|
|||
dispatchUpdateUser(...args: ConstructorParameters<typeof UpdateUser>) { |
|||
return this.store.dispatch(new UpdateUser(...args)); |
|||
} |
|||
|
|||
dispatchGetUserRoles(...args: ConstructorParameters<typeof GetUserRoles>) { |
|||
return this.store.dispatch(new GetUserRoles(...args)); |
|||
} |
|||
} |
|||
@ -1 +0,0 @@ |
|||
export * from './identity-state.service'; |
|||
@ -1,138 +0,0 @@ |
|||
import { Injectable } from '@angular/core'; |
|||
import { Action, Selector, State, StateContext } from '@ngxs/store'; |
|||
import { pluck, tap } from 'rxjs/operators'; |
|||
import { |
|||
CreateRole, |
|||
CreateUser, |
|||
DeleteRole, |
|||
DeleteUser, |
|||
GetRoleById, |
|||
GetRoles, |
|||
GetUserById, |
|||
GetUserRoles, |
|||
GetUsers, |
|||
UpdateRole, |
|||
UpdateUser, |
|||
} from '../actions/identity.actions'; |
|||
import { Identity } from '../models/identity'; |
|||
import { IdentityRoleService } from '../proxy/identity/identity-role.service'; |
|||
import { IdentityUserService } from '../proxy/identity/identity-user.service'; |
|||
import { IdentityRoleDto, IdentityUserDto } from '../proxy/identity/models'; |
|||
|
|||
@State<Identity.State>({ |
|||
name: 'IdentityState', |
|||
defaults: { roles: {}, selectedRole: {}, users: {}, selectedUser: {} } as Identity.State, |
|||
}) |
|||
@Injectable() |
|||
export class IdentityState { |
|||
@Selector() |
|||
static getRoles({ roles }: Identity.State): IdentityRoleDto[] { |
|||
return roles.items || []; |
|||
} |
|||
|
|||
@Selector() |
|||
static getRolesTotalCount({ roles }: Identity.State): number { |
|||
return roles.totalCount || 0; |
|||
} |
|||
|
|||
@Selector() |
|||
static getUsers({ users }: Identity.State): IdentityUserDto[] { |
|||
return users.items || []; |
|||
} |
|||
|
|||
@Selector() |
|||
static getUsersTotalCount({ users }: Identity.State): number { |
|||
return users.totalCount || 0; |
|||
} |
|||
|
|||
constructor( |
|||
private identityUserService: IdentityUserService, |
|||
private identityRoleService: IdentityRoleService, |
|||
) {} |
|||
|
|||
@Action(GetRoles) |
|||
getRoles({ patchState }: StateContext<Identity.State>, { payload }: GetRoles) { |
|||
return this.identityRoleService.getList(payload).pipe( |
|||
tap(roles => |
|||
patchState({ |
|||
roles, |
|||
}), |
|||
), |
|||
); |
|||
} |
|||
|
|||
@Action(GetRoleById) |
|||
getRole({ patchState }: StateContext<Identity.State>, { payload }: GetRoleById) { |
|||
return this.identityRoleService.get(payload).pipe( |
|||
tap(selectedRole => |
|||
patchState({ |
|||
selectedRole, |
|||
}), |
|||
), |
|||
); |
|||
} |
|||
|
|||
@Action(DeleteRole) |
|||
deleteRole(_, { payload }: GetRoleById) { |
|||
return this.identityRoleService.delete(payload); |
|||
} |
|||
|
|||
@Action(CreateRole) |
|||
addRole(_, { payload }: CreateRole) { |
|||
return this.identityRoleService.create(payload); |
|||
} |
|||
|
|||
@Action(UpdateRole) |
|||
updateRole({ getState }: StateContext<Identity.State>, { payload }: UpdateRole) { |
|||
return this.identityRoleService.update(payload.id, { ...getState().selectedRole, ...payload }); |
|||
} |
|||
|
|||
@Action(GetUsers) |
|||
getUsers({ patchState }: StateContext<Identity.State>, { payload }: GetUsers) { |
|||
return this.identityUserService.getList(payload).pipe( |
|||
tap(users => |
|||
patchState({ |
|||
users, |
|||
}), |
|||
), |
|||
); |
|||
} |
|||
|
|||
@Action(GetUserById) |
|||
getUser({ patchState }: StateContext<Identity.State>, { payload }: GetUserById) { |
|||
return this.identityUserService.get(payload).pipe( |
|||
tap(selectedUser => |
|||
patchState({ |
|||
selectedUser, |
|||
}), |
|||
), |
|||
); |
|||
} |
|||
|
|||
@Action(DeleteUser) |
|||
deleteUser(_, { payload }: GetUserById) { |
|||
return this.identityUserService.delete(payload); |
|||
} |
|||
|
|||
@Action(CreateUser) |
|||
addUser(_, { payload }: CreateUser) { |
|||
return this.identityUserService.create(payload); |
|||
} |
|||
|
|||
@Action(UpdateUser) |
|||
updateUser({ getState }: StateContext<Identity.State>, { payload }: UpdateUser) { |
|||
return this.identityUserService.update(payload.id, { ...getState().selectedUser, ...payload }); |
|||
} |
|||
|
|||
@Action(GetUserRoles) |
|||
getUserRoles({ patchState }: StateContext<Identity.State>, { payload }: GetUserRoles) { |
|||
return this.identityUserService.getRoles(payload).pipe( |
|||
pluck('items'), |
|||
tap(selectedUserRoles => |
|||
patchState({ |
|||
selectedUserRoles, |
|||
}), |
|||
), |
|||
); |
|||
} |
|||
} |
|||
@ -1 +0,0 @@ |
|||
export * from './identity.state'; |
|||
Loading…
Reference in new issue