From c02c47efcb00782feb1461534923023a711d4f15 Mon Sep 17 00:00:00 2001 From: sowgro Date: Sun, 2 Mar 2025 11:22:48 -0500 Subject: First attempt at an authentication system. --- ufund-ui/src/app/app.component.html | 4 ++- ufund-ui/src/app/app.component.ts | 21 ++++++++++-- .../src/app/components/login/login.component.html | 8 ++--- .../src/app/components/login/login.component.ts | 14 +++++++- ufund-ui/src/app/models/Need.ts | 2 +- ufund-ui/src/app/models/User.ts | 2 +- ufund-ui/src/app/services/cupboard.service.ts | 3 +- ufund-ui/src/app/services/users.service.ts | 40 ++++++++++++++++++---- 8 files changed, 75 insertions(+), 19 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/app.component.html b/ufund-ui/src/app/app.component.html index cfebc2b..6b9338c 100644 --- a/ufund-ui/src/app/app.component.html +++ b/ufund-ui/src/app/app.component.html @@ -1,4 +1,6 @@ -

jelly solutions:

+

jelly solutions

+{{currentUser$ | async}} +
diff --git a/ufund-ui/src/app/app.component.ts b/ufund-ui/src/app/app.component.ts index 2dbf33c..a85d04b 100644 --- a/ufund-ui/src/app/app.component.ts +++ b/ufund-ui/src/app/app.component.ts @@ -1,4 +1,7 @@ -import { Component } from '@angular/core'; +import {Component, OnInit} from '@angular/core'; +import {UsersService} from './services/users.service'; +import {BehaviorSubject, Observable, Subject} from 'rxjs'; +import {User} from './models/User'; @Component({ selector: 'app-root', @@ -6,6 +9,18 @@ import { Component } from '@angular/core'; standalone: false, styleUrl: './app.component.css' }) -export class AppComponent { - title = 'ufund-ui'; +export class AppComponent implements OnInit { + // title = 'ufund-ui'; + currentUser$: BehaviorSubject = new BehaviorSubject("Logged out."); + + constructor( + private userService: UsersService + ) {} + + ngOnInit() { + this.userService.getCurrentUser().subscribe(r => { + this.currentUser$?.next("Logged in as " + r.username) + }) + } + } diff --git a/ufund-ui/src/app/components/login/login.component.html b/ufund-ui/src/app/components/login/login.component.html index 41427ae..178ddbf 100644 --- a/ufund-ui/src/app/components/login/login.component.html +++ b/ufund-ui/src/app/components/login/login.component.html @@ -1,5 +1,5 @@

Login:

- - - - + + + + diff --git a/ufund-ui/src/app/components/login/login.component.ts b/ufund-ui/src/app/components/login/login.component.ts index efb8a58..9a4eb0f 100644 --- a/ufund-ui/src/app/components/login/login.component.ts +++ b/ufund-ui/src/app/components/login/login.component.ts @@ -1,4 +1,5 @@ -import { Component } from '@angular/core'; +import { Component } from '@angular/core' +import {UsersService} from '../../services/users.service'; @Component({ selector: 'app-login', @@ -7,5 +8,16 @@ import { Component } from '@angular/core'; styleUrl: './login.component.css' }) export class LoginComponent { + constructor( + protected usersService: UsersService + ) {} + login(username: string | null, password: string | null) { + console.log(`attempting to log in with ${username} ${password}`) + if (!username || !password) { + return; + } + + this.usersService.login(username, password) + } } diff --git a/ufund-ui/src/app/models/Need.ts b/ufund-ui/src/app/models/Need.ts index c0425ec..9e97fd4 100644 --- a/ufund-ui/src/app/models/Need.ts +++ b/ufund-ui/src/app/models/Need.ts @@ -1,7 +1,7 @@ export interface Need { name: string, id: number, - filterAttributes: String[], + filterAttributes: string[], type: GoalType; maxGoal: number; current: number; diff --git a/ufund-ui/src/app/models/User.ts b/ufund-ui/src/app/models/User.ts index 46fe4a1..9149fe7 100644 --- a/ufund-ui/src/app/models/User.ts +++ b/ufund-ui/src/app/models/User.ts @@ -2,5 +2,5 @@ import {Need} from './Need'; export interface User { username: string; - cupboard: Need[]; + basket: Need[]; } diff --git a/ufund-ui/src/app/services/cupboard.service.ts b/ufund-ui/src/app/services/cupboard.service.ts index c123841..4a2b4b0 100644 --- a/ufund-ui/src/app/services/cupboard.service.ts +++ b/ufund-ui/src/app/services/cupboard.service.ts @@ -18,8 +18,7 @@ export class CupboardService { ) {} createNeed(need: Need): Observable { - return this.http.post( - this.url, need, this.httpOptions) + return this.http.post(this.url, need, this.httpOptions) } getNeeds(): Observable { diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts index 571c004..28cc266 100644 --- a/ufund-ui/src/app/services/users.service.ts +++ b/ufund-ui/src/app/services/users.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import {HttpClient, HttpHeaders} from '@angular/common/http'; -import {Observable} from 'rxjs'; +import {firstValueFrom, Observable, of, Subject} from 'rxjs'; import {User} from '../models/User'; @Injectable({ @@ -8,11 +8,24 @@ import {User} from '../models/User'; }) export class UsersService { - private currentUserID? : number + private currentUser : Subject = new Subject(); + private apiKey: string = ""; private url = "http://localhost:8080/users" + private authUrl = "http://localhost:8080/auth" private httpOptions = { - headers: new HttpHeaders({'Content-Type': 'application/json'}) + headers: new HttpHeaders({ + 'Content-Type': 'application/json', + "jelly-api-key": this.apiKey + }) + }; + private httpOptions2 = { + headers: new HttpHeaders({ + 'Content-Type': 'application/json', + "jelly-api-key": this.apiKey + }), + responseType: "text" as "json" // don't ask me how or why this works, bc i have no clue... + // see the relevant angular bug report https://github.com/angular/angular/issues/18586 }; constructor( @@ -23,7 +36,7 @@ export class UsersService { return this.http.post(this.url, data, this.httpOptions) } - getUser(id: number): Observable { + getUser(id: string): Observable { return this.http.get(`${this.url}/${id}`, this.httpOptions) } @@ -35,7 +48,22 @@ export class UsersService { return this.http.delete(`${this.url}/${id}`, this.httpOptions) } - getCurrentUser(): Observable | undefined { - return this.currentUserID ? this.getUser(this.currentUserID) : undefined + getCurrentUser() { + return this.currentUser; + } + + async login(username: string, password: string) { + let res = this.http.post(this.authUrl, {username: username, password: password}, this.httpOptions2); + this.apiKey = await firstValueFrom(res); + console.log("apikey: "+this.apiKey) + let res2 = this.http.get(`${this.url}/${username}`, { + headers: new HttpHeaders({ + 'Content-Type': 'application/json', + "jelly-api-key": this.apiKey + }) + }) + let currentU = await firstValueFrom(res2); + this.currentUser.next(currentU); + // this.currentUser.subscribe(r => console.log("currentUser: "+r.username)) } } -- cgit v1.2.3 From ab7aa87d3a6249352a14b5a9c3c3c9e08577657f Mon Sep 17 00:00:00 2001 From: benal01 Date: Tue, 4 Mar 2025 09:43:37 -0500 Subject: cupboard component form creation and interfacing with the controller --- ufund-ui/src/app/app.module.ts | 2 ++ .../app/components/cupboard/cupboard.component.css | 4 +++ .../components/cupboard/cupboard.component.html | 32 ++++++++++--------- .../app/components/cupboard/cupboard.component.ts | 36 +++++++++++++--------- 4 files changed, 46 insertions(+), 28 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/app.module.ts b/ufund-ui/src/app/app.module.ts index d818841..c0e1dd5 100644 --- a/ufund-ui/src/app/app.module.ts +++ b/ufund-ui/src/app/app.module.ts @@ -8,6 +8,7 @@ import {HomePageComponent} from './components/home-page/home-page.component'; import {FundingBasketComponent} from './components/funding-basket/funding-basket.component'; import {CupboardComponent} from './components/cupboard/cupboard.component'; import {NeedListComponent} from './components/need-list/need-list.component'; +import {FormsModule} from '@angular/forms'; import {HttpClientModule} from '@angular/common/http'; @NgModule({ @@ -22,6 +23,7 @@ import {HttpClientModule} from '@angular/common/http'; imports: [ BrowserModule, AppRoutingModule, + FormsModule, HttpClientModule, ], providers: [], diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.css b/ufund-ui/src/app/components/cupboard/cupboard.component.css index e69de29..b530d36 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.css +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.css @@ -0,0 +1,4 @@ +#create-form { + margin: auto; + border: 5px solid black; +} \ No newline at end of file diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index ad8e60c..b87540e 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -1,17 +1,21 @@

Cupboard

-
-
-
-
-
-
-
-
- -
- -
-
- +
+

Create a new need

+
+
+
+
+
+
+
+
+ +
+ +
+ +
+
+ diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 53dad8a..409cf6c 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -1,7 +1,8 @@ import { Component, OnInit } from '@angular/core'; import { CupboardService } from '../../services/cupboard.service'; import { NeedListComponent } from '../need-list/need-list.component'; - +import { HttpClient } from '@angular/common/http'; +import { FormsModule } from '@angular/forms'; import { Need, GoalType } from '../../models/Need'; @Component({ @@ -12,20 +13,27 @@ import { Need, GoalType } from '../../models/Need'; }) export class CupboardComponent implements OnInit { + need: Need = { + id: 0, + name: '', + maxGoal: 0, + type: GoalType.MONETARY, + filterAttributes: [], + current: 0 + }; - constructor(private cupboardService: CupboardService){} - ngOnInit() { - - + + constructor(private cupboardService: CupboardService, private http: HttpClient) { } + ngOnInit(): void { + console.log('CupboardComponent.ngOnInit'); } - need!: Need; - submit(name: string, id: number, maxGoal: number, type: string) { - if (this.need) { - this.need.name = name; - this.need.id = id; - this.need.maxGoal = maxGoal; - console.log(type); - this.cupboardService.createNeed(this.need); - } + + submit(form: any) { + console.log(form); + this.need.name = form.name; + this.need.id = form.id; + this.need.maxGoal = form.maxGoal; + this.need.type = GoalType[form.type as keyof typeof GoalType]; + console.log(this.cupboardService.createNeed(this.need)); } } -- cgit v1.2.3 From a1343c65e30f7f3fe13a2c336f37dfa1bb1bbcc3 Mon Sep 17 00:00:00 2001 From: benal01 Date: Tue, 4 Mar 2025 10:29:01 -0500 Subject: basic css styles for orginization --- .../app/components/cupboard/cupboard.component.css | 23 +++++++++++++++++++--- .../components/need-list/need-list.component.css | 16 +++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.css b/ufund-ui/src/app/components/cupboard/cupboard.component.css index b530d36..315db50 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.css +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.css @@ -1,4 +1,21 @@ -#create-form { - margin: auto; - border: 5px solid black; +:host { + display: block; + border: 2px solid #000; + border-radius: 5px; + padding: 10px 20px; +} + +#create-form, #create-button { + background-color: #d9d9d9; + padding: 10px 20px 20px 20px; + border: 2px solid #000; + border-radius: 5px; + width: 20%; + visibility: visible; + +} + +#create-button { + padding: 10px 20px; + } \ No newline at end of file diff --git a/ufund-ui/src/app/components/need-list/need-list.component.css b/ufund-ui/src/app/components/need-list/need-list.component.css index e69de29..1bcaed9 100644 --- a/ufund-ui/src/app/components/need-list/need-list.component.css +++ b/ufund-ui/src/app/components/need-list/need-list.component.css @@ -0,0 +1,16 @@ +:host { + list-style-type:circle; + border: 2px solid #000; + display: block; + width: 30%; + border-radius: 5px; + +} + +li { + border: 2px solid #000; + border-radius: 5px; + padding: 5px; + margin: 5px; + +} \ No newline at end of file -- cgit v1.2.3 From bedb5fd032d645130ce804e1a36a356cf39ee9f0 Mon Sep 17 00:00:00 2001 From: benal01 Date: Tue, 4 Mar 2025 10:29:40 -0500 Subject: opening and closing functionality to expand the form for data entry --- .../components/cupboard/cupboard.component.html | 8 +++-- .../app/components/cupboard/cupboard.component.ts | 34 ++++++++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index b87540e..b767439 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -1,4 +1,8 @@

Cupboard

+
+ +
+

Create a new need

@@ -14,8 +18,8 @@
+
- - +
diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 409cf6c..cc09393 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -1,8 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { CupboardService } from '../../services/cupboard.service'; import { NeedListComponent } from '../need-list/need-list.component'; -import { HttpClient } from '@angular/common/http'; -import { FormsModule } from '@angular/forms'; import { Need, GoalType } from '../../models/Need'; @Component({ @@ -22,10 +20,36 @@ export class CupboardComponent implements current: 0 }; - - constructor(private cupboardService: CupboardService, private http: HttpClient) { } + + constructor(private cupboardService: CupboardService) { } ngOnInit(): void { - console.log('CupboardComponent.ngOnInit'); + this.close(); + } + + open() { + const formElement = document.getElementById('create-form'); + if (formElement) { + formElement.style.visibility = 'visible'; + formElement.style.position = 'relative'; + } + const buttonElement = document.getElementById('create-button'); + if (buttonElement) { + buttonElement.style.visibility = 'hidden'; + buttonElement.style.position = 'absolute'; + } + } + + close() { + const formElement = document.getElementById('create-form'); + if (formElement) { + formElement.style.visibility = 'hidden'; + formElement.style.position = 'absolute'; + } + const buttonElement = document.getElementById('create-button'); + if (buttonElement) { + buttonElement.style.visibility = 'visible'; + buttonElement.style.position = 'relative'; + } } submit(form: any) { -- cgit v1.2.3 From ba5259048771cc780bce4d2c6977496606a7d6ca Mon Sep 17 00:00:00 2001 From: benal01 Date: Thu, 6 Mar 2025 10:40:22 -0500 Subject: API interaction for creation form and increased menu usability --- .../app/components/cupboard/cupboard.component.css | 2 +- .../components/cupboard/cupboard.component.html | 14 ++- .../app/components/cupboard/cupboard.component.ts | 109 +++++++++++++-------- 3 files changed, 77 insertions(+), 48 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.css b/ufund-ui/src/app/components/cupboard/cupboard.component.css index 315db50..18a4d1b 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.css +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.css @@ -5,7 +5,7 @@ padding: 10px 20px; } -#create-form, #create-button { +#menu, #create-form, #delete-form { background-color: #d9d9d9; padding: 10px 20px 20px 20px; border: 2px solid #000; diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index b767439..6faea9b 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -1,8 +1,12 @@

Cupboard

-
- + +
+ +
-

Create a new need

@@ -18,8 +22,8 @@
- +

- + \ No newline at end of file diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index cc09393..213296d 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -1,6 +1,5 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, ViewChild } from '@angular/core'; import { CupboardService } from '../../services/cupboard.service'; -import { NeedListComponent } from '../need-list/need-list.component'; import { Need, GoalType } from '../../models/Need'; @Component({ @@ -9,55 +8,81 @@ import { Need, GoalType } from '../../models/Need'; templateUrl: './cupboard.component.html', styleUrl: './cupboard.component.css' }) -export class CupboardComponent implements - OnInit { - need: Need = { - id: 0, - name: '', - maxGoal: 0, - type: GoalType.MONETARY, - filterAttributes: [], - current: 0 - }; - - + +export class CupboardComponent implements OnInit { constructor(private cupboardService: CupboardService) { } + ngOnInit(): void { this.close(); + this.openmenu(); } - - open() { - const formElement = document.getElementById('create-form'); - if (formElement) { - formElement.style.visibility = 'visible'; - formElement.style.position = 'relative'; + + private hideElement(element: any) { + if (element){ + element.style.visibility = 'hidden'; + element.style.position = 'absolute'; } - const buttonElement = document.getElementById('create-button'); - if (buttonElement) { - buttonElement.style.visibility = 'hidden'; - buttonElement.style.position = 'absolute'; + } + + private showElement(element: any) { + if (element){ + element.style.visibility = 'visible'; + element.style.position = 'relative'; } } + openmenu() { + const menuElement = document.getElementById('menu'); + this.showElement(menuElement); + } + + opencreate() { + this.close(); + this.showElement(document.getElementById('create-form')); + } + + opendestroy() { + this.close(); + this.showElement(document.getElementById('destroy-form')); + } + + destroy() { + + } + + back() { + this.close(); + this.openmenu(); + } + close() { - const formElement = document.getElementById('create-form'); - if (formElement) { - formElement.style.visibility = 'hidden'; - formElement.style.position = 'absolute'; - } - const buttonElement = document.getElementById('create-button'); - if (buttonElement) { - buttonElement.style.visibility = 'visible'; - buttonElement.style.position = 'relative'; - } + this.hideElement(document.getElementById('create-form')); + this.hideElement(document.getElementById('destroy-form')); + this.hideElement(document.getElementById('menu')); } + + submit(form: any) { - console.log(form); - this.need.name = form.name; - this.need.id = form.id; - this.need.maxGoal = form.maxGoal; - this.need.type = GoalType[form.type as keyof typeof GoalType]; - console.log(this.cupboardService.createNeed(this.need)); - } - } + const need: Need = { + name: form.name, + id: form.id, + maxGoal: form.maxGoal, + type: GoalType[form.type as keyof typeof GoalType], + filterAttributes: [], + current: 0 + }; + console.log("form submitted. creating need: ", need); + this.cupboardService.createNeed(need).subscribe( + (result) => { + if (result) { + console.log("need created successfully"); + location.reload(); + } else { + console.log("need creation failed"); + } + } + + ); + } + } \ No newline at end of file -- cgit v1.2.3 From 482f60ca28be372a9f45d4160130d90c64770126 Mon Sep 17 00:00:00 2001 From: benal01 Date: Thu, 6 Mar 2025 11:01:26 -0500 Subject: removal of delete all form --- .../src/app/components/cupboard/cupboard.component.html | 8 ++------ ufund-ui/src/app/components/cupboard/cupboard.component.ts | 13 ++++--------- 2 files changed, 6 insertions(+), 15 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index 6faea9b..d9a247d 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -1,11 +1,6 @@

Cupboard

-
- -

Create a new need

@@ -22,8 +17,9 @@
- + +

\ No newline at end of file diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 213296d..2fccf18 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -41,15 +41,6 @@ export class CupboardComponent implements OnInit { this.showElement(document.getElementById('create-form')); } - opendestroy() { - this.close(); - this.showElement(document.getElementById('destroy-form')); - } - - destroy() { - - } - back() { this.close(); this.openmenu(); @@ -85,4 +76,8 @@ export class CupboardComponent implements OnInit { ); } + + destroy() { + + } } \ No newline at end of file -- cgit v1.2.3 From b90f796f2ebedccb4af9ccfd550913e4e7e54cab Mon Sep 17 00:00:00 2001 From: benal01 Date: Thu, 6 Mar 2025 11:10:08 -0500 Subject: changed delete method to use DELETE instead of PUT --- ufund-ui/src/app/services/cupboard.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/services/cupboard.service.ts b/ufund-ui/src/app/services/cupboard.service.ts index c123841..5a92b0a 100644 --- a/ufund-ui/src/app/services/cupboard.service.ts +++ b/ufund-ui/src/app/services/cupboard.service.ts @@ -39,6 +39,6 @@ export class CupboardService { } deleteNeed(id: number): Observable { - return this.http.put(`${this.url}/${id}`, this.httpOptions) + return this.http.delete(`${this.url}/${id}`, this.httpOptions) } } -- cgit v1.2.3 From bb9ce55cb5b55a6aaed2399e39a01d68f2491ce3 Mon Sep 17 00:00:00 2001 From: sowgro Date: Thu, 6 Mar 2025 21:41:39 -0500 Subject: Push current changes (working on documentation and tests) --- ufund-ui/src/app/app.module.ts | 6 ++++++ ufund-ui/src/app/components/dashboard/dashboard.component.html | 2 ++ ufund-ui/src/app/components/dashboard/dashboard.component.ts | 2 +- ufund-ui/src/app/components/login/login.component.ts | 8 ++++++-- 4 files changed, 15 insertions(+), 3 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/app.module.ts b/ufund-ui/src/app/app.module.ts index d818841..9203e3b 100644 --- a/ufund-ui/src/app/app.module.ts +++ b/ufund-ui/src/app/app.module.ts @@ -9,6 +9,8 @@ import {FundingBasketComponent} from './components/funding-basket/funding-basket import {CupboardComponent} from './components/cupboard/cupboard.component'; import {NeedListComponent} from './components/need-list/need-list.component'; import {HttpClientModule} from '@angular/common/http'; +import {FormsModule} from '@angular/forms'; +import {RouterLink, RouterLinkActive, RouterOutlet} from '@angular/router'; @NgModule({ declarations: [ @@ -22,6 +24,10 @@ import {HttpClientModule} from '@angular/common/http'; imports: [ BrowserModule, AppRoutingModule, + FormsModule, + RouterLink, + RouterLinkActive, + RouterOutlet, HttpClientModule, ], providers: [], diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.html b/ufund-ui/src/app/components/dashboard/dashboard.component.html index 9c5fce9..f41ccef 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.html +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.html @@ -1 +1,3 @@

dashboard works!

+Go to the Cupboard +Go to my basket diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.ts b/ufund-ui/src/app/components/dashboard/dashboard.component.ts index 6da4013..dd323c4 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.ts +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.ts @@ -7,5 +7,5 @@ import { Component } from '@angular/core'; styleUrl: './dashboard.component.css' }) export class DashboardComponent { - + constructor() {} } diff --git a/ufund-ui/src/app/components/login/login.component.ts b/ufund-ui/src/app/components/login/login.component.ts index 9a4eb0f..50dd018 100644 --- a/ufund-ui/src/app/components/login/login.component.ts +++ b/ufund-ui/src/app/components/login/login.component.ts @@ -1,5 +1,6 @@ import { Component } from '@angular/core' import {UsersService} from '../../services/users.service'; +import {Router} from '@angular/router'; @Component({ selector: 'app-login', @@ -9,7 +10,8 @@ import {UsersService} from '../../services/users.service'; }) export class LoginComponent { constructor( - protected usersService: UsersService + protected usersService: UsersService, + private router: Router ) {} login(username: string | null, password: string | null) { @@ -18,6 +20,8 @@ export class LoginComponent { return; } - this.usersService.login(username, password) + this.usersService.login(username, password).then(() => { + this.router.navigate(['/dashboard']); + }) } } -- cgit v1.2.3 From caaf278d1fa69fef69c210edb337fa54102d2737 Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 7 Mar 2025 12:52:24 -0500 Subject: Fix login in angular --- ufund-ui/src/app/app-routing.module.ts | 2 +- ufund-ui/src/app/app.module.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/app-routing.module.ts b/ufund-ui/src/app/app-routing.module.ts index d4f14da..4b76654 100644 --- a/ufund-ui/src/app/app-routing.module.ts +++ b/ufund-ui/src/app/app-routing.module.ts @@ -12,7 +12,7 @@ const routes: Routes = [ {path: 'login', component: LoginComponent}, {path: 'cupboard', component: CupboardComponent}, {path: 'dashboard', component: DashboardComponent}, - {path: 'funding-basket', component: FundingBasketComponent}, + {path: 'basket', component: FundingBasketComponent}, {path: 'need/:id', component: NeedPageComponent} ]; diff --git a/ufund-ui/src/app/app.module.ts b/ufund-ui/src/app/app.module.ts index 9203e3b..fa54c58 100644 --- a/ufund-ui/src/app/app.module.ts +++ b/ufund-ui/src/app/app.module.ts @@ -11,6 +11,7 @@ import {NeedListComponent} from './components/need-list/need-list.component'; import {HttpClientModule} from '@angular/common/http'; import {FormsModule} from '@angular/forms'; import {RouterLink, RouterLinkActive, RouterOutlet} from '@angular/router'; +import {DashboardComponent} from './components/dashboard/dashboard.component'; @NgModule({ declarations: [ @@ -19,7 +20,8 @@ import {RouterLink, RouterLinkActive, RouterOutlet} from '@angular/router'; HomePageComponent, FundingBasketComponent, CupboardComponent, - NeedListComponent + NeedListComponent, + DashboardComponent ], imports: [ BrowserModule, -- cgit v1.2.3 From 51f0322db803ed3baf1f24f18a6e7a83dab58a3b Mon Sep 17 00:00:00 2001 From: sowgro Date: Sat, 15 Mar 2025 17:28:01 -0400 Subject: Add login redirection --- ufund-ui/src/app/app.component.ts | 10 ++++++---- ufund-ui/src/app/app.module.ts | 6 +++++- .../app/components/dashboard/dashboard.component.html | 6 ++++-- .../funding-basket/funding-basket.component.ts | 16 ++++++++++++++-- .../src/app/components/login/login.component.html | 1 + ufund-ui/src/app/components/login/login.component.ts | 19 ++++++++++++++----- ufund-ui/src/app/services/users.service.ts | 10 +++++++--- 7 files changed, 51 insertions(+), 17 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/app.component.ts b/ufund-ui/src/app/app.component.ts index a85d04b..6f4e1f5 100644 --- a/ufund-ui/src/app/app.component.ts +++ b/ufund-ui/src/app/app.component.ts @@ -1,7 +1,6 @@ import {Component, OnInit} from '@angular/core'; import {UsersService} from './services/users.service'; -import {BehaviorSubject, Observable, Subject} from 'rxjs'; -import {User} from './models/User'; +import {BehaviorSubject} from 'rxjs'; @Component({ selector: 'app-root', @@ -18,8 +17,11 @@ export class AppComponent implements OnInit { ) {} ngOnInit() { - this.userService.getCurrentUser().subscribe(r => { - this.currentUser$?.next("Logged in as " + r.username) + this.userService.getCurrentUserSubject().subscribe(r => { + this.currentUser$?.next(r + ? "Logged in as " + r.username + : "Logged out." + ) }) } diff --git a/ufund-ui/src/app/app.module.ts b/ufund-ui/src/app/app.module.ts index fa54c58..4b50580 100644 --- a/ufund-ui/src/app/app.module.ts +++ b/ufund-ui/src/app/app.module.ts @@ -12,6 +12,8 @@ import {HttpClientModule} from '@angular/common/http'; import {FormsModule} from '@angular/forms'; import {RouterLink, RouterLinkActive, RouterOutlet} from '@angular/router'; import {DashboardComponent} from './components/dashboard/dashboard.component'; +import {CommonModule} from '@angular/common'; +import {LoginComponent} from './components/login/login.component'; @NgModule({ declarations: [ @@ -21,7 +23,8 @@ import {DashboardComponent} from './components/dashboard/dashboard.component'; FundingBasketComponent, CupboardComponent, NeedListComponent, - DashboardComponent + DashboardComponent, + LoginComponent ], imports: [ BrowserModule, @@ -30,6 +33,7 @@ import {DashboardComponent} from './components/dashboard/dashboard.component'; RouterLink, RouterLinkActive, RouterOutlet, + CommonModule, HttpClientModule, ], providers: [], diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.html b/ufund-ui/src/app/components/dashboard/dashboard.component.html index f41ccef..c73849f 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.html +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.html @@ -1,3 +1,5 @@

dashboard works!

-Go to the Cupboard -Go to my basket + 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 8b12306..c44aa27 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,6 @@ -import { Component } from '@angular/core'; +import {Component, OnInit} from '@angular/core'; +import {Router} from '@angular/router'; +import {UsersService} from '../../services/users.service'; @Component({ selector: 'app-funding-basket', @@ -6,6 +8,16 @@ import { Component } from '@angular/core'; templateUrl: './funding-basket.component.html', styleUrl: './funding-basket.component.css' }) -export class FundingBasketComponent { +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}}) + } + } } diff --git a/ufund-ui/src/app/components/login/login.component.html b/ufund-ui/src/app/components/login/login.component.html index 178ddbf..bfd7f5e 100644 --- a/ufund-ui/src/app/components/login/login.component.html +++ b/ufund-ui/src/app/components/login/login.component.html @@ -1,3 +1,4 @@ +
You must be logged in to view this page

Login:

diff --git a/ufund-ui/src/app/components/login/login.component.ts b/ufund-ui/src/app/components/login/login.component.ts index 50dd018..7d90624 100644 --- a/ufund-ui/src/app/components/login/login.component.ts +++ b/ufund-ui/src/app/components/login/login.component.ts @@ -1,6 +1,6 @@ -import { Component } from '@angular/core' +import {Component, OnInit} from '@angular/core' import {UsersService} from '../../services/users.service'; -import {Router} from '@angular/router'; +import {ActivatedRoute, Router} from '@angular/router'; @Component({ selector: 'app-login', @@ -8,20 +8,29 @@ import {Router} from '@angular/router'; templateUrl: './login.component.html', styleUrl: './login.component.css' }) -export class LoginComponent { +export class LoginComponent implements OnInit { + + protected next?: string | null; + constructor( protected usersService: UsersService, - private router: Router + private router: Router, + private route: ActivatedRoute ) {} + ngOnInit() { + this.next = this.route.snapshot.queryParamMap.get('redir') + } + login(username: string | null, password: string | null) { + let next = this.next || '/dashboard' console.log(`attempting to log in with ${username} ${password}`) if (!username || !password) { return; } this.usersService.login(username, password).then(() => { - this.router.navigate(['/dashboard']); + this.router.navigate([next]); }) } } diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts index 28cc266..b3bbbd4 100644 --- a/ufund-ui/src/app/services/users.service.ts +++ b/ufund-ui/src/app/services/users.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import {HttpClient, HttpHeaders} from '@angular/common/http'; -import {firstValueFrom, Observable, of, Subject} from 'rxjs'; +import {BehaviorSubject, firstValueFrom, Observable} from 'rxjs'; import {User} from '../models/User'; @Injectable({ @@ -8,7 +8,7 @@ import {User} from '../models/User'; }) export class UsersService { - private currentUser : Subject = new Subject(); + private currentUser : BehaviorSubject = new BehaviorSubject(null); private apiKey: string = ""; private url = "http://localhost:8080/users" @@ -48,10 +48,14 @@ export class UsersService { return this.http.delete(`${this.url}/${id}`, this.httpOptions) } - getCurrentUser() { + getCurrentUserSubject() { return this.currentUser; } + getCurrentUser() { + return this.currentUser.getValue() + } + async login(username: string, password: string) { let res = this.http.post(this.authUrl, {username: username, password: password}, this.httpOptions2); this.apiKey = await firstValueFrom(res); -- cgit v1.2.3 From d97d4d430113088c4f52f53c040d8705c66b410e Mon Sep 17 00:00:00 2001 From: sowgro Date: Sat, 15 Mar 2025 18:34:58 -0400 Subject: Add support for account creation --- ufund-ui/src/app/app.module.ts | 2 +- .../src/app/components/login/login.component.css | 12 +++- .../src/app/components/login/login.component.html | 5 +- .../src/app/components/login/login.component.ts | 66 +++++++++++++++++++++- ufund-ui/src/app/services/users.service.ts | 4 +- 5 files changed, 82 insertions(+), 7 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/app.module.ts b/ufund-ui/src/app/app.module.ts index 4b50580..9f525fe 100644 --- a/ufund-ui/src/app/app.module.ts +++ b/ufund-ui/src/app/app.module.ts @@ -24,7 +24,7 @@ import {LoginComponent} from './components/login/login.component'; CupboardComponent, NeedListComponent, DashboardComponent, - LoginComponent + LoginComponent, ], imports: [ BrowserModule, diff --git a/ufund-ui/src/app/components/login/login.component.css b/ufund-ui/src/app/components/login/login.component.css index afd4bf1..435cc87 100644 --- a/ufund-ui/src/app/components/login/login.component.css +++ b/ufund-ui/src/app/components/login/login.component.css @@ -1,6 +1,16 @@ -:host { +:host, .border { display: flex; flex-direction: column; max-width: 300px; gap: 5px } + +.border { + border-style: solid; + border-width: 1px; + padding: 10px; + margin: 10px; + position: absolute; + background-color: white; + box-shadow: 0 0 10px 10px black; +} diff --git a/ufund-ui/src/app/components/login/login.component.html b/ufund-ui/src/app/components/login/login.component.html index bfd7f5e..2cdb6d0 100644 --- a/ufund-ui/src/app/components/login/login.component.html +++ b/ufund-ui/src/app/components/login/login.component.html @@ -1,6 +1,7 @@ -
You must be logged in to view this page
+You must be logged in to view this page

Login:

- + +{{statusText | async}} diff --git a/ufund-ui/src/app/components/login/login.component.ts b/ufund-ui/src/app/components/login/login.component.ts index 7d90624..9d806f5 100644 --- a/ufund-ui/src/app/components/login/login.component.ts +++ b/ufund-ui/src/app/components/login/login.component.ts @@ -1,6 +1,7 @@ import {Component, OnInit} from '@angular/core' import {UsersService} from '../../services/users.service'; import {ActivatedRoute, Router} from '@angular/router'; +import {BehaviorSubject} from 'rxjs'; @Component({ selector: 'app-login', @@ -11,10 +12,11 @@ import {ActivatedRoute, Router} from '@angular/router'; export class LoginComponent implements OnInit { protected next?: string | null; + protected statusText = new BehaviorSubject("") constructor( protected usersService: UsersService, - private router: Router, + protected router: Router, private route: ActivatedRoute ) {} @@ -31,6 +33,68 @@ export class LoginComponent implements OnInit { this.usersService.login(username, password).then(() => { this.router.navigate([next]); + }).catch(ex => { + this.statusText.next("Unable to login: " + friendlyHttpStatus[ex.status]) + console.log(ex) + }) + } + + signup(username: string | null, password: string | null) { + console.log(`attempting to sign up with ${username} ${password}`) + if (!username || !password) { + return; + } + + this.usersService.createUser(username, password).then(() => { + this.statusText.next("Account created, click login.") + }).catch(ex => { + this.statusText.next("Unable to create account: " + friendlyHttpStatus[ex.status]) + console.log(ex) }) } } + +// temporary +let friendlyHttpStatus: {[key: number]: string} = { + 200: 'OK', + 201: 'Created', + 202: 'Accepted', + 203: 'Non-Authoritative Information', + 204: 'No Content', + 205: 'Reset Content', + 206: 'Partial Content', + 300: 'Multiple Choices', + 301: 'Moved Permanently', + 302: 'Found', + 303: 'See Other', + 304: 'Not Modified', + 305: 'Use Proxy', + 306: 'Unused', + 307: 'Temporary Redirect', + 400: 'Bad Request', + 401: 'Unauthorized', + 402: 'Payment Required', + 403: 'Forbidden', + 404: 'Not Found', + 405: 'Method Not Allowed', + 406: 'Not Acceptable', + 407: 'Proxy Authentication Required', + 408: 'Request Timeout', + 409: 'Conflict', + 410: 'Gone', + 411: 'Length Required', + 412: 'Precondition Required', + 413: 'Request Entry Too Large', + 414: 'Request-URI Too Long', + 415: 'Unsupported Media Type', + 416: 'Requested Range Not Satisfiable', + 417: 'Expectation Failed', + 418: 'I\'m a teapot', + 429: 'Too Many Requests', + 500: 'Internal Server Error', + 501: 'Not Implemented', + 502: 'Bad Gateway', + 503: 'Service Unavailable', + 504: 'Gateway Timeout', + 505: 'HTTP Version Not Supported', +}; diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts index b3bbbd4..c570ccf 100644 --- a/ufund-ui/src/app/services/users.service.ts +++ b/ufund-ui/src/app/services/users.service.ts @@ -32,8 +32,8 @@ export class UsersService { private http: HttpClient ) {} - createUser(data: User): Observable { - return this.http.post(this.url, data, this.httpOptions) + async createUser(username:string, password:string) { + await firstValueFrom(this.http.post(this.url, {username: username, password: password}, this.httpOptions)) } getUser(id: string): Observable { -- cgit v1.2.3 From 86e01c6b0d252dabaa261b1be26c905da70ec94f Mon Sep 17 00:00:00 2001 From: sowgro Date: Mon, 17 Mar 2025 16:28:18 -0400 Subject: Add userType to frontend --- ufund-ui/src/app/models/User.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/models/User.ts b/ufund-ui/src/app/models/User.ts index 9149fe7..141f8aa 100644 --- a/ufund-ui/src/app/models/User.ts +++ b/ufund-ui/src/app/models/User.ts @@ -1,6 +1,12 @@ import {Need} from './Need'; +enum userType { + HELPER, + MANAGER +} + export interface User { username: string; basket: Need[]; + type: userType } -- cgit v1.2.3 From 0790d1a6fbe62be5d7cf1a688f01419928abe51a Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 17 Mar 2025 17:04:15 -0400 Subject: corrected incorrect formatting for update-need api controller --- ufund-ui/src/app/services/cupboard.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/services/cupboard.service.ts b/ufund-ui/src/app/services/cupboard.service.ts index 5a92b0a..6727060 100644 --- a/ufund-ui/src/app/services/cupboard.service.ts +++ b/ufund-ui/src/app/services/cupboard.service.ts @@ -35,7 +35,7 @@ export class CupboardService { } updateNeed(id: number, data: Need): Observable { - return this.http.put(`${this.url}/${id}`, data, this.httpOptions) + return this.http.put(`${this.url}`, data, this.httpOptions) } deleteNeed(id: number): Observable { -- cgit v1.2.3 From 9917e8a4eb02eab5e770bb1e95c28f98e02d1265 Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 17 Mar 2025 17:07:11 -0400 Subject: cupboard edit form with default values --- .../app/components/cupboard/cupboard.component.css | 2 +- .../components/cupboard/cupboard.component.html | 24 +++++++++++ .../app/components/cupboard/cupboard.component.ts | 47 +++++++++++++++++++++- 3 files changed, 70 insertions(+), 3 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.css b/ufund-ui/src/app/components/cupboard/cupboard.component.css index 18a4d1b..fe4971a 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.css +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.css @@ -5,7 +5,7 @@ padding: 10px 20px; } -#menu, #create-form, #delete-form { +#menu, #create-form, #delete-form, #update-form { background-color: #d9d9d9; padding: 10px 20px 20px 20px; border: 2px solid #000; diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index d9a247d..2749850 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -1,6 +1,7 @@

Cupboard

Create a new need

@@ -20,6 +21,29 @@ +
+
+

Update a need

+
+
+
+ + +
+
+
+
+
+
+
+ +
+ +
+ +
+ +

\ No newline at end of file diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 2fccf18..e3f33ac 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit, ViewChild } from '@angular/core'; import { CupboardService } from '../../services/cupboard.service'; import { Need, GoalType } from '../../models/Need'; +import { Form } from '@angular/forms'; @Component({ selector: 'app-cupboard', @@ -10,13 +11,23 @@ import { Need, GoalType } from '../../models/Need'; }) export class CupboardComponent implements OnInit { +needs: any; constructor(private cupboardService: CupboardService) { } ngOnInit(): void { + this.cupboardService.getNeeds().subscribe(n => this.needs = n); this.close(); this.openmenu(); } - + + selectedNeed: any = { + name: '', + id: null, + maxGoal: null, + type: '' + }; + selectedNeedId: number | null = null; + private hideElement(element: any) { if (element){ element.style.visibility = 'hidden'; @@ -41,6 +52,11 @@ export class CupboardComponent implements OnInit { this.showElement(document.getElementById('create-form')); } + openupdate() { + this.close(); + this.showElement(document.getElementById('update-form')); + } + back() { this.close(); this.openmenu(); @@ -50,9 +66,36 @@ export class CupboardComponent implements OnInit { 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 }; + } + + update(form: any) { + console.log(form); + const need: Need = { + name: form.name, + id: form.id, + maxGoal: form.maxGoal, + type: GoalType[form.type as keyof typeof GoalType], + filterAttributes: [], + current: 0 + }; + console.log(need.id, need, "need updated"); + this.cupboardService.updateNeed(need.id, need).subscribe( + (result) => { + if (result) { + console.log("need updated successfully"); + location.reload(); + } else { + console.log("need update failed"); + } + } + + ); + } submit(form: any) { const need: Need = { -- cgit v1.2.3 From bf33fa3ca9f29b1e75cc077ae2eaaf4f5725e4b3 Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 17 Mar 2025 17:08:04 -0400 Subject: need list delete button --- ufund-ui/src/app/components/need-list/need-list.component.html | 1 + ufund-ui/src/app/components/need-list/need-list.component.ts | 6 ++++++ 2 files changed, 7 insertions(+) (limited to 'ufund-ui/src/app') 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 6e48d96..b8774f1 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 @@ -3,4 +3,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 a3eb072..579565c 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 @@ -18,4 +18,10 @@ export class NeedListComponent { ngOnInit(): void { this.cupboardService.getNeeds().subscribe(n => this.needs = n) } + + delete(id : number) { + this.cupboardService.deleteNeed(id).subscribe(() => { + this.needs = this.needs.filter(n => n.id !== id) + }) + } } -- cgit v1.2.3 From 88f6a4174d7fcc53028b78d0d9b3d91b6d17d2c6 Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 17 Mar 2025 18:25:19 -0400 Subject: search needs with timeout to throttle api calls --- .../app/components/cupboard/cupboard.component.ts | 2 +- .../components/need-list/need-list.component.css | 12 +++- .../components/need-list/need-list.component.html | 19 +++++++ .../components/need-list/need-list.component.ts | 66 +++++++++++++++++++++- 4 files changed, 95 insertions(+), 4 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index e3f33ac..adc38b0 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -19,7 +19,7 @@ needs: any; this.close(); this.openmenu(); } - + selectedNeed: any = { name: '', id: null, diff --git a/ufund-ui/src/app/components/need-list/need-list.component.css b/ufund-ui/src/app/components/need-list/need-list.component.css index 1bcaed9..bbc3f2c 100644 --- a/ufund-ui/src/app/components/need-list/need-list.component.css +++ b/ufund-ui/src/app/components/need-list/need-list.component.css @@ -7,10 +7,18 @@ } -li { +li, div { border: 2px solid #000; border-radius: 5px; padding: 5px; margin: 5px; -} \ No newline at end of file +} + +#search-form { + background-color: #d9d9d9; + padding: 10px 20px 20px 20px; + border: 2px solid #000; + border-radius: 5px; + visibility: visible; + } \ No newline at end of file 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 b8774f1..6dd6511 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 @@ -1,4 +1,23 @@

Needs List

+ +
+
+
+ +
+
+ +
+

Search Results:

+
+ + {{need.name}} + + +
+
+
+
  • {{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 579565c..8451d5b 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 @@ -10,13 +10,73 @@ import {CupboardService} from '../../services/cupboard.service'; }) export class NeedListComponent { needs: Need[] = []; - + searchResults: Need[] = []; + constructor( private cupboardService: CupboardService ) {} ngOnInit(): void { this.cupboardService.getNeeds().subscribe(n => this.needs = n) + this.close(); + } + + private showElement(element: any) { + if (element){ + element.style.visibility = 'visible'; + element.style.position = 'relative'; + } + } + + private hideElement(element: any) { + if (element){ + element.style.visibility = 'hidden'; + element.style.position = 'absolute'; + } + } + + private updateSearchStatus(text: string) { + let element = document.getElementById('search-status'); + if (element) { + element.innerHTML = text; + } + } + + open() { + this.hideElement(document.getElementById('search-button')); + this.showElement(document.getElementById('search-form')); + } + + close() { + this.hideElement(document.getElementById('search-form')); + this.showElement(document.getElementById('search-button')); + } + + private searchDelay: any; + + 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); + } + + this.searchDelay = setTimeout(() => { + const currentSearchValue = form.search; //latest value of the search + this.cupboardService.searchNeeds(currentSearchValue).subscribe((n) => { + this.searchResults = n; + console.log(currentSearchValue, this.searchResults); + if (this.searchResults.length === this.needs.length) { + this.updateSearchStatus("Please refine your search"); + this.searchResults = []; + } else if (this.searchResults.length === 0) { + this.updateSearchStatus("No results found"); + } else { + this.updateSearchStatus("Search results:"); + } + }); + }, 250); } delete(id : number) { @@ -24,4 +84,8 @@ export class NeedListComponent { this.needs = this.needs.filter(n => n.id !== id) }) } + + back() { + this.searchResults = []; + } } -- cgit v1.2.3 From b0f0589afdb319de8a01cb53f8a89c7265e634ae Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 17 Mar 2025 18:30:26 -0400 Subject: remove useless id input for need creation --- ufund-ui/src/app/components/cupboard/cupboard.component.html | 2 -- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index 2749850..23aaec7 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -8,8 +8,6 @@


    -
    -



    diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index adc38b0..b5726cf 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -77,7 +77,7 @@ needs: any; console.log(form); const need: Need = { name: form.name, - id: form.id, + id: 0, //system will control this maxGoal: form.maxGoal, type: GoalType[form.type as keyof typeof GoalType], filterAttributes: [], -- cgit v1.2.3 From 7057f8ad5e0aaf6527477a68c229db659cd674ff Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 17 Mar 2025 18:42:10 -0400 Subject: exporting usertype enum --- ufund-ui/src/app/models/User.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/models/User.ts b/ufund-ui/src/app/models/User.ts index 141f8aa..5ed3a3f 100644 --- a/ufund-ui/src/app/models/User.ts +++ b/ufund-ui/src/app/models/User.ts @@ -1,6 +1,6 @@ import {Need} from './Need'; -enum userType { +export enum userType { HELPER, MANAGER } -- cgit v1.2.3 From 0287d0ebd22b88c2d41f2bdb67db812c35d9024c Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 17 Mar 2025 18:42:40 -0400 Subject: hide admin only management elements if user is not an admin --- ufund-ui/src/app/components/cupboard/cupboard.component.html | 3 ++- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 9 +++++++-- ufund-ui/src/app/components/need-list/need-list.component.html | 4 ++-- ufund-ui/src/app/components/need-list/need-list.component.ts | 10 ++++++++-- 4 files changed, 19 insertions(+), 7 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index 23aaec7..65545e8 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -1,5 +1,6 @@

    Cupboard

    -
  • @@ -22,5 +22,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 8451d5b..6ad9397 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 @@ -1,7 +1,8 @@ import { Component } from '@angular/core'; import {Need} from '../../models/Need'; import {CupboardService} from '../../services/cupboard.service'; - +import { UsersService } from '../../services/users.service'; +import { userType } from '../../models/User'; @Component({ selector: 'app-need-list', standalone: false, @@ -13,7 +14,8 @@ export class NeedListComponent { searchResults: Need[] = []; constructor( - private cupboardService: CupboardService + private cupboardService: CupboardService, + private usersService: UsersService ) {} ngOnInit(): void { @@ -85,6 +87,10 @@ export class NeedListComponent { }) } + isManager() { + return this.usersService.getCurrentUser()?.type == userType.MANAGER; + } + back() { this.searchResults = []; } -- cgit v1.2.3 From 3f64404c23a95f3625754a79a753ed5ed4df3001 Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 17 Mar 2025 18:44:51 -0400 Subject: console feedback based on user access level --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 5a8773d..fc5d7dd 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -19,6 +19,12 @@ needs: any; 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 = { -- cgit v1.2.3 From 8951d00eddb147e5301454f250e503ad19aa47d3 Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 17 Mar 2025 20:52:59 -0400 Subject: fixed user authentication bug where user was never admin --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 3 ++- ufund-ui/src/app/components/need-list/need-list.component.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index fc5d7dd..c1bf66c 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -81,7 +81,8 @@ needs: any; } isManager() { - return this.usersService.getCurrentUser()?.type == userType.MANAGER; + const type = this.usersService.getCurrentUser()?.type; + return type === ("MANAGER" as unknown as userType); } update(form: any) { 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 6ad9397..4409b63 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 @@ -88,7 +88,8 @@ export class NeedListComponent { } isManager() { - return this.usersService.getCurrentUser()?.type == userType.MANAGER; + const type = this.usersService.getCurrentUser()?.type; + return type === ("MANAGER" as unknown as userType); } back() { -- cgit v1.2.3 From 674b158932394d3cad8bce8dedca49b1efdfd453 Mon Sep 17 00:00:00 2001 From: sowgro Date: Mon, 17 Mar 2025 21:17:06 -0400 Subject: Attempt at fixing connection to front end --- .../src/app/components/cupboard/cupboard.component.ts | 18 ++++++++++-------- ufund-ui/src/app/models/User.ts | 6 +++--- 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index c1bf66c..0fec0e0 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 { UsersService } from '../../services/users.service'; import { Need, GoalType } from '../../models/Need'; -import { userType } from '../../models/User'; +import { userType } from '../../models/User'; @Component({ selector: 'app-cupboard', @@ -14,7 +14,7 @@ import { userType } from '../../models/User'; export class CupboardComponent implements OnInit { needs: any; constructor(private cupboardService: CupboardService, private usersService: UsersService) { } - + ngOnInit(): void { this.cupboardService.getNeeds().subscribe(n => this.needs = n); this.close(); @@ -34,7 +34,7 @@ needs: any; type: '' }; selectedNeedId: number | null = null; - + private hideElement(element: any) { if (element){ element.style.visibility = 'hidden'; @@ -53,7 +53,7 @@ needs: any; const menuElement = document.getElementById('menu'); this.showElement(menuElement); } - + opencreate() { this.close(); this.showElement(document.getElementById('create-form')); @@ -68,7 +68,7 @@ needs: any; this.close(); this.openmenu(); } - + close() { this.hideElement(document.getElementById('create-form')); this.hideElement(document.getElementById('destroy-form')); @@ -95,6 +95,7 @@ needs: any; filterAttributes: [], current: 0 }; + console.log("need:", need); console.log(need.id, need, "need updated"); this.cupboardService.updateNeed(need.id, need).subscribe( (result) => { @@ -112,12 +113,13 @@ needs: any; submit(form: any) { const need: Need = { name: form.name, - id: form.id, + id: 0, maxGoal: form.maxGoal, - type: GoalType[form.type as keyof typeof GoalType], + type: form.type, filterAttributes: [], current: 0 }; + console.log("need:", need); console.log("form submitted. creating need: ", need); this.cupboardService.createNeed(need).subscribe( (result) => { @@ -135,4 +137,4 @@ needs: any; destroy() { } - } \ No newline at end of file + } diff --git a/ufund-ui/src/app/models/User.ts b/ufund-ui/src/app/models/User.ts index 5ed3a3f..b640e04 100644 --- a/ufund-ui/src/app/models/User.ts +++ b/ufund-ui/src/app/models/User.ts @@ -6,7 +6,7 @@ export enum userType { } export interface User { - username: string; - basket: Need[]; - type: userType + username: string; + basket: Need[]; + type: userType } -- cgit v1.2.3 From 3fb96dd979d280a739175a9fa5bc0596f411cd7a Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 17 Mar 2025 21:31:06 -0400 Subject: embed elements into dashboard --- ufund-ui/src/app/components/dashboard/dashboard.component.html | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.html b/ufund-ui/src/app/components/dashboard/dashboard.component.html index c73849f..09dc311 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 works!

    - + +

    Dashboard

    + + -- cgit v1.2.3 From 13c0042f9c6e130a061cbb448cff6bcd9e8ab5e6 Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 17 Mar 2025 21:31:16 -0400 Subject: embed element into dashboard --- ufund-ui/src/app/components/home-page/home-page.component.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/components/home-page/home-page.component.html b/ufund-ui/src/app/components/home-page/home-page.component.html index e13c539..d41e670 100644 --- a/ufund-ui/src/app/components/home-page/home-page.component.html +++ b/ufund-ui/src/app/components/home-page/home-page.component.html @@ -1,4 +1,3 @@ Login/Sign Up - -

    home-page works!

    + \ No newline at end of file -- cgit v1.2.3 From 54876363de44791ba65b6c43b795f8d0c3548ecc Mon Sep 17 00:00:00 2001 From: sowgro Date: Mon, 17 Mar 2025 21:45:31 -0400 Subject: Fix tests --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 2 +- ufund-ui/src/app/services/cupboard.service.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 0fec0e0..a930f06 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -89,7 +89,7 @@ needs: any; console.log(form); const need: Need = { name: form.name, - id: 0, //system will control this + id: form.id, //system will control this maxGoal: form.maxGoal, type: GoalType[form.type as keyof typeof GoalType], filterAttributes: [], diff --git a/ufund-ui/src/app/services/cupboard.service.ts b/ufund-ui/src/app/services/cupboard.service.ts index 3b9aef6..9e14106 100644 --- a/ufund-ui/src/app/services/cupboard.service.ts +++ b/ufund-ui/src/app/services/cupboard.service.ts @@ -34,7 +34,7 @@ export class CupboardService { } updateNeed(id: number, data: Need): Observable { - return this.http.put(`${this.url}`, data, this.httpOptions) + return this.http.put(`${this.url}/${id}`, data, this.httpOptions) } deleteNeed(id: number): Observable { -- cgit v1.2.3 From 7dead0216c5847ed808bebaae106137be19784d4 Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 17 Mar 2025 22:02:12 -0400 Subject: back button for needs and dashboard --- ufund-ui/src/app/components/dashboard/dashboard.component.html | 3 ++- ufund-ui/src/app/components/dashboard/dashboard.component.ts | 4 ++++ ufund-ui/src/app/components/need-page/need-page.component.html | 3 ++- ufund-ui/src/app/components/need-page/need-page.component.ts | 4 ++++ 4 files changed, 12 insertions(+), 2 deletions(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.html b/ufund-ui/src/app/components/dashboard/dashboard.component.html index 09dc311..fc8baf0 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.html +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.html @@ -1,4 +1,5 @@

    Dashboard

    + - + \ No newline at end of file diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.ts b/ufund-ui/src/app/components/dashboard/dashboard.component.ts index dd323c4..48c5894 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.ts +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.ts @@ -8,4 +8,8 @@ import { Component } from '@angular/core'; }) export class DashboardComponent { constructor() {} + + back() { + window.history.back(); + } } 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 0bc4746..4bb001e 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,7 +1,8 @@ +

    Need page

    id: {{need?.id}}

    name: {{need?.name}}

    filterAttributes: {{need?.filterAttributes}}

    type: {{need?.type}}

    max goal: {{need?.maxGoal}}

    -

    current: {{need?.maxGoal}}

    +

    current: {{need?.maxGoal}}

    \ No newline at end of file diff --git a/ufund-ui/src/app/components/need-page/need-page.component.ts b/ufund-ui/src/app/components/need-page/need-page.component.ts index 15c1e87..0673f86 100644 --- a/ufund-ui/src/app/components/need-page/need-page.component.ts +++ b/ufund-ui/src/app/components/need-page/need-page.component.ts @@ -21,4 +21,8 @@ export class NeedPageComponent { const id = Number(this.route.snapshot.paramMap.get('id')); this.cupboardService.getNeed(id).subscribe(n => this.need = n); } + + back() { + window.history.back(); + } } -- cgit v1.2.3 From 065f90f1f759ed4b97dc22a02e331f7a30eb8ee3 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 17 Mar 2025 22:17:28 -0400 Subject: Added statusText to components to disable error messages --- .../components/cupboard/cupboard.component.html | 1 + .../app/components/cupboard/cupboard.component.ts | 55 +++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index 65545e8..59d77e0 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -19,6 +19,7 @@ + {{statusText | async}}
    diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index a930f06..4088ae4 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -3,6 +3,7 @@ import { CupboardService } from '../../services/cupboard.service'; import { UsersService } from '../../services/users.service'; import { Need, GoalType } from '../../models/Need'; import { userType } from '../../models/User'; +import { BehaviorSubject, catchError, of } from 'rxjs'; @Component({ selector: 'app-cupboard', @@ -12,6 +13,9 @@ import { userType } from '../../models/User'; }) export class CupboardComponent implements OnInit { + + protected statusText = new BehaviorSubject("") + needs: any; constructor(private cupboardService: CupboardService, private usersService: UsersService) { } @@ -121,7 +125,12 @@ needs: any; }; console.log("need:", need); console.log("form submitted. creating need: ", need); - this.cupboardService.createNeed(need).subscribe( + 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"); @@ -138,3 +147,47 @@ needs: any; } } + +let friendlyHttpStatus: {[key: number]: string} = { + 200: 'OK', + 201: 'Created', + 202: 'Accepted', + 203: 'Non-Authoritative Information', + 204: 'No Content', + 205: 'Reset Content', + 206: 'Partial Content', + 300: 'Multiple Choices', + 301: 'Moved Permanently', + 302: 'Found', + 303: 'See Other', + 304: 'Not Modified', + 305: 'Use Proxy', + 306: 'Unused', + 307: 'Temporary Redirect', + 400: 'Bad Request', + 401: 'Unauthorized', + 402: 'Payment Required', + 403: 'Forbidden', + 404: 'Not Found', + 405: 'Method Not Allowed', + 406: 'Not Acceptable', + 407: 'Proxy Authentication Required', + 408: 'Request Timeout', + 409: 'Conflict', + 410: 'Gone', + 411: 'Length Required', + 412: 'Precondition Required', + 413: 'Request Entry Too Large', + 414: 'Request-URI Too Long', + 415: 'Unsupported Media Type', + 416: 'Requested Range Not Satisfiable', + 417: 'Expectation Failed', + 418: 'I\'m a teapot', + 429: 'Too Many Requests', + 500: 'Internal Server Error', + 501: 'Not Implemented', + 502: 'Bad Gateway', + 503: 'Service Unavailable', + 504: 'Gateway Timeout', + 505: 'HTTP Version Not Supported', +}; \ No newline at end of file -- cgit v1.2.3 From e9950afde68bb6e5e659ac182334bf2b18088f90 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 17 Mar 2025 22:49:37 -0400 Subject: Added status message when update need fails --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 4088ae4..1b6d658 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -101,7 +101,12 @@ needs: any; }; console.log("need:", need); console.log(need.id, need, "need updated"); - this.cupboardService.updateNeed(need.id, need).subscribe( + 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"); -- cgit v1.2.3 From b5797b53eddf5a52ea9bbd8f3c638edd678407ab Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Mon, 17 Mar 2025 22:56:19 -0400 Subject: please work, i backmerged and everything. -ak --- .../components/need-page/need-page.component.html | 29 ++++++++++++++++------ .../components/need-page/need-page.component.ts | 7 ++++-- 2 files changed, 26 insertions(+), 10 deletions(-) (limited to 'ufund-ui/src/app') 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 4bb001e..8234ac7 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,8 +1,21 @@ - -

    Need page

    -

    id: {{need?.id}}

    -

    name: {{need?.name}}

    -

    filterAttributes: {{need?.filterAttributes}}

    -

    type: {{need?.type}}

    -

    max goal: {{need?.maxGoal}}

    -

    current: {{need?.maxGoal}}

    \ No newline at end of file +

    Viewing Need: {{need?.name}}

    +internal id: {{need?.id}} +
    +

    Looking for

    +

    {{need?.type}}

    +

    Donations.

    +
    +
    +

    Tags:

    +
      +
    • +

      {{tag}}

      +
    • +
    +
    + +
    + +

    Goal: {{need?.maxGoal}}

    +

    Current: {{need?.current}}

    +

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

    \ No newline at end of file diff --git a/ufund-ui/src/app/components/need-page/need-page.component.ts b/ufund-ui/src/app/components/need-page/need-page.component.ts index 0673f86..597d0e0 100644 --- a/ufund-ui/src/app/components/need-page/need-page.component.ts +++ b/ufund-ui/src/app/components/need-page/need-page.component.ts @@ -1,7 +1,8 @@ import {Component, Input} from '@angular/core'; -import {Need} from '../../models/Need'; +import {GoalType, Need} from '../../models/Need'; import {ActivatedRoute} from "@angular/router"; import {CupboardService} from "../../services/cupboard.service"; +import { NgFor } from '@angular/common'; @Component({ selector: 'app-need-page', @@ -15,6 +16,8 @@ export class NeedPageComponent { private cupboardService: CupboardService, ) {} + public GoalType = GoalType; + @Input() need?: Need; ngOnInit(): void { @@ -25,4 +28,4 @@ export class NeedPageComponent { back() { window.history.back(); } -} +} \ No newline at end of file -- cgit v1.2.3 From 2b847078b7af4ade35461b8af52352bc88994be3 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 17 Mar 2025 23:04:17 -0400 Subject: Added status text to update form --- ufund-ui/src/app/components/cupboard/cupboard.component.html | 1 + 1 file changed, 1 insertion(+) (limited to 'ufund-ui/src/app') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index 59d77e0..76fdf0a 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -43,6 +43,7 @@ + {{statusText | async}}

    -- cgit v1.2.3