From e42948093397c2b749a84bedc11448ebe650b4d3 Mon Sep 17 00:00:00 2001 From: Vishali Sakar <46264876+vishalisakar@users.noreply.github.com> Date: Wed, 16 Feb 2022 13:06:37 +0530 Subject: [PATCH] fix: block and unblock fixes (#115) (#116) (#117) Co-authored-by: Vishali Sakar Co-authored-by: Vishali Sakar Co-authored-by: Vishali Sakar --- .../routes/users-view/users-view.component.ts | 76 +++++++++++++------ .../routes/users/services/users.service.ts | 33 ++++++++ src/app/services/loader.service.ts | 15 ++++ 3 files changed, 102 insertions(+), 22 deletions(-) create mode 100644 src/app/services/loader.service.ts diff --git a/project/ws/app/src/lib/routes/home/routes/users-view/users-view.component.ts b/project/ws/app/src/lib/routes/home/routes/users-view/users-view.component.ts index 4e53faa40..e5451777d 100644 --- a/project/ws/app/src/lib/routes/home/routes/users-view/users-view.component.ts +++ b/project/ws/app/src/lib/routes/home/routes/users-view/users-view.component.ts @@ -12,11 +12,13 @@ import { MatSnackBar } from '@angular/material' import { EventService } from '@sunbird-cb/utils' import { NsContent } from '@sunbird-cb/collection' import { TelemetryEvents } from '../../../../head/_services/telemetry.event.model' +import { LoaderService } from '../../../../../../../../../src/app/services/loader.service' @Component({ selector: 'ws-app-users-view', templateUrl: './users-view.component.html', styleUrls: ['./users-view.component.scss'], + providers: [LoaderService], /* tslint:disable */ host: { class: 'flex flex-1 margin-top-l' }, /* tslint:enable */ @@ -61,6 +63,7 @@ export class UsersViewComponent implements OnInit, OnDestroy { private router: Router, private snackBar: MatSnackBar, private events: EventService, + private loaderService: LoaderService, // private telemetrySvc: TelemetryService, // private configSvc: ConfigurationsService, // private discussService: DiscussService, @@ -72,8 +75,9 @@ export class UsersViewComponent implements OnInit, OnDestroy { this.Math = Math this.configSvc = this.route.parent && this.route.parent.snapshot.data.configService this.currentUser = this.configSvc.userProfile && this.configSvc.userProfile.userId - this.usersData = _.get(this.route, 'snapshot.data.usersList.data') || {} - this.filterData() + // console.log(_.get(this.route, 'snapshot.data.usersList.data')) + // this.usersData = _.get(this.route, 'snapshot.data.usersList.data') || {} + // this.filterData() } // decideAPICall() { @@ -84,7 +88,7 @@ export class UsersViewComponent implements OnInit, OnDestroy { } } ngOnInit() { - + this.getAllUsers() } filter(filter: string) { @@ -109,6 +113,7 @@ export class UsersViewComponent implements OnInit, OnDestroy { } get dataForTable() { + switch (this.currentFilter) { case 'active': return this.activeUsersData @@ -126,6 +131,7 @@ export class UsersViewComponent implements OnInit, OnDestroy { this.inactiveUsersData = this.inActiveUsers } get activeUsers() { + this.loaderService.changeLoad.next(true) const activeUsersData: any[] = [] if (this.usersData && this.usersData.content && this.usersData.content.length > 0) { _.filter(this.usersData.content, { isDeleted: false }).forEach((user: any) => { @@ -145,6 +151,7 @@ export class UsersViewComponent implements OnInit, OnDestroy { return activeUsersData } get inActiveUsers() { + this.loaderService.changeLoad.next(true) const inactiveUsersData: any[] = [] if (this.usersData && this.usersData.content && this.usersData.content.length > 0) { _.filter(this.usersData.content, { isDeleted: true }).forEach((user: any) => { @@ -183,16 +190,23 @@ export class UsersViewComponent implements OnInit, OnDestroy { } getAllUsers() { - const filterObj = { - request: { - query: '', - filters: { - rootOrgId: this.configSvc, - }, - }, - } - this.usersService.getAllUsers(filterObj).subscribe(data => { - this.usersData = data + this.loaderService.changeLoad.next(true) + const rootOrgId = _.get(this.route.snapshot.parent, 'data.configService.unMappedUser.rootOrg.rootOrgId') + // const filterObj = { + // request: { + // query: '', + // filters: { + // rootOrgId: this.configSvc, + // }, + // }, + // } + // this.usersService.getAllUsers(filterObj).subscribe(data => { + // console.log(data) + // this.usersData = data + // this.filterData() + // }) + this.usersService.getAllKongUsers(rootOrgId).subscribe(data => { + this.usersData = data.result.response this.filterData() }) } @@ -223,6 +237,8 @@ export class UsersViewComponent implements OnInit, OnDestroy { ) } menuActions($event: { action: string, row: any }) { + this.loaderService.changeLoad.next(true) + const loggedInUserId = _.get(this.route, 'snapshot.parent.data.configService.userProfile.userId') // const user = { userId: _.get($event.row, 'userId') } // _.set(user, 'deptId', _.get(_.first(_.filter(this.usersData.content, { id: user.userId })), 'rootOrgId')) // _.set(user, 'isBlocked', _.get($event.row, 'blocked')) @@ -246,7 +262,7 @@ export class UsersViewComponent implements OnInit, OnDestroy { this.usersService.blockUser(user).subscribe(response => { if (response) { this.getAllUsers() - this.snackBar.open('Updated successfully !') + this.snackBar.open(response.result.response) } }) break @@ -263,10 +279,19 @@ export class UsersViewComponent implements OnInit, OnDestroy { case 'deactive': // _.set(user, 'isDeleted', true) // _.set(user, 'roles', _.map(_.get($event.row, 'role'), i => i)) - this.usersService.deActiveUser(user).subscribe(response => { - if (response) { - this.getAllUsers() - this.snackBar.open('Updated successfully !') + // this.usersService.deActiveUser(user).subscribe(response => { + this.usersService.newBlockUser(loggedInUserId, user.request.userId).subscribe(response => { + if (response.params.status === 'success') { + setTimeout(() => { + this.getAllUsers() + + this.snackBar.open('Deactivated successfully!') + }, 1500) + // this.changeDetectorRefs.detectChanges() + } + else { + this.loaderService.changeLoad.next(false) + this.snackBar.open('Update unsuccess!') } }, // tslint:disable-next-line:align @@ -283,10 +308,17 @@ export class UsersViewComponent implements OnInit, OnDestroy { _.set(user, 'isDeleted', false) } _.set(user, 'roles', _.map(_.get($event.row, 'role'), i => i)) - this.usersService.deActiveUser(user).subscribe(response => { - if (response) { - this.getAllUsers() - this.snackBar.open('Updated successfully !') + // this.usersService.deActiveUser(user).subscribe(response => { + this.usersService.newUnBlockUser(loggedInUserId, user.request.userId).subscribe(response => { + if (response.params.status === 'success') { + setTimeout(() => { + this.getAllUsers() + this.snackBar.open('Activated successfully!') + + }, 1500) + } else { + this.loaderService.changeLoad.next(false) + this.snackBar.open('Update unsuccess!') } }) break diff --git a/project/ws/app/src/lib/routes/users/services/users.service.ts b/project/ws/app/src/lib/routes/users/services/users.service.ts index ba875e3ab..a38423635 100644 --- a/project/ws/app/src/lib/routes/users/services/users.service.ts +++ b/project/ws/app/src/lib/routes/users/services/users.service.ts @@ -21,6 +21,9 @@ const API_END_POINTS = { USER_BDD: '/apis/protected/v8/portal/mdo/deptAction/userrole', ACTIVE_USER: 'apis/proxies/v8/user/v1/unblock', DE_ACTIVE_USER: 'apis/proxies/v8/user/v1/block', + NEW_USER_BLOCK_API: '/apis/proxies/v8/user/v1/block', + NEW_USER_UN_BLOCK_API: '/apis/proxies/v8/user/v1/unblock' + // GET_BULKUPLOAD_DATA: '/apis/protected/v8/admin/userRegistration/bulkUploadData', } @@ -84,4 +87,34 @@ export class UsersService { // getBulkUploadData(): Observable { // return this.http.get(`${API_END_POINTS.GET_BULKUPLOAD_DATA}`) // } + + newBlockUser(loggedInUser: string, userId: string): Observable { + const org = { + request: { + userId, + requestedBy: loggedInUser, + }, + } + return this.http.post(`${API_END_POINTS.NEW_USER_BLOCK_API}`, org) + } + newUnBlockUser(loggedInUser: string, userId: string): Observable { + const org = { + request: { + userId, + requestedBy: loggedInUser, + }, + } + return this.http.post(`${API_END_POINTS.NEW_USER_UN_BLOCK_API}`, org) + } + + getAllKongUsers(depId: string): Observable { + const reqBody = { + request: { + filters: { + rootOrgId: depId, + }, + }, + } + return this.http.post(`${API_END_POINTS.GET_ALL_USERS}`, reqBody) + } } diff --git a/src/app/services/loader.service.ts b/src/app/services/loader.service.ts new file mode 100644 index 000000000..58154cdad --- /dev/null +++ b/src/app/services/loader.service.ts @@ -0,0 +1,15 @@ +import { BehaviorSubject } from 'rxjs' +import { Injectable } from '@angular/core' + +@Injectable() +export class LoaderService { + changeLoad = new BehaviorSubject(false) + + private doubleBack = new BehaviorSubject(false) + currentState = this.doubleBack.asObservable() + + changeLoadState(state: boolean) { + this.doubleBack.next(state) + } + +}