11import { Component , Inject } from '@angular/core' ;
22import { ActivatedRoute , Router } from '@angular/router' ;
33import { 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' ;
511import { Location } from '@angular/common' ;
6- import { Observable } from 'rxjs' ;
12+ import { Observable , combineLatest , map } from 'rxjs' ;
713import { TenantFacadeService } from '../../../shared/services/tenant-list-facade.service' ;
814import { Tenant } from '../../../shared/models' ;
915import { AnyObject , BackendFilter } from '@project-lib/core/api' ;
1016import { TenantStatus } from '../../../shared/enum/tenant-status.enum' ;
1117import { APP_CONFIG } from '@project-lib/app-config' ;
1218import { IAnyObject } from '@project-lib/core/i-any-object' ;
1319import { 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' ;
1521import { HttpClient } from '@angular/common/http' ;
1622
1723@Component ( {
@@ -23,6 +29,7 @@ export class OnboardingTenantListComponent extends RouteComponentBaseDirective {
2329 gridApi : GridApi ;
2430 params : AnyObject ;
2531 gridOptions : GridOptions ;
32+ limit = 10 ;
2633 defaultColDef : ColDef = {
2734 flex : 1 ,
2835 minWidth : 150 ,
@@ -44,15 +51,15 @@ export class OnboardingTenantListComponent extends RouteComponentBaseDirective {
4451 pagination : true ,
4552
4653 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 ,
5159 onGridReady : this . onGridReady . bind ( this ) ,
5260 rowHeight : 60 ,
5361 defaultColDef : { flex : 1 } ,
5462 } ;
55- this . getTenantDetails ( ) ;
5663 }
5764
5865 colDefs : ColDef [ ] = [
@@ -120,56 +127,95 @@ export class OnboardingTenantListComponent extends RouteComponentBaseDirective {
120127 filter : 'agTextColumnFilter' ,
121128 floatingFilter : true ,
122129 } ,
123- {
124- headerName : 'Actions' ,
125- minWidth : 100 ,
126- cellRenderer : EyeIconRendererComponent ,
127- } ,
130+ // {
131+ // headerName: 'Actions',
132+ // minWidth: 100,
133+ // cellRenderer: EyeIconRendererComponent,
134+ // },
128135 ] ;
129136
130137 rowData : any [ ] = [ ] ;
131138 onGridReady ( params : AnyObject ) {
132139 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 ) ;
133157 }
134158
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 ( ' ' ) ;
146180
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 ( ' ' ) ;
150188
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 [ ] ;
166210 }
167- } ) ;
168- if ( this . gridApi ) {
169- this . gridApi . setRowData ( this . rowData ) ;
170- }
171- } ) ;
211+ } ) ,
212+ ) ;
172213 }
214+
215+ getTotal ( ) {
216+ return this . tenantFacade . getTotalTenant ( ) ;
217+ }
218+
173219 createCompanyLink ( params : any ) {
174220 const url = this . appConfig . baseApiUrl . replace (
175221 '//' ,
0 commit comments