aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/components/cupboard/cupboard.component.ts
diff options
context:
space:
mode:
authorbenal01 <bja4245@rit.edu>2025-03-27 08:18:29 -0400
committerGitHub <noreply@github.com>2025-03-27 08:18:29 -0400
commit2dc001c80af113d8d01ba545a0dbfda960e0f7fe (patch)
tree222807b745ff1cdff83153821deb088afcd0f05b /ufund-ui/src/app/components/cupboard/cupboard.component.ts
parent07d191cb1fc8890f66e9af7d19e8276089d18d8b (diff)
parentd5ae670dbce9e5cabbd594759df490176fd8cecd (diff)
downloadJellySolutions-2dc001c80af113d8d01ba545a0dbfda960e0f7fe.tar.gz
JellySolutions-2dc001c80af113d8d01ba545a0dbfda960e0f7fe.tar.bz2
JellySolutions-2dc001c80af113d8d01ba545a0dbfda960e0f7fe.zip
Merge branch 'list-and-cupboard-component-refactor' into need-sorting
Diffstat (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts')
-rw-r--r--ufund-ui/src/app/components/cupboard/cupboard.component.ts70
1 files changed, 26 insertions, 44 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..a8b9c14 100644
--- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts
+++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts
@@ -1,4 +1,4 @@
-import { Component, OnInit, ViewChild } from '@angular/core';
+import {Component, Input, OnInit, ViewChild} from '@angular/core';
import { CupboardService } from '../../services/cupboard.service';
import { UsersService } from '../../services/users.service';
import { Need, GoalType } from '../../models/Need';
@@ -16,17 +16,13 @@ import { NeedListComponent } from '../need-list/need-list.component';
export class CupboardComponent implements OnInit {
protected statusText = new BehaviorSubject("")
-
+ selectedForm = "create";
needs: any;
- @ViewChild("needList") needList?: NeedListComponent
-
+ @ViewChild("needList") needList?: NeedListComponent;
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 {
@@ -41,49 +37,36 @@ export class CupboardComponent implements OnInit {
type: ''
};
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 };
}
@@ -96,14 +79,13 @@ export class CupboardComponent implements OnInit {
console.log(form);
const need: Need = {
name: form.name,
- id: form.id, //system will control this
+ id: this.selectedNeed.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) {