diff options
Diffstat (limited to 'ufund-ui/src/app/components/cupboard')
-rw-r--r-- | ufund-ui/src/app/components/cupboard/cupboard.component.css | 33 | ||||
-rw-r--r-- | ufund-ui/src/app/components/cupboard/cupboard.component.ts | 45 |
2 files changed, 48 insertions, 30 deletions
diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.css b/ufund-ui/src/app/components/cupboard/cupboard.component.css index e45d929..9c37582 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.css +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.css @@ -52,3 +52,36 @@ margin-top: 3px; } } + +#header2 { + display: flex; + flex-direction: column; + gap: 10px +} + +#searchArea { + display: flex; + + form { + display: flex; + width: 100%; + gap: 10px; + } + + input[type=text] { + display: flex; + width: 100%; + } +} + +#sortArea { + display: flex; + flex-direction: row; + gap: 10px; + align-items: center; +} + +select { + font-size: 14pt; + padding: 5px; +} diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 95845e7..5139738 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -2,7 +2,7 @@ import {Component, OnInit, ViewChild} from '@angular/core'; import { CupboardService } from '../../services/cupboard.service'; import { Need, GoalType } from '../../models/Need'; import { userType } from '../../models/User'; -import {BehaviorSubject, catchError, of} from 'rxjs'; +import { catchError, of } from 'rxjs'; import { NeedListComponent } from '../need-list/need-list.component'; import {AuthService} from '../../services/auth.service'; import {ToastsService, ToastType} from '../../services/toasts.service'; @@ -24,21 +24,10 @@ export class CupboardComponent implements OnInit { private searchDelay: any; selectedNeed: Need | null = null; needs: Need[] = []; - searchResults = new BehaviorSubject<Need[]>([]); + searchResults: Need[] = []; sortMode: 'Ascending' | 'Descending' = 'Ascending' - // selectedNeed: any = { - // name: '', - // location:'', - // id: null, - // maxGoal: null, - // type: '', - // urgent: false - // }; - selectedNeedId: number | null = null; - // searchResults: any[] = []; currentSortAlgo = SortingAlgoArrays.sortByPriority; - // sortSelection: string = 'sortByPriority'; constructor( private cupboardService: CupboardService, @@ -48,12 +37,10 @@ export class CupboardComponent implements OnInit { ) {} ngOnInit(): void { - this.cupboardService.getNeeds().subscribe(n => this.needs = n); - if (this.isManager()) { - console.log("Admin view of Cupboard"); - } else { - console.log("Limited helper view of Cupboard"); - } + this.cupboardService.getNeeds().subscribe(n => { + this.needs = n; + this.refresh() + }); } refresh() { @@ -63,7 +50,7 @@ export class CupboardComponent implements OnInit { } else { this.needs = n.sort(this.currentSortAlgo.func).reverse(); } - this.searchResults.next(this.needs); + this.searchResults = this.needs; // this.updateVisibleNeeds(); }); @@ -112,9 +99,9 @@ export class CupboardComponent implements OnInit { const currentSearchValue = form.search; //latest value of the search this.cupboardService.searchNeeds(currentSearchValue).subscribe((n) => { if (this.sortMode == 'Ascending') { - this.searchResults.next(n.sort(this.currentSortAlgo.func)); + this.searchResults = n.sort(this.currentSortAlgo.func); } else { - this.searchResults.next(n.sort(this.currentSortAlgo.func).reverse()); + this.searchResults = n.sort(this.currentSortAlgo.func).reverse(); } // this.updateVisibleNeeds(); }); @@ -124,7 +111,7 @@ export class CupboardComponent implements OnInit { //user has cleared the search bar, we can skip the timeout for a 1/4 second faster response //clear timeout to stop pending search clearTimeout(this.searchDelay); - this.searchResults.next(this.needs); + this.searchResults = this.needs; } } @@ -137,13 +124,6 @@ export class CupboardComponent implements OnInit { this.search(form) } - - - isHelper() { - const type = this.authService.getCurrentUser()?.type; - return type === ("HELPER" as unknown as userType); - } - changeText(id : number, text : string) { const span = document.getElementById('hover-status-label-' + id); if (span) { @@ -170,6 +150,11 @@ export class CupboardComponent implements OnInit { return type === ("MANAGER" as unknown as userType); } + isHelper() { + const type = this.authService.getCurrentUser()?.type; + return type === ("HELPER" as unknown as userType); + } + // -------------- DISPLAY FUNCTIONS -------------- // select(need : Need) { |