diff options
| author | benal01 <bja4245@rit.edu> | 2025-03-31 22:15:37 -0400 | 
|---|---|---|
| committer | benal01 <bja4245@rit.edu> | 2025-03-31 22:15:37 -0400 | 
| commit | 786a6db3f5a22f7bb2cc249731ef654b675c3c86 (patch) | |
| tree | e45792d92bf263b59fdfecf8a595cc9b7ff899c7 /ufund-ui/src/app/components/need-edit | |
| parent | 4f8ddd385924b3c7c2b36acd28daf658ecc2cb09 (diff) | |
| download | JellySolutions-786a6db3f5a22f7bb2cc249731ef654b675c3c86.tar.gz JellySolutions-786a6db3f5a22f7bb2cc249731ef654b675c3c86.tar.bz2 JellySolutions-786a6db3f5a22f7bb2cc249731ef654b675c3c86.zip  | |
moving functionality to new component
Diffstat (limited to '')
3 files changed, 83 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..e69de29 --- /dev/null +++ b/ufund-ui/src/app/components/need-edit/need-edit.component.css 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..bcb166b --- /dev/null +++ b/ufund-ui/src/app/components/need-edit/need-edit.component.html @@ -0,0 +1,22 @@ +<div id="update-form"> +    <h1> Update Need </h1> +    <label>Needs:</label><br> +    <form #updateForm="ngForm" (ngSubmit)="update(updateForm.value)"> +        <input type="text" name="name" [(ngModel)]="selectedNeed.name"><br> +        <input type="text" name="image" [(ngModel)]="selectedNeed.image"><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>
\ No newline at end of file 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..02ffb71 --- /dev/null +++ b/ufund-ui/src/app/components/need-edit/need-edit.component.ts @@ -0,0 +1,61 @@ +import { Component, Input, Output } 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() selectedNeedID: number | null = null; + +  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.needList?.refresh() +                } else { +                    console.log("need update failed"); +                } +            } + +        ); +  } +}
\ No newline at end of file  | 
