aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/components/need-edit
diff options
context:
space:
mode:
authorGunther6070 <haydenhartman10@yahoo.com>2025-04-01 07:45:28 -0400
committerGunther6070 <haydenhartman10@yahoo.com>2025-04-01 07:45:28 -0400
commit726b527af983025a95daae67864122761bcc4e78 (patch)
tree2046e58c146097aac21c9e352771420c31df6589 /ufund-ui/src/app/components/need-edit
parentb544f2617843af29875af81923d3bec539aca704 (diff)
parent0e9c0803e35a23ef2e873dc7ebf224a49a92f207 (diff)
downloadJellySolutions-726b527af983025a95daae67864122761bcc4e78.tar.gz
JellySolutions-726b527af983025a95daae67864122761bcc4e78.tar.bz2
JellySolutions-726b527af983025a95daae67864122761bcc4e78.zip
Merge branch 'css' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b into css
Diffstat (limited to 'ufund-ui/src/app/components/need-edit')
-rw-r--r--ufund-ui/src/app/components/need-edit/need-edit.component.css21
-rw-r--r--ufund-ui/src/app/components/need-edit/need-edit.component.html24
-rw-r--r--ufund-ui/src/app/components/need-edit/need-edit.component.ts61
3 files changed, 106 insertions, 0 deletions
diff --git a/ufund-ui/src/app/components/need-edit/need-edit.component.css b/ufund-ui/src/app/components/need-edit/need-edit.component.css
new file mode 100644
index 0000000..17605c2
--- /dev/null
+++ b/ufund-ui/src/app/components/need-edit/need-edit.component.css
@@ -0,0 +1,21 @@
+:host {
+ /*position: absolute;*/
+ /*background-color: rgba(0, 0, 0, 0.5);*/
+ /*display: flex;*/
+ /*height: 100%;*/
+ /*top: 0;*/
+ /*left: 0;*/
+ /*right: 0;*/
+ /*z-index: 5;*/
+ /*justify-content: center;*/
+}
+
+#create-form, #delete-form, #update-form {
+ margin-top: 50px;
+ background-color: #3a3a3a;
+ padding: 10px 20px 20px 20px;
+ border: 2px solid #000;
+ border-radius: 5px;
+ /*visibility: visible;*/
+ /*position: absolute;*/
+}
diff --git a/ufund-ui/src/app/components/need-edit/need-edit.component.html b/ufund-ui/src/app/components/need-edit/need-edit.component.html
new file mode 100644
index 0000000..e776415
--- /dev/null
+++ b/ufund-ui/src/app/components/need-edit/need-edit.component.html
@@ -0,0 +1,24 @@
+<div id="update-form">
+ <h1> Update Need </h1>
+ <form #updateForm="ngForm" (ngSubmit)="update(updateForm.value)">
+ <label>Name:</label><br>
+ <input type="text" name="name" [(ngModel)]="selectedNeed.name"><br>
+ <label>Image:</label><br>
+ <input type="text" name="image" [(ngModel)]="selectedNeed.image"><br>
+ <label>Location:</label><br>
+ <input type="text" name="location" [(ngModel)]="selectedNeed.location"><br>
+ <label>Max Goal:</label><br>
+ <input type="number" name="maxGoal" [(ngModel)]="selectedNeed.maxGoal"><br>
+ <label>Type</label><br>
+ <input type="radio" name="type" value="MONETARY" [(ngModel)]="selectedNeed.type">
+ <label>Monetary</label><br>
+ <input type="radio" name="type" value="PHYSICAL" [(ngModel)]="selectedNeed.type">
+ <label>Physical</label><br>
+ <input type="checkbox" name="urgent" [(ngModel)]="selectedNeed.urgent">
+ <label>Urgent</label> <br>
+ <label>Description</label> <br>
+ <textarea name="description" [(ngModel)]="selectedNeed.description"></textarea><br>
+ <input type="submit" value="Submit">
+
+ </form>
+</div>
diff --git a/ufund-ui/src/app/components/need-edit/need-edit.component.ts b/ufund-ui/src/app/components/need-edit/need-edit.component.ts
new file mode 100644
index 0000000..2462534
--- /dev/null
+++ b/ufund-ui/src/app/components/need-edit/need-edit.component.ts
@@ -0,0 +1,61 @@
+import { Component, Input, Output, EventEmitter } from '@angular/core';
+import { Need, GoalType } from '../../models/Need';
+import { CupboardService } from '../../services/cupboard.service';
+import { catchError, of } from 'rxjs';
+import { ToastsService, ToastType } from '../../services/toasts.service';
+
+@Component({
+ selector: 'app-need-edit',
+ standalone: false,
+ templateUrl: './need-edit.component.html',
+ styleUrl: './need-edit.component.css'
+})
+export class NeedEditComponent {
+ constructor(
+ private cupboardService: CupboardService,
+ private toastService: ToastsService
+
+ ) {}
+
+ @Input() selectedNeed!: Need;
+ @Output() refreshNeedList = new EventEmitter<void>();
+
+ update(form: any) {
+ console.log(form);
+ const need: Need = {
+ name: form.name,
+ image: form.image,
+ location: form.location,
+ id: this.selectedNeed.id, //system will control this
+ maxGoal: form.maxGoal,
+ type: GoalType[form.type as keyof typeof GoalType],
+ urgent: form.urgent,
+ filterAttributes: [],
+ current: 0,
+ description: form.description
+ };
+
+ this.cupboardService.updateNeed(need.id, need)
+ .pipe(catchError((ex, _) => {
+ if (ex.status == 500) {
+ this.toastService.sendToast(ToastType.ERROR, 'Fields cannot be blank');
+ } else if (ex.status == 400) {
+ this.toastService.sendToast(ToastType.ERROR, ex.error);
+ } else {
+ this.toastService.sendToast(ToastType.ERROR, "Error on creating need");
+ }
+ return of()
+ }))
+ .subscribe(
+ (result) => {
+ if (result) {
+ console.log("need updated successfully");
+ this.refreshNeedList.emit();
+ } else {
+ console.log("need update failed");
+ }
+ }
+
+ );
+ }
+} \ No newline at end of file