From 0b41684e57c79374aee3a564307cd4fdef603e7c Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 11:41:04 -0400 Subject: THE UPDATE USER WORKS! -ak --- .../src/app/components/need-list/need-list.component.html | 2 +- .../src/app/components/need-list/need-list.component.ts | 13 ++++++------- ufund-ui/src/app/services/users.service.ts | 7 ++++--- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'ufund-ui/src') 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 4a67dfa..36c12d0 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 @@ -24,5 +24,5 @@ {{need.name}} - + 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 e1c0de1..46e09f0 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 @@ -105,15 +105,14 @@ export class NeedListComponent { return type === ("HELPER" as unknown as userType); } - add(need: number) { + add(need: Need) { const currentUser = this.usersService.getCurrentUser(); + console.log("get current user in angular:", currentUser) if (currentUser) { - this.usersService.updateUser(currentUser.username, currentUser).subscribe(() => { - const currentUser = this.usersService.getCurrentUser(); - if (currentUser && currentUser.basket) { - currentUser.basket.push(need); - console.log("added to basket"); - } + currentUser.basket.push(need.id); + console.log("pushed to basket: " + currentUser.basket) + this.usersService.updateUser(currentUser).subscribe(() => { + console.log("rah"); error: (err: any) => { console.error(err); } diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts index bc31870..2a95202 100644 --- a/ufund-ui/src/app/services/users.service.ts +++ b/ufund-ui/src/app/services/users.service.ts @@ -40,10 +40,11 @@ export class UsersService { return this.http.get(`${this.url}/${id}`, this.httpOptions) } - updateUser(id: string, user: User): Observable { - console.log(id, user) + updateUser(user: User): Observable { + console.log(user, user.basket) console.log(this.apiKey) - return this.http.put(`${this.url}/${id}`,user, this.httpOptions) + + return this.http.put(`${this.url}/${user.username}`,user, this.httpOptions2) } deleteUser(id: number): Observable { -- cgit v1.2.3 From cbb02fb9fe06601ac419e804a7c87ff8452ed889 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 12:38:29 -0400 Subject: Configured status messages based on responses --- .../app/components/cupboard/cupboard.component.ts | 204 +++++++++++---------- 1 file changed, 108 insertions(+), 96 deletions(-) (limited to 'ufund-ui/src') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 9574de3..6ad0a5f 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -4,13 +4,13 @@ import { UsersService } from '../../services/users.service'; import { Need, GoalType } from '../../models/Need'; import { userType } from '../../models/User'; import { BehaviorSubject, catchError, of } from 'rxjs'; -import {NeedListComponent} from '../need-list/need-list.component'; +import { NeedListComponent } from '../need-list/need-list.component'; @Component({ - selector: 'app-cupboard', - standalone: false, - templateUrl: './cupboard.component.html', - styleUrl: './cupboard.component.css' + selector: 'app-cupboard', + standalone: false, + templateUrl: './cupboard.component.html', + styleUrl: './cupboard.component.css' }) export class CupboardComponent implements OnInit { @@ -23,140 +23,152 @@ export class CupboardComponent implements OnInit { constructor(private cupboardService: CupboardService, private usersService: UsersService) { } ngOnInit(): void { - this.cupboardService.getNeeds().subscribe(n => this.needs = n); - this.close(); - this.openmenu(); - - 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.close(); + this.openmenu(); + + if (this.isManager()) { + console.log("Admin view of Cupboard"); + } else { + console.log("Limited helper view of Cupboard"); + } } selectedNeed: any = { - name: '', - id: null, - maxGoal: null, - type: '' + name: '', + id: null, + maxGoal: null, + type: '' }; selectedNeedId: number | null = null; private hideElement(element: any) { - if (element){ - element.style.visibility = 'hidden'; - element.style.position = 'absolute'; - } + if (element) { + element.style.visibility = 'hidden'; + element.style.position = 'absolute'; + } } private showElement(element: any) { - if (element){ - element.style.visibility = 'visible'; - element.style.position = 'relative'; - } + if (element) { + element.style.visibility = 'visible'; + element.style.position = 'relative'; + } } openmenu() { - const menuElement = document.getElementById('menu'); - this.showElement(menuElement); + const menuElement = document.getElementById('menu'); + this.showElement(menuElement); } opencreate() { - this.close(); - this.showElement(document.getElementById('create-form')); + this.close(); + this.showElement(document.getElementById('create-form')); } openupdate() { - this.close(); - this.showElement(document.getElementById('update-form')); + this.close(); + this.showElement(document.getElementById('update-form')); } back() { - this.close(); - this.openmenu(); + this.close(); + this.openmenu(); } close() { - this.hideElement(document.getElementById('create-form')); - this.hideElement(document.getElementById('destroy-form')); - this.hideElement(document.getElementById('menu')); - this.hideElement(document.getElementById('update-form')); + this.hideElement(document.getElementById('create-form')); + this.hideElement(document.getElementById('destroy-form')); + this.hideElement(document.getElementById('menu')); + this.hideElement(document.getElementById('update-form')); } populateForm(need: any): void { - this.selectedNeed = { ...need }; + this.selectedNeed = { ...need }; } isManager() { - const type = this.usersService.getCurrentUser()?.type; - return type === ("MANAGER" as unknown as userType); + const type = this.usersService.getCurrentUser()?.type; + return type === ("MANAGER" as unknown as userType); } update(form: any) { - console.log(form); - const need: Need = { - name: form.name, - id: form.id, //system will control this - maxGoal: form.maxGoal, - type: GoalType[form.type as keyof typeof GoalType], - filterAttributes: [], - current: 0 - }; - console.log("need:", need); - console.log(need.id, need, "need updated"); - this.cupboardService.updateNeed(need.id, need) - .pipe(catchError((ex, r) => { - this.statusText.next("Max goal must be greater than 0 " + friendlyHttpStatus[ex.status]) - return of() - })) - .subscribe( - (result) => { - if (result) { - console.log("need updated successfully"); - this.needList?.refresh() - } else { - console.log("need update failed"); - } - } - - ); + console.log(form); + const need: Need = { + name: form.name, + id: form.id, //system will control this + maxGoal: form.maxGoal, + type: GoalType[form.type as keyof typeof GoalType], + filterAttributes: [], + current: 0 + }; + console.log("need:", need); + console.log(need.id, need, "need updated"); + this.cupboardService.updateNeed(need.id, need) + .pipe(catchError((ex, r) => { + if (ex.status = 500) { + this.statusText.next("Fields cannot be blank"); + } else if (ex.status = 400) { + this.statusText.next("Goal must be greater than 0"); + } else { + this.statusText.next("Error on creating need"); + } + return of() + })) + .subscribe( + (result) => { + if (result) { + console.log("need updated successfully"); + this.needList?.refresh() + } else { + console.log("need update failed"); + } + } + + ); } submit(form: any) { - const need: Need = { - name: form.name, - id: 0, - maxGoal: form.maxGoal, - type: form.type, - filterAttributes: [], - current: 0 - }; - console.log("need:", need); - console.log("form submitted. creating need: ", need); - this.cupboardService.createNeed(need) - .pipe(catchError((ex, r) => { - this.statusText.next("Max goal must be greater than 0 " + friendlyHttpStatus[ex.status]) - return of() - })) - .subscribe( - (result) => { - if (result) { - console.log("need created successfully"); - this.needList?.refresh() - } else { - console.log("need creation failed"); - } - } - - ); + const need: Need = { + name: form.name, + id: 0, + maxGoal: form.maxGoal, + type: form.type, + filterAttributes: [], + current: 0 + }; + console.log("need:", need); + console.log("form submitted. creating need: ", need); + this.cupboardService.createNeed(need) + .pipe(catchError((ex, r) => { + if (ex.status = 500) { + this.statusText.next("Fields cannot be blank"); + } else if (ex.status = 400) { + this.statusText.next("Goal must be greater than 0"); + } else { + this.statusText.next("Error on creating need"); + } + return of() + })) + .subscribe( + (result) => { + if (result) { + console.log("need created successfully"); + this.needList?.refresh() + } else { + console.log("need creation failed"); + } + } + + ); } destroy() { } - } +} -let friendlyHttpStatus: {[key: number]: string} = { +let friendlyHttpStatus: { [key: number]: string } = { 200: 'OK', 201: 'Created', 202: 'Accepted', -- cgit v1.2.3 From 98431cd75078fd671270039ad9fa4d42759dc502 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 12:42:37 -0400 Subject: reworked funding basket to accept need-list component. -ak --- .../funding-basket/funding-basket.component.ts | 71 +++------------------- .../components/need-list/need-list.component.ts | 6 +- ufund-ui/src/app/services/users.service.ts | 20 +++++- 3 files changed, 31 insertions(+), 66 deletions(-) (limited to 'ufund-ui/src') 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 dd68c0c..bc7f087 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 @@ -5,6 +5,7 @@ import { Need } from '../../models/Need'; import { NeedListComponent } from '../need-list/need-list.component'; import { Router } from '@angular/router'; import { CupboardService } from '../../services/cupboard.service'; +import { BehaviorSubject, firstValueFrom } from 'rxjs'; @Component({ selector: 'app-funding-basket', @@ -12,80 +13,26 @@ import { CupboardService } from '../../services/cupboard.service'; templateUrl: './funding-basket.component.html', styleUrl: './funding-basket.component.css' }) -export class FundingBasketComponent implements - OnInit { - user!: User; - needs: Need[] = []; - basket: Need[] = []; - needCount = 0; - need_quantity: {[key: number]: number} = {}; +export class FundingBasketComponent implements OnInit { + basket = new BehaviorSubject([]); constructor( private router: Router, - private cupboardService: CupboardService, private usersService: UsersService + private cupboardService: CupboardService, + private usersService: UsersService ) {} + // this is for login rerouting 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--; - } - } + this.usersService.refreshBasket(); + // this.usersService.removeNeed(); <- call this to remove + } - removeAllNeeds(): void { - this.basket.forEach(need => { - this.need_quantity = []; - }); - this.basket = []; - this.needCount = 0; - } - isBasketEmpty(): boolean { - return this.needCount === 0; - } - checkout(): void { - this.removeAllNeeds(); - } } 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 46e09f0..2764c7e 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 @@ -107,12 +107,12 @@ export class NeedListComponent { add(need: Need) { const currentUser = this.usersService.getCurrentUser(); - console.log("get current user in angular:", currentUser) + //console.log("get current user in angular:", currentUser) if (currentUser) { currentUser.basket.push(need.id); - console.log("pushed to basket: " + currentUser.basket) + //console.log("pushed to basket: " + currentUser.basket) this.usersService.updateUser(currentUser).subscribe(() => { - console.log("rah"); + this.usersService.refreshBasket(); error: (err: any) => { console.error(err); } diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts index 2a95202..a0d316c 100644 --- a/ufund-ui/src/app/services/users.service.ts +++ b/ufund-ui/src/app/services/users.service.ts @@ -2,6 +2,8 @@ import { Injectable } from '@angular/core'; import {HttpClient, HttpHeaders} from '@angular/common/http'; import {BehaviorSubject, firstValueFrom, Observable} from 'rxjs'; import {User} from '../models/User'; +import { Need } from '../models/Need'; +import { CupboardService } from './cupboard.service'; @Injectable({ providedIn: 'root' @@ -10,6 +12,7 @@ export class UsersService { private currentUser : BehaviorSubject = new BehaviorSubject(null); private apiKey: string = ""; + private basket = new BehaviorSubject([]); private url = "http://localhost:8080/users" private authUrl = "http://localhost:8080/auth" @@ -29,7 +32,8 @@ export class UsersService { }; constructor( - private http: HttpClient + private http: HttpClient, + private cupboardService: CupboardService, ) {} async createUser(username:string, password:string) { @@ -73,4 +77,18 @@ export class UsersService { this.currentUser.next(currentU); // this.currentUser.subscribe(r => console.log("currentUser: "+r.username)) } + + refreshBasket() { + let promiseArr = this.getCurrentUser()!.basket.map(async needID => { + return await firstValueFrom(this.cupboardService.getNeed(needID)); + }) + Promise.all(promiseArr).then(r => this.basket.next(r)); + } + + removeNeed(id: number) { + let newArr = this.basket.getValue().filter(v => v.id != id); + this.basket.next(newArr); + this.getCurrentUser()!.basket = newArr.map(need => need.id); + this.updateUser(this.getCurrentUser()!); + } } -- cgit v1.2.3 From 45bb79cd56e93ee26f1227ed15a9161a59fe6f35 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 12:55:16 -0400 Subject: Fixed logic on status checks --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'ufund-ui/src') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 6ad0a5f..45346b4 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -106,9 +106,9 @@ export class CupboardComponent implements OnInit { console.log(need.id, need, "need updated"); this.cupboardService.updateNeed(need.id, need) .pipe(catchError((ex, r) => { - if (ex.status = 500) { + if (ex.status == 500) { this.statusText.next("Fields cannot be blank"); - } else if (ex.status = 400) { + } else if (ex.status == 400) { this.statusText.next("Goal must be greater than 0"); } else { this.statusText.next("Error on creating need"); @@ -141,9 +141,9 @@ export class CupboardComponent implements OnInit { console.log("form submitted. creating need: ", need); this.cupboardService.createNeed(need) .pipe(catchError((ex, r) => { - if (ex.status = 500) { + if (ex.status == 500) { this.statusText.next("Fields cannot be blank"); - } else if (ex.status = 400) { + } else if (ex.status == 400) { this.statusText.next("Goal must be greater than 0"); } else { this.statusText.next("Error on creating need"); -- cgit v1.2.3 From 28a8fde7d57ee5ef762bd20f41c728966ab74d06 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 12:59:11 -0400 Subject: connected backend to frontend for funding basket. -ak --- .../funding-basket/funding-basket.component.html | 17 ++++++++--------- .../funding-basket/funding-basket.component.ts | 5 ++--- ufund-ui/src/app/services/users.service.ts | 9 +++++++-- 3 files changed, 17 insertions(+), 14 deletions(-) (limited to 'ufund-ui/src') diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html index 0a880af..dd02e98 100644 --- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html +++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html @@ -2,33 +2,33 @@
- {{ needCount }} + {{ this.usersService.getBasket().getValue().length }}
-
+

There are no needs in the basket

- +
- + @@ -36,6 +36,5 @@
{{need.name}}
- +

+ (click)="this.usersService.removeNeed(need.id)">Remove Need

- +
\ No newline at end of file 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 bc7f087..061e3fa 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 @@ -14,12 +14,11 @@ import { BehaviorSubject, firstValueFrom } from 'rxjs'; styleUrl: './funding-basket.component.css' }) export class FundingBasketComponent implements OnInit { - basket = new BehaviorSubject([]); constructor( private router: Router, - private cupboardService: CupboardService, - private usersService: UsersService + protected cupboardService: CupboardService, + protected usersService: UsersService ) {} // this is for login rerouting diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts index a0d316c..62aea79 100644 --- a/ufund-ui/src/app/services/users.service.ts +++ b/ufund-ui/src/app/services/users.service.ts @@ -83,12 +83,17 @@ export class UsersService { return await firstValueFrom(this.cupboardService.getNeed(needID)); }) Promise.all(promiseArr).then(r => this.basket.next(r)); - } + } - removeNeed(id: number) { + removeNeed(id: number) { let newArr = this.basket.getValue().filter(v => v.id != id); this.basket.next(newArr); this.getCurrentUser()!.basket = newArr.map(need => need.id); this.updateUser(this.getCurrentUser()!); } + + getBasket() { + return this.basket; + } + } -- cgit v1.2.3 From fe04a7078f6b381d45715f80662628410ca8dc72 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 13:19:41 -0400 Subject: added descriptions to funding basket. -ak --- .../src/app/components/funding-basket/funding-basket.component.html | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ufund-ui/src') diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html index dd02e98..b8633b8 100644 --- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html +++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html @@ -21,6 +21,9 @@ {{need.name}} +

Goal: {{need.maxGoal}}

+

Current: {{need.current}}

+

How much to Contribute:

-- cgit v1.2.3 From c135f56c7b2d0d283ea279fa7934929fb2e09aa3 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 13:35:09 -0400 Subject: Modified status codes to properly display error messages on creation and updating of needs --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ufund-ui/src') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 45346b4..13eddad 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -106,6 +106,7 @@ export class CupboardComponent implements OnInit { console.log(need.id, need, "need updated"); this.cupboardService.updateNeed(need.id, need) .pipe(catchError((ex, r) => { + console.log(ex.status); if (ex.status == 500) { this.statusText.next("Fields cannot be blank"); } else if (ex.status == 400) { @@ -141,6 +142,7 @@ export class CupboardComponent implements OnInit { console.log("form submitted. creating need: ", need); this.cupboardService.createNeed(need) .pipe(catchError((ex, r) => { + console.log(ex.status); if (ex.status == 500) { this.statusText.next("Fields cannot be blank"); } else if (ex.status == 400) { @@ -203,6 +205,7 @@ let friendlyHttpStatus: { [key: number]: string } = { 416: 'Requested Range Not Satisfiable', 417: 'Expectation Failed', 418: 'I\'m a teapot', + 422: 'Unprocessable Entity', 429: 'Too Many Requests', 500: 'Internal Server Error', 501: 'Not Implemented', -- cgit v1.2.3 From 054857f51d1397d1122219e407a25c18472733f6 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 14:32:56 -0400 Subject: add alert on duplicate entry --- .../app/components/need-list/need-list.component.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'ufund-ui/src') 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 2764c7e..25f05d6 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 @@ -109,14 +109,18 @@ export class NeedListComponent { const currentUser = this.usersService.getCurrentUser(); //console.log("get current user in angular:", currentUser) if (currentUser) { - currentUser.basket.push(need.id); - //console.log("pushed to basket: " + currentUser.basket) - this.usersService.updateUser(currentUser).subscribe(() => { - this.usersService.refreshBasket(); - error: (err: any) => { - console.error(err); - } - }); + if (!currentUser.basket.includes(need.id)) { + currentUser.basket.push(need.id); + this.usersService.updateUser(currentUser).subscribe(() => { + this.usersService.refreshBasket(); + error: (err: any) => { + console.error(err); + } + }); + } else { + window.alert("This need is already in your basket!") + } + } -- cgit v1.2.3 From 67f7914faefcb227c0c9b1010b437ee874f3c56a Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 14:45:06 -0400 Subject: Added basic css to funding basket needs --- .../src/app/components/funding-basket/funding-basket.component.css | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'ufund-ui/src') diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.css b/ufund-ui/src/app/components/funding-basket/funding-basket.component.css index e69de29..3dec496 100644 --- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.css +++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.css @@ -0,0 +1,7 @@ +td, p { + border: 2px solid #000; + border-radius: 5px; + padding: 5px; + margin: 5px; + +} \ No newline at end of file -- cgit v1.2.3 From 521c8a49bbebb514a0a309a4f4f28d6e1204b7d2 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 14:45:26 -0400 Subject: Removed back button from dashboard and added back to the needs page --- ufund-ui/src/app/components/dashboard/dashboard.component.html | 1 - ufund-ui/src/app/components/need-page/need-page.component.html | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'ufund-ui/src') diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.html b/ufund-ui/src/app/components/dashboard/dashboard.component.html index fc8baf0..12ecc8b 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.html +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.html @@ -1,5 +1,4 @@

Dashboard

- \ No newline at end of file diff --git a/ufund-ui/src/app/components/need-page/need-page.component.html b/ufund-ui/src/app/components/need-page/need-page.component.html index 8234ac7..21f0771 100644 --- a/ufund-ui/src/app/components/need-page/need-page.component.html +++ b/ufund-ui/src/app/components/need-page/need-page.component.html @@ -1,3 +1,4 @@ +

Viewing Need: {{need?.name}}

internal id: {{need?.id}}
-- cgit v1.2.3 From 080f7ce14770dd8b6bc893160afd357fada883b2 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 15:33:43 -0400 Subject: Removed old back button --- ufund-ui/src/app/components/dashboard/dashboard.component.ts | 3 --- 1 file changed, 3 deletions(-) (limited to 'ufund-ui/src') diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.ts b/ufund-ui/src/app/components/dashboard/dashboard.component.ts index 48c5894..d3dc1d8 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.ts +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.ts @@ -9,7 +9,4 @@ import { Component } from '@angular/core'; export class DashboardComponent { constructor() {} - back() { - window.history.back(); - } } -- cgit v1.2.3 From cd9dfcec9e7ae9fe6f08b61927b16cf76b8bcef7 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 15:49:08 -0400 Subject: debug of checkout. -ak --- .../funding-basket/funding-basket.component.html | 19 ++++++--------- .../funding-basket/funding-basket.component.ts | 28 +++++++++++++++++++++- 2 files changed, 34 insertions(+), 13 deletions(-) (limited to 'ufund-ui/src') diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html index b8633b8..178a2cd 100644 --- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html +++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html @@ -9,7 +9,7 @@

There are no needs in the basket

- +
@@ -18,20 +18,14 @@ @@ -39,5 +33,6 @@
- - {{need.name}} - + {{need.name}}

Goal: {{need.maxGoal}}

Current: {{need.current}}

-

How much to Contribute:

-
- -
+

How much to Contribute:


- +

- +

Invalid input in funding basket!

+
\ No newline at end of file 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 061e3fa..a7a38b8 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,4 +1,4 @@ -import {Component, OnInit} from '@angular/core'; +import {Component, Input, OnInit, ViewChild} from '@angular/core'; import {User} from '../../models/User'; import { UsersService } from '../../services/users.service'; import { Need } from '../../models/Need'; @@ -21,6 +21,9 @@ export class FundingBasketComponent implements OnInit { protected usersService: UsersService ) {} + @ViewChild("contribution") contribution?: Input; + @Input() isValid: boolean = true; + // this is for login rerouting ngOnInit(): void { if (!this.usersService.getCurrentUser()) { @@ -32,6 +35,29 @@ export class FundingBasketComponent implements OnInit { // this.usersService.removeNeed(); <- call this to remove } + async checkout() { + this.isValid = true; + for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) { + var contribution = c as HTMLInputElement; + console.log(contribution.value, contribution.id); + contribution.setAttribute("style",""); + if ( contribution.value == '' || contribution.valueAsNumber < 0) { + this.isValid = false; + contribution.setAttribute("style","color: #ff0000"); + } + } + if (this.isValid) { + for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) { + var contribution = c as HTMLInputElement; + var need = await firstValueFrom(this.cupboardService.getNeed(+contribution.id)); + need.current +=+ contribution.value; + console.log(need); + this.cupboardService.updateNeed(+contribution.id, need); + this.usersService.removeNeed(+contribution.id); + } + } + } + } -- cgit v1.2.3 From 9d90b2a29b1f47b6271fd9ea87989a4195cf5ee6 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 15:59:16 -0400 Subject: working update need; broken remove basket. -ak --- .../funding-basket/funding-basket.component.html | 1 + .../funding-basket/funding-basket.component.ts | 35 ++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) (limited to 'ufund-ui/src') diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html index 178a2cd..30c3167 100644 --- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html +++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html @@ -35,4 +35,5 @@

Invalid input in funding basket!

+ {{statusText | async}}
\ No newline at end of file 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 a7a38b8..7f086ec 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 @@ -5,7 +5,7 @@ import { Need } from '../../models/Need'; import { NeedListComponent } from '../need-list/need-list.component'; import { Router } from '@angular/router'; import { CupboardService } from '../../services/cupboard.service'; -import { BehaviorSubject, firstValueFrom } from 'rxjs'; +import { BehaviorSubject, catchError, firstValueFrom, Observable } from 'rxjs'; @Component({ selector: 'app-funding-basket', @@ -14,6 +14,7 @@ import { BehaviorSubject, firstValueFrom } from 'rxjs'; styleUrl: './funding-basket.component.css' }) export class FundingBasketComponent implements OnInit { + statusText: any; constructor( private router: Router, @@ -38,7 +39,7 @@ export class FundingBasketComponent implements OnInit { async checkout() { this.isValid = true; for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) { - var contribution = c as HTMLInputElement; + let contribution = c as HTMLInputElement; console.log(contribution.value, contribution.id); contribution.setAttribute("style",""); if ( contribution.value == '' || contribution.valueAsNumber < 0) { @@ -48,12 +49,34 @@ export class FundingBasketComponent implements OnInit { } if (this.isValid) { for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) { - var contribution = c as HTMLInputElement; - var need = await firstValueFrom(this.cupboardService.getNeed(+contribution.id)); + let contribution = c as HTMLInputElement; + let need = await firstValueFrom(this.cupboardService.getNeed(+contribution.id)); need.current +=+ contribution.value; console.log(need); - this.cupboardService.updateNeed(+contribution.id, need); - this.usersService.removeNeed(+contribution.id); + this.usersService.removeNeed(need.id); + this.cupboardService.updateNeed(need.id, need) + .pipe(catchError((ex, r) => { + console.log(ex.status); + if (ex.status == 500) { + this.statusText.next("Fields cannot be blank"); + } else if (ex.status == 400) { + this.statusText.next("Goal must be greater than 0"); + } else { + this.statusText.next("Error on creating need"); + } + return new Observable(); + })) + .subscribe( + (result) => { + if (result) { + console.log("need updated successfully"); + //this.needList?.refresh() + } else { + console.log("need update failed"); + } + } + + ); } } } -- cgit v1.2.3 From 20f717cab504a988ef8da4b34acf8ef7a7adfdd7 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 16:23:22 -0400 Subject: Removed decimal values of percents on needs --- ufund-ui/src/app/components/need-page/need-page.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ufund-ui/src') diff --git a/ufund-ui/src/app/components/need-page/need-page.component.html b/ufund-ui/src/app/components/need-page/need-page.component.html index 21f0771..90fd459 100644 --- a/ufund-ui/src/app/components/need-page/need-page.component.html +++ b/ufund-ui/src/app/components/need-page/need-page.component.html @@ -19,4 +19,4 @@

Goal: {{need?.maxGoal}}

Current: {{need?.current}}

-

This goal is {{((need?.current ?? 0)*100) / (need?.maxGoal ?? 0)}}% complete!

\ No newline at end of file +

This goal is {{(((need?.current ?? 0)*100) / (need?.maxGoal ?? 0)).toFixed(0)}}% complete!

\ No newline at end of file -- cgit v1.2.3 From 81b93fc671ba35d67c414937e18b686fd6d5f861 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 16:53:39 -0400 Subject: idk but it works. funding basket worsk. -ak --- .../funding-basket/funding-basket.component.ts | 45 ++++++++++------------ ufund-ui/src/app/services/users.service.ts | 9 ++++- 2 files changed, 29 insertions(+), 25 deletions(-) (limited to 'ufund-ui/src') 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 7f086ec..66b9fd1 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 @@ -42,7 +42,7 @@ export class FundingBasketComponent implements OnInit { let contribution = c as HTMLInputElement; console.log(contribution.value, contribution.id); contribution.setAttribute("style",""); - if ( contribution.value == '' || contribution.valueAsNumber < 0) { + if ( contribution.value == '' || contribution.valueAsNumber <= 0) { this.isValid = false; contribution.setAttribute("style","color: #ff0000"); } @@ -53,30 +53,27 @@ export class FundingBasketComponent implements OnInit { let need = await firstValueFrom(this.cupboardService.getNeed(+contribution.id)); need.current +=+ contribution.value; console.log(need); - this.usersService.removeNeed(need.id); + this.usersService.removeNeed(+need.id); this.cupboardService.updateNeed(need.id, need) - .pipe(catchError((ex, r) => { - console.log(ex.status); - if (ex.status == 500) { - this.statusText.next("Fields cannot be blank"); - } else if (ex.status == 400) { - this.statusText.next("Goal must be greater than 0"); - } else { - this.statusText.next("Error on creating need"); - } - return new Observable(); - })) - .subscribe( - (result) => { - if (result) { - console.log("need updated successfully"); - //this.needList?.refresh() - } else { - console.log("need update failed"); - } - } - - ); + .pipe(catchError((ex, r) => { + console.log(ex.status); + if (ex.status == 500) { + this.statusText.next('Fields cannot be blank'); + } else if (ex.status == 400) { + this.statusText.next('Goal must be greater than 0'); + } else { + this.statusText.next('Error on creating need'); + } + return new Observable(); + })) + .subscribe((result) => { + if (result) { + console.log('need updated successfully'); + //this.needList?.refresh() + } else { + console.log('need update failed'); + } + }); } } } diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts index 62aea79..ddbd322 100644 --- a/ufund-ui/src/app/services/users.service.ts +++ b/ufund-ui/src/app/services/users.service.ts @@ -45,6 +45,7 @@ export class UsersService { } updateUser(user: User): Observable { + console.log("REMOVING USER IN ANGULAR: ", user) console.log(user, user.basket) console.log(this.apiKey) @@ -89,7 +90,13 @@ export class UsersService { let newArr = this.basket.getValue().filter(v => v.id != id); this.basket.next(newArr); this.getCurrentUser()!.basket = newArr.map(need => need.id); - this.updateUser(this.getCurrentUser()!); + console.log(this.getCurrentUser()!.basket) + this.updateUser(this.getCurrentUser()!).subscribe(() => { + this.refreshBasket(); + error: (err: any) => { + console.error(err); + } + }); } getBasket() { -- cgit v1.2.3 From ca7d72e43407a49b147673ebc5ab8b155a8216ac Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 17:01:00 -0400 Subject: fixed odd rounding errors in funding basket. -ak --- .../src/app/components/funding-basket/funding-basket.component.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ufund-ui/src') diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html index 30c3167..504e694 100644 --- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html +++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html @@ -20,8 +20,8 @@ {{need.name}}

Goal: {{need.maxGoal}}

-

Current: {{need.current}}

-

How much to Contribute:

+

Current: {{(need.current).toFixed(2)}}

+

How much to Contribute: