From a1343c65e30f7f3fe13a2c336f37dfa1bb1bbcc3 Mon Sep 17 00:00:00 2001
From: benal01 <bja4245@rit.edu>
Date: Tue, 4 Mar 2025 10:29:01 -0500
Subject: basic css styles for orginization

---
 .../src/app/components/need-list/need-list.component.css | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

(limited to 'ufund-ui/src/app/components/need-list')

diff --git a/ufund-ui/src/app/components/need-list/need-list.component.css b/ufund-ui/src/app/components/need-list/need-list.component.css
index e69de29..1bcaed9 100644
--- a/ufund-ui/src/app/components/need-list/need-list.component.css
+++ b/ufund-ui/src/app/components/need-list/need-list.component.css
@@ -0,0 +1,16 @@
+:host {
+    list-style-type:circle;
+    border: 2px solid #000;
+    display: block;
+    width: 30%;
+    border-radius: 5px;
+    
+}
+
+li {
+    border: 2px solid #000;
+    border-radius: 5px;
+    padding: 5px;
+    margin: 5px;
+
+}
\ No newline at end of file
-- 
cgit v1.2.3


From bf33fa3ca9f29b1e75cc077ae2eaaf4f5725e4b3 Mon Sep 17 00:00:00 2001
From: benal01 <bja4245@rit.edu>
Date: Mon, 17 Mar 2025 17:08:04 -0400
Subject: need list delete button

---
 ufund-ui/src/app/components/need-list/need-list.component.html | 1 +
 ufund-ui/src/app/components/need-list/need-list.component.ts   | 6 ++++++
 2 files changed, 7 insertions(+)

(limited to 'ufund-ui/src/app/components/need-list')

diff --git a/ufund-ui/src/app/components/need-list/need-list.component.html b/ufund-ui/src/app/components/need-list/need-list.component.html
index 6e48d96..b8774f1 100644
--- a/ufund-ui/src/app/components/need-list/need-list.component.html
+++ b/ufund-ui/src/app/components/need-list/need-list.component.html
@@ -3,4 +3,5 @@
     <a routerLink="/need/{{need.id}}">
         {{need.name}}
     </a>
+    <button (click)="delete(need.id)">Delete</button>
 </li>
diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts
index a3eb072..579565c 100644
--- a/ufund-ui/src/app/components/need-list/need-list.component.ts
+++ b/ufund-ui/src/app/components/need-list/need-list.component.ts
@@ -18,4 +18,10 @@ export class NeedListComponent {
   ngOnInit(): void {
     this.cupboardService.getNeeds().subscribe(n => this.needs = n)
   }
+
+  delete(id : number) { 
+    this.cupboardService.deleteNeed(id).subscribe(() => {
+      this.needs = this.needs.filter(n => n.id !== id)
+    })
+  }
 }
-- 
cgit v1.2.3


From 88f6a4174d7fcc53028b78d0d9b3d91b6d17d2c6 Mon Sep 17 00:00:00 2001
From: benal01 <bja4245@rit.edu>
Date: Mon, 17 Mar 2025 18:25:19 -0400
Subject: search needs with timeout to throttle api calls

---
 .../components/need-list/need-list.component.css   | 12 +++-
 .../components/need-list/need-list.component.html  | 19 +++++++
 .../components/need-list/need-list.component.ts    | 66 +++++++++++++++++++++-
 3 files changed, 94 insertions(+), 3 deletions(-)

(limited to 'ufund-ui/src/app/components/need-list')

diff --git a/ufund-ui/src/app/components/need-list/need-list.component.css b/ufund-ui/src/app/components/need-list/need-list.component.css
index 1bcaed9..bbc3f2c 100644
--- a/ufund-ui/src/app/components/need-list/need-list.component.css
+++ b/ufund-ui/src/app/components/need-list/need-list.component.css
@@ -7,10 +7,18 @@
     
 }
 
-li {
+li, div {
     border: 2px solid #000;
     border-radius: 5px;
     padding: 5px;
     margin: 5px;
 
-}
\ No newline at end of file
+}
+
+#search-form {
+    background-color: #d9d9d9;
+    padding: 10px 20px 20px 20px;
+    border: 2px solid #000;
+    border-radius: 5px;  
+    visibility: visible;
+ }
\ No newline at end of file
diff --git a/ufund-ui/src/app/components/need-list/need-list.component.html b/ufund-ui/src/app/components/need-list/need-list.component.html
index b8774f1..6dd6511 100644
--- a/ufund-ui/src/app/components/need-list/need-list.component.html
+++ b/ufund-ui/src/app/components/need-list/need-list.component.html
@@ -1,4 +1,23 @@
 <h1>Needs List</h1>
+<input id="search-button" type="button" value="Search" (click)="open()">
+<div id="search-form">
+    <form #searchForm="ngForm">
+        <label>Search:</label><br>
+        <input type="text" name="search" (input)="search(searchForm.value)" ngModel>
+        <input type="button" value="Clear" (click)="searchForm.reset()"> <br>
+    </form>
+    <button (click)="close()">Close</button>
+    <div>
+        <h2 id="search-status">Search Results:</h2>
+        <div *ngFor="let need of searchResults">
+            <a routerLink="/need/{{need.id}}">
+                {{need.name}}
+            </a>
+            <button (click)="delete(need.id)">Delete</button>
+        </div>
+    </div>
+</div>
+
 <li *ngFor="let need of needs">
     <a routerLink="/need/{{need.id}}">
         {{need.name}}
diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts
index 579565c..8451d5b 100644
--- a/ufund-ui/src/app/components/need-list/need-list.component.ts
+++ b/ufund-ui/src/app/components/need-list/need-list.component.ts
@@ -10,13 +10,73 @@ import {CupboardService} from '../../services/cupboard.service';
 })
 export class NeedListComponent {
   needs: Need[] = [];
-
+  searchResults: Need[] = [];
+  
   constructor(
     private cupboardService: CupboardService
   ) {}
 
   ngOnInit(): void {
     this.cupboardService.getNeeds().subscribe(n => this.needs = n)
+    this.close();
+  }
+
+  private showElement(element: any) {
+    if (element){
+      element.style.visibility = 'visible';
+      element.style.position = 'relative';
+    }
+  }
+
+  private hideElement(element: any) {
+    if (element){
+      element.style.visibility = 'hidden';
+      element.style.position = 'absolute';
+    }
+  }
+
+  private updateSearchStatus(text: string) {
+    let element = document.getElementById('search-status');
+    if (element) {
+      element.innerHTML = text;
+    }
+  }
+
+  open() {
+    this.hideElement(document.getElementById('search-button'));
+    this.showElement(document.getElementById('search-form'));
+  }
+
+  close() {
+    this.hideElement(document.getElementById('search-form'));
+    this.showElement(document.getElementById('search-button'));
+  }
+
+  private searchDelay: any;
+
+  async search(form: any) {
+    //wait .25 seconds before searching but cancel if another search is made during the wait to prevent too many api calls
+
+    //remove previous search if it exists
+    if (this.searchDelay) {
+      clearTimeout(this.searchDelay);
+    }
+    
+    this.searchDelay = setTimeout(() => {
+      const currentSearchValue = form.search; //latest value of the search
+      this.cupboardService.searchNeeds(currentSearchValue).subscribe((n) => {
+        this.searchResults = n;
+        console.log(currentSearchValue, this.searchResults);
+        if (this.searchResults.length === this.needs.length) {
+          this.updateSearchStatus("Please refine your search");
+          this.searchResults = [];
+        } else if (this.searchResults.length === 0) {
+          this.updateSearchStatus("No results found");
+        } else {
+          this.updateSearchStatus("Search results:");
+        }
+      });
+    }, 250);
   }
 
   delete(id : number) { 
@@ -24,4 +84,8 @@ export class NeedListComponent {
       this.needs = this.needs.filter(n => n.id !== id)
     })
   }
+
+  back() {
+    this.searchResults = [];
+  }
 }
-- 
cgit v1.2.3


From 0287d0ebd22b88c2d41f2bdb67db812c35d9024c Mon Sep 17 00:00:00 2001
From: benal01 <bja4245@rit.edu>
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/need-list/need-list.component.html |  4 ++--
 ufund-ui/src/app/components/need-list/need-list.component.ts   | 10 ++++++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

(limited to 'ufund-ui/src/app/components/need-list')

diff --git a/ufund-ui/src/app/components/need-list/need-list.component.html b/ufund-ui/src/app/components/need-list/need-list.component.html
index 6dd6511..07f6735 100644
--- a/ufund-ui/src/app/components/need-list/need-list.component.html
+++ b/ufund-ui/src/app/components/need-list/need-list.component.html
@@ -13,7 +13,7 @@
             <a routerLink="/need/{{need.id}}">
                 {{need.name}}
             </a>
-            <button (click)="delete(need.id)">Delete</button>
+            <button (click)="delete(need.id)" *ngIf="isManager()">Delete</button>
         </div>
     </div>
 </div>
@@ -22,5 +22,5 @@
     <a routerLink="/need/{{need.id}}">
         {{need.name}}
     </a>
-    <button (click)="delete(need.id)">Delete</button>
+    <button (click)="delete(need.id)" *ngIf="isManager()">Delete</button>
 </li>
diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts
index 8451d5b..6ad9397 100644
--- a/ufund-ui/src/app/components/need-list/need-list.component.ts
+++ b/ufund-ui/src/app/components/need-list/need-list.component.ts
@@ -1,7 +1,8 @@
 import { Component } from '@angular/core';
 import {Need} from '../../models/Need';
 import {CupboardService} from '../../services/cupboard.service';
-
+import { UsersService } from '../../services/users.service';
+import { userType } from '../../models/User'; 
 @Component({
   selector: 'app-need-list',
   standalone: false,
@@ -13,7 +14,8 @@ export class NeedListComponent {
   searchResults: Need[] = [];
   
   constructor(
-    private cupboardService: CupboardService
+    private cupboardService: CupboardService,
+    private usersService: UsersService
   ) {}
 
   ngOnInit(): void {
@@ -85,6 +87,10 @@ export class NeedListComponent {
     })
   }
 
+  isManager() {
+    return this.usersService.getCurrentUser()?.type == userType.MANAGER;
+  }
+
   back() {
     this.searchResults = [];
   }
-- 
cgit v1.2.3


From 8951d00eddb147e5301454f250e503ad19aa47d3 Mon Sep 17 00:00:00 2001
From: benal01 <bja4245@rit.edu>
Date: Mon, 17 Mar 2025 20:52:59 -0400
Subject: fixed user authentication bug where user was never admin

---
 ufund-ui/src/app/components/need-list/need-list.component.ts | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

(limited to 'ufund-ui/src/app/components/need-list')

diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts
index 6ad9397..4409b63 100644
--- a/ufund-ui/src/app/components/need-list/need-list.component.ts
+++ b/ufund-ui/src/app/components/need-list/need-list.component.ts
@@ -88,7 +88,8 @@ export class NeedListComponent {
   }
 
   isManager() {
-    return this.usersService.getCurrentUser()?.type == userType.MANAGER;
+    const type = this.usersService.getCurrentUser()?.type;
+    return type === ("MANAGER" as unknown as userType);
   }
 
   back() {
-- 
cgit v1.2.3