diff options
Diffstat (limited to 'ufund-ui/src/app/components/funding-basket/funding-basket.component.ts')
-rw-r--r-- | ufund-ui/src/app/components/funding-basket/funding-basket.component.ts | 18 |
1 files changed, 15 insertions, 3 deletions
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 371015a..78ce958 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 @@ -2,10 +2,11 @@ import {Component, Input, OnInit, ViewChild} from '@angular/core'; import {UsersService} from '../../services/users.service'; import {Router} from '@angular/router'; import {CupboardService} from '../../services/cupboard.service'; -import {firstValueFrom, of} from 'rxjs'; +import {BehaviorSubject, firstValueFrom, of} from 'rxjs'; import {AuthService} from '../../services/auth.service'; import {ToastsService, ToastType} from '../../services/toasts.service'; import {userType} from '../../models/User'; +import {GoalType} from '../../models/Need'; @Component({ selector: 'app-funding-basket', @@ -23,6 +24,7 @@ export class FundingBasketComponent implements OnInit { private toastService: ToastsService ) {} + public runningTotal = new BehaviorSubject(0) @ViewChild("contribution") contribution?: Input; ngOnInit(): void { @@ -59,8 +61,18 @@ export class FundingBasketComponent implements OnInit { } resetColor(ev: any) { - // for (let contribution of document.querySelectorAll<HTMLInputElement>('.contribution')!) {} - (ev.target as HTMLInputElement).setAttribute("style", "") + let total = 0 + this.runningTotal.next(total); + for (let contribution of document.querySelectorAll<HTMLInputElement>('.contribution')!) { + this.cupboardService.getNeed(+contribution.id).subscribe(need => { + if (contribution.value != '' && need.type != GoalType.PHYSICAL) { + total += contribution.valueAsNumber + } + this.runningTotal.next(total); + }) + } + + (ev.target as HTMLInputElement).setAttribute("style", "border-color: unset") } protected readonly of = of; |