11import { Component , OnInit } from '@angular/core' ;
22import { ActivatedRoute , Router } from '@angular/router' ;
3- import { AnyObject } from '@project-lib/core/api' ;
3+ import { AnyObject , BackendFilter , Count } from '@project-lib/core/api' ;
44import { RouteComponentBaseDirective } from '@project-lib/core/route-component-base' ;
5- import { ColDef } from 'ag-grid-community' ;
6- import { takeUntil } from 'rxjs' ;
5+ import {
6+ ColDef ,
7+ GridApi ,
8+ GridOptions ,
9+ IDatasource ,
10+ IGetRowsParams ,
11+ } from 'ag-grid-community' ;
12+ import { Observable , combineLatest , map , takeUntil } from 'rxjs' ;
713import { Location } from '@angular/common' ;
814
915import { BillingPlanService } from '../../../shared/services/billing-plan-service' ;
1016import { SubscriptionStatus } from '../../../shared/enum/subscription-status.enum' ;
17+ import { Plan } from '../../../shared/models' ;
1118
1219@Component ( {
1320 selector : 'app-billing-plan' ,
1421 templateUrl : './billing-plan.component.html' ,
1522 styleUrls : [ './billing-plan.component.scss' ] ,
1623} )
17- export class BillingPlanComponent
18- extends RouteComponentBaseDirective
19- implements OnInit
20- {
24+ export class BillingPlanComponent extends RouteComponentBaseDirective {
25+ gridApi : GridApi ;
26+ gridOptions : GridOptions ;
27+ limit = 5 ;
2128 colDefs : ColDef [ ] = [
2229 { field : 'companyName' , width : 200 , minWidth : 20 } ,
2330 { field : 'userName' , width : 200 , minWidth : 20 } ,
@@ -37,18 +44,47 @@ export class BillingPlanComponent
3744 private readonly billingplanService : BillingPlanService ,
3845 ) {
3946 super ( route , location ) ;
47+ this . gridOptions = {
48+ pagination : true ,
49+ rowModelType : 'infinite' ,
50+ paginationPageSize : this . limit ,
51+ paginationPageSizeSelector : [ this . limit , 10 , 20 , 50 , 100 ] ,
52+ cacheBlockSize : this . limit ,
53+ onGridReady : this . onGridReady . bind ( this ) ,
54+ rowHeight : 60 ,
55+ defaultColDef : { flex : 1 } ,
56+ } ;
4057 }
4158
42- ngOnInit ( ) : void {
43- this . getBillingPlan ( ) ;
59+ onGridReady ( params : AnyObject ) {
60+ this . gridApi = params . api ;
61+ const dataSource : IDatasource = {
62+ getRows : ( params : IGetRowsParams ) => {
63+ const page = params . endRow / this . limit ;
64+ const paginatedLeads = this . getPaginatedBillPlans ( page , this . limit ) ;
65+ const totalLead = this . getTotal ( ) ;
66+ combineLatest ( [ paginatedLeads , totalLead ] ) . subscribe (
67+ ( [ data , count ] ) => {
68+ params . successCallback ( data , count . count ) ;
69+ } ,
70+
71+ err => {
72+ params . failCallback ( ) ;
73+ } ,
74+ ) ;
75+ } ,
76+ } ;
77+ params . api . setDatasource ( dataSource ) ;
4478 }
4579
46- getBillingPlan ( ) {
47- this . billingplanService
48- . getBillingDetails ( )
49- . pipe ( takeUntil ( this . _destroy$ ) )
50- . subscribe ( res => {
51- this . rowData = res . map ( item => {
80+ getPaginatedBillPlans ( page : number , limit : number ) : Observable < AnyObject [ ] > {
81+ const filter : BackendFilter < Plan > = {
82+ offset : limit * ( page - 1 ) ,
83+ limit : limit ,
84+ } ;
85+ return this . billingplanService . getBillingDetails ( filter ) . pipe (
86+ map ( res => {
87+ const rows = res . map ( item => {
5288 return {
5389 companyName : item . companyName ,
5490 userName : item . userName ,
@@ -58,6 +94,12 @@ export class BillingPlanComponent
5894 status : SubscriptionStatus [ item . status ] ,
5995 } ;
6096 } ) ;
61- } ) ;
97+ return rows ;
98+ } ) ,
99+ ) ;
100+ }
101+
102+ getTotal ( ) : Observable < Count > {
103+ return this . billingplanService . getTotalBillingPlan ( ) ;
62104 }
63105}
0 commit comments