Skip to content

Commit

Permalink
Merge pull request #53 from sourcefuse/saas-ui-test-page
Browse files Browse the repository at this point in the history
fix(saas-ui):pagination of billing component
  • Loading branch information
yeshamavani authored Jun 3, 2024
2 parents 62afa25 + f2150e2 commit f1abd7c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ <h2 class="heading">Billing Details</h2>
<div class="grid">
<ag-grid-angular
class="ag-theme-quartz"
[rowData]="rowData"
[columnDefs]="colDefs"
[gridOptions]="gridOptions"
>
</ag-grid-angular>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import {Component, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {AnyObject} from '@project-lib/core/api';
import {AnyObject, BackendFilter, Count} from '@project-lib/core/api';
import {RouteComponentBaseDirective} from '@project-lib/core/route-component-base';
import {ColDef} from 'ag-grid-community';
import {takeUntil} from 'rxjs';
import {
ColDef,
GridApi,
GridOptions,
IDatasource,
IGetRowsParams,
} from 'ag-grid-community';
import {Observable, combineLatest, map, takeUntil} from 'rxjs';
import {Location} from '@angular/common';

import {BillingPlanService} from '../../../shared/services/billing-plan-service';
import {SubscriptionStatus} from '../../../shared/enum/subscription-status.enum';
import {Plan} from '../../../shared/models';

@Component({
selector: 'app-billing-plan',
templateUrl: './billing-plan.component.html',
styleUrls: ['./billing-plan.component.scss'],
})
export class BillingPlanComponent
extends RouteComponentBaseDirective
implements OnInit
{
export class BillingPlanComponent extends RouteComponentBaseDirective {
gridApi: GridApi;
gridOptions: GridOptions;
limit = 5;
colDefs: ColDef[] = [
{field: 'companyName', width: 200, minWidth: 20},
{field: 'userName', width: 200, minWidth: 20},
Expand All @@ -37,18 +44,47 @@ export class BillingPlanComponent
private readonly billingplanService: BillingPlanService,
) {
super(route, location);
this.gridOptions = {
pagination: true,
rowModelType: 'infinite',
paginationPageSize: this.limit,
paginationPageSizeSelector: [this.limit, 10, 20, 50, 100],
cacheBlockSize: this.limit,
onGridReady: this.onGridReady.bind(this),
rowHeight: 60,
defaultColDef: {flex: 1},
};
}

ngOnInit(): void {
this.getBillingPlan();
onGridReady(params: AnyObject) {
this.gridApi = params.api;
const dataSource: IDatasource = {
getRows: (params: IGetRowsParams) => {
const page = params.endRow / this.limit;
const paginatedLeads = this.getPaginatedBillPlans(page, this.limit);
const totalLead = this.getTotal();
combineLatest([paginatedLeads, totalLead]).subscribe(
([data, count]) => {
params.successCallback(data, count.count);
},

err => {
params.failCallback();
},
);
},
};
params.api.setDatasource(dataSource);
}

getBillingPlan() {
this.billingplanService
.getBillingDetails()
.pipe(takeUntil(this._destroy$))
.subscribe(res => {
this.rowData = res.map(item => {
getPaginatedBillPlans(page: number, limit: number): Observable<AnyObject[]> {
const filter: BackendFilter<Plan> = {
offset: limit * (page - 1),
limit: limit,
};
return this.billingplanService.getBillingDetails(filter).pipe(
map(res => {
const rows = res.map(item => {
return {
companyName: item.companyName,
userName: item.userName,
Expand All @@ -58,6 +94,12 @@ export class BillingPlanComponent
status: SubscriptionStatus[item.status],
};
});
});
return rows;
}),
);
}

getTotal(): Observable<Count> {
return this.billingplanService.getTotalBillingPlan();
}
}
12 changes: 11 additions & 1 deletion projects/saas-ui/src/app/shared/services/billing-plan-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,22 @@ export class BillingPlanService {
};
return command.execute();
}
getBillingDetails() {

getBillingDetails(filter?: BackendFilter<AnyObject>) {
const command: GetBillingDetails<AnyObject> = new GetBillingDetails(
this.apiService,
this.anyAdapter,
this.appConfig,
);
const backendFilter: BackendFilter<AnyObject> = filter
? {
where: filter.where,
offset: filter.offset,
limit: filter.limit,
order: filter.order,
include: filter.include || [], // Adding include from filter parameter
}
: {};
return command.execute();
}
getCurrencyDetails() {
Expand Down

0 comments on commit f1abd7c

Please sign in to comment.