1
- import { Component } from '@angular/core' ;
1
+ import { Component , ViewChild } from '@angular/core' ;
2
2
import { AccountMapperService } from '../services/account-mapper.service' ;
3
3
import { UntypedFormControl } from '@angular/forms' ;
4
4
import { TransactionsDataSource } from 'app/payment-hub/transactions/dataSource/transactions.datasource' ;
5
+ import { MatPaginator , PageEvent } from '@angular/material/paginator' ;
6
+ import { MatSort } from '@angular/material/sort' ;
7
+ import { MatTableDataSource } from '@angular/material/table' ;
8
+ import { AccountData } from '../models/account-mapper.model' ;
9
+ import { Dates } from 'app/core/utils/dates' ;
5
10
6
11
@Component ( {
7
12
selector : 'mifosx-account-mapper' ,
8
13
templateUrl : './account-mapper.component.html' ,
9
14
styleUrls : [ './account-mapper.component.scss' ]
10
15
} )
11
16
export class AccountMapperComponent {
17
+
18
+ @ViewChild ( MatPaginator ) paginator : MatPaginator ;
19
+ @ViewChild ( MatSort ) sort : MatSort ;
20
+
12
21
/** government Entity form control. */
13
22
governmentEntity = new UntypedFormControl ( ) ;
14
23
/** financial Institution form control. */
@@ -21,26 +30,47 @@ export class AccountMapperComponent {
21
30
/** Columns to be displayed in transactions table. */
22
31
displayedColumns : string [ ] = [ 'governmentEntity' , 'financialInstitution' , 'functionalId' , 'financialAddress' ] ;
23
32
/** Data source for transactions table. */
24
- dataSource : TransactionsDataSource ;
33
+ dataSource = new MatTableDataSource ( ) ;
25
34
26
- batchesData : any ;
35
+ totalRows : number = 0 ;
36
+ currentPage : number = 0 ;
27
37
28
- page : number = 0 ;
29
- size : number = 100 ;
38
+ pageSize = 50 ;
39
+ isLoading = false ;
30
40
31
- constructor ( private accountMapperService : AccountMapperService ) { }
41
+ accountsData : AccountData ;
42
+
43
+ constructor ( private dates : Dates ,
44
+ private accountMapperService : AccountMapperService ) { }
32
45
33
46
ngOnInit ( ) : void {
34
47
this . getAccounts ( ) ;
35
48
}
36
49
37
50
getAccounts ( ) : void {
38
- this . accountMapperService . getAccounts ( this . page , this . size , 'requestFile' , 'asc' )
39
- . subscribe ( ( batches : any ) => {
40
- this . batchesData = batches ;
51
+ this . isLoading = true ;
52
+ this . accountMapperService . getAccounts ( this . currentPage , this . pageSize , 'requestFile' , 'asc' )
53
+ . subscribe ( ( accounts : AccountData ) => {
54
+ this . dataSource = new MatTableDataSource ( accounts . content ) ;
55
+ this . totalRows = accounts . totalElements ;
56
+ this . isLoading = false ;
57
+ } , ( error : any ) => {
58
+ this . isLoading = false ;
41
59
} ) ;
42
60
}
43
61
62
+ convertTimestampToUTCDate ( timestamp : any ) {
63
+ if ( ! timestamp ) {
64
+ return undefined ;
65
+ }
66
+ return this . dates . formatUTCDate ( new Date ( timestamp ) ) ;
67
+ }
68
+
69
+ pageChanged ( event : PageEvent ) {
70
+ this . pageSize = event . pageSize ;
71
+ this . currentPage = event . pageIndex ;
72
+ this . getAccounts ( ) ;
73
+ }
44
74
45
75
searchAccounts ( ) : void {
46
76
0 commit comments