diff options
author | Hayden Hartman <haydenhartman10@gmail.com> | 2025-03-17 21:49:35 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-17 21:49:35 -0400 |
commit | d1b7b81cbedc673cf6f52ac5745438f95083b78e (patch) | |
tree | 948255f18f05f2a26e22126de44fa433635876df /ufund-ui/src/app/components/need-list | |
parent | 1bf10f9f26f47ea5cff7ff48d5664febb0ed2585 (diff) | |
parent | 54876363de44791ba65b6c43b795f8d0c3548ecc (diff) | |
download | JellySolutions-d1b7b81cbedc673cf6f52ac5745438f95083b78e.tar.gz JellySolutions-d1b7b81cbedc673cf6f52ac5745438f95083b78e.tar.bz2 JellySolutions-d1b7b81cbedc673cf6f52ac5745438f95083b78e.zip |
Merge pull request #10 from RIT-SWEN-261-02/cupboard-component
Cupboard component
Diffstat (limited to 'ufund-ui/src/app/components/need-list')
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 = []; } } |