Skip to content

Commit 62afa25

Browse files
authored
Merge pull request #51 from sourcefuse/saas-ui-13
fix(arc-saas): pagination of components
2 parents 44b2602 + 8a28f99 commit 62afa25

19 files changed

+361
-96
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {
2+
ApiService,
3+
Count,
4+
GetAPICommand,
5+
IAdapter,
6+
} from '@project-lib/core/api';
7+
8+
import {IAnyObject} from '@project-lib/core/i-any-object';
9+
10+
export class GetTotalBillingPlanCommand<T> extends GetAPICommand<Count> {
11+
constructor(
12+
apiService: ApiService,
13+
adapter: IAdapter<Count>,
14+
appConfig: IAnyObject,
15+
) {
16+
super(
17+
apiService,
18+
adapter,
19+
`${appConfig.baseApiUrl}${appConfig.subscriptionServiceUrl}/subscriptions/count`,
20+
);
21+
}
22+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
ApiService,
3+
Count,
4+
GetAPICommand,
5+
GetListAPICommand,
6+
IAdapter,
7+
} from '@project-lib/core/api';
8+
import {Lead} from '../../shared/models';
9+
10+
import {IAnyObject} from '@project-lib/core/i-any-object';
11+
12+
export class GetTotalLeadCommand<T> extends GetAPICommand<Count> {
13+
constructor(
14+
apiService: ApiService,
15+
adapter: IAdapter<Count>,
16+
appConfig: IAnyObject,
17+
) {
18+
super(
19+
apiService,
20+
adapter,
21+
`${appConfig.baseApiUrl}${appConfig.tenantmgmtServiceUrl}/leads/count`,
22+
);
23+
}
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {
2+
IApiService,
3+
IAdapter,
4+
GetAPICommand,
5+
Count,
6+
} from '@project-lib/core/api';
7+
import {Observable} from 'rxjs';
8+
import {Inject} from '@angular/core';
9+
import {APP_CONFIG} from '@project-lib/app-config';
10+
import {IAnyObject} from '@project-lib/core/i-any-object';
11+
import {Plan} from '../../shared/models';
12+
13+
export class GetTotalPlanCommand<T> extends GetAPICommand<Count> {
14+
constructor(
15+
apiService: IApiService,
16+
adapter: IAdapter<Count>,
17+
appConfig: IAnyObject,
18+
) {
19+
super(
20+
apiService,
21+
adapter,
22+
`${appConfig.baseApiUrl}${appConfig.subscriptionServiceUrl}/plans/count`,
23+
);
24+
}
25+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {
2+
ApiService,
3+
Count,
4+
GetAPICommand,
5+
GetListAPICommand,
6+
IAdapter,
7+
} from '@project-lib/core/api';
8+
9+
import {IAnyObject} from '@project-lib/core/i-any-object';
10+
11+
export class GetTotalTenantCommand<T> extends GetAPICommand<Count> {
12+
constructor(
13+
apiService: ApiService,
14+
adapter: IAdapter<Count>,
15+
appConfig: IAnyObject,
16+
) {
17+
super(
18+
apiService,
19+
adapter,
20+
`${appConfig.baseApiUrl}${appConfig.tenantmgmtServiceUrl}/tenants/count`,
21+
);
22+
}
23+
}

projects/saas-ui/src/app/main/commands/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ export * from './get-billing.command';
1111
export * from './get-currency-command';
1212
export * from './get-plan-by-id.command';
1313
export * from './get-plan.command';
14+
export * from './get-total-lead.command';
15+
export * from './get-total-tenant.command';
16+
export * from './get-total-plan.command';
17+
export * from './get-total-billing-plan.command';

projects/saas-ui/src/app/main/components/button-renderer/button-renderer.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ import {BillingPlanService} from '../../../shared/services/billing-plan-service'
77
import {AddPlanComponent} from '../add-plan/add-plan.component';
88
import {FormBuilder, Validators} from '@angular/forms';
99
import {Location} from '@angular/common';
10+
import {AnyObject} from '@project-lib/core/api';
1011
@Component({
1112
selector: 'app-button-renderer',
1213
templateUrl: './button-renderer.component.html',
1314
styleUrls: ['./button-renderer.component.scss'],
1415
})
1516
export class ButtonRendererComponent implements ICellRendererAngularComp {
16-
params: any;
17+
params: AnyObject;
1718
gridApi: GridApi;
18-
addPlanForm: any;
19+
addPlanForm: AnyObject;
1920
constructor(
2021
private readonly router: Router,
2122
private toastrService: ToasterService,

projects/saas-ui/src/app/main/components/lead-list/lead-list.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ <h2 class="heading">Lead List</h2>
66
<!-- ag-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: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
import {Component, OnInit} from '@angular/core';
22
import {ActivatedRoute} from '@angular/router';
33
import {RouteComponentBaseDirective} from '@project-lib/core/route-component-base';
4-
import {ColDef} from 'ag-grid-community';
4+
import {
5+
ColDef,
6+
GridApi,
7+
GridOptions,
8+
IDatasource,
9+
IGetRowsParams,
10+
} from 'ag-grid-community';
511
import {Location} from '@angular/common';
6-
import {takeUntil} from 'rxjs';
12+
import {Observable, combineLatest, map, of, takeUntil} from 'rxjs';
713
import {OnBoardingService} from '../../../shared/services/on-boarding-service';
814
import {Lead} from '../../../shared/models';
9-
import {AnyObject, BackendFilter} from '@project-lib/core/index';
15+
import {AnyObject, BackendFilter, Count} from '@project-lib/core/index';
16+
import {HttpClient} from '@angular/common/http';
1017

1118
@Component({
1219
selector: 'app-lead',
1320
templateUrl: './lead-list.component.html',
1421
styleUrls: ['./lead-list.component.scss'],
1522
})
16-
export class LeadListComponent
17-
extends RouteComponentBaseDirective
18-
implements OnInit
19-
{
23+
export class LeadListComponent extends RouteComponentBaseDirective {
2024
// defining column names here
2125
colDefs: ColDef[] = [
2226
{field: 'firstName', width: 250, minWidth: 20},
@@ -31,32 +35,71 @@ export class LeadListComponent
3135
filter: BackendFilter<Lead> = {
3236
include: [{relation: 'address'}],
3337
};
38+
gridApi: GridApi;
39+
gridOptions: GridOptions;
40+
limit = 5;
3441

3542
constructor(
3643
protected override readonly location: Location,
3744
protected override readonly route: ActivatedRoute,
3845
private readonly onboardingService: OnBoardingService,
46+
private http: HttpClient,
3947
) {
4048
super(route, location);
49+
this.gridOptions = {
50+
pagination: true,
51+
rowModelType: 'infinite',
52+
paginationPageSize: this.limit,
53+
paginationPageSizeSelector: [this.limit, 10, 20, 50, 100],
54+
cacheBlockSize: this.limit,
55+
onGridReady: this.onGridReady.bind(this),
56+
rowHeight: 60,
57+
defaultColDef: {flex: 1},
58+
};
4159
}
4260

43-
ngOnInit(): void {
44-
this.getTenants();
61+
onGridReady(params: AnyObject) {
62+
this.gridApi = params.api;
63+
const dataSource: IDatasource = {
64+
getRows: (params: IGetRowsParams) => {
65+
const page = params.endRow / this.limit;
66+
const paginatedLeads = this.getPaginatedLeads(page, this.limit);
67+
const totalLead = this.getTotal();
68+
combineLatest([paginatedLeads, totalLead]).subscribe(
69+
([data, count]) => {
70+
params.successCallback(data, count.count);
71+
},
72+
73+
err => {
74+
params.failCallback();
75+
},
76+
);
77+
},
78+
};
79+
params.api.setDatasource(dataSource);
4580
}
4681

47-
getTenants() {
48-
this.onboardingService
49-
.getLeadList(null, null, this.filter)
50-
.pipe(takeUntil(this._destroy$))
51-
.subscribe(res => {
52-
const data = res;
53-
this.rowData = data.map(item => ({
82+
getPaginatedLeads(page: number, limit: number): Observable<AnyObject[]> {
83+
const filter: BackendFilter<Lead> = {
84+
offset: limit * (page - 1),
85+
limit: limit,
86+
include: [{relation: 'address'}],
87+
};
88+
return this.onboardingService.getLeadList(filter).pipe(
89+
map(res => {
90+
const rows = res.map(item => ({
5491
firstName: item.firstName,
5592
lastName: item.lastName,
5693
companyName: item.companyName,
5794
email: item.email,
5895
country: item.address.country,
5996
}));
60-
});
97+
return rows;
98+
}),
99+
);
100+
}
101+
102+
getTotal(): Observable<Count> {
103+
return this.onboardingService.getTotalLead();
61104
}
62105
}

projects/saas-ui/src/app/main/components/manage-plans/manage-plans.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ <h2 class="heading">Manage Plan</h2>
66
<div class="grid">
77
<ag-grid-angular
88
class="ag-theme-quartz"
9-
[rowData]="rowData"
109
[columnDefs]="colDefs"
1110
[editType]="'fullRow'"
1211
[rowSelection]="rowSelection"
12+
[gridOptions]="gridOptions"
1313
(gridReady)="onGridReady($event)"
1414
(rowEditingStopped)="(onRowEditingStopped)"
1515
>

projects/saas-ui/src/app/main/components/manage-plans/manage-plans.component.ts

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import {Component, OnInit} from '@angular/core';
22
import {ActivatedRoute, Router} from '@angular/router';
3-
import {ColDef, GridApi} from 'ag-grid-community';
3+
import {
4+
ColDef,
5+
GridApi,
6+
GridOptions,
7+
IDatasource,
8+
IGetRowsParams,
9+
} from 'ag-grid-community';
410
import {OnBoardingService} from '../../../shared/services/on-boarding-service';
511
import {NbToastrService} from '@nebular/theme';
612
import {Location} from '@angular/common';
7-
import {takeUntil} from 'rxjs';
13+
import {Observable, combineLatest, map, takeUntil} from 'rxjs';
814
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
915
import {Plan} from '../../../shared/models';
1016
import {RouteComponentBaseDirective} from '@project-lib/core/route-component-base';
11-
import {AnyObject, BackendFilter} from '@project-lib/core/api';
17+
import {AnyObject, BackendFilter, Count} from '@project-lib/core/api';
1218
import {BillingPlanService} from '../../../shared/services/billing-plan-service';
1319
import {ToasterService} from '@project-lib/theme/toaster';
1420
import {ButtonRendererComponent} from '../button-renderer/button-renderer.component';
@@ -17,11 +23,11 @@ import {ButtonRendererComponent} from '../button-renderer/button-renderer.compon
1723
templateUrl: './manage-plans.component.html',
1824
styleUrls: ['./manage-plans.component.scss'],
1925
})
20-
export class ManagePlansComponent
21-
extends RouteComponentBaseDirective
22-
implements OnInit
23-
{
26+
export class ManagePlansComponent extends RouteComponentBaseDirective {
2427
[x: string]: any;
28+
gridApi: GridApi;
29+
gridOptions: GridOptions;
30+
limit = 5;
2531
colDefs: ColDef[] = [
2632
{field: 'name', headerName: 'Plan Name', width: 200, minWidth: 20},
2733
{field: 'description', width: 200, minWidth: 20},
@@ -35,8 +41,6 @@ export class ManagePlansComponent
3541
width: 200,
3642
},
3743
];
38-
39-
gridApi: GridApi;
4044
rowData = [];
4145
public rowSelection: 'single' | 'multiple' = 'single';
4246
tenants: AnyObject[];
@@ -53,18 +57,48 @@ export class ManagePlansComponent
5357
private fb: FormBuilder,
5458
) {
5559
super(route, location);
60+
this.gridOptions = {
61+
pagination: true,
62+
rowModelType: 'infinite',
63+
paginationPageSize: this.limit,
64+
paginationPageSizeSelector: [this.limit, 10, 20, 50, 100],
65+
cacheBlockSize: this.limit,
66+
onGridReady: this.onGridReady.bind(this),
67+
rowHeight: 60,
68+
defaultColDef: {flex: 1},
69+
};
5670
}
5771

58-
ngOnInit(): void {
59-
this.getPlans();
72+
onGridReady(params: AnyObject) {
73+
this.gridApi = params.api;
74+
const dataSource: IDatasource = {
75+
getRows: (params: IGetRowsParams) => {
76+
const page = params.endRow / this.limit;
77+
const paginatedLeads = this.getPaginatedPlans(page, this.limit);
78+
const totalLead = this.getTotal();
79+
combineLatest([paginatedLeads, totalLead]).subscribe(
80+
([data, count]) => {
81+
params.successCallback(data, count.count);
82+
},
83+
84+
err => {
85+
params.failCallback();
86+
},
87+
);
88+
},
89+
};
90+
params.api.setDatasource(dataSource);
6091
}
6192

62-
getPlans() {
63-
this.billingPlanService
64-
.getPlanOptions(null, null, this.filter)
65-
.pipe(takeUntil(this._destroy$))
66-
.subscribe(res => {
67-
this.rowData = res.map(item => {
93+
getPaginatedPlans(page: number, limit: number): Observable<AnyObject[]> {
94+
const filter: BackendFilter<Plan> = {
95+
offset: limit * (page - 1),
96+
limit: limit,
97+
include: [{relation: 'currency'}, {relation: 'billingCycle'}],
98+
};
99+
return this.billingPlanService.getPlanOptions(filter).pipe(
100+
map(res => {
101+
const rows = res.map(item => {
68102
return {
69103
id: item.id,
70104
name: item.name,
@@ -74,12 +108,15 @@ export class ManagePlansComponent
74108
price: item.price,
75109
};
76110
});
77-
});
111+
return rows;
112+
}),
113+
);
78114
}
79115

80-
onGridReady(params) {
81-
this.gridApi = params.api;
116+
getTotal(): Observable<Count> {
117+
return this.billingPlanService.getTotalPlan();
82118
}
119+
83120
showManagePlan() {
84121
this.router.navigate(['/main/add-plan']);
85122
}

0 commit comments

Comments
 (0)