diff options
author | Gunther6070 <haydenhartman10@yahoo.com> | 2025-04-01 07:45:28 -0400 |
---|---|---|
committer | Gunther6070 <haydenhartman10@yahoo.com> | 2025-04-01 07:45:28 -0400 |
commit | 726b527af983025a95daae67864122761bcc4e78 (patch) | |
tree | 2046e58c146097aac21c9e352771420c31df6589 /ufund-ui/src/app/components/need-list/need-list.component.ts | |
parent | b544f2617843af29875af81923d3bec539aca704 (diff) | |
parent | 0e9c0803e35a23ef2e873dc7ebf224a49a92f207 (diff) | |
download | JellySolutions-726b527af983025a95daae67864122761bcc4e78.tar.gz JellySolutions-726b527af983025a95daae67864122761bcc4e78.tar.bz2 JellySolutions-726b527af983025a95daae67864122761bcc4e78.zip |
Merge branch 'css' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b into css
Diffstat (limited to 'ufund-ui/src/app/components/need-list/need-list.component.ts')
-rw-r--r-- | ufund-ui/src/app/components/need-list/need-list.component.ts | 38 |
1 files changed, 33 insertions, 5 deletions
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 7a9d647..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); @@ -160,6 +190,7 @@ export class NeedListComponent { delete(id : number) { this.cupboardService.deleteNeed(id).subscribe(() => { + this.toastService.sendToast(ToastType.INFO, "Need deleted.") this.needs = this.needs.filter(n => n.id !== id) }) this.refresh(); @@ -199,10 +230,7 @@ export class NeedListComponent { } else { this.toastService.sendToast(ToastType.ERROR, "This need is already in your basket!") } - - } - } back() { |