From 1f643b347cc1dd04910e600787327e77406e5d08 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Sun, 28 Mar 2021 11:15:33 +0000 Subject: [PATCH] [Library | Trunk]: Roles users fix filter form on role change git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60734 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../users/role-users/role-users.component.ts | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/dashboard/users/role-users/role-users.component.ts b/dashboard/users/role-users/role-users.component.ts index dc690516..8790332b 100644 --- a/dashboard/users/role-users/role-users.component.ts +++ b/dashboard/users/role-users/role-users.component.ts @@ -69,25 +69,17 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges { } ngOnInit() { - this.filterForm = this.fb.group({ - active: this.fb.control(''), - pending: this.fb.control('') + this.initForm(); + this.updateLists(); + this.userManagementService.getUserInfo().subscribe(user => { + this.user = user; }); - this.subs.push(this.filterForm.get('active').valueChanges.subscribe(value => { - this.filterActiveBySearch(value); - })); - this.subs.push(this.filterForm.get('pending').valueChanges.subscribe(value => { - this.filterPendingBySearch(value); - })); - this.updateLists(); - this.userManagementService.getUserInfo().subscribe(user => { - this.user = user; - }); } ngOnChanges(changes: SimpleChanges) { - if(changes.role) { + if (changes.role) { this.unsubscribe(); + this.initForm(); this.updateLists(); } } @@ -104,11 +96,24 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges { }); } + initForm() { + this.filterForm = this.fb.group({ + active: this.fb.control(''), + pending: this.fb.control('') + }); + this.subs.push(this.filterForm.get('active').valueChanges.subscribe(value => { + this.filterActiveBySearch(value); + })); + this.subs.push(this.filterForm.get('pending').valueChanges.subscribe(value => { + this.filterPendingBySearch(value); + })); + } + updateLists() { this.loadActive = true; this.loadPending = true; this.subs.push(this.userRegistryService.getActiveEmail(this.type, this.id, this.role).subscribe(users => { - if(this.role === 'member') { + if (this.role === 'member') { this.subs.push(this.userRegistryService.getActiveEmail(this.type, this.id, 'manager').subscribe(managers => { this.managers = managers; this.active = users; @@ -127,7 +132,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges { } }, error => { this.active = []; - if(error.status === 404) { + if (error.status === 404) { this.exists = false; } this.loadActive = false; @@ -232,7 +237,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges { this.pending.push(this.invited.value); this.filterPendingBySearch(this.filterForm.value.pending); } - if(this.notificationFn) { + if (this.notificationFn) { this.subs.push(this.notificationService.sendNotification(this.notificationFn(this.name, this.invited.value, this.role, invitation)).subscribe(notification => { UIkit.notification('A notification has been sent successfully', { status: 'success',