aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkash Keshav <112591754+domesticchores@users.noreply.github.com>2025-03-18 12:42:47 -0400
committerAkash Keshav <112591754+domesticchores@users.noreply.github.com>2025-03-18 12:42:47 -0400
commit4c965e92244316ac4f432efa6e8cebf70c0c1053 (patch)
treef259e4a985bd55a9b4d3c46eefecc25cede06ffe
parent98431cd75078fd671270039ad9fa4d42759dc502 (diff)
parentcd24514f7b75e1cde515c99607bf3b2bc0f4fc88 (diff)
downloadJellySolutions-4c965e92244316ac4f432efa6e8cebf70c0c1053.tar.gz
JellySolutions-4c965e92244316ac4f432efa6e8cebf70c0c1053.tar.bz2
JellySolutions-4c965e92244316ac4f432efa6e8cebf70c0c1053.zip
Merge branch 'funding_basket' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b-jellysolutions into funding_basket
-rw-r--r--ufund-ui/src/app/components/cupboard/cupboard.component.ts204
1 files changed, 108 insertions, 96 deletions
diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts
index 9574de3..6ad0a5f 100644
--- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts
+++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts
@@ -4,13 +4,13 @@ import { UsersService } from '../../services/users.service';
import { Need, GoalType } from '../../models/Need';
import { userType } from '../../models/User';
import { BehaviorSubject, catchError, of } from 'rxjs';
-import {NeedListComponent} from '../need-list/need-list.component';
+import { NeedListComponent } from '../need-list/need-list.component';
@Component({
- selector: 'app-cupboard',
- standalone: false,
- templateUrl: './cupboard.component.html',
- styleUrl: './cupboard.component.css'
+ selector: 'app-cupboard',
+ standalone: false,
+ templateUrl: './cupboard.component.html',
+ styleUrl: './cupboard.component.css'
})
export class CupboardComponent implements OnInit {
@@ -23,140 +23,152 @@ export class CupboardComponent implements OnInit {
constructor(private cupboardService: CupboardService, private usersService: UsersService) { }
ngOnInit(): void {
- this.cupboardService.getNeeds().subscribe(n => this.needs = n);
- this.close();
- this.openmenu();
-
- if (this.isManager()) {
- console.log("Admin view of Cupboard");
- } else {
- console.log("Limited helper view of Cupboard");
- }
+ this.cupboardService.getNeeds().subscribe(n => this.needs = n);
+ this.close();
+ this.openmenu();
+
+ if (this.isManager()) {
+ console.log("Admin view of Cupboard");
+ } else {
+ console.log("Limited helper view of Cupboard");
+ }
}
selectedNeed: any = {
- name: '',
- id: null,
- maxGoal: null,
- type: ''
+ name: '',
+ id: null,
+ maxGoal: null,
+ type: ''
};
selectedNeedId: number | null = null;
private hideElement(element: any) {
- if (element){
- element.style.visibility = 'hidden';
- element.style.position = 'absolute';
- }
+ if (element) {
+ element.style.visibility = 'hidden';
+ element.style.position = 'absolute';
+ }
}
private showElement(element: any) {
- if (element){
- element.style.visibility = 'visible';
- element.style.position = 'relative';
- }
+ if (element) {
+ element.style.visibility = 'visible';
+ element.style.position = 'relative';
+ }
}
openmenu() {
- const menuElement = document.getElementById('menu');
- this.showElement(menuElement);
+ const menuElement = document.getElementById('menu');
+ this.showElement(menuElement);
}
opencreate() {
- this.close();
- this.showElement(document.getElementById('create-form'));
+ this.close();
+ this.showElement(document.getElementById('create-form'));
}
openupdate() {
- this.close();
- this.showElement(document.getElementById('update-form'));
+ this.close();
+ this.showElement(document.getElementById('update-form'));
}
back() {
- this.close();
- this.openmenu();
+ 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'));
+ 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 };
+ this.selectedNeed = { ...need };
}
isManager() {
- const type = this.usersService.getCurrentUser()?.type;
- return type === ("MANAGER" as unknown as userType);
+ const type = this.usersService.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) => {
- this.statusText.next("Max goal must be greater than 0 " + friendlyHttpStatus[ex.status])
- return of()
- }))
- .subscribe(
- (result) => {
- if (result) {
- console.log("need updated successfully");
- this.needList?.refresh()
- } else {
- console.log("need update failed");
- }
- }
-
- );
+ 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,
- id: 0,
- maxGoal: form.maxGoal,
- type: form.type,
- filterAttributes: [],
- current: 0
- };
- console.log("need:", need);
- console.log("form submitted. creating need: ", need);
- this.cupboardService.createNeed(need)
- .pipe(catchError((ex, r) => {
- this.statusText.next("Max goal must be greater than 0 " + friendlyHttpStatus[ex.status])
- return of()
- }))
- .subscribe(
- (result) => {
- if (result) {
- console.log("need created successfully");
- this.needList?.refresh()
- } else {
- console.log("need creation failed");
- }
- }
-
- );
+ const need: Need = {
+ name: form.name,
+ id: 0,
+ maxGoal: form.maxGoal,
+ type: form.type,
+ filterAttributes: [],
+ current: 0
+ };
+ console.log("need:", need);
+ console.log("form submitted. creating need: ", need);
+ this.cupboardService.createNeed(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 created successfully");
+ this.needList?.refresh()
+ } else {
+ console.log("need creation failed");
+ }
+ }
+
+ );
}
destroy() {
}
- }
+}
-let friendlyHttpStatus: {[key: number]: string} = {
+let friendlyHttpStatus: { [key: number]: string } = {
200: 'OK',
201: 'Created',
202: 'Accepted',