diff options
author | sowgro <tpoke.ferrari@gmail.com> | 2025-04-04 22:58:26 -0400 |
---|---|---|
committer | sowgro <tpoke.ferrari@gmail.com> | 2025-04-04 22:58:26 -0400 |
commit | f70e86470f7083cda1949ff97556d9e39578ce1d (patch) | |
tree | 5cc8a3e1089409e10fd92896625605a7f8f6897b /ufund-ui/src/app/components/dashboard | |
parent | edfc9a8450d140ba1650b38e4b707000710b2faa (diff) | |
parent | 5a5d31896d79a736bce33b7d1aa7b3168ba308a9 (diff) | |
download | JellySolutions-f70e86470f7083cda1949ff97556d9e39578ce1d.tar.gz JellySolutions-f70e86470f7083cda1949ff97556d9e39578ce1d.tar.bz2 JellySolutions-f70e86470f7083cda1949ff97556d9e39578ce1d.zip |
Merge branch 'main' into need-list-abstraction
# Conflicts:
# ufund-ui/src/app/components/cupboard/cupboard.component.ts
# ufund-ui/src/app/components/funding-basket/funding-basket.component.html
# ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
# ufund-ui/src/app/components/need-list/need-list.component.html
# ufund-ui/src/app/components/need-list/need-list.component.ts
# ufund-ui/src/app/components/need-page/need-page.component.html
Diffstat (limited to 'ufund-ui/src/app/components/dashboard')
-rw-r--r-- | ufund-ui/src/app/components/dashboard/dashboard.component.html | 8 | ||||
-rw-r--r-- | ufund-ui/src/app/components/dashboard/dashboard.component.ts | 35 |
2 files changed, 30 insertions, 13 deletions
diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.html b/ufund-ui/src/app/components/dashboard/dashboard.component.html index 2d7b4c3..2af467c 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.html +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.html @@ -4,7 +4,11 @@ <!--<app-mini-need-list [needList]="almostThere" jtitle="Almost there" url="/cupboard"/>--> <!--<app-mini-need-list [needList]="inBasket" jtitle="In your basket" url="/basket"/>--> <span>_ Registered users</span> -<span>_ Needs with overflow</span> -<span>_ Needs in peoples baskets</span> +<span *ngIf="count"> {{count | async}} </span> +<span>_ Fulfilled needs</span> +<app-mini-need-list [needList]="fulfilledNeeds.getValue()" jtitle="Fulfilled needs"> </app-mini-need-list> +<span>_ Most fulfilled needs</span> +<app-mini-need-list [needList]="mostFulfilledNeeds.getValue()" jtitle="Most fulfilled"> </app-mini-need-list> <span>_ Total monetary contributions</span> +<span *ngIf="totalDonations">${{totalDonations | async}} </span> <span>_ </span> diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.ts b/ufund-ui/src/app/components/dashboard/dashboard.component.ts index c94b5c6..9bf7627 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.ts +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.ts @@ -1,10 +1,10 @@ import {Component, OnInit} from '@angular/core'; import {AuthService} from '../../services/auth.service'; import {Router} from '@angular/router'; -import {Need} from '../../models/Need'; import {CupboardService} from '../../services/cupboard.service'; -import {firstValueFrom} from 'rxjs'; import {UsersService} from '../../services/users.service'; +import {BehaviorSubject} from 'rxjs'; +import {GoalType, Need} from '../../models/Need'; @Component({ selector: 'app-dashboard', @@ -14,9 +14,11 @@ import {UsersService} from '../../services/users.service'; }) export class DashboardComponent implements OnInit{ - topNeeds?: Need[] - almostThere?: Need[] - inBasket?: Need[] + protected count = new BehaviorSubject<number | undefined>(undefined) + protected totalDonations = new BehaviorSubject<number | undefined>(undefined) + protected totalNeeds = new BehaviorSubject<number | undefined>(undefined) + protected fulfilledNeeds = new BehaviorSubject<Need[] | undefined>(undefined) + protected mostFulfilledNeeds = new BehaviorSubject<Need[] | undefined>(undefined) constructor( protected authService: AuthService, @@ -32,14 +34,25 @@ export class DashboardComponent implements OnInit{ return } - firstValueFrom(this.cupboardService.getNeeds()).then(r => { - this.topNeeds = r.sort((a, b) => b.current - a.current) - this.almostThere = r.sort((a, b) => a.current/a.maxGoal - b.current/b.maxGoal) - }) + this.userService.getCount().subscribe(count => this.count.next(count)) + this.cupboardService.getNeeds().subscribe(needs => { + let totalValue = 0 + for (let need of needs) { + if (need.type === GoalType.MONETARY) { + totalValue += need.current + this.totalDonations.next(totalValue) + } + + } + this.fulfilledNeeds.next(needs.filter(a => ((a.current / a.maxGoal)) >= 1)) + needs.sort((a, b) => b.current/b.maxGoal - a.current/a.maxGoal) - this.userService.getBasket().subscribe(r => { - this.inBasket = r; + needs = needs.filter(a => a.current != 0) + this.totalNeeds.next(needs.length) + this.mostFulfilledNeeds.next(needs.slice(0, 5)) }) + + } } |