aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/components/cupboard/cupboard.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts')
-rw-r--r--ufund-ui/src/app/components/cupboard/cupboard.component.ts47
1 files changed, 45 insertions, 2 deletions
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 = {