diff options
| author | benal01 <bja4245@rit.edu> | 2025-03-27 10:09:19 -0400 | 
|---|---|---|
| committer | benal01 <bja4245@rit.edu> | 2025-03-27 10:09:19 -0400 | 
| commit | ee4154df85a971f3a0f8e43fd6afdfa6a620ea99 (patch) | |
| tree | 1dbbd0d14cabbcc7fb15a58376b270f7316a1bf1 /ufund-ui/src/app | |
| parent | 65590e6dfbed90e4acd342a72feb8d7b5120d70c (diff) | |
| download | JellySolutions-ee4154df85a971f3a0f8e43fd6afdfa6a620ea99.tar.gz JellySolutions-ee4154df85a971f3a0f8e43fd6afdfa6a620ea99.tar.bz2 JellySolutions-ee4154df85a971f3a0f8e43fd6afdfa6a620ea99.zip  | |
refactor change sort algo func with [(ngModel)] binding
Diffstat (limited to '')
| -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') {  | 
