aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/components/cupboard/cupboard.component.ts
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-04-03 23:11:05 -0400
committersowgro <tpoke.ferrari@gmail.com>2025-04-03 23:11:05 -0400
commit6a5033afc3c8e0d5d12d709b35b306b6ea1f70e8 (patch)
tree15511941490e8010dacaf20c704f9b314da5634b /ufund-ui/src/app/components/cupboard/cupboard.component.ts
parentad651c44ce2515d497c8e5214147c69126e25903 (diff)
downloadJellySolutions-6a5033afc3c8e0d5d12d709b35b306b6ea1f70e8.tar.gz
JellySolutions-6a5033afc3c8e0d5d12d709b35b306b6ea1f70e8.tar.bz2
JellySolutions-6a5033afc3c8e0d5d12d709b35b306b6ea1f70e8.zip
Implemented action buttons with ng-template!!!
Diffstat (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts')
-rw-r--r--ufund-ui/src/app/components/cupboard/cupboard.component.ts160
1 files changed, 73 insertions, 87 deletions
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;
}