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-api/data/cupboard.json | 4 +-- 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 +++++++++++++--------- 5 files changed, 47 insertions(+), 31 deletions(-) diff --git a/ufund-api/data/cupboard.json b/ufund-api/data/cupboard.json index bb7ec03..325371d 100644 --- a/ufund-api/data/cupboard.json +++ b/ufund-api/data/cupboard.json @@ -1,3 +1 @@ -[ - {"name":"Money for coral","id":1,"maxGoal":100.0,"type":"MONETARY","filterAttributes":null,"Current":0.0} -] \ No newline at end of file +[{"name":"Money for coral","id":1,"maxGoal":100.0,"type":"MONETARY","filterAttributes":null,"Current":0.0},{"name":"Test","id":2,"maxGoal":100.0,"type":"PHYSICAL","filterAttributes":null,"Current":0.0},{"name":"e","id":3,"maxGoal":3.0,"type":"MONETARY","filterAttributes":[],"Current":0.0}] \ No newline at end of file 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