1
1
import { Component , OnInit } from '@angular/core' ;
2
2
import { ActivatedRoute , Router } from '@angular/router' ;
3
- import { AnyObject } from '@project-lib/core/api' ;
3
+ import { AnyObject , BackendFilter , Count } from '@project-lib/core/api' ;
4
4
import { 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' ;
7
13
import { Location } from '@angular/common' ;
8
14
9
15
import { BillingPlanService } from '../../../shared/services/billing-plan-service' ;
10
16
import { SubscriptionStatus } from '../../../shared/enum/subscription-status.enum' ;
17
+ import { Plan } from '../../../shared/models' ;
11
18
12
19
@Component ( {
13
20
selector : 'app-billing-plan' ,
@@ -18,6 +25,9 @@ export class BillingPlanComponent
18
25
extends RouteComponentBaseDirective
19
26
implements OnInit
20
27
{
28
+ gridApi : GridApi ;
29
+ gridOptions : GridOptions ;
30
+ limit = 5 ;
21
31
colDefs : ColDef [ ] = [
22
32
{ field : 'companyName' , width : 200 , minWidth : 20 } ,
23
33
{ field : 'userName' , width : 200 , minWidth : 20 } ,
@@ -37,12 +47,65 @@ export class BillingPlanComponent
37
47
private readonly billingplanService : BillingPlanService ,
38
48
) {
39
49
super ( route , location ) ;
50
+ this . gridOptions = {
51
+ pagination : true ,
52
+ rowModelType : 'infinite' ,
53
+ paginationPageSize : this . limit ,
54
+ paginationPageSizeSelector : [ this . limit , 10 , 20 , 50 , 100 ] ,
55
+ cacheBlockSize : this . limit ,
56
+ onGridReady : this . onGridReady . bind ( this ) ,
57
+ rowHeight : 60 ,
58
+ defaultColDef : { flex : 1 } ,
59
+ } ;
40
60
}
41
61
42
62
ngOnInit ( ) : void {
43
63
this . getBillingPlan ( ) ;
64
+ // this.getTotal();
44
65
}
45
66
67
+ onGridReady ( params : any ) {
68
+ this . gridApi = params . api ;
69
+ const dataSource : IDatasource = {
70
+ getRows : ( params : IGetRowsParams ) => {
71
+ const page = params . endRow / this . limit ;
72
+ const paginatedLeads = this . getPaginatedBillPlans ( page , this . limit ) ;
73
+ const totalLead = this . getTotal ( ) ;
74
+ combineLatest ( [ paginatedLeads , totalLead ] ) . subscribe (
75
+ ( [ data , count ] ) => {
76
+ params . successCallback ( data , count . count ) ;
77
+ } ,
78
+
79
+ err => {
80
+ params . failCallback ( ) ;
81
+ } ,
82
+ ) ;
83
+ } ,
84
+ } ;
85
+ params . api . setDatasource ( dataSource ) ;
86
+ }
87
+
88
+ getPaginatedBillPlans ( page : number , limit : number ) : Observable < any [ ] > {
89
+ const filter : BackendFilter < Plan > = {
90
+ offset : limit * ( page - 1 ) ,
91
+ limit : limit ,
92
+ } ;
93
+ return this . billingplanService . getBillingDetails ( filter ) . pipe (
94
+ map ( res => {
95
+ const rows = res . map ( item => {
96
+ return {
97
+ companyName : item . companyName ,
98
+ userName : item . userName ,
99
+ planName : item . planName ,
100
+ startDate : item . startDate ,
101
+ endDate : item . endDate ,
102
+ status : SubscriptionStatus [ item . status ] ,
103
+ } ;
104
+ } ) ;
105
+ return rows ;
106
+ } ) ,
107
+ ) ;
108
+ }
46
109
getBillingPlan ( ) {
47
110
this . billingplanService
48
111
. getBillingDetails ( )
@@ -60,4 +123,14 @@ export class BillingPlanComponent
60
123
} ) ;
61
124
} ) ;
62
125
}
126
+ filter ( filter : any ) {
127
+ throw new Error ( 'Method not implemented.' ) ;
128
+ }
129
+
130
+ getTotal ( ) : Observable < Count > {
131
+ return this . billingplanService . getTotalBillingPlan ( ) ;
132
+ // .subscribe(resp => {
133
+ // console.log(resp);
134
+ // });
135
+ }
63
136
}
0 commit comments