aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/components
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-ui/src/app/components')
-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
3 files changed, 44 insertions, 28 deletions
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));
}
}