Skip to content

Commit

Permalink
fix: block and unblock fixes (#115) (#116) (#117)
Browse files Browse the repository at this point in the history
Co-authored-by: Vishali Sakar <[email protected]>

Co-authored-by: Vishali Sakar <[email protected]>

Co-authored-by: Vishali Sakar <[email protected]>
  • Loading branch information
vishalisakar and Vishali Sakar authored Feb 16, 2022
1 parent 93bd449 commit e429480
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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,
Expand All @@ -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() {
Expand All @@ -84,7 +88,7 @@ export class UsersViewComponent implements OnInit, OnDestroy {
}
}
ngOnInit() {

this.getAllUsers()
}

filter(filter: string) {
Expand All @@ -109,6 +113,7 @@ export class UsersViewComponent implements OnInit, OnDestroy {
}

get dataForTable() {

switch (this.currentFilter) {
case 'active':
return this.activeUsersData
Expand All @@ -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) => {
Expand All @@ -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) => {
Expand Down Expand Up @@ -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()
})
}
Expand Down Expand Up @@ -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'))
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
33 changes: 33 additions & 0 deletions project/ws/app/src/lib/routes/users/services/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

Expand Down Expand Up @@ -84,4 +87,34 @@ export class UsersService {
// getBulkUploadData(): Observable<any> {
// return this.http.get<any>(`${API_END_POINTS.GET_BULKUPLOAD_DATA}`)
// }

newBlockUser(loggedInUser: string, userId: string): Observable<any> {
const org = {
request: {
userId,
requestedBy: loggedInUser,
},
}
return this.http.post<any>(`${API_END_POINTS.NEW_USER_BLOCK_API}`, org)
}
newUnBlockUser(loggedInUser: string, userId: string): Observable<any> {
const org = {
request: {
userId,
requestedBy: loggedInUser,
},
}
return this.http.post<any>(`${API_END_POINTS.NEW_USER_UN_BLOCK_API}`, org)
}

getAllKongUsers(depId: string): Observable<any> {
const reqBody = {
request: {
filters: {
rootOrgId: depId,
},
},
}
return this.http.post<any>(`${API_END_POINTS.GET_ALL_USERS}`, reqBody)
}
}
15 changes: 15 additions & 0 deletions src/app/services/loader.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BehaviorSubject } from 'rxjs'
import { Injectable } from '@angular/core'

@Injectable()
export class LoaderService {
changeLoad = new BehaviorSubject<boolean>(false)

private doubleBack = new BehaviorSubject(false)
currentState = this.doubleBack.asObservable()

changeLoadState(state: boolean) {
this.doubleBack.next(state)
}

}

0 comments on commit e429480

Please sign in to comment.