aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
diff options
context:
space:
mode:
authorHayden Hartman <haydenhartman10@gmail.com>2025-03-18 07:50:55 -0400
committerGitHub <noreply@github.com>2025-03-18 07:50:55 -0400
commit3362bba1ccf1cee3985be95ab74a2456e6503d7a (patch)
tree64f6b52fbd4714a29be0102ac988cb7ab02dbb33 /ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
parentf063bf6e8634386f6ae3a3cf13fe2228e74454c9 (diff)
parentbd41fc58b5537a12072625bbf75baf75d5ed2274 (diff)
downloadJellySolutions-2.0.tar.gz
JellySolutions-2.0.tar.bz2
JellySolutions-2.0.zip
Merge pull request #13 from RIT-SWEN-261-02/funding_basketv2.0
funding-basket merge
Diffstat (limited to 'ufund-ui/src/app/components/funding-basket/funding-basket.component.ts')
-rw-r--r--ufund-ui/src/app/components/funding-basket/funding-basket.component.ts98
1 files changed, 83 insertions, 15 deletions
diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts b/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
index c44aa27..dd68c0c 100644
--- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
+++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
@@ -1,23 +1,91 @@
import {Component, OnInit} from '@angular/core';
-import {Router} from '@angular/router';
-import {UsersService} from '../../services/users.service';
+import {User} from '../../models/User';
+import { UsersService } from '../../services/users.service';
+import { Need } from '../../models/Need';
+import { NeedListComponent } from '../need-list/need-list.component';
+import { Router } from '@angular/router';
+import { CupboardService } from '../../services/cupboard.service';
@Component({
- selector: 'app-funding-basket',
- standalone: false,
- templateUrl: './funding-basket.component.html',
- styleUrl: './funding-basket.component.css'
+ selector: 'app-funding-basket',
+ standalone: false,
+ templateUrl: './funding-basket.component.html',
+ styleUrl: './funding-basket.component.css'
})
-export class FundingBasketComponent implements OnInit{
- constructor(
- private router: Router,
- private userService: UsersService
- ) {}
-
- ngOnInit() {
- if (!this.userService.getCurrentUser()) {
- this.router.navigate(['/login'], {queryParams: {redir: this.router.url}})
+export class FundingBasketComponent implements
+ OnInit {
+ user!: User;
+ needs: Need[] = [];
+ basket: Need[] = [];
+ needCount = 0;
+ need_quantity: {[key: number]: number} = {};
+
+ constructor(
+ private router: Router,
+ private cupboardService: CupboardService, private usersService: UsersService
+ ) {}
+
+ ngOnInit(): void {
+ if (!this.usersService.getCurrentUser()) {
+ this.router.navigate(['/login'], {queryParams: {redir: this.router.url}});
+ return;
+ }
+ this.cupboardService.getNeeds().subscribe(n => this.needs = n)
+ const currentUser = this.usersService.getCurrentUser();
+ if (currentUser) {
+ this.user = currentUser;
+ }
+ this.getBasketNeeds();
+ }
+
+ getBasketNeeds(): void {
+ if (this.user && this.user.basket) {
+ this.user.basket.forEach(need => {
+ // if (this.isInBasket(need)) {
+ // this.basket.push(need);
+ // }
+ });
}
}
+ isInBasket(need: Need): boolean {
+ return this.basket.includes(need)
+ }
+
+ addNeed(need: Need, quantity: number = 1): void {
+ if (this.user && !this.isInBasket(need)) {
+ this.basket.push(need);
+ this.need_quantity[need.id] = quantity;
+ }
+ if (this.isInBasket(need)) {
+ this.need_quantity[need.id] += quantity;
+ }
+ this.needCount++;
+ }
+
+ removeNeed(need: Need, quantity: number = 1): void {
+ if (this.user && this.isInBasket(need)) {
+ this.need_quantity[need.id] -= quantity;
+ if (this.need_quantity[need.id] === 0) {
+ this.basket = this.basket.filter(n => need.id !== n.id);
+ }
+ this.needCount--;
+ }
+ }
+
+ removeAllNeeds(): void {
+ this.basket.forEach(need => {
+ this.need_quantity = [];
+ });
+ this.basket = [];
+ this.needCount = 0;
+ }
+
+ isBasketEmpty(): boolean {
+ return this.needCount === 0;
+ }
+
+ checkout(): void {
+ this.removeAllNeeds();
+ }
}