1
- import { AfterViewInit , Component , ElementRef , OnInit , ViewChild } from '@angular/core' ;
1
+ import { Component , OnInit , ViewChild } from '@angular/core' ;
2
2
import { Dropdown , DropdownModule } from 'primeng/dropdown' ;
3
3
import { DropdownOption } from '../../../common/models/dropdown-option' ;
4
4
import { CommonModule } from '@angular/common' ;
@@ -18,7 +18,7 @@ import { UserDataService } from '../../../common/services/user-data.service';
18
18
import { InputTextModule } from 'primeng/inputtext' ;
19
19
import { ToastModule } from 'primeng/toast' ;
20
20
import { GlobalLoaderService } from '../../../common/services/global-loader.service' ;
21
- import { Router , RouterModule } from '@angular/router' ;
21
+ import { RouterModule } from '@angular/router' ;
22
22
23
23
@Component ( {
24
24
selector : 'app-user-management' ,
@@ -50,6 +50,7 @@ export class UserManagementComponent implements OnInit {
50
50
organizations = new Array < DropdownOption > ( ) ;
51
51
filteredOrganizations = new Array < DropdownOption > ( ) ;
52
52
organizationDropdown = new Array < DropdownOption > ( ) ;
53
+ sort ! : { prop : string , dir : 'asc' | 'desc' }
53
54
54
55
accessRequests = new Array < AccessRequestTableItem > ( ) ;
55
56
currentPage ! : PagingResponsePageInfo ;
@@ -77,7 +78,6 @@ export class UserManagementComponent implements OnInit {
77
78
private confirmationService : ConfirmationService ,
78
79
private messageService : MessageService ,
79
80
private loaderService : GlobalLoaderService ,
80
- private router : Router ,
81
81
) { }
82
82
83
83
ngOnInit ( ) : void {
@@ -232,6 +232,22 @@ export class UserManagementComponent implements OnInit {
232
232
} ) ;
233
233
}
234
234
235
+ onSort ( property : string ) : void {
236
+ if ( this . sort ) {
237
+ if ( this . sort . prop === property ) {
238
+ this . sort . dir = this . sort . dir === 'asc' ? 'desc' : 'asc' ;
239
+ } else {
240
+ this . sort . prop = property ;
241
+ this . sort . dir = 'asc' ;
242
+ }
243
+ }
244
+ else {
245
+ this . sort = { prop : property , dir : 'asc' } ;
246
+ }
247
+
248
+ this . getUsers ( this . currentPage . pageNumber ) ;
249
+ }
250
+
235
251
private handleConcurrencyError ( errorMsg : any ) : void {
236
252
let details = `${ errorMsg . error . errors . entity [ 0 ] } Instance: ${ errorMsg . error . instance } ` ;
237
253
this . showErrorToast ( errorMsg . error . title , details ) ;
@@ -248,7 +264,7 @@ export class UserManagementComponent implements OnInit {
248
264
this . loaderService . loadingStart ( ) ;
249
265
this . userDataService . getStatuses ( ) . subscribe ( {
250
266
next : ( data : Array < DropdownOption > ) => {
251
- this . statuses = [ { label : 'All' , value : '' } , ...data ] ;
267
+ this . statuses = [ { label : 'All' , value : '' } , ...data . sort ( ( a , b ) => this . sortHandler ( a . label , b . label ) ) ] ;
252
268
} ,
253
269
error : ( error ) => {
254
270
this . showErrorToast ( 'Error' , 'Unable to retrieve Statuses. Check console for additional details' )
@@ -262,9 +278,9 @@ export class UserManagementComponent implements OnInit {
262
278
this . loaderService . loadingStart ( ) ;
263
279
this . requestAccessService . getOrganizations ( ) . subscribe ( {
264
280
next : ( data ) => {
265
- this . organizations = data ;
266
- this . filteredOrganizations = data ;
267
- this . organizationDropdown = [ { label : 'All' , value : '' } , ...data ] ;
281
+ this . organizations = data . sort ( ( a , b ) => this . sortHandler ( a . label , b . label ) ) ;
282
+ this . filteredOrganizations = data . sort ( ( a , b ) => this . sortHandler ( a . label , b . label ) ) ;
283
+ this . organizationDropdown = [ { label : 'All' , value : '' } , ...data . sort ( ( a , b ) => this . sortHandler ( a . label , b . label ) ) ] ;
268
284
} ,
269
285
error : ( error : any ) => {
270
286
this . showErrorToast ( 'Error' , 'Unable to retrieve Organizations. Check console for additional details' )
@@ -278,10 +294,10 @@ export class UserManagementComponent implements OnInit {
278
294
this . loaderService . loadingStart ( ) ;
279
295
this . requestAccessService . getOrganizationTypes ( ) . subscribe ( {
280
296
next : ( data ) => {
281
- this . organizationTypes = data ;
297
+ this . organizationTypes = data . sort ( ( a , b ) => this . sortHandler ( a . label , b . label ) ) ;
282
298
} ,
283
299
error : ( error : any ) => {
284
- this . showErrorToast ( 'Error' , 'Unable to retrieve Organization Types. Check console for additional details' )
300
+ this . showErrorToast ( 'Error' , 'Unable to retrieve Organization Types. Check console for additional details' ) ;
285
301
console . error ( error ) ;
286
302
} ,
287
303
complete : ( ) => {
@@ -292,26 +308,30 @@ export class UserManagementComponent implements OnInit {
292
308
this . getUsers ( ) ;
293
309
}
294
310
311
+ private sortHandler ( a : string , b : string ) : number {
312
+ if ( a > b ) return 1 ;
313
+ if ( a < b ) return - 1 ;
314
+ return 0
315
+ }
316
+
295
317
private getUsers ( selectedPageNumber ?: number ) : void {
296
318
const status = this . searchParams . searchStatus ;
297
319
const search = this . searchParams . searchTerm ;
298
320
const organizationId = this . searchParams . searchOrganization ;
299
321
const pageSize = this . currentPage ?. pageSize || 10 ;
300
322
const pageNumber = selectedPageNumber ?? ( this . currentPage ?. pageNumber || 0 ) ;
301
- const orderBy = '' ;
302
- const direction = 'desc' ;
323
+ const orderBy = this . sort ? this . sort . prop : '' ;
324
+ const direction = this . sort ? this . sort . dir : 'asc' ; ;
303
325
this . loaderService . loadingStart ( ) ;
304
326
305
327
this . userDataService . getUsers ( status , search , organizationId , pageSize , pageNumber , orderBy , direction ) . subscribe ( {
306
328
next : ( response : PagingResponse < AccessRequestTableItem > ) => {
307
329
this . accessRequests = response . sourceList ;
308
330
this . currentPage = response . pageInfo ;
309
-
310
331
} ,
311
332
error : ( error : any ) => {
312
333
this . showErrorToast ( 'Error' , 'Unable to retrieve users. Check console for additional details' )
313
334
console . error ( error ) ;
314
-
315
335
} ,
316
336
complete : ( ) => {
317
337
this . loaderService . loadingEnd ( ) ;
0 commit comments