aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/components/need-list
diff options
context:
space:
mode:
authorGunther6070 <haydenhartman10@yahoo.com>2025-03-17 23:12:49 -0400
committerGunther6070 <haydenhartman10@yahoo.com>2025-03-17 23:12:49 -0400
commit5b6c20479fbb6ed0cabbbc88b42280c5a7dbd22c (patch)
tree16f93b3ce3b40de1e550f3824f60ca3aac632265 /ufund-ui/src/app/components/need-list
parent7a5c5073e9e410b3ccc3ab7902a0d6f558277c7d (diff)
parent2b847078b7af4ade35461b8af52352bc88994be3 (diff)
downloadJellySolutions-5b6c20479fbb6ed0cabbbc88b42280c5a7dbd22c.tar.gz
JellySolutions-5b6c20479fbb6ed0cabbbc88b42280c5a7dbd22c.tar.bz2
JellySolutions-5b6c20479fbb6ed0cabbbc88b42280c5a7dbd22c.zip
Merge branch 'main' into funding_basket
Diffstat (limited to 'ufund-ui/src/app/components/need-list')
-rw-r--r--ufund-ui/src/app/components/need-list/need-list.component.css24
-rw-r--r--ufund-ui/src/app/components/need-list/need-list.component.html20
-rw-r--r--ufund-ui/src/app/components/need-list/need-list.component.ts83
3 files changed, 124 insertions, 3 deletions
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..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
@@ -0,0 +1,24 @@
+:host {
+ list-style-type:circle;
+ border: 2px solid #000;
+ display: block;
+ width: 30%;
+ border-radius: 5px;
+
+}
+
+li, div {
+ border: 2px solid #000;
+ border-radius: 5px;
+ padding: 5px;
+ margin: 5px;
+
+}
+
+#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 6e48d96..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
@@ -1,6 +1,26 @@
<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)" *ngIf="isManager()">Delete</button>
+ </div>
+ </div>
+</div>
+
<li *ngFor="let need of needs">
<a routerLink="/need/{{need.id}}">
{{need.name}}
</a>
+ <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 a3eb072..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
@@ -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,
@@ -10,12 +11,88 @@ import {CupboardService} from '../../services/cupboard.service';
})
export class NeedListComponent {
needs: Need[] = [];
-
+ searchResults: Need[] = [];
+
constructor(
- private cupboardService: CupboardService
+ private cupboardService: CupboardService,
+ private usersService: UsersService
) {}
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) {
+ this.cupboardService.deleteNeed(id).subscribe(() => {
+ this.needs = this.needs.filter(n => n.id !== id)
+ })
+ }
+
+ isManager() {
+ const type = this.usersService.getCurrentUser()?.type;
+ return type === ("MANAGER" as unknown as userType);
+ }
+
+ back() {
+ this.searchResults = [];
}
}