diff options
Diffstat (limited to 'ufund-ui')
-rw-r--r-- | ufund-ui/src/app/components/need-list/need-list.component.html | 9 | ||||
-rw-r--r-- | ufund-ui/src/app/components/need-list/need-list.component.ts | 34 |
2 files changed, 40 insertions, 3 deletions
diff --git a/ufund-ui/src/app/components/need-list/need-list.component.html b/ufund-ui/src/app/components/need-list/need-list.component.html index e00ba47..8ea7b88 100644 --- a/ufund-ui/src/app/components/need-list/need-list.component.html +++ b/ufund-ui/src/app/components/need-list/need-list.component.html @@ -24,8 +24,15 @@ <h2 *ngIf="searchResults.length == needs.length"> All Needs </h2> <h2 *ngIf="searchResults.length == 0"> No Results Found </h2> +<div id="page-selector"> + <span>Page {{currentPage + 1}} of {{totalPages}} </span> <br> + <label>Needs per page: </label> + <input type ="number" [(ngModel)]="itemsPerPage" (change)="resetVisibleNeeds()" min="1" max="{{searchResults.length}}"> + <button *ngIf="currentPage > 0" (click)="decrementPage()">Previous</button> + <button *ngIf="currentPage < totalPages - 1" (click)="incrementPage()">Next</button> +</div> <div id="needList"> - <div *ngFor="let need of searchResults" class="needEntry"> + <div *ngFor="let need of visibleNeeds" class="needEntry"> <div [routerLink]="'/need/' + need.id" class="clickable"> <div class="split"> <div class="left"> diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts index d641acf..cd3d9bd 100644 --- a/ufund-ui/src/app/components/need-list/need-list.component.ts +++ b/ufund-ui/src/app/components/need-list/need-list.component.ts @@ -66,7 +66,36 @@ export class NeedListComponent { selectedNeed: Need | null = null; needs: Need[] = []; searchResults: Need[] = []; + visibleNeeds: Need[] = []; sortMode: 'Ascending' | 'Descending' = 'Ascending' + currentPage: number = 0; + itemsPerPage: number = 5; + totalPages: number = Math.ceil(this.needs.length / this.itemsPerPage); + + decrementPage() { + this.currentPage--; + this.updateVisibleNeeds(); + } + + incrementPage() { + this.currentPage++; + this.updateVisibleNeeds(); + } + + editNeedsPerPage(amount: number) { + this.itemsPerPage = amount; + this.updateVisibleNeeds(); + } + + updateVisibleNeeds() { + this.totalPages = Math.ceil(this.searchResults.length / this.itemsPerPage); + this.visibleNeeds = this.searchResults.slice(this.currentPage * this.itemsPerPage, (this.currentPage + 1) * this.itemsPerPage); + } + + resetVisibleNeeds() { + this.currentPage = 0; + this.updateVisibleNeeds(); + } currentSortAlgo: sortAlgo = sortByPriority; sortSelection: string = 'sortByPriority'; @@ -96,6 +125,7 @@ export class NeedListComponent { this.needs = n.sort(this.currentSortAlgo).reverse(); } this.searchResults = this.needs; + this.updateVisibleNeeds(); }); const form = document.getElementById('search-form') as HTMLFormElement; @@ -105,6 +135,7 @@ export class NeedListComponent { ngOnInit(): void { this.refresh() + } changeSortMode(form : any) { @@ -145,8 +176,7 @@ export class NeedListComponent { } else { this.searchResults = n.sort(this.currentSortAlgo).reverse(); } - - console.log(currentSearchValue, this.searchResults); + this.updateVisibleNeeds(); }); } }, 250); |