diff options
Diffstat (limited to 'ufund-ui/src/app/components/need-page')
-rw-r--r-- | ufund-ui/src/app/components/need-page/need-page.component.html | 96 | ||||
-rw-r--r-- | ufund-ui/src/app/components/need-page/need-page.component.ts | 13 |
2 files changed, 51 insertions, 58 deletions
diff --git a/ufund-ui/src/app/components/need-page/need-page.component.html b/ufund-ui/src/app/components/need-page/need-page.component.html index aed3e95..592a71e 100644 --- a/ufund-ui/src/app/components/need-page/need-page.component.html +++ b/ufund-ui/src/app/components/need-page/need-page.component.html @@ -1,48 +1,52 @@ <div id="box"> - <h1>{{need.name}}</h1> - <span class="needType">{{need.type}} GOAL</span> - - <img *ngIf="need.image" alt="Need image" [src]="need.image"/> - - <p>{{need.description}}</p> - <div class="prog"> -<!-- <span>{{need?.current}} / {{need?.maxGoal}}</span>--> - <progress [value]="need.current" [max]="need.maxGoal"></progress> - <span>This goal is <strong>{{(((need.current)*100) / (need.maxGoal)).toFixed(0)}}%</strong> complete!</span> - </div> - - <span><strong>Target Goal:</strong> {{need.maxGoal}}</span> - - <span><strong>Amount Currently Collected:</strong> {{need.current}}</span> - - <span><strong>Location:</strong> {{need.location}}</span> - - <span><strong>Urgency: </strong> - <span *ngIf="!need.urgent">Not urgent</span> - <span *ngIf="need.urgent" class="urgent">URGENT</span> - </span> - - <div *ngIf="need.filterAttributes.length > 0"> - <strong>Tags:</strong> - <ul style="display: flex; column-gap: 24px;"> - <li *ngFor="let tag of need?.filterAttributes"> - <p>{{tag}}</p> - </li> - </ul> - </div> - - <div class="actionArea"> - <button *ngIf="isHelper()" (click)="add(need!)"> - <span class="icon">add</span>Add To Basket - </button> - <ng-template #edit> - <app-need-edit [mode]="'Edit'" *ngIf="need" [need]="need" (refreshNeedList)="ngOnInit()"></app-need-edit> - </ng-template> - <button *ngIf="isManager()" (click)="modalService.showModal(edit)"> - <span class="icon">edit</span>Edit Need - </button> - <button *ngIf="isManager()" (click)="delete(need!.id)" > - <span class="icon">delete</span>Delete Need - </button> - </div> + @if (need) { + <h1>{{need.name}}</h1> + <span class="needType">{{need.type}} GOAL</span> + + <img *ngIf="need.image" alt="Need image" [src]="need.image"/> + + <p>{{need.description}}</p> + <div class="prog"> + <progress [value]="need.current" [max]="need.maxGoal"></progress> + <span>This goal is <strong>{{(((need.current)*100) / (need.maxGoal)).toFixed(0)}}%</strong> complete!</span> + </div> + + <span><strong>Target Goal:</strong> {{need.maxGoal}}</span> + + <span><strong>Amount Currently Collected:</strong> {{need.current}}</span> + + <span><strong>Location:</strong> {{need.location}}</span> + + <span><strong>Urgency: </strong> + <span *ngIf="!need.urgent">Not urgent</span> + <span *ngIf="need.urgent" class="urgent">URGENT</span> + </span> + + <div *ngIf="need.filterAttributes?.length"> + <strong>Tags:</strong> + <ul style="display: flex; column-gap: 24px;"> + <li *ngFor="let tag of need?.filterAttributes"> + <p>{{tag}}</p> + </li> + </ul> + </div> + + <div class="actionArea"> + <button *ngIf="usersService.isHelper()" (click)="add(need)" [disabled]="usersService.inBasket(usersService.getBasket() | async, need)"> + <span class="icon">{{usersService.inBasket(usersService.getBasket() | async, need)? "check": "add" }}</span>Add To Basket + </button> + <ng-template #edit> + <app-need-edit [mode]="'Edit'" *ngIf="need" [need]="need" (refreshNeedList)="ngOnInit()"></app-need-edit> + </ng-template> + <button *ngIf="usersService.isManager()" (click)="modalService.showModal(edit)"> + <span class="icon">edit</span>Edit Need + </button> + <button *ngIf="usersService.isManager()" (click)="delete(need!.id)" > + <span class="icon">delete</span>Delete Need + </button> + </div> + } @else { + <h1>Need not found</h1> + <span>The requested need does not exist. <a routerLink="/cupboard">Browse the cupboard</a></span> + } </div> diff --git a/ufund-ui/src/app/components/need-page/need-page.component.ts b/ufund-ui/src/app/components/need-page/need-page.component.ts index 1c6d8e4..45d6db5 100644 --- a/ufund-ui/src/app/components/need-page/need-page.component.ts +++ b/ufund-ui/src/app/components/need-page/need-page.component.ts @@ -2,7 +2,6 @@ import {Component, Input, OnInit} from '@angular/core'; import {Need} from '../../models/Need'; import {ActivatedRoute, Router} from "@angular/router"; import {CupboardService} from "../../services/cupboard.service"; -import {userType} from '../../models/User'; import {AuthService} from '../../services/auth.service'; import {catchError, of} from 'rxjs'; import {ToastsService, ToastType} from '../../services/toasts.service'; @@ -20,7 +19,7 @@ export class NeedPageComponent implements OnInit { private route: ActivatedRoute, private cupboardService: CupboardService, private authService: AuthService, - private usersService: UsersService, + protected usersService: UsersService, private toastService: ToastsService, private router: Router, protected modalService: ModalService @@ -37,16 +36,6 @@ export class NeedPageComponent implements OnInit { window.history.back(); } - isManager() { - const type = this.authService.getCurrentUser()?.type; - return type === ("MANAGER" as unknown as userType); - } - - isHelper() { - const type = this.authService.getCurrentUser()?.type; - return type === ("HELPER" as unknown as userType); - } - add(need: Need) { const currentUser = this.authService.getCurrentUser(); //console.log("get current user in angular:", currentUser) |