1
1
import { Component , Inject } from '@angular/core' ;
2
2
import { ActivatedRoute , Router } from '@angular/router' ;
3
3
import { RouteComponentBaseDirective } from '@project-lib/core/route-component-base' ;
4
- import { ColDef , GridApi , GridOptions } from 'ag-grid-community' ;
4
+ import {
5
+ ColDef ,
6
+ GridApi ,
7
+ GridOptions ,
8
+ IDatasource ,
9
+ IGetRowsParams ,
10
+ } from 'ag-grid-community' ;
5
11
import { Location } from '@angular/common' ;
6
- import { Observable } from 'rxjs' ;
12
+ import { Observable , combineLatest , map } from 'rxjs' ;
7
13
import { TenantFacadeService } from '../../../shared/services/tenant-list-facade.service' ;
8
14
import { Tenant } from '../../../shared/models' ;
9
15
import { AnyObject , BackendFilter } from '@project-lib/core/api' ;
10
16
import { TenantStatus } from '../../../shared/enum/tenant-status.enum' ;
11
17
import { APP_CONFIG } from '@project-lib/app-config' ;
12
18
import { IAnyObject } from '@project-lib/core/i-any-object' ;
13
19
import { EyeIconRendererComponent } from '../eye-icon-renderer/eye-icon-renderer.component' ;
14
- import { tenantDetails } from '../../../shared/models/tenantDetails.model' ;
20
+ import { TenantDetails } from '../../../shared/models/tenantDetails.model' ;
15
21
import { HttpClient } from '@angular/common/http' ;
16
22
17
23
@Component ( {
@@ -23,6 +29,7 @@ export class OnboardingTenantListComponent extends RouteComponentBaseDirective {
23
29
gridApi : GridApi ;
24
30
params : AnyObject ;
25
31
gridOptions : GridOptions ;
32
+ limit = 10 ;
26
33
defaultColDef : ColDef = {
27
34
flex : 1 ,
28
35
minWidth : 150 ,
@@ -44,15 +51,15 @@ export class OnboardingTenantListComponent extends RouteComponentBaseDirective {
44
51
pagination : true ,
45
52
46
53
alwaysShowHorizontalScroll : true ,
47
- rowModelType : 'clientSide' ,
48
- paginationPageSize : 5 ,
49
- paginationPageSizeSelector : [ 5 , 10 , 20 , 50 , 100 ] ,
50
- cacheBlockSize : 5 ,
54
+ rowModelType : 'infinite' ,
55
+ paginationPageSize : this . limit ,
56
+
57
+ paginationPageSizeSelector : [ this . limit , 20 , 50 , 100 ] ,
58
+ cacheBlockSize : this . limit ,
51
59
onGridReady : this . onGridReady . bind ( this ) ,
52
60
rowHeight : 60 ,
53
61
defaultColDef : { flex : 1 } ,
54
62
} ;
55
- this . getTenantDetails ( ) ;
56
63
}
57
64
58
65
colDefs : ColDef [ ] = [
@@ -120,56 +127,95 @@ export class OnboardingTenantListComponent extends RouteComponentBaseDirective {
120
127
filter : 'agTextColumnFilter' ,
121
128
floatingFilter : true ,
122
129
} ,
123
- {
124
- headerName : 'Actions' ,
125
- minWidth : 100 ,
126
- cellRenderer : EyeIconRendererComponent ,
127
- } ,
130
+ // {
131
+ // headerName: 'Actions',
132
+ // minWidth: 100,
133
+ // cellRenderer: EyeIconRendererComponent,
134
+ // },
128
135
] ;
129
136
130
137
rowData : any [ ] = [ ] ;
131
138
onGridReady ( params : AnyObject ) {
132
139
this . gridApi = params . api ;
140
+ const dataSource : IDatasource = {
141
+ getRows : ( params : IGetRowsParams ) => {
142
+ const page = params . endRow / this . limit ;
143
+ const paginatedLeads = this . getPaginatedTenantDetails ( page , this . limit ) ;
144
+ const totalLead = this . getTotal ( ) ;
145
+ combineLatest ( [ paginatedLeads , totalLead ] ) . subscribe (
146
+ ( [ data , count ] ) => {
147
+ params . successCallback ( data , count . count ) ;
148
+ } ,
149
+
150
+ err => {
151
+ params . failCallback ( ) ;
152
+ } ,
153
+ ) ;
154
+ } ,
155
+ } ;
156
+ params . api . setDatasource ( dataSource ) ;
133
157
}
134
158
135
- getTenantDetails ( ) {
136
- this . tenantFacade . getTenantDetails ( ) . subscribe ( resp => {
137
- this . rowData = resp . map ( item => {
138
- if ( item ) {
139
- const fullTenantName = [
140
- item . contacts [ 0 ] ?. firstName ,
141
- ' ' ,
142
- item . contacts [ 0 ] ?. lastName ,
143
- ]
144
- . filter ( ele => ele != null && ele . trim ( ) != '' )
145
- . join ( ' ' ) ;
159
+ getPaginatedTenantDetails (
160
+ page : number ,
161
+ limit : number ,
162
+ ) : Observable < AnyObject [ ] > {
163
+ const filter : BackendFilter < TenantDetails > = {
164
+ offset : limit * ( page - 1 ) ,
165
+ limit : limit ,
166
+ } ;
167
+ return this . tenantFacade . getTenantDetails ( filter ) . pipe (
168
+ map ( resp => {
169
+ console . log ( resp ) ;
170
+ try {
171
+ const rows = resp . map ( item => {
172
+ if ( item ) {
173
+ const fullTenantName = [
174
+ item ?. firstName || '' ,
175
+ ' ' ,
176
+ item ?. lastName || '' ,
177
+ ]
178
+ . filter ( ele => ele != null && ele . trim ( ) != '' )
179
+ . join ( ' ' ) ;
146
180
147
- const addressString = [ item . address . zip , ' ' , item . address . country ]
148
- . filter ( ele => ele != null && ele . trim ( ) != '' )
149
- . join ( ' ' ) ;
181
+ const addressString = [
182
+ item . address . zip ,
183
+ ' ' ,
184
+ item . address . country ,
185
+ ]
186
+ . filter ( ele => ele != null && ele . trim ( ) != '' )
187
+ . join ( ' ' ) ;
150
188
151
- return {
152
- id : item . id ,
153
- name : item . name ,
154
- tenant_name : fullTenantName ,
155
- email : item . contacts [ 0 ] . email ,
156
- address : addressString ,
157
- planName : item . subscription ?. plan . name ,
158
- status : TenantStatus [ item . subscription ?. status ] ,
159
- startDate : item . subscription ?. startDate
160
- ? new Date ( item . subscription . startDate ) . toLocaleDateString ( )
161
- : 'N/A' ,
162
- endDate : item . subscription ?. endDate
163
- ? new Date ( item . subscription . endDate ) . toLocaleDateString ( )
164
- : 'N/A' ,
165
- } ;
189
+ return {
190
+ id : item . id ,
191
+ name : item . name ,
192
+ tenant_name : fullTenantName ,
193
+ email : item . email ,
194
+ address : addressString ,
195
+ planName : item . subscription ?. plan . name ,
196
+ status : TenantStatus [ item . subscription ?. status ] ,
197
+ startDate : item . subscription ?. startDate
198
+ ? new Date ( item . subscription . startDate ) . toLocaleDateString ( )
199
+ : 'N/A' ,
200
+ endDate : item . subscription ?. endDate
201
+ ? new Date ( item . subscription . endDate ) . toLocaleDateString ( )
202
+ : 'N/A' ,
203
+ } ;
204
+ }
205
+ } ) ;
206
+ return rows ;
207
+ } catch ( error ) {
208
+ console . error ( 'Error processing response:' , error ) ;
209
+ return [ ] ;
166
210
}
167
- } ) ;
168
- if ( this . gridApi ) {
169
- this . gridApi . setRowData ( this . rowData ) ;
170
- }
171
- } ) ;
211
+ } ) ,
212
+ ) ;
172
213
}
214
+
215
+ getTotal ( ) {
216
+ return this . tenantFacade . getTotalTenant ( ) ;
217
+ }
218
+
173
219
createCompanyLink ( params : any ) {
174
220
const url = this . appConfig . baseApiUrl . replace (
175
221
'//' ,
0 commit comments