Skip to content

Commit 0c7c28b

Browse files
committed
fix(arc-saas): page test
page test GH-34
1 parent 62afa25 commit 0c7c28b

File tree

3 files changed

+88
-5
lines changed

3 files changed

+88
-5
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>

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

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
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',
@@ -18,6 +25,9 @@ export class BillingPlanComponent
1825
extends RouteComponentBaseDirective
1926
implements OnInit
2027
{
28+
gridApi: GridApi;
29+
gridOptions: GridOptions;
30+
limit = 5;
2131
colDefs: ColDef[] = [
2232
{field: 'companyName', width: 200, minWidth: 20},
2333
{field: 'userName', width: 200, minWidth: 20},
@@ -37,12 +47,65 @@ export class BillingPlanComponent
3747
private readonly billingplanService: BillingPlanService,
3848
) {
3949
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+
};
4060
}
4161

4262
ngOnInit(): void {
4363
this.getBillingPlan();
64+
// this.getTotal();
4465
}
4566

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+
}
46109
getBillingPlan() {
47110
this.billingplanService
48111
.getBillingDetails()
@@ -60,4 +123,14 @@ export class BillingPlanComponent
60123
});
61124
});
62125
}
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+
}
63136
}

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)