aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/components/cupboard/cupboard.component.ts
diff options
context:
space:
mode:
authorbenal01 <bja4245@rit.edu>2025-04-01 09:34:36 -0400
committerbenal01 <bja4245@rit.edu>2025-04-01 09:34:36 -0400
commit7ed26c5ee7171a502f6f8527fc55de2bb77eab3b (patch)
tree2046e58c146097aac21c9e352771420c31df6589 /ufund-ui/src/app/components/cupboard/cupboard.component.ts
parentef46ddd082bb91d0262363536d46fe3eb4da47be (diff)
parentd8330f1ac85b26d08ca4df5ce3875078d7b4f47f (diff)
downloadJellySolutions-7ed26c5ee7171a502f6f8527fc55de2bb77eab3b.tar.gz
JellySolutions-7ed26c5ee7171a502f6f8527fc55de2bb77eab3b.tar.bz2
JellySolutions-7ed26c5ee7171a502f6f8527fc55de2bb77eab3b.zip
Merge branch 'main' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b-jellysolutions
Diffstat (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts')
-rw-r--r--ufund-ui/src/app/components/cupboard/cupboard.component.ts175
1 files changed, 44 insertions, 131 deletions
diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts
index 24b3e2d..2230cd3 100644
--- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts
+++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts
@@ -1,10 +1,11 @@
-import { Component, OnInit, ViewChild } from '@angular/core';
+import {Component, OnInit, ViewChild} from '@angular/core';
import { CupboardService } from '../../services/cupboard.service';
-import { UsersService } from '../../services/users.service';
import { Need, GoalType } from '../../models/Need';
import { userType } from '../../models/User';
-import { BehaviorSubject, catchError, of } from 'rxjs';
+import { catchError, of } from 'rxjs';
import { NeedListComponent } from '../need-list/need-list.component';
+import {AuthService} from '../../services/auth.service';
+import {ToastsService, ToastType} from '../../services/toasts.service';
@Component({
selector: 'app-cupboard',
@@ -15,18 +16,18 @@ import { NeedListComponent } from '../need-list/need-list.component';
export class CupboardComponent implements OnInit {
- protected statusText = new BehaviorSubject("")
-
+ selectedForm?: string = undefined;
needs: any;
@ViewChild("needList") needList?: NeedListComponent
- constructor(private cupboardService: CupboardService, private usersService: UsersService) { }
+ constructor(
+ private cupboardService: CupboardService,
+ private authService: AuthService,
+ private toastService: ToastsService
+ ) {}
ngOnInit(): void {
this.cupboardService.getNeeds().subscribe(n => this.needs = n);
- this.close();
- this.openmenu();
-
if (this.isManager()) {
console.log("Admin view of Cupboard");
} else {
@@ -36,117 +37,74 @@ export class CupboardComponent implements OnInit {
selectedNeed: any = {
name: '',
+ location:'',
id: null,
maxGoal: null,
- type: ''
+ type: '',
+ urgent: false
};
selectedNeedId: number | null = null;
+ searchResults: any[] = [];
- private hideElement(element: any) {
- if (element) {
- element.style.visibility = 'hidden';
- element.style.position = 'absolute';
+ selectForm(name: string) {
+ //get search results from the need list
+ if (this.needList) {
+ this.searchResults = this.needList.searchResults;
}
- }
+ console.log(this.searchResults)
+ this.selectedForm = name;
+ if (name == 'update') {
+ if (this.searchResults) {
+ this.searchResults.forEach((element: any) => {
+ console.log(element)
+ });
+ }
- private showElement(element: any) {
- if (element) {
- element.style.visibility = 'visible';
- element.style.position = 'relative';
}
}
- openmenu() {
- const menuElement = document.getElementById('menu');
- this.showElement(menuElement);
- }
-
- opencreate() {
- this.close();
- this.showElement(document.getElementById('create-form'));
- }
-
- openupdate() {
- this.close();
- this.showElement(document.getElementById('update-form'));
- }
-
- back() {
- this.close();
- this.openmenu();
- }
-
- close() {
- this.hideElement(document.getElementById('create-form'));
- this.hideElement(document.getElementById('destroy-form'));
- this.hideElement(document.getElementById('menu'));
- this.hideElement(document.getElementById('update-form'));
+ async updateSearchResults() {
+ if (this.needList) {
+ while (this.selectedForm == 'update') {
+ this.searchResults = this.needList.searchResults
+ await new Promise(resolve => setTimeout(resolve, 100));
+ }
+ }
}
populateForm(need: any): void {
+ this.selectForm('update');
this.selectedNeed = { ...need };
}
isManager() {
- const type = this.usersService.getCurrentUser()?.type;
+ const type = this.authService.getCurrentUser()?.type;
return type === ("MANAGER" as unknown as userType);
}
- update(form: any) {
- console.log(form);
- const need: Need = {
- name: form.name,
- id: form.id, //system will control this
- maxGoal: form.maxGoal,
- type: GoalType[form.type as keyof typeof GoalType],
- filterAttributes: [],
- current: 0
- };
- console.log("need:", need);
- console.log(need.id, need, "need updated");
- this.cupboardService.updateNeed(need.id, need)
- .pipe(catchError((ex, r) => {
- if (ex.status == 500) {
- this.statusText.next("Fields cannot be blank");
- } else if (ex.status == 400) {
- this.statusText.next("Goal must be greater than 0");
- } else {
- this.statusText.next("Error on creating need");
- }
- return of()
- }))
- .subscribe(
- (result) => {
- if (result) {
- console.log("need updated successfully");
- this.needList?.refresh()
- } else {
- console.log("need update failed");
- }
- }
-
- );
- }
-
submit(form: any) {
const need: Need = {
name: form.name,
+ image: form.image,
+ location: form.location,
id: 0,
maxGoal: form.maxGoal,
type: form.type,
+ urgent: form.urgent ? true : false,
filterAttributes: [],
- current: 0
+ current: 0,
+ description: form.description
};
console.log("need:", need);
console.log("form submitted. creating need: ", need);
this.cupboardService.createNeed(need)
- .pipe(catchError((ex, r) => {
+ .pipe(catchError((ex, _) => {
if (ex.status == 500) {
- this.statusText.next("Fields cannot be blank");
+ this.toastService.sendToast(ToastType.ERROR, "Fields cannot be blank");
} else if (ex.status == 400) {
- this.statusText.next("Goal must be greater than 0");
+ this.toastService.sendToast(ToastType.ERROR, ex.error);
} else {
- this.statusText.next("Error on creating need");
+ this.toastService.sendToast(ToastType.ERROR, "Error on creating need");
}
return of()
}))
@@ -167,48 +125,3 @@ export class CupboardComponent implements OnInit {
}
}
-
-let friendlyHttpStatus: { [key: number]: string } = {
- 200: 'OK',
- 201: 'Created',
- 202: 'Accepted',
- 203: 'Non-Authoritative Information',
- 204: 'No Content',
- 205: 'Reset Content',
- 206: 'Partial Content',
- 300: 'Multiple Choices',
- 301: 'Moved Permanently',
- 302: 'Found',
- 303: 'See Other',
- 304: 'Not Modified',
- 305: 'Use Proxy',
- 306: 'Unused',
- 307: 'Temporary Redirect',
- 400: 'Bad Request',
- 401: 'Unauthorized',
- 402: 'Payment Required',
- 403: 'Forbidden',
- 404: 'Not Found',
- 405: 'Method Not Allowed',
- 406: 'Not Acceptable',
- 407: 'Proxy Authentication Required',
- 408: 'Request Timeout',
- 409: 'Conflict',
- 410: 'Gone',
- 411: 'Length Required',
- 412: 'Precondition Required',
- 413: 'Request Entry Too Large',
- 414: 'Request-URI Too Long',
- 415: 'Unsupported Media Type',
- 416: 'Requested Range Not Satisfiable',
- 417: 'Expectation Failed',
- 418: 'I\'m a teapot',
- 422: 'Unprocessable Entity',
- 429: 'Too Many Requests',
- 500: 'Internal Server Error',
- 501: 'Not Implemented',
- 502: 'Bad Gateway',
- 503: 'Service Unavailable',
- 504: 'Gateway Timeout',
- 505: 'HTTP Version Not Supported',
-};