Revision 60732
Added by Konstantinos Triantafyllou about 3 years ago
role-users.component.ts | ||
---|---|---|
37 | 37 |
public notificationFn: Function; |
38 | 38 |
public user: User = null; |
39 | 39 |
public active: any[]; |
40 |
public showActive: any[] = []; |
|
40 | 41 |
public managers: any[]; |
41 | 42 |
public pending: any[]; |
42 |
public showActive: boolean = true; |
|
43 |
public showPending: any[] = []; |
|
44 |
public showCurrent: boolean = true; |
|
43 | 45 |
public subs: any[] = []; |
44 | 46 |
public loadActive: boolean = true; |
45 | 47 |
public loadPending: boolean = true; |
... | ... | |
48 | 50 |
public properties: EnvProperties = properties; |
49 | 51 |
public exists: boolean = true; |
50 | 52 |
public roleFb: FormGroup; |
53 |
/** Paging */ |
|
54 |
activePage: number = 1; |
|
55 |
pendingPage: number = 1; |
|
56 |
pageSize: number = 5; |
|
57 |
/** Search */ |
|
58 |
filterForm: FormGroup; |
|
51 | 59 |
@ViewChild('inviteModal') inviteModal: AlertModal; |
52 | 60 |
@ViewChild('deleteModal') deleteModal: AlertModal; |
53 | 61 |
@ViewChild('deletePendingModal') deletePendingModal: AlertModal; |
... | ... | |
61 | 69 |
} |
62 | 70 |
|
63 | 71 |
ngOnInit() { |
72 |
this.filterForm = this.fb.group({ |
|
73 |
active: this.fb.control(''), |
|
74 |
pending: this.fb.control('') |
|
75 |
}); |
|
76 |
this.subs.push(this.filterForm.get('active').valueChanges.subscribe(value => { |
|
77 |
this.filterActiveBySearch(value); |
|
78 |
})); |
|
79 |
this.subs.push(this.filterForm.get('pending').valueChanges.subscribe(value => { |
|
80 |
this.filterPendingBySearch(value); |
|
81 |
})); |
|
64 | 82 |
this.updateLists(); |
65 | 83 |
this.userManagementService.getUserInfo().subscribe(user => { |
66 | 84 |
this.user = user; |
... | ... | |
86 | 104 |
}); |
87 | 105 |
} |
88 | 106 |
|
89 |
|
|
90 | 107 |
updateLists() { |
91 | 108 |
this.loadActive = true; |
92 | 109 |
this.loadPending = true; |
... | ... | |
98 | 115 |
this.active.forEach(user => { |
99 | 116 |
user['isManager'] = this.managers.find(manager => manager.email === user.email); |
100 | 117 |
}); |
118 |
this.filterActiveBySearch(this.filterForm.value.active); |
|
101 | 119 |
this.loadActive = false; |
102 | 120 |
this.exists = true; |
103 | 121 |
})) |
104 | 122 |
} else { |
105 | 123 |
this.active = users; |
124 |
this.filterActiveBySearch(this.filterForm.value.active); |
|
106 | 125 |
this.loadActive = false; |
107 | 126 |
this.exists = true; |
108 | 127 |
} |
... | ... | |
115 | 134 |
})); |
116 | 135 |
this.subs.push(this.userRegistryService.getPending(this.type, this.id, this.role).subscribe(users => { |
117 | 136 |
this.pending = users; |
137 |
this.filterPendingBySearch(this.filterForm.value.pending); |
|
118 | 138 |
this.loadPending = false; |
119 | 139 |
}, error => { |
120 | 140 |
this.pending = []; |
... | ... | |
123 | 143 |
} |
124 | 144 |
|
125 | 145 |
openDeleteModal(item: any) { |
126 |
if (this.showActive) {
|
|
146 |
if (this.showCurrent) {
|
|
127 | 147 |
this.selectedUser = item.email; |
128 | 148 |
this.deleteModal.alertTitle = 'Delete ' + this.role; |
129 | 149 |
this.deleteModal.open(); |
... | ... | |
160 | 180 |
this.loadActive = true; |
161 | 181 |
this.subs.push(this.userRegistryService.remove(this.type, this.id, this.selectedUser, this.role).subscribe(() => { |
162 | 182 |
this.active = this.active.filter(user => user.email != this.selectedUser); |
183 |
this.filterActiveBySearch(this.filterForm.value.active); |
|
163 | 184 |
this.userManagementService.updateUserInfo(); |
164 | 185 |
UIkit.notification(this.selectedUser + ' <b>is no longer</b> ' + this.role + ' of ' + this.name + ' Dashboard', { |
165 | 186 |
status: 'success', |
... | ... | |
181 | 202 |
this.loadPending = true; |
182 | 203 |
this.subs.push(this.userRegistryService.cancelInvitation(this.type, this.id, this.selectedUser, this.role).subscribe(() => { |
183 | 204 |
this.pending = this.pending.filter(user => user != this.selectedUser); |
205 |
this.filterPendingBySearch(this.filterForm.value.pending); |
|
184 | 206 |
UIkit.notification(StringUtils.capitalize(this.role) + ' invitation to ' + this.selectedUser + ' has been <b>canceled</b>', { |
185 | 207 |
status: 'success', |
186 | 208 |
timeout: 6000, |
... | ... | |
198 | 220 |
} |
199 | 221 |
|
200 | 222 |
invite() { |
201 |
this.showActive = false;
|
|
223 |
this.showCurrent = false;
|
|
202 | 224 |
this.loadPending = true; |
203 | 225 |
this.selectedUser = this.invited.value; |
204 | 226 |
let details = { |
... | ... | |
208 | 230 |
this.subs.push(this.userRegistryService.invite(this.type, this.id, details, this.role).subscribe(invitation => { |
209 | 231 |
if (!this.pending.includes(this.invited.value)) { |
210 | 232 |
this.pending.push(this.invited.value); |
233 |
this.filterPendingBySearch(this.filterForm.value.pending); |
|
211 | 234 |
} |
212 | 235 |
if(this.notificationFn) { |
213 | 236 |
this.subs.push(this.notificationService.sendNotification(this.notificationFn(this.name, this.invited.value, this.role, invitation)).subscribe(notification => { |
... | ... | |
269 | 292 |
public get isPortalAdmin(): boolean { |
270 | 293 |
return !!Session.isPortalAdministrator(this.user); |
271 | 294 |
} |
295 |
|
|
296 |
updateActivePage(event: any) { |
|
297 |
this.activePage = event.value; |
|
298 |
} |
|
299 |
|
|
300 |
updatePendingPage(event: any) { |
|
301 |
this.pendingPage = event.value; |
|
302 |
} |
|
303 |
|
|
304 |
private filterActiveBySearch(value: any) { |
|
305 |
this.showActive = this.active.filter(active => !value || active.email.includes(value)); |
|
306 |
this.activePage = 1; |
|
307 |
} |
|
308 |
|
|
309 |
private filterPendingBySearch(value: any) { |
|
310 |
this.showPending = this.pending.filter(pending => !value || pending.includes(value)); |
|
311 |
this.pendingPage = 1; |
|
312 |
} |
|
272 | 313 |
} |
Also available in: Unified diff
[Library | Trunk]: Add paging and search on role users