aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbenal01 <bja4245@rit.edu>2025-03-04 09:43:37 -0500
committerbenal01 <bja4245@rit.edu>2025-03-04 09:43:37 -0500
commitab7aa87d3a6249352a14b5a9c3c3c9e08577657f (patch)
tree5cef39580ad1b6d8d5ca815ccf11549a76198e56
parent8e93fe31c81c4c36e66c48e7efcdbfedb1877385 (diff)
downloadJellySolutions-ab7aa87d3a6249352a14b5a9c3c3c9e08577657f.tar.gz
JellySolutions-ab7aa87d3a6249352a14b5a9c3c3c9e08577657f.tar.bz2
JellySolutions-ab7aa87d3a6249352a14b5a9c3c3c9e08577657f.zip
cupboard component form creation and interfacing with the controller
-rw-r--r--ufund-api/data/cupboard.json4
-rw-r--r--ufund-ui/src/app/app.module.ts2
-rw-r--r--ufund-ui/src/app/components/cupboard/cupboard.component.css4
-rw-r--r--ufund-ui/src/app/components/cupboard/cupboard.component.html32
-rw-r--r--ufund-ui/src/app/components/cupboard/cupboard.component.ts36
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 @@
<h1> Cupboard </h1>
-<form>
- <label for="name">Name:</label><br>
- <input #name type="text" name="name"><br>
- <label for="id">Id:</label><br>
- <input #id type="number" name="id"><br>
- <label for="max-goal">Max Goal:</label><br>
- <input #maxgoal type="number" name="max-goal"><br>
- <label>Type</label><br>
- <input id="monetary" type="radio" name="type" value="MONETARY">
- <label for="monetary">Monetary</label><br>
- <input #physical type="radio" name="type" value="PHYSICAL">
- <label for="physical">Physical</label><br>
-</form>
-<button (click)="submit(name.value, id.valueAsNumber, maxgoal.valueAsNumber, physical.value)">Submit</button>
+<div id="create-form">
+ <h1> Create a new need </h1>
+ <form #cupboardForm="ngForm" (ngSubmit)="submit(cupboardForm.value)">
+ <label>Name:</label><br>
+ <input type="text" name="name" ngModel><br>
+ <label>Id:</label><br>
+ <input type="number" name="id" ngModel><br>
+ <label>Max Goal:</label><br>
+ <input type="number" name="maxGoal" ngModel><br>
+ <label>Type</label><br>
+ <input type="radio" name="type" value="MONETARY" ngModel>
+ <label>Monetary</label><br>
+ <input type="radio" name="type" value="PHYSICAL" ngModel>
+ <label>Physical</label><br>
+ <input type="submit" value="Submit">
+ </form>
+</div>
+
<app-need-list></app-need-list>
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));
}
}