Skip to content

Commit 8e19c51

Browse files
authored
Add paging to UI (#44)
* Add paging to UI * Fixed queryparms on apiservice
1 parent 7231701 commit 8e19c51

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

frontend/src/app/angor/project/project.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ <h1>Angor Project</h1>
133133
</tr>
134134
</tbody>
135135
</table>
136+
<ngb-pagination [collectionSize]="(projectStats$ | async)?.investorCount" [pageSize]="investmentsPerPage"
137+
[(page)]="investmentPage" (pageChange)="onInvestmentPageChange($event)" [boundaryLinks]="true">
138+
</ngb-pagination>
136139
</div>
137140
</div>
138141
</ng-container>

frontend/src/app/angor/project/project.component.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export class ProjectComponent implements OnInit {
1717
projectInvestments$: Observable<AngorProjectInvestment[]> | null = null;
1818
isLoading = true;
1919
error: HttpErrorResponse | null = null;
20+
investmentPage: number = 1;
21+
investmentsPerPage: number = 10;
2022

2123
constructor(
2224
private route: ActivatedRoute,
@@ -42,7 +44,9 @@ export class ProjectComponent implements OnInit {
4244
return this.apiService.getAngorProjectStats$(angorId).pipe(
4345
switchMap(stats => {
4446
this.projectStats$ = of(stats);
45-
return this.apiService.getAngorProjectInvestments(angorId);
47+
const limit = this.investmentsPerPage;
48+
const offset = (this.investmentPage - 1) * limit;
49+
return this.apiService.getAngorProjectInvestments(angorId, offset, limit);
4650
}),
4751
map(investments => {
4852
this.projectInvestments$ = of(investments);
@@ -63,4 +67,22 @@ export class ProjectComponent implements OnInit {
6367
)
6468
.subscribe();
6569
}
70+
71+
onInvestmentPageChange(newPage: number): void {
72+
this.investmentPage = newPage;
73+
this.angorId$.pipe(
74+
switchMap(angorId => {
75+
if (!angorId) {
76+
throw new Error('Angor ID is missing.');
77+
}
78+
this.isLoading = true;
79+
const limit = this.investmentsPerPage;
80+
const offset = (this.investmentPage - 1) * limit;
81+
return this.apiService.getAngorProjectInvestments(angorId, offset, limit);
82+
})
83+
).subscribe(investments => {
84+
this.projectInvestments$ = of(investments);
85+
this.isLoading = false;
86+
});
87+
}
6688
}

frontend/src/app/services/api.service.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,17 @@ export class ApiService {
603603
);
604604
}
605605

606-
getAngorProjectInvestments(angorId: string): Observable<AngorProjectInvestment[]> {
606+
getAngorProjectInvestments(angorId: string, from?: number, limit?: number): Observable<AngorProjectInvestment[]> {
607+
const queryParams = new URLSearchParams();
608+
if (from) {
609+
queryParams.append('offset', from.toString());
610+
}
611+
if (limit) {
612+
queryParams.append('limit', limit.toString());
613+
}
614+
const queryString = queryParams.toString();
607615
return this.httpClient.get<AngorProjectInvestment[]>(
608-
this.apiBaseUrl + this.apiBasePath + '/api/v1/query/Angor/projects/' + angorId + '/investments'
616+
this.apiBaseUrl + this.apiBasePath + '/api/v1/query/Angor/projects/' + angorId + '/investments/' + queryString
609617
);
610618
}
611619
}

0 commit comments

Comments
 (0)