Skip to content

Commit f1abd7c

Browse files
authored
Merge pull request #53 from sourcefuse/saas-ui-test-page
fix(saas-ui):pagination of billing component
2 parents 62afa25 + f2150e2 commit f1abd7c

File tree

3 files changed

+70
-18
lines changed

3 files changed

+70
-18
lines changed

projects/saas-ui/src/app/main/components/billing-plan/billing-plan.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ <h2 class="heading">Billing Details</h2>
66
<div class="grid">
77
<ag-grid-angular
88
class="ag-theme-quartz"
9-
[rowData]="rowData"
109
[columnDefs]="colDefs"
10+
[gridOptions]="gridOptions"
1111
>
1212
</ag-grid-angular>
1313
</div>
Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
import {Component, OnInit} from '@angular/core';
22
import {ActivatedRoute, Router} from '@angular/router';
3-
import {AnyObject} from '@project-lib/core/api';
3+
import {AnyObject, BackendFilter, Count} from '@project-lib/core/api';
44
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';
713
import {Location} from '@angular/common';
814

915
import {BillingPlanService} from '../../../shared/services/billing-plan-service';
1016
import {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
}

projects/saas-ui/src/app/shared/services/billing-plan-service.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,22 @@ export class BillingPlanService {
6666
};
6767
return command.execute();
6868
}
69-
getBillingDetails() {
69+
70+
getBillingDetails(filter?: BackendFilter<AnyObject>) {
7071
const command: GetBillingDetails<AnyObject> = new GetBillingDetails(
7172
this.apiService,
7273
this.anyAdapter,
7374
this.appConfig,
7475
);
76+
const backendFilter: BackendFilter<AnyObject> = filter
77+
? {
78+
where: filter.where,
79+
offset: filter.offset,
80+
limit: filter.limit,
81+
order: filter.order,
82+
include: filter.include || [], // Adding include from filter parameter
83+
}
84+
: {};
7585
return command.execute();
7686
}
7787
getCurrencyDetails() {

0 commit comments

Comments
 (0)