From b578584a1208178100bf90e8b06971772c7fc00f Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 4 Apr 2025 21:55:12 -0400 Subject: Fix many bugs and code clean up --- .../components/cupboard/cupboard.component.html | 10 +-- .../app/components/cupboard/cupboard.component.ts | 15 ---- .../funding-basket/funding-basket.component.html | 35 ++++---- .../funding-basket/funding-basket.component.ts | 9 +- .../components/need-edit/need-edit.component.html | 1 - .../components/need-list/need-list.component.css | 4 + .../components/need-page/need-page.component.html | 96 +++++++++++----------- .../components/need-page/need-page.component.ts | 13 +-- ufund-ui/src/app/services/users.service.ts | 18 +++- 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 @@ - +
@@ -33,16 +33,16 @@

No Results Found

- - - 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 @@
-

Funding Basket

- - - - + @if ((authService.getCurrentUserSubject() | async)?.type === userType.HELPER) { +

Funding Basket

+ + + + + + +
+
- -
- 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 @@
- Location:
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 @@
-

{{need.name}}

- {{need.type}} GOAL - - Need image - -

{{need.description}}

-
- - - This goal is {{(((need.current)*100) / (need.maxGoal)).toFixed(0)}}% complete! -
- - Target Goal: {{need.maxGoal}} - - Amount Currently Collected: {{need.current}} - - Location: {{need.location}} - - Urgency: - Not urgent - URGENT - - -
- Tags: -
    -
  • -

    {{tag}}

    -
  • -
-
- -
- - - - - - -
+ @if (need) { +

{{need.name}}

+ {{need.type}} GOAL + + Need image + +

{{need.description}}

+
+ + This goal is {{(((need.current)*100) / (need.maxGoal)).toFixed(0)}}% complete! +
+ + Target Goal: {{need.maxGoal}} + + Amount Currently Collected: {{need.current}} + + Location: {{need.location}} + + Urgency: + Not urgent + URGENT + + +
+ Tags: +
    +
  • +

    {{tag}}

    +
  • +
+
+ +
+ + + + + + +
+ } @else { +

Need not found

+ The requested need does not exist. Browse the cupboard + }
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(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); + } + } -- cgit v1.2.3