Skip to content

Commit

Permalink
#2014 added general admin actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Patraboi committed Mar 19, 2023
1 parent f1434af commit f2696e7
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 110 deletions.
28 changes: 27 additions & 1 deletion src/app/shared/store/admin.actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HttpErrorResponse } from '@angular/common/http';
import { AdminTabTypes } from '../enum/admins';
import { BaseAdmin, BaseAdminBlockData, BaseAdminParameters } from 'shared/models/admin.model';
import { AdminRoles, AdminTabTypes } from '../enum/admins';
import { Direction, DirectionParameters } from '../models/category.model';
import { ChildrenParameters } from '../models/child.model';
import { FilterData } from '../models/history-log.model';
Expand Down Expand Up @@ -170,11 +171,26 @@ export class GetAllMinistryAdmins {
constructor(public parameters?: MinistryAdminParameters) {}
}

export class GetAllAdmins {
static readonly type = '[admin] Get All Admins';
constructor(public adminType: AdminRoles, public parameters?: BaseAdminParameters) {}
}

export class GetAdminById {
static readonly type = '[admin] Get Admin By Id';
constructor(public payload: string, public adminType: AdminRoles) {}
}

export class GetMinistryAdminById {
static readonly type = '[admin] Get Ministry Admin By Id';
constructor(public payload: string) {}
}

export class DeleteAdminById {
static readonly type = '[admin] delete Admin';
constructor(public payload: string, public adminType: AdminRoles) {}
}

