diff options
| author | sowgro <tpoke.ferrari@gmail.com> | 2025-03-17 23:16:29 -0400 | 
|---|---|---|
| committer | sowgro <tpoke.ferrari@gmail.com> | 2025-03-17 23:16:29 -0400 | 
| commit | 68515441acd77d3356e8ec8b58700411661fec13 (patch) | |
| tree | f3e08e4eecb5c06c8149d56ca08253a3c2d92607 /ufund-ui/src/app/components/need-list | |
| parent | 7a5c5073e9e410b3ccc3ab7902a0d6f558277c7d (diff) | |
| parent | 275a6062007380389b7a8f1b8958e8033b4f0925 (diff) | |
| download | JellySolutions-68515441acd77d3356e8ec8b58700411661fec13.tar.gz JellySolutions-68515441acd77d3356e8ec8b58700411661fec13.tar.bz2 JellySolutions-68515441acd77d3356e8ec8b58700411661fec13.zip  | |
Merge remote-tracking branch 'refs/remotes/origin/main' into funding_basket
# Conflicts:
#	ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
Diffstat (limited to 'ufund-ui/src/app/components/need-list')
3 files changed, 128 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..b21979f 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,92 @@ import {CupboardService} from '../../services/cupboard.service';  })  export class NeedListComponent {    needs: Need[] = []; +  searchResults: Need[] = [];    constructor( -    private cupboardService: CupboardService +    private cupboardService: CupboardService, +    private usersService: UsersService    ) {} +    refresh() { +        this.cupboardService.getNeeds().subscribe(n => this.needs = n) +    } +    ngOnInit(): void { -    this.cupboardService.getNeeds().subscribe(n => this.needs = n) +    this.refresh() +    // 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 = [];    }  }  | 
