diff options
Diffstat (limited to 'ufund-ui/src/app/components')
-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 | 25 |
2 files changed, 12 insertions, 15 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 5be915c..4f259a0 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 @@ -1,7 +1,7 @@ <h1>Needs List</h1> <div id="search-container"> <label for="sort">Sort by:</label> - <select [(ngModel)]="sortSelection" id="sort" (change)="changeSortAlgo(sortSelection, searchForm.value)"> + <select [(ngModel)] = "sortSelection" id="sort" (change)="search(searchForm.value)"> <option *ngFor="let algorithm of SortingAlgoArrays" value="{{algorithm.name}}"> {{algorithm.display[sortMode === 'Ascending' ? 0 : 1]}} </option> 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 97be0cb..177d9f7 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 @@ -38,8 +38,9 @@ export class NeedListComponent { needs: Need[] = []; searchResults: Need[] = []; sortMode = 'Ascending' - sortSelection: string = ''; + currentSortAlgo: sortAlgo = sortByGoal; + sortSelection: string = this.currentSortAlgo.name; SortingAlgoArrays: {func:sortAlgo,name:string, display:string[]}[] = [ {func:sortByGoal,name:"sortByMaxGoal", display:["Max Goal", "Min Goal"]}, @@ -77,19 +78,6 @@ export class NeedListComponent { this.search(form) } - changeSortAlgo(algoName: string, form: any) { - console.log(algoName); - this.SortingAlgoArrays.forEach(algo => { - if(algo.name === algoName) { - this.currentSortAlgo = algo.func; - console.log("changed sorting algorithm to: ", algo.name + this.sortMode) - return - } - }); - this.refresh() - this.search(form); - } - private searchDelay: any; async search(form: any) { @@ -103,6 +91,15 @@ export class NeedListComponent { this.searchDelay = setTimeout(() => { if (form) { + //sorting based on algo selected + this.SortingAlgoArrays.forEach(algo => { + if(algo.name === this.sortSelection) { + this.currentSortAlgo = algo.func; + console.log("changed sorting algorithm to: ", algo.name + this.sortMode) + return + } + }); + const currentSearchValue = form.search; //latest value of the search this.cupboardService.searchNeeds(currentSearchValue).subscribe((n) => { if (this.sortMode == 'Ascending') { |