diff options
author | sowgro <tpoke.ferrari@gmail.com> | 2025-03-30 20:36:19 -0400 |
---|---|---|
committer | sowgro <tpoke.ferrari@gmail.com> | 2025-03-30 20:36:19 -0400 |
commit | 2c2957da48b62d16ce24addcc46d0d0ed66f7a9d (patch) | |
tree | 209e3fa65cd61dfd6785178ae438b919d69f0de7 /ufund-ui/src/app/components/cupboard/cupboard.component.ts | |
parent | 6bfbf7fa3b5b14b04f99f2dd6c33d336f6f081f6 (diff) | |
parent | b29f29eca643648381bfb62a4b90ad29e17f48a7 (diff) | |
download | JellySolutions-2c2957da48b62d16ce24addcc46d0d0ed66f7a9d.tar.gz JellySolutions-2c2957da48b62d16ce24addcc46d0d0ed66f7a9d.tar.bz2 JellySolutions-2c2957da48b62d16ce24addcc46d0d0ed66f7a9d.zip |
Merge branch 'list-and-cupboard-component-refactor' into css
# Conflicts:
# ufund-api/data/cupboard.json
# ufund-ui/src/app/components/cupboard/cupboard.component.css
# ufund-ui/src/app/components/need-list/need-list.component.css
# ufund-ui/src/app/components/need-page/need-page.component.html
Diffstat (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts')
-rw-r--r-- | ufund-ui/src/app/components/cupboard/cupboard.component.ts | 75 |
1 files changed, 32 insertions, 43 deletions
diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index a812baf..85ffd17 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 { Need, GoalType } from '../../models/Need'; import { userType } from '../../models/User'; @@ -16,7 +16,7 @@ import {AuthService} from '../../services/auth.service'; export class CupboardComponent implements OnInit { protected statusText = new BehaviorSubject("") - + selectedForm = "create"; needs: any; @ViewChild("needList") needList?: NeedListComponent @@ -27,9 +27,6 @@ export class CupboardComponent implements OnInit { ngOnInit(): void { this.cupboardService.getNeeds().subscribe(n => this.needs = n); - this.close(); - this.openmenu(); - if (this.isManager()) { console.log("Admin view of Cupboard"); } else { @@ -39,54 +36,43 @@ 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 }; } @@ -99,14 +85,15 @@ export class CupboardComponent implements OnInit { console.log(form); const need: Need = { name: form.name, - id: form.id, //system will control this + 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 }; - console.log("need:", need); - console.log(need.id, need, "need updated"); + this.cupboardService.updateNeed(need.id, need) .pipe(catchError((ex, _) => { if (ex.status == 500) { @@ -134,9 +121,11 @@ export class CupboardComponent implements OnInit { submit(form: any) { const need: Need = { name: form.name, + location: form.location, id: 0, maxGoal: form.maxGoal, type: form.type, + urgent: form.urgent ? true : false, filterAttributes: [], current: 0 }; |