diff options
Diffstat (limited to 'ufund-ui/src/app')
-rw-r--r-- | ufund-ui/src/app/components/need-list/need-list.component.html | 2 | ||||
-rw-r--r-- | ufund-ui/src/app/components/need-list/need-list.component.ts | 15 |
2 files changed, 16 insertions, 1 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 c5faf74..283cc99 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 @@ -3,7 +3,9 @@ <h3>Sort by:</h3> <table style="margin-left: 10px; display: flex; column-gap: 24px;"> <tr><h3><button (click)="changeSortAlgo('sortByName',searchForm.value)">Name(A-Z)</button></h3></tr> + <tr><h3><button (click)="changeSortAlgo('sortByNameReverse',searchForm.value)">Name(Z-A)</button></h3></tr> <tr><h3><button (click)="changeSortAlgo('sortByMaxGoal',searchForm.value)">Max Goal(Descending)</button></h3></tr> + <tr><h3><button (click)="changeSortAlgo('sortByMinGoal',searchForm.value)">Max Goal(Ascending)</button></h3></tr> </table> </div> <input id="search-button" type="button" value="Search" (click)="open()"> 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 be444fb..06bb17e 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 @@ -16,13 +16,24 @@ const sortByName: sortAlgo = (a: Need, b: Need): number => { return 1; } +const sortByNameReverse: sortAlgo = (a: Need, b: Need): number => { + return sortByName(a,b)*-1; +} + const sortByMaxGoal: sortAlgo = (a: Need, b: Need): number => { - if(a.maxGoal >= b.maxGoal) { + if(a.maxGoal == b.maxGoal) { + return sortByName(a,b); + } + else if(a.maxGoal > b.maxGoal) { return -1; } return 1; } +const sortByMinGoal: sortAlgo = (a: Need, b: Need): number => { + return sortByMaxGoal(a,b)*-1; +} + @Component({ selector: 'app-need-list', standalone: false, @@ -37,6 +48,8 @@ export class NeedListComponent { SortingAlgoArrays: {func:sortAlgo,name:string}[] = [ {func:sortByMaxGoal,name:"sortByMaxGoal"}, {func:sortByName,name:"sortByName"}, + {func:sortByNameReverse,name:"sortByNameReverse"}, + {func:sortByMinGoal,name:"sortByMinGoal"}, ]; constructor( |