From 0652eb445728806d7fd6a50021a763051503ab36 Mon Sep 17 00:00:00 2001 From: sowgro Date: Thu, 3 Apr 2025 14:55:55 -0400 Subject: get checkout abstraction kinda working --- .../app/components/cupboard/cupboard.component.ts | 184 ++++++++++++++++++--- 1 file changed, 160 insertions(+), 24 deletions(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 2230cd3..5139738 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -6,6 +6,8 @@ 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'; +import {UsersService} from '../../services/users.service'; +import {SortingAlgoArrays} from './sorting'; @Component({ selector: 'app-cupboard', @@ -13,43 +15,54 @@ import {ToastsService, ToastType} from '../../services/toasts.service'; templateUrl: './cupboard.component.html', styleUrl: './cupboard.component.css' }) - export class CupboardComponent implements OnInit { selectedForm?: string = undefined; - needs: any; + // needs: any; @ViewChild("needList") needList?: NeedListComponent + private searchDelay: any; + selectedNeed: Need | null = null; + needs: Need[] = []; + searchResults: Need[] = []; + sortMode: 'Ascending' | 'Descending' = 'Ascending' + + currentSortAlgo = SortingAlgoArrays.sortByPriority; + constructor( private cupboardService: CupboardService, private authService: AuthService, - private toastService: ToastsService + private toastService: ToastsService, + private usersService: UsersService ) {} 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() + }); } - selectedNeed: any = { - name: '', - location:'', - id: null, - maxGoal: null, - type: '', - urgent: false - }; - selectedNeedId: number | null = null; - searchResults: any[] = []; + refresh() { + this.cupboardService.getNeeds().subscribe(n => { + if (this.sortMode == 'Ascending') { + this.needs = n.sort(this.currentSortAlgo.func); + } else { + this.needs = n.sort(this.currentSortAlgo.func).reverse(); + } + this.searchResults = this.needs; + // this.updateVisibleNeeds(); + }); + + const form = document.getElementById('search-form') as HTMLFormElement; + form.reset(); + this.search(null); + } selectForm(name: string) { //get search results from the need list if (this.needList) { - this.searchResults = this.needList.searchResults; + // this.searchResults = this.needList.searchResults; } console.log(this.searchResults) this.selectedForm = name; @@ -63,10 +76,65 @@ export class CupboardComponent implements OnInit { } } + async search(form: any) { + //wait .25 seconds before searching but cancel if another search is made during the wait to prevent too many api calls + + //remove previous search if it exists + if (this.searchDelay) { + clearTimeout(this.searchDelay); + } + if (form) { + this.searchDelay = setTimeout(() => { + + if (form) { + //sorting based on algo selected + // SortingAlgoArrays.forEach(algo => { + // if(algo.name === this.sortSelection) { + // this.currentSortAlgo = SortingAlgoArrays[this.sort]; + // 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') { + this.searchResults = n.sort(this.currentSortAlgo.func); + } else { + this.searchResults = n.sort(this.currentSortAlgo.func).reverse(); + } + // this.updateVisibleNeeds(); + }); + } + }, 250); + } else { + //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 = this.needs; + } + } + + changeSortMode(form : any) { + if (this.sortMode == 'Ascending'){ + this.sortMode = 'Descending' + } else { + this.sortMode = 'Ascending' + } + this.search(form) + } + + changeText(id : number, text : string) { + const span = document.getElementById('hover-status-label-' + id); + if (span) { + span.innerHTML = ' ' + text; + } + } + async updateSearchResults() { if (this.needList) { while (this.selectedForm == 'update') { - this.searchResults = this.needList.searchResults + // this.searchResults = this.needList.searchResults await new Promise(resolve => setTimeout(resolve, 100)); } } @@ -82,6 +150,45 @@ 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) { + //emit value + // this.currentNeed.emit(need); + if (this.selectedNeed) { + //revert already selected need to previous style + console.log(need.id); + let button = document.getElementById('need-button-' + this.selectedNeed.id); + if (button) { + console.log(button) + button.style.background = 'lightgray'; + button.style.marginLeft = '0%'; + button.style.width = '98%'; + } + button = document.getElementById('need-edit-button-' + this.selectedNeed.id); + if (button) { + button.style.visibility = 'visible'; + } + } + //change selected need to selected style + this.selectedNeed = need; + let button = document.getElementById('need-button-' + need.id); + if (button) { + button.style.background = 'white'; + button.style.marginLeft = '4%'; + button.style.width = '100%'; + } + button = document.getElementById('need-edit-button-' + need.id); + if (button) { + button.style.visibility = 'hidden'; + } + } + submit(form: any) { const need: Need = { name: form.name, @@ -90,7 +197,7 @@ export class CupboardComponent implements OnInit { id: 0, maxGoal: form.maxGoal, type: form.type, - urgent: form.urgent ? true : false, + urgent: !!form.urgent, filterAttributes: [], current: 0, description: form.description @@ -112,7 +219,7 @@ export class CupboardComponent implements OnInit { (result) => { if (result) { console.log("need created successfully"); - this.needList?.refresh() + // this.needList?.refresh() } else { console.log("need creation failed"); } @@ -121,7 +228,36 @@ export class CupboardComponent implements OnInit { ); } - destroy() { + // -------------- CRUD OPERATIONS -------------- // + 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(); } + + add(need: Need) { + const currentUser = this.authService.getCurrentUser(); + //console.log("get current user in angular:", currentUser) + if (currentUser) { + if (!currentUser.basket.includes(need.id)) { + currentUser.basket.push(need.id); + this.usersService.updateUser(currentUser) + .pipe(catchError((err, _) => { + console.error(err); + return of(); + })) + .subscribe(() => { + this.usersService.refreshBasket(); + }); + } else { + this.toastService.sendToast(ToastType.ERROR, "This need is already in your basket!") + } + } + } + + protected readonly SortingAlgoArrays = SortingAlgoArrays; + protected readonly Object = Object; } -- cgit v1.2.3 From ad651c44ce2515d497c8e5214147c69126e25903 Mon Sep 17 00:00:00 2001 From: sowgro Date: Thu, 3 Apr 2025 19:48:54 -0400 Subject: abstraction working with search and sort --- .../app/components/cupboard/cupboard.component.ts | 277 ++++++++++----------- 1 file changed, 137 insertions(+), 140 deletions(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 5139738..f723755 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 { catchError, of } from 'rxjs'; +import {BehaviorSubject, catchError, Observable, of} from 'rxjs'; import { NeedListComponent } from '../need-list/need-list.component'; import {AuthService} from '../../services/auth.service'; import {ToastsService, ToastType} from '../../services/toasts.service'; @@ -17,17 +17,17 @@ import {SortingAlgoArrays} from './sorting'; }) export class CupboardComponent implements OnInit { - selectedForm?: string = undefined; + // selectedForm?: string = undefined; // needs: any; @ViewChild("needList") needList?: NeedListComponent private searchDelay: any; - selectedNeed: Need | null = null; + // selectedNeed: Need | null = null; needs: Need[] = []; searchResults: Need[] = []; sortMode: 'Ascending' | 'Descending' = 'Ascending' - - currentSortAlgo = SortingAlgoArrays.sortByPriority; + itemsPerPage = 5; + currentSortAlgo = 'sortByPriority'; constructor( private cupboardService: CupboardService, @@ -39,16 +39,17 @@ export class CupboardComponent implements OnInit { ngOnInit(): void { this.cupboardService.getNeeds().subscribe(n => { this.needs = n; - this.refresh() + // this.refresh() + this.search(null) }); } refresh() { this.cupboardService.getNeeds().subscribe(n => { if (this.sortMode == 'Ascending') { - this.needs = n.sort(this.currentSortAlgo.func); + this.needs = n.sort(SortingAlgoArrays[this.currentSortAlgo].func); } else { - this.needs = n.sort(this.currentSortAlgo.func).reverse(); + this.needs = n.sort(SortingAlgoArrays[this.currentSortAlgo].func).reverse(); } this.searchResults = this.needs; // this.updateVisibleNeeds(); @@ -59,24 +60,8 @@ export class CupboardComponent implements OnInit { this.search(null); } - selectForm(name: string) { - //get search results from the need list - if (this.needList) { - // this.searchResults = this.needList.searchResults; - } - console.log(this.searchResults) - this.selectedForm = name; - if (name == 'update') { - if (this.searchResults) { - this.searchResults.forEach((element: any) => { - console.log(element) - }); - } - - } - } - async search(form: any) { + console.log(this.currentSortAlgo) //wait .25 seconds before searching but cancel if another search is made during the wait to prevent too many api calls //remove previous search if it exists @@ -99,9 +84,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 = n.sort(this.currentSortAlgo.func); + this.searchResults = n.sort(SortingAlgoArrays[this.currentSortAlgo].func); } else { - this.searchResults = n.sort(this.currentSortAlgo.func).reverse(); + this.searchResults = n.sort(SortingAlgoArrays[this.currentSortAlgo].func).reverse(); } // this.updateVisibleNeeds(); }); @@ -115,7 +100,7 @@ export class CupboardComponent implements OnInit { } } - changeSortMode(form : any) { + toggleSortMode(form : any) { if (this.sortMode == 'Ascending'){ this.sortMode = 'Descending' } else { @@ -124,26 +109,16 @@ export class CupboardComponent implements OnInit { this.search(form) } - changeText(id : number, text : string) { - const span = document.getElementById('hover-status-label-' + id); - if (span) { - span.innerHTML = ' ' + text; - } - } - async updateSearchResults() { - if (this.needList) { - while (this.selectedForm == 'update') { - // this.searchResults = this.needList.searchResults - await new Promise(resolve => setTimeout(resolve, 100)); - } - } + // if (this.needList) { + // while (this.selectedForm == 'update') { + // // this.searchResults = this.needList.searchResults + // await new Promise(resolve => setTimeout(resolve, 100)); + // } + // } } - populateForm(need: any): void { - this.selectForm('update'); - this.selectedNeed = { ...need }; - } + // ------------ HELPER FUNCTIONS --------------- // isManager() { const type = this.authService.getCurrentUser()?.type; @@ -157,107 +132,129 @@ export class CupboardComponent implements OnInit { // -------------- DISPLAY FUNCTIONS -------------- // - select(need : Need) { - //emit value - // this.currentNeed.emit(need); - if (this.selectedNeed) { - //revert already selected need to previous style - console.log(need.id); - let button = document.getElementById('need-button-' + this.selectedNeed.id); - if (button) { - console.log(button) - button.style.background = 'lightgray'; - button.style.marginLeft = '0%'; - button.style.width = '98%'; - } - button = document.getElementById('need-edit-button-' + this.selectedNeed.id); - if (button) { - button.style.visibility = 'visible'; - } - } - //change selected need to selected style - this.selectedNeed = need; - let button = document.getElementById('need-button-' + need.id); - if (button) { - button.style.background = 'white'; - button.style.marginLeft = '4%'; - button.style.width = '100%'; - } - button = document.getElementById('need-edit-button-' + need.id); - if (button) { - button.style.visibility = 'hidden'; - } + selectForm(name: string) { + // //get search results from the need list + // if (this.needList) { + // // this.searchResults = this.needList.searchResults; + // } + // console.log(this.searchResults) + // this.selectedForm = name; + // if (name == 'update') { + // if (this.searchResults) { + // this.searchResults.forEach((element: any) => { + // console.log(element) + // }); + // } + // + // } } - submit(form: any) { - const need: Need = { - name: form.name, - image: form.image, - location: form.location, - id: 0, - maxGoal: form.maxGoal, - type: form.type, - urgent: !!form.urgent, - filterAttributes: [], - current: 0, - description: form.description - }; - console.log("need:", need); - console.log("form submitted. creating need: ", need); - this.cupboardService.createNeed(need) - .pipe(catchError((ex, _) => { - if (ex.status == 500) { - this.toastService.sendToast(ToastType.ERROR, "Fields cannot be blank"); - } else if (ex.status == 400) { - this.toastService.sendToast(ToastType.ERROR, ex.error); - } else { - this.toastService.sendToast(ToastType.ERROR, "Error on creating need"); - } - return of() - })) - .subscribe( - (result) => { - if (result) { - console.log("need created successfully"); - // this.needList?.refresh() - } else { - console.log("need creation failed"); - } - } + // populateForm(need: any): void { + // this.selectForm('update'); + // this.selectedNeed = { ...need }; + // } + // + // select(need : Need) { + // //emit value + // // this.currentNeed.emit(need); + // if (this.selectedNeed) { + // //revert already selected need to previous style + // console.log(need.id); + // let button = document.getElementById('need-button-' + this.selectedNeed.id); + // if (button) { + // console.log(button) + // button.style.background = 'lightgray'; + // button.style.marginLeft = '0%'; + // button.style.width = '98%'; + // } + // button = document.getElementById('need-edit-button-' + this.selectedNeed.id); + // if (button) { + // button.style.visibility = 'visible'; + // } + // } + // //change selected need to selected style + // this.selectedNeed = need; + // let button = document.getElementById('need-button-' + need.id); + // if (button) { + // button.style.background = 'white'; + // button.style.marginLeft = '4%'; + // button.style.width = '100%'; + // } + // button = document.getElementById('need-edit-button-' + need.id); + // if (button) { + // button.style.visibility = 'hidden'; + // } + // } - ); - } + // submit(form: any) { + // const need: Need = { + // name: form.name, + // image: form.image, + // location: form.location, + // id: 0, + // maxGoal: form.maxGoal, + // type: form.type, + // urgent: !!form.urgent, + // filterAttributes: [], + // current: 0, + // description: form.description + // }; + // console.log("need:", need); + // console.log("form submitted. creating need: ", need); + // this.cupboardService.createNeed(need) + // .pipe(catchError((ex, _) => { + // if (ex.status == 500) { + // this.toastService.sendToast(ToastType.ERROR, "Fields cannot be blank"); + // } else if (ex.status == 400) { + // this.toastService.sendToast(ToastType.ERROR, ex.error); + // } else { + // this.toastService.sendToast(ToastType.ERROR, "Error on creating need"); + // } + // return of() + // })) + // .subscribe( + // (result) => { + // if (result) { + // console.log("need created successfully"); + // // this.needList?.refresh() + // } else { + // console.log("need creation failed"); + // } + // } + // + // ); + // } // -------------- CRUD OPERATIONS -------------- // - 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(); - } - - add(need: Need) { - const currentUser = this.authService.getCurrentUser(); - //console.log("get current user in angular:", currentUser) - if (currentUser) { - if (!currentUser.basket.includes(need.id)) { - currentUser.basket.push(need.id); - this.usersService.updateUser(currentUser) - .pipe(catchError((err, _) => { - console.error(err); - return of(); - })) - .subscribe(() => { - this.usersService.refreshBasket(); - }); - } else { - this.toastService.sendToast(ToastType.ERROR, "This need is already in your basket!") - } - } - } + // 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(); + // } + // + // add(need: Need) { + // const currentUser = this.authService.getCurrentUser(); + // //console.log("get current user in angular:", currentUser) + // if (currentUser) { + // if (!currentUser.basket.includes(need.id)) { + // currentUser.basket.push(need.id); + // this.usersService.updateUser(currentUser) + // .pipe(catchError((err, _) => { + // console.error(err); + // return of(); + // })) + // .subscribe(() => { + // this.usersService.refreshBasket(); + // }); + // } else { + // this.toastService.sendToast(ToastType.ERROR, "This need is already in your basket!") + // } + // } + // } - protected readonly SortingAlgoArrays = SortingAlgoArrays; + protected readonly SortingAlgorithms = SortingAlgoArrays; protected readonly Object = Object; } -- cgit v1.2.3 From 6a5033afc3c8e0d5d12d709b35b306b6ea1f70e8 Mon Sep 17 00:00:00 2001 From: sowgro Date: Thu, 3 Apr 2025 23:11:05 -0400 Subject: Implemented action buttons with ng-template!!! --- .../app/components/cupboard/cupboard.component.ts | 160 ++++++++++----------- 1 file changed, 73 insertions(+), 87 deletions(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index f723755..a4f8db2 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -1,9 +1,9 @@ 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, Observable, of} from 'rxjs'; -import { NeedListComponent } from '../need-list/need-list.component'; +import {CupboardService} from '../../services/cupboard.service'; +import {Need} from '../../models/Need'; +import {userType} from '../../models/User'; +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'; import {UsersService} from '../../services/users.service'; @@ -72,14 +72,6 @@ export class CupboardComponent implements OnInit { this.searchDelay = setTimeout(() => { if (form) { - //sorting based on algo selected - // SortingAlgoArrays.forEach(algo => { - // if(algo.name === this.sortSelection) { - // this.currentSortAlgo = SortingAlgoArrays[this.sort]; - // 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) => { @@ -109,28 +101,52 @@ export class CupboardComponent implements OnInit { this.search(form) } - async updateSearchResults() { - // if (this.needList) { - // while (this.selectedForm == 'update') { - // // this.searchResults = this.needList.searchResults - // await new Promise(resolve => setTimeout(resolve, 100)); - // } - // } + deleteNeed(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(); } - // ------------ HELPER FUNCTIONS --------------- // + addToBasket(need: Need) { + const currentUser = this.authService.getCurrentUser(); + //console.log("get current user in angular:", currentUser) + if (currentUser) { + if (!currentUser.basket.includes(need.id)) { + currentUser.basket.push(need.id); + this.usersService.updateUser(currentUser) + .pipe(catchError((err, _) => { + console.error(err); + return of(); + })) + .subscribe(() => { + this.usersService.refreshBasket(); + }); + } else { + this.toastService.sendToast(ToastType.ERROR, "This need is already in your basket!") + } + } + } isManager() { - const type = this.authService.getCurrentUser()?.type; - return type === ("MANAGER" as unknown as userType); + return this.authService.getCurrentUser()?.type === userType.MANAGER } isHelper() { - const type = this.authService.getCurrentUser()?.type; - return type === ("HELPER" as unknown as userType); + return this.authService.getCurrentUser()?.type === userType.HELPER } - // -------------- DISPLAY FUNCTIONS -------------- // + // --------------- FORM STUFF NOT IMPLEMENTED YET --------------- // + + // async updateSearchResults() { + // if (this.needList) { + // while (this.selectedForm == 'update') { + // // this.searchResults = this.needList.searchResults + // await new Promise(resolve => setTimeout(resolve, 100)); + // } + // } + // } selectForm(name: string) { // //get search results from the need list @@ -154,37 +170,37 @@ export class CupboardComponent implements OnInit { // this.selectedNeed = { ...need }; // } // - // select(need : Need) { - // //emit value - // // this.currentNeed.emit(need); - // if (this.selectedNeed) { - // //revert already selected need to previous style - // console.log(need.id); - // let button = document.getElementById('need-button-' + this.selectedNeed.id); - // if (button) { - // console.log(button) - // button.style.background = 'lightgray'; - // button.style.marginLeft = '0%'; - // button.style.width = '98%'; - // } - // button = document.getElementById('need-edit-button-' + this.selectedNeed.id); - // if (button) { - // button.style.visibility = 'visible'; - // } - // } - // //change selected need to selected style - // this.selectedNeed = need; - // let button = document.getElementById('need-button-' + need.id); - // if (button) { - // button.style.background = 'white'; - // button.style.marginLeft = '4%'; - // button.style.width = '100%'; - // } - // button = document.getElementById('need-edit-button-' + need.id); - // if (button) { - // button.style.visibility = 'hidden'; - // } - // } + select(need : Need) { + // //emit value + // // this.currentNeed.emit(need); + // if (this.selectedNeed) { + // //revert already selected need to previous style + // console.log(need.id); + // let button = document.getElementById('need-button-' + this.selectedNeed.id); + // if (button) { + // console.log(button) + // button.style.background = 'lightgray'; + // button.style.marginLeft = '0%'; + // button.style.width = '98%'; + // } + // button = document.getElementById('need-edit-button-' + this.selectedNeed.id); + // if (button) { + // button.style.visibility = 'visible'; + // } + // } + // //change selected need to selected style + // this.selectedNeed = need; + // let button = document.getElementById('need-button-' + need.id); + // if (button) { + // button.style.background = 'white'; + // button.style.marginLeft = '4%'; + // button.style.width = '100%'; + // } + // button = document.getElementById('need-edit-button-' + need.id); + // if (button) { + // button.style.visibility = 'hidden'; + // } + } // submit(form: any) { // const need: Need = { @@ -225,36 +241,6 @@ export class CupboardComponent implements OnInit { // ); // } - // -------------- CRUD OPERATIONS -------------- // - - // 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(); - // } - // - // add(need: Need) { - // const currentUser = this.authService.getCurrentUser(); - // //console.log("get current user in angular:", currentUser) - // if (currentUser) { - // if (!currentUser.basket.includes(need.id)) { - // currentUser.basket.push(need.id); - // this.usersService.updateUser(currentUser) - // .pipe(catchError((err, _) => { - // console.error(err); - // return of(); - // })) - // .subscribe(() => { - // this.usersService.refreshBasket(); - // }); - // } else { - // this.toastService.sendToast(ToastType.ERROR, "This need is already in your basket!") - // } - // } - // } - protected readonly SortingAlgorithms = SortingAlgoArrays; protected readonly Object = Object; } -- cgit v1.2.3 From a5567b2ed092af3a50da75eef28d46c06760a266 Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 4 Apr 2025 10:48:31 -0400 Subject: Improve add to basket feedback --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index a4f8db2..bde8e27 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -8,6 +8,7 @@ import {AuthService} from '../../services/auth.service'; import {ToastsService, ToastType} from '../../services/toasts.service'; import {UsersService} from '../../services/users.service'; import {SortingAlgoArrays} from './sorting'; +import {Router} from '@angular/router'; @Component({ selector: 'app-cupboard', @@ -33,7 +34,8 @@ export class CupboardComponent implements OnInit { private cupboardService: CupboardService, private authService: AuthService, private toastService: ToastsService, - private usersService: UsersService + protected usersService: UsersService, + private router: Router ) {} ngOnInit(): void { @@ -42,6 +44,8 @@ export class CupboardComponent implements OnInit { // this.refresh() this.search(null) }); + this.authService.getCurrentUserSubject().subscribe( + () => this.usersService.refreshBasket()) } refresh() { @@ -121,6 +125,8 @@ export class CupboardComponent implements OnInit { return of(); })) .subscribe(() => { + let action = {label: "View Basket", onAction: () => this.router.navigate(['/basket'])} + this.toastService.sendToast(ToastType.INFO, `"${need.name}" Added to basket`, action) this.usersService.refreshBasket(); }); } else { @@ -137,6 +143,12 @@ export class CupboardComponent implements OnInit { return this.authService.getCurrentUser()?.type === userType.HELPER } + inBasket(basket: Need[] | null, need: Need) { + console.log(basket) + console.log(need) + return basket?.map(r => r.id).includes(need.id); + } + // --------------- FORM STUFF NOT IMPLEMENTED YET --------------- // // async updateSearchResults() { -- cgit v1.2.3 From d85eeb6918d521197c2e6ad1e3da2dec8ce95398 Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 4 Apr 2025 17:22:10 -0400 Subject: Edit modal --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index bde8e27..f5e4c00 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -9,6 +9,7 @@ import {ToastsService, ToastType} from '../../services/toasts.service'; import {UsersService} from '../../services/users.service'; import {SortingAlgoArrays} from './sorting'; import {Router} from '@angular/router'; +import {ModalService} from '../../services/modal.service'; @Component({ selector: 'app-cupboard', @@ -29,13 +30,15 @@ export class CupboardComponent implements OnInit { sortMode: 'Ascending' | 'Descending' = 'Ascending' itemsPerPage = 5; currentSortAlgo = 'sortByPriority'; + // activeEdit?: Need; constructor( private cupboardService: CupboardService, private authService: AuthService, private toastService: ToastsService, protected usersService: UsersService, - private router: Router + private router: Router, + protected modalService: ModalService ) {} ngOnInit(): void { @@ -149,6 +152,10 @@ export class CupboardComponent implements OnInit { return basket?.map(r => r.id).includes(need.id); } + // editNeed(need : Need) { + // this.activeEdit = need + // } + // --------------- FORM STUFF NOT IMPLEMENTED YET --------------- // // async updateSearchResults() { @@ -182,7 +189,7 @@ export class CupboardComponent implements OnInit { // this.selectedNeed = { ...need }; // } // - select(need : Need) { + // select(need : Need) { // //emit value // // this.currentNeed.emit(need); // if (this.selectedNeed) { @@ -212,7 +219,7 @@ export class CupboardComponent implements OnInit { // if (button) { // button.style.visibility = 'hidden'; // } - } + // } // submit(form: any) { // const need: Need = { -- cgit v1.2.3 From feba88fed855d1694d292e401a4cb336e0ff9d69 Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 4 Apr 2025 20:56:02 -0400 Subject: Fix create-need dialog --- .../app/components/cupboard/cupboard.component.ts | 108 --------------------- 1 file changed, 108 deletions(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index f5e4c00..56fdd70 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -152,114 +152,6 @@ export class CupboardComponent implements OnInit { return basket?.map(r => r.id).includes(need.id); } - // editNeed(need : Need) { - // this.activeEdit = need - // } - - // --------------- FORM STUFF NOT IMPLEMENTED YET --------------- // - - // async updateSearchResults() { - // if (this.needList) { - // while (this.selectedForm == 'update') { - // // this.searchResults = this.needList.searchResults - // await new Promise(resolve => setTimeout(resolve, 100)); - // } - // } - // } - - selectForm(name: string) { - // //get search results from the need list - // if (this.needList) { - // // this.searchResults = this.needList.searchResults; - // } - // console.log(this.searchResults) - // this.selectedForm = name; - // if (name == 'update') { - // if (this.searchResults) { - // this.searchResults.forEach((element: any) => { - // console.log(element) - // }); - // } - // - // } - } - - // populateForm(need: any): void { - // this.selectForm('update'); - // this.selectedNeed = { ...need }; - // } - // - // select(need : Need) { - // //emit value - // // this.currentNeed.emit(need); - // if (this.selectedNeed) { - // //revert already selected need to previous style - // console.log(need.id); - // let button = document.getElementById('need-button-' + this.selectedNeed.id); - // if (button) { - // console.log(button) - // button.style.background = 'lightgray'; - // button.style.marginLeft = '0%'; - // button.style.width = '98%'; - // } - // button = document.getElementById('need-edit-button-' + this.selectedNeed.id); - // if (button) { - // button.style.visibility = 'visible'; - // } - // } - // //change selected need to selected style - // this.selectedNeed = need; - // let button = document.getElementById('need-button-' + need.id); - // if (button) { - // button.style.background = 'white'; - // button.style.marginLeft = '4%'; - // button.style.width = '100%'; - // } - // button = document.getElementById('need-edit-button-' + need.id); - // if (button) { - // button.style.visibility = 'hidden'; - // } - // } - - // submit(form: any) { - // const need: Need = { - // name: form.name, - // image: form.image, - // location: form.location, - // id: 0, - // maxGoal: form.maxGoal, - // type: form.type, - // urgent: !!form.urgent, - // filterAttributes: [], - // current: 0, - // description: form.description - // }; - // console.log("need:", need); - // console.log("form submitted. creating need: ", need); - // this.cupboardService.createNeed(need) - // .pipe(catchError((ex, _) => { - // if (ex.status == 500) { - // this.toastService.sendToast(ToastType.ERROR, "Fields cannot be blank"); - // } else if (ex.status == 400) { - // this.toastService.sendToast(ToastType.ERROR, ex.error); - // } else { - // this.toastService.sendToast(ToastType.ERROR, "Error on creating need"); - // } - // return of() - // })) - // .subscribe( - // (result) => { - // if (result) { - // console.log("need created successfully"); - // // this.needList?.refresh() - // } else { - // console.log("need creation failed"); - // } - // } - // - // ); - // } - protected readonly SortingAlgorithms = SortingAlgoArrays; protected readonly Object = Object; } -- cgit v1.2.3 From b578584a1208178100bf90e8b06971772c7fc00f Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 4 Apr 2025 21:55:12 -0400 Subject: Fix many bugs and code clean up --- .../src/app/components/cupboard/cupboard.component.ts | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 56fdd70..289618f 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -1,7 +1,6 @@ import {Component, OnInit, ViewChild} from '@angular/core'; import {CupboardService} from '../../services/cupboard.service'; import {Need} from '../../models/Need'; -import {userType} from '../../models/User'; import {catchError, of} from 'rxjs'; import {NeedListComponent} from '../need-list/need-list.component'; import {AuthService} from '../../services/auth.service'; @@ -138,20 +137,6 @@ export class CupboardComponent implements OnInit { } } - isManager() { - return this.authService.getCurrentUser()?.type === userType.MANAGER - } - - isHelper() { - return this.authService.getCurrentUser()?.type === userType.HELPER - } - - inBasket(basket: Need[] | null, need: Need) { - console.log(basket) - console.log(need) - return basket?.map(r => r.id).includes(need.id); - } - protected readonly SortingAlgorithms = SortingAlgoArrays; protected readonly Object = Object; } -- cgit v1.2.3 From 7c49fcd788692a898e985cb156dd9fd910c05790 Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 4 Apr 2025 23:14:14 -0400 Subject: Add new authentication to dashboard, cleanup --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 2 -- 1 file changed, 2 deletions(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 289618f..b03b77e 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -23,13 +23,11 @@ export class CupboardComponent implements OnInit { @ViewChild("needList") needList?: NeedListComponent private searchDelay: any; - // selectedNeed: Need | null = null; needs: Need[] = []; searchResults: Need[] = []; sortMode: 'Ascending' | 'Descending' = 'Ascending' itemsPerPage = 5; currentSortAlgo = 'sortByPriority'; - // activeEdit?: Need; constructor( private cupboardService: CupboardService, -- cgit v1.2.3