export class DeleteMinistryAdminById {
static readonly type = '[admin] delete Ministry Admin';
constructor(public payload: string) {}
Expand Down Expand Up @@ -215,6 +231,11 @@ export class OnDeleteRegionAdminFail {
constructor(public payload: HttpErrorResponse) {}
}

export class BlockAdminById {
static readonly type = '[admin] block Admin';
constructor(public payload: BaseAdminBlockData, public adminType: AdminRoles) {}
}

export class BlockMinistryAdminById {
static readonly type = '[admin] block Ministry Admin';
constructor(public payload: MinistryAdminBlockData) {}
Expand All @@ -235,6 +256,11 @@ export class OnBlockFail {
constructor(public payload: HttpErrorResponse) {}
}

export class UpdateAdmin {
static readonly type = '[admin] update Admin';
constructor(public payload: BaseAdmin, public adminType: AdminRoles) {}
}

export class UpdateMinistryAdmin {
static readonly type = '[admin] update Ministry Admin';
constructor(public payload: MinistryAdmin) {}
Expand Down
105 changes: 90 additions & 15 deletions src/app/shared/store/admin.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ import { ProviderService } from '../services/provider/provider.service';
import { Router } from '@angular/router';
import { Location } from '@angular/common';
import {
BlockAdminById,
BlockMinistryAdminById,
BlockProviderById,
BlockRegionAdminById,
CreateDirection,
CreateMinistryAdmin,
CreateRegionAdmin,
DeleteAdminById,
DeleteDirectionById,
DeleteMinistryAdminById,
DeleteRegionAdminById,
DownloadStatisticReport,
GetAboutPortal,
GetAdminById,
GetAllAdmins,
GetAllMinistryAdmins,
GetAllRegionAdmins,
GetApplicationHistory,
Expand Down Expand Up @@ -75,7 +79,7 @@ import { MinistryAdmin } from '../models/ministryAdmin.model';
import { MinistryAdminService } from '../services/ministry-admin/ministry-admin.service';
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
import { ApplicationHistory, ProviderAdminHistory, ProviderHistory } from '../models/history-log.model';
import { EMPTY_RESULT, PaginationConstants } from '../constants/constants';
import { EMPTY_RESULT } from '../constants/constants';
import { HistoryLogService } from '../services/history-log/history-log.service';
import { SearchResponse } from '../models/search.model';
import { GetMainPageInfo } from './main-page.actions';
Expand All @@ -101,8 +105,7 @@ export interface AdminStateModel {
providers: SearchResponse<Provider[]>;
selectedAdmin: BaseAdmin;
selectedRegionAdmin: RegionAdmin;
ministryAdmins: SearchResponse<MinistryAdmin[]>;
regionAdmins: SearchResponse<RegionAdmin[]>;
admins: SearchResponse<BaseAdmin[]>;
providerHistory: SearchResponse<ProviderHistory[]>;
providerAdminHistory: SearchResponse<ProviderAdminHistory[]>;
applicationHistory: SearchResponse<ApplicationHistory[]>;
Expand All @@ -125,8 +128,7 @@ export interface AdminStateModel {
parents: null,
selectedAdmin: null,
selectedRegionAdmin: null,
ministryAdmins: null,
regionAdmins: null,
admins: null,
providerHistory: null,
providerAdminHistory: null,
applicationHistory: null,
Expand All @@ -148,12 +150,8 @@ export class AdminState {
return state.providers;
}

@Selector() static ministryAdmins(state: AdminStateModel): SearchResponse<MinistryAdmin[]> {
return state.ministryAdmins;
}

@Selector() static regionAdmins(state: AdminStateModel): SearchResponse<RegionAdmin[]> {
return state.regionAdmins;
@Selector() static admins(state: AdminStateModel): SearchResponse<BaseAdmin[]> {
return state.admins;
}

@Selector() static selectedAdmin(state: AdminStateModel): BaseAdmin {
Expand Down Expand Up @@ -541,6 +539,26 @@ export class AdminState {
this.router.navigate(['/admin-tools/data/admins']);
}

@Action(GetAllAdmins)
getAllAdmin(
{ dispatch }: StateContext<AdminStateModel>,
{ adminType, parameters }: GetAllAdmins
): void {
switch(adminType) {
case AdminRoles.ministryAdmin: {
dispatch(new GetAllMinistryAdmins(parameters));
break;
}
case AdminRoles.regionAdmin: {
dispatch(new GetAllRegionAdmins(parameters));
break;
}
default: {
dispatch(new GetAllMinistryAdmins(parameters));
}
}
}

@Action(GetAllMinistryAdmins)
getAllMinistryAdmin(
{ patchState }: StateContext<AdminStateModel>,
Expand All @@ -550,12 +568,29 @@ export class AdminState {
return this.ministryAdminService
.getAllAdmin(parameters)
.pipe(
tap((ministryAdmins: SearchResponse<MinistryAdmin[]>) =>
patchState({ ministryAdmins: ministryAdmins ?? EMPTY_RESULT, isLoading: false })
tap((admins: SearchResponse<MinistryAdmin[]>) =>
patchState({ admins: admins ?? EMPTY_RESULT, isLoading: false })
)
);
}

@Action(GetAdminById)
getAdminById({dispatch}: StateContext<AdminState>, {payload, adminType}: GetAdminById): void {
switch(adminType) {
case AdminRoles.ministryAdmin: {
dispatch(new GetMinistryAdminById(payload));
break;
}
case AdminRoles.regionAdmin: {
dispatch(new GetRegionAdminById(payload));
break;
}
default: {
dispatch(new GetMinistryAdminById(payload));
}
}
}

@Action(GetMinistryAdminById)
getMinistryAdminById({ patchState }: StateContext<AdminStateModel>, { payload }: GetMinistryAdminById): Observable<MinistryAdmin> {
patchState({ isLoading: true });
Expand All @@ -564,6 +599,26 @@ export class AdminState {
.pipe(tap((selectedAdmin: MinistryAdmin) => patchState({ selectedAdmin, isLoading: false })));
}

@Action(DeleteAdminById)
deleteAdminById(
{ dispatch }: StateContext<AdminStateModel>,
{ payload, adminType }: DeleteAdminById
):void {
switch(adminType) {
case AdminRoles.ministryAdmin: {
dispatch(new DeleteMinistryAdminById(payload));
break;
}
case AdminRoles.regionAdmin: {
dispatch(new DeleteRegionAdminById(payload));
break;
}
default: {
dispatch(new DeleteMinistryAdminById(payload));
}
}
}

@Action(DeleteMinistryAdminById)
deleteMinistryAdminById(
{ dispatch }: StateContext<AdminStateModel>,
Expand Down Expand Up @@ -591,6 +646,26 @@ export class AdminState {
]);
}

@Action(BlockAdminById)
blockAdmin(
{ dispatch }: StateContext<AdminStateModel>,
{ payload, adminType }: BlockAdminById
): void {
switch(adminType) {
case AdminRoles.ministryAdmin: {
dispatch(new BlockMinistryAdminById(payload));
break;
}
case AdminRoles.regionAdmin: {
dispatch(new BlockRegionAdminById(payload));
break;
}
default: {
dispatch(new BlockMinistryAdminById(payload));
}
}
}

@Action(BlockMinistryAdminById)
blockMinistryAdmin(
{ dispatch }: StateContext<AdminStateModel>,
Expand Down Expand Up @@ -751,8 +826,8 @@ export class AdminState {
return this.regionAdminService
.getAllAdmin(parameters)
.pipe(
tap((regionAdmins: SearchResponse<RegionAdmin[]>) =>
patchState({ regionAdmins: regionAdmins ?? EMPTY_RESULT, isLoading: false })
tap((admins: SearchResponse<RegionAdmin[]>) =>
patchState({ admins: admins ?? EMPTY_RESULT, isLoading: false })
)
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/shell/admin-tools/data/admins/admins.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
<div class="tab-wrapper">
<mat-tab-group mat-align-tabs="start" (selectedTabChange)="onTabChange($event)" [selectedIndex]="tabIndex">
<mat-tab label="{{ AdminRolesTitles.ministryAdmin | translate }}">
<ng-container *ngTemplateOutlet="AdminsList; context: { admins: ministryAdminsTable }"> </ng-container>
<ng-container *ngTemplateOutlet="AdminsList; context: { admins: adminsTable }"> </ng-container>
</mat-tab>
<mat-tab label="{{ AdminRolesTitles.regionAdmin | translate }}">
<ng-container *ngTemplateOutlet="AdminsList; context: { admins: regionAdminsTable }"> </ng-container>
<ng-container *ngTemplateOutlet="AdminsList; context: { admins: adminsTable }"> </ng-container>
</mat-tab>
<mat-tab label="{{ AdminRolesTitles.territorialCommunityAdmin | translate }}">
<ng-container *ngTemplateOutlet="AdminsList"> </ng-container>
Expand All @@ -59,7 +59,7 @@
</app-users-list>
</div>
<app-paginator
*ngIf="!(isLoadingCabinet$ | async) && ministryAdminsTable"
*ngIf="!(isLoadingCabinet$ | async) && adminsTable"
[totalEntities]="totalEntities"
[currentPage]="currentPage"
[itemsPerPage]="adminParams.size"
Expand Down
Loading

0 comments on commit f2696e7

Please sign in to comment.