diff options
| author | sowgro <tpoke.ferrari@gmail.com> | 2025-04-04 21:55:12 -0400 | 
|---|---|---|
| committer | sowgro <tpoke.ferrari@gmail.com> | 2025-04-04 21:55:12 -0400 | 
| commit | b578584a1208178100bf90e8b06971772c7fc00f (patch) | |
| tree | 6c2e5ee5fd3cc7e96e036704ebe3b1ba7cbfc9f5 | |
| parent | 03431245f71385c5d641f66a7f63c1a22ab65210 (diff) | |
| download | JellySolutions-b578584a1208178100bf90e8b06971772c7fc00f.tar.gz JellySolutions-b578584a1208178100bf90e8b06971772c7fc00f.tar.bz2 JellySolutions-b578584a1208178100bf90e8b06971772c7fc00f.zip  | |
Fix many bugs and code clean up
9 files changed, 99 insertions, 102 deletions
diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index 3873719..cd8fec2 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -4,7 +4,7 @@          <ng-template #create>              <app-need-edit [mode]="'Create'" (refreshNeedList)="refresh()"></app-need-edit>          </ng-template> -        <button *ngIf="isManager()" class="button2" (click)="modalService.showModal(create)"><span class="icon">add</span>Create Need</button> +        <button *ngIf="usersService.isManager()" class="button2" (click)="modalService.showModal(create)"><span class="icon">add</span>Create Need</button>      </div>      <div id="header2"> @@ -33,16 +33,16 @@      <h2 *ngIf="searchResults.length == 0"> No Results Found </h2>      <ng-template let-need #NLActions> -        <button *ngIf="isHelper()" (click)="addToBasket(need)" [disabled]="inBasket(usersService.getBasket() | async, need)"> -            <span class="icon">{{inBasket(usersService.getBasket() | async, need)? "check": "add" }}</span>Add To Basket +        <button *ngIf="usersService.isHelper()" (click)="addToBasket(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 *ngIf="need" [mode]="'Edit'" [need]="need" (refreshNeedList)="refresh()"></app-need-edit>          </ng-template> -        <button *ngIf="isManager()" (click)="modalService.showModal(edit)"> +        <button *ngIf="usersService.isManager()" (click)="modalService.showModal(edit)">              <span class="icon">edit</span>Edit Need          </button> -        <button *ngIf="isManager()" (click)="deleteNeed(need.id)" > +        <button *ngIf="usersService.isManager()" (click)="deleteNeed(need.id)" >              <span class="icon">delete</span>Delete Need          </button>      </ng-template> diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 56fdd70..289618f 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -1,7 +1,6 @@  import {Component, OnInit, ViewChild} from '@angular/core';  import {CupboardService} from '../../services/cupboard.service';  import {Need} from '../../models/Need'; -import {userType} from '../../models/User';  import {catchError, of} from 'rxjs';  import {NeedListComponent} from '../need-list/need-list.component';  import {AuthService} from '../../services/auth.service'; @@ -138,20 +137,6 @@ export class CupboardComponent implements OnInit {          }      } -    isManager() { -        return this.authService.getCurrentUser()?.type === userType.MANAGER -    } - -    isHelper() { -        return this.authService.getCurrentUser()?.type === userType.HELPER -    } - -    inBasket(basket: Need[] | null, need: Need) { -        console.log(basket) -        console.log(need) -        return basket?.map(r => r.id).includes(need.id); -    } -      protected readonly SortingAlgorithms = SortingAlgoArrays;      protected readonly Object = Object;  } diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html index edc9609..fcd5437 100644 --- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html +++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html @@ -1,19 +1,24 @@  <div id="box"> -    <h1>Funding Basket</h1> -    <ng-template [ngIf]="(usersService.getBasket() | async)?.length"> -        <ng-template let-need #NLActions> -            <input type="number" placeholder="Quantity" min="1" [id]="need?.id" class="contribution"> -            <button class="removeNeed" (click)="this.usersService.removeNeed(need.id)"> -                <span class="icon">delete</span>Remove from Basket -            </button> +    @if ((authService.getCurrentUserSubject() | async)?.type === userType.HELPER) { +        <h1>Funding Basket</h1> +        <ng-template [ngIf]="(usersService.getBasket() | async)?.length"> +            <ng-template let-need #NLActions> +                <input type="number" placeholder="Quantity" min="1" [id]="need?.id" class="contribution"> +                <button class="removeNeed" (click)="this.usersService.removeNeed(need.id)"> +                    <span class="icon">delete</span>Remove from Basket +                </button> +            </ng-template> +            <app-need-list [actionArea]="NLActions" [needs]="(usersService.getBasket() | async)!"/> +            <br> +            <div id="footer"> +                <button class="button2" title="checkout" (click)="checkout()">Checkout</button> +            </div>          </ng-template> -        <app-need-list [actionArea]="NLActions" [needs]="(usersService.getBasket() | async)!"/> -        <br> -        <div id="footer"> -            <button class="button2" title="checkout" (click)="checkout()">Checkout</button> +        <div *ngIf="!usersService.getBasket().getValue().length"> +            <span>There are no needs in your basket! </span><a routerLink="/cupboard">Browse the cupboard</a>          </div> -    </ng-template> -    <div *ngIf="!usersService.getBasket().getValue().length"> -        <span>There are no needs in your basket! </span><a routerLink="/cupboard">Browse the cupboard</a> -    </div> +    } @else { +        <h1>Unauthorized</h1> +        <span>This page requires you to be logged in as a user! <a routerLink="/login">Log In</a></span> +    }  </div> diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts b/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts index 0b3b9f3..767327e 100644 --- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts +++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts @@ -5,6 +5,7 @@ import {CupboardService} from '../../services/cupboard.service';  import {catchError, firstValueFrom, Observable, of} from 'rxjs';  import {AuthService} from '../../services/auth.service';  import {ToastsService, ToastType} from '../../services/toasts.service'; +import {userType} from '../../models/User';  @Component({      selector: 'app-funding-basket', @@ -18,19 +19,14 @@ export class FundingBasketComponent implements OnInit {          private router: Router,          protected cupboardService: CupboardService,          protected usersService: UsersService, -        private authService: AuthService, +        protected authService: AuthService,          private toastService: ToastsService      ) {}      @ViewChild("contribution") contribution?: Input;      @Input() isValid: boolean = true; -    // this is for login rerouting      ngOnInit(): void { -        if (!this.authService.getCurrentUser()) { -            this.router.navigate(['/login'], {queryParams: {redir: this.router.url}}); -            return; -        }          this.usersService.refreshBasket();          // this.usersService.removeNeed(); <- call this to remove @@ -92,4 +88,5 @@ export class FundingBasketComponent implements OnInit {      protected readonly of = of; +    protected readonly userType = userType;  } diff --git a/ufund-ui/src/app/components/need-edit/need-edit.component.html b/ufund-ui/src/app/components/need-edit/need-edit.component.html index ed4bfb3..0adbda7 100644 --- a/ufund-ui/src/app/components/need-edit/need-edit.component.html +++ b/ufund-ui/src/app/components/need-edit/need-edit.component.html @@ -11,7 +11,6 @@              <input type="text" name="image" [(ngModel)]="needCopy.image">          </div>          <div> -            <span>Location:</span>              <input type="text" name="location" [(ngModel)]="needCopy.location">          </div>          <div> 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 582b832..622b64a 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 @@ -72,6 +72,10 @@      gap: 5px;  } +.actionArea:empty { +    padding: 0; +} +  #page-selector {      display: flex;      align-items: center; 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) diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts index 4080ebf..d23b59b 100644 --- a/ufund-ui/src/app/services/users.service.ts +++ b/ufund-ui/src/app/services/users.service.ts @@ -1,7 +1,7 @@  import { Injectable } from '@angular/core';  import {HttpClient, HttpHeaders} from '@angular/common/http';  import {BehaviorSubject, catchError, firstValueFrom, Observable, of} from 'rxjs'; -import {User} from '../models/User'; +import {User, userType} from '../models/User';  import { Need } from '../models/Need';  import { CupboardService } from './cupboard.service';  import {AuthService} from './auth.service'; @@ -25,7 +25,9 @@ export class UsersService {          private http: HttpClient,          private cupboardService: CupboardService,          private authService: AuthService -    ) {} +    ) { +        authService.getCurrentUserSubject().subscribe(() => this.refreshBasket()) +    }      async createUser(username:string, password:string) {          await firstValueFrom(this.http.post<User>(this.url, {username: username, password: password}, this.httpOptions())) @@ -71,4 +73,16 @@ export class UsersService {          return this.basket;      } +    isManager() { +        return this.authService.getCurrentUser()?.type === userType.MANAGER +    } + +    isHelper() { +        return this.authService.getCurrentUser()?.type === userType.HELPER +    } + +    inBasket(basket: Need[] | null, need: Need) { +        return basket?.map(r => r.id).includes(need.id); +    } +  }  | 
