From ab7aa87d3a6249352a14b5a9c3c3c9e08577657f Mon Sep 17 00:00:00 2001 From: benal01 Date: Tue, 4 Mar 2025 09:43:37 -0500 Subject: cupboard component form creation and interfacing with the controller --- .../app/components/cupboard/cupboard.component.ts | 36 +++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 53dad8a..409cf6c 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -1,7 +1,8 @@ import { Component, OnInit } from '@angular/core'; import { CupboardService } from '../../services/cupboard.service'; import { NeedListComponent } from '../need-list/need-list.component'; - +import { HttpClient } from '@angular/common/http'; +import { FormsModule } from '@angular/forms'; import { Need, GoalType } from '../../models/Need'; @Component({ @@ -12,20 +13,27 @@ import { Need, GoalType } from '../../models/Need'; }) export class CupboardComponent implements OnInit { + need: Need = { + id: 0, + name: '', + maxGoal: 0, + type: GoalType.MONETARY, + filterAttributes: [], + current: 0 + }; - constructor(private cupboardService: CupboardService){} - ngOnInit() { - - + + constructor(private cupboardService: CupboardService, private http: HttpClient) { } + ngOnInit(): void { + console.log('CupboardComponent.ngOnInit'); } - need!: Need; - submit(name: string, id: number, maxGoal: number, type: string) { - if (this.need) { - this.need.name = name; - this.need.id = id; - this.need.maxGoal = maxGoal; - console.log(type); - this.cupboardService.createNeed(this.need); - } + + submit(form: any) { + console.log(form); + this.need.name = form.name; + this.need.id = form.id; + this.need.maxGoal = form.maxGoal; + this.need.type = GoalType[form.type as keyof typeof GoalType]; + console.log(this.cupboardService.createNeed(this.need)); } } -- cgit v1.2.3 From bedb5fd032d645130ce804e1a36a356cf39ee9f0 Mon Sep 17 00:00:00 2001 From: benal01 Date: Tue, 4 Mar 2025 10:29:40 -0500 Subject: opening and closing functionality to expand the form for data entry --- .../app/components/cupboard/cupboard.component.ts | 34 ++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 409cf6c..cc09393 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -1,8 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { CupboardService } from '../../services/cupboard.service'; import { NeedListComponent } from '../need-list/need-list.component'; -import { HttpClient } from '@angular/common/http'; -import { FormsModule } from '@angular/forms'; import { Need, GoalType } from '../../models/Need'; @Component({ @@ -22,10 +20,36 @@ export class CupboardComponent implements current: 0 }; - - constructor(private cupboardService: CupboardService, private http: HttpClient) { } + + constructor(private cupboardService: CupboardService) { } ngOnInit(): void { - console.log('CupboardComponent.ngOnInit'); + this.close(); + } + + open() { + const formElement = document.getElementById('create-form'); + if (formElement) { + formElement.style.visibility = 'visible'; + formElement.style.position = 'relative'; + } + const buttonElement = document.getElementById('create-button'); + if (buttonElement) { + buttonElement.style.visibility = 'hidden'; + buttonElement.style.position = 'absolute'; + } + } + + close() { + const formElement = document.getElementById('create-form'); + if (formElement) { + formElement.style.visibility = 'hidden'; + formElement.style.position = 'absolute'; + } + const buttonElement = document.getElementById('create-button'); + if (buttonElement) { + buttonElement.style.visibility = 'visible'; + buttonElement.style.position = 'relative'; + } } submit(form: any) { -- cgit v1.2.3 From ba5259048771cc780bce4d2c6977496606a7d6ca Mon Sep 17 00:00:00 2001 From: benal01 Date: Thu, 6 Mar 2025 10:40:22 -0500 Subject: API interaction for creation form and increased menu usability --- .../app/components/cupboard/cupboard.component.ts | 109 +++++++++++++-------- 1 file changed, 67 insertions(+), 42 deletions(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index cc09393..213296d 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -1,6 +1,5 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, ViewChild } from '@angular/core'; import { CupboardService } from '../../services/cupboard.service'; -import { NeedListComponent } from '../need-list/need-list.component'; import { Need, GoalType } from '../../models/Need'; @Component({ @@ -9,55 +8,81 @@ import { Need, GoalType } from '../../models/Need'; templateUrl: './cupboard.component.html', styleUrl: './cupboard.component.css' }) -export class CupboardComponent implements - OnInit { - need: Need = { - id: 0, - name: '', - maxGoal: 0, - type: GoalType.MONETARY, - filterAttributes: [], - current: 0 - }; - - + +export class CupboardComponent implements OnInit { constructor(private cupboardService: CupboardService) { } + ngOnInit(): void { this.close(); + this.openmenu(); } - - open() { - const formElement = document.getElementById('create-form'); - if (formElement) { - formElement.style.visibility = 'visible'; - formElement.style.position = 'relative'; + + private hideElement(element: any) { + if (element){ + element.style.visibility = 'hidden'; + element.style.position = 'absolute'; } - const buttonElement = document.getElementById('create-button'); - if (buttonElement) { - buttonElement.style.visibility = 'hidden'; - buttonElement.style.position = 'absolute'; + } + + 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')); + } + + opendestroy() { + this.close(); + this.showElement(document.getElementById('destroy-form')); + } + + destroy() { + + } + + back() { + this.close(); + this.openmenu(); + } + close() { - const formElement = document.getElementById('create-form'); - if (formElement) { - formElement.style.visibility = 'hidden'; - formElement.style.position = 'absolute'; - } - const buttonElement = document.getElementById('create-button'); - if (buttonElement) { - buttonElement.style.visibility = 'visible'; - buttonElement.style.position = 'relative'; - } + this.hideElement(document.getElementById('create-form')); + this.hideElement(document.getElementById('destroy-form')); + this.hideElement(document.getElementById('menu')); } + + submit(form: any) { - console.log(form); - this.need.name = form.name; - this.need.id = form.id; - this.need.maxGoal = form.maxGoal; - this.need.type = GoalType[form.type as keyof typeof GoalType]; - console.log(this.cupboardService.createNeed(this.need)); - } - } + const need: Need = { + name: form.name, + id: form.id, + maxGoal: form.maxGoal, + type: GoalType[form.type as keyof typeof GoalType], + filterAttributes: [], + current: 0 + }; + console.log("form submitted. creating need: ", need); + this.cupboardService.createNeed(need).subscribe( + (result) => { + if (result) { + console.log("need created successfully"); + location.reload(); + } else { + console.log("need creation failed"); + } + } + + ); + } + } \ No newline at end of file -- cgit v1.2.3 From 482f60ca28be372a9f45d4160130d90c64770126 Mon Sep 17 00:00:00 2001 From: benal01 Date: Thu, 6 Mar 2025 11:01:26 -0500 Subject: removal of delete all form --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 213296d..2fccf18 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -41,15 +41,6 @@ export class CupboardComponent implements OnInit { this.showElement(document.getElementById('create-form')); } - opendestroy() { - this.close(); - this.showElement(document.getElementById('destroy-form')); - } - - destroy() { - - } - back() { this.close(); this.openmenu(); @@ -85,4 +76,8 @@ export class CupboardComponent implements OnInit { ); } + + destroy() { + + } } \ No newline at end of file -- cgit v1.2.3 From 9917e8a4eb02eab5e770bb1e95c28f98e02d1265 Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 17 Mar 2025 17:07:11 -0400 Subject: cupboard edit form with default values --- .../app/components/cupboard/cupboard.component.ts | 47 +++++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 2fccf18..e3f33ac 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit, ViewChild } from '@angular/core'; import { CupboardService } from '../../services/cupboard.service'; import { Need, GoalType } from '../../models/Need'; +import { Form } from '@angular/forms'; @Component({ selector: 'app-cupboard', @@ -10,13 +11,23 @@ import { Need, GoalType } from '../../models/Need'; }) export class CupboardComponent implements OnInit { +needs: any; constructor(private cupboardService: CupboardService) { } ngOnInit(): void { + this.cupboardService.getNeeds().subscribe(n => this.needs = n); this.close(); this.openmenu(); } - + + selectedNeed: any = { + name: '', + id: null, + maxGoal: null, + type: '' + }; + selectedNeedId: number | null = null; + private hideElement(element: any) { if (element){ element.style.visibility = 'hidden'; @@ -41,6 +52,11 @@ export class CupboardComponent implements OnInit { this.showElement(document.getElementById('create-form')); } + openupdate() { + this.close(); + this.showElement(document.getElementById('update-form')); + } + back() { this.close(); this.openmenu(); @@ -50,9 +66,36 @@ export class CupboardComponent implements OnInit { 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 }; + } + + update(form: any) { + console.log(form); + const need: Need = { + name: form.name, + id: form.id, + maxGoal: form.maxGoal, + type: GoalType[form.type as keyof typeof GoalType], + filterAttributes: [], + current: 0 + }; + console.log(need.id, need, "need updated"); + this.cupboardService.updateNeed(need.id, need).subscribe( + (result) => { + if (result) { + console.log("need updated successfully"); + location.reload(); + } else { + console.log("need update failed"); + } + } + + ); + } submit(form: any) { const need: Need = { -- cgit v1.2.3 From 88f6a4174d7fcc53028b78d0d9b3d91b6d17d2c6 Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 17 Mar 2025 18:25:19 -0400 Subject: search needs with timeout to throttle api calls --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index e3f33ac..adc38b0 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -19,7 +19,7 @@ needs: any; this.close(); this.openmenu(); } - + selectedNeed: any = { name: '', id: null, -- cgit v1.2.3 From b0f0589afdb319de8a01cb53f8a89c7265e634ae Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 17 Mar 2025 18:30:26 -0400 Subject: remove useless id input for need creation --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index adc38b0..b5726cf 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -77,7 +77,7 @@ needs: any; console.log(form); const need: Need = { name: form.name, - id: form.id, + id: 0, //system will control this maxGoal: form.maxGoal, type: GoalType[form.type as keyof typeof GoalType], filterAttributes: [], -- cgit v1.2.3 From 0287d0ebd22b88c2d41f2bdb67db812c35d9024c Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 17 Mar 2025 18:42:40 -0400 Subject: hide admin only management elements if user is not an admin --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index b5726cf..5a8773d 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -1,7 +1,8 @@ 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 { Form } from '@angular/forms'; +import { userType } from '../../models/User'; @Component({ selector: 'app-cupboard', @@ -12,7 +13,7 @@ import { Form } from '@angular/forms'; export class CupboardComponent implements OnInit { needs: any; - constructor(private cupboardService: CupboardService) { } + constructor(private cupboardService: CupboardService, private usersService: UsersService) { } ngOnInit(): void { this.cupboardService.getNeeds().subscribe(n => this.needs = n); @@ -73,6 +74,10 @@ needs: any; this.selectedNeed = { ...need }; } + isManager() { + return this.usersService.getCurrentUser()?.type == userType.MANAGER; + } + update(form: any) { console.log(form); const need: Need = { -- cgit v1.2.3 From 3f64404c23a95f3625754a79a753ed5ed4df3001 Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 17 Mar 2025 18:44:51 -0400 Subject: console feedback based on user access level --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 5a8773d..fc5d7dd 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -19,6 +19,12 @@ needs: any; 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 = { -- cgit v1.2.3 From 8951d00eddb147e5301454f250e503ad19aa47d3 Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 17 Mar 2025 20:52:59 -0400 Subject: fixed user authentication bug where user was never admin --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index fc5d7dd..c1bf66c 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -81,7 +81,8 @@ needs: any; } isManager() { - return this.usersService.getCurrentUser()?.type == userType.MANAGER; + const type = this.usersService.getCurrentUser()?.type; + return type === ("MANAGER" as unknown as userType); } update(form: any) { -- cgit v1.2.3 From 674b158932394d3cad8bce8dedca49b1efdfd453 Mon Sep 17 00:00:00 2001 From: sowgro Date: Mon, 17 Mar 2025 21:17:06 -0400 Subject: Attempt at fixing connection to front end --- .../src/app/components/cupboard/cupboard.component.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index c1bf66c..0fec0e0 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -2,7 +2,7 @@ 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 { userType } from '../../models/User'; @Component({ selector: 'app-cupboard', @@ -14,7 +14,7 @@ import { userType } from '../../models/User'; export class CupboardComponent implements OnInit { needs: any; constructor(private cupboardService: CupboardService, private usersService: UsersService) { } - + ngOnInit(): void { this.cupboardService.getNeeds().subscribe(n => this.needs = n); this.close(); @@ -34,7 +34,7 @@ needs: any; type: '' }; selectedNeedId: number | null = null; - + private hideElement(element: any) { if (element){ element.style.visibility = 'hidden'; @@ -53,7 +53,7 @@ needs: any; const menuElement = document.getElementById('menu'); this.showElement(menuElement); } - + opencreate() { this.close(); this.showElement(document.getElementById('create-form')); @@ -68,7 +68,7 @@ needs: any; this.close(); this.openmenu(); } - + close() { this.hideElement(document.getElementById('create-form')); this.hideElement(document.getElementById('destroy-form')); @@ -95,6 +95,7 @@ needs: any; filterAttributes: [], current: 0 }; + console.log("need:", need); console.log(need.id, need, "need updated"); this.cupboardService.updateNeed(need.id, need).subscribe( (result) => { @@ -112,12 +113,13 @@ needs: any; submit(form: any) { const need: Need = { name: form.name, - id: form.id, + id: 0, maxGoal: form.maxGoal, - type: GoalType[form.type as keyof typeof GoalType], + type: form.type, filterAttributes: [], current: 0 }; + console.log("need:", need); console.log("form submitted. creating need: ", need); this.cupboardService.createNeed(need).subscribe( (result) => { @@ -135,4 +137,4 @@ needs: any; destroy() { } - } \ No newline at end of file + } -- cgit v1.2.3 From 54876363de44791ba65b6c43b795f8d0c3548ecc Mon Sep 17 00:00:00 2001 From: sowgro Date: Mon, 17 Mar 2025 21:45:31 -0400 Subject: Fix tests --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 0fec0e0..a930f06 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -89,7 +89,7 @@ needs: any; console.log(form); const need: Need = { name: form.name, - id: 0, //system will control this + id: form.id, //system will control this maxGoal: form.maxGoal, type: GoalType[form.type as keyof typeof GoalType], filterAttributes: [], -- cgit v1.2.3