diff options
| author | Gunther6070 <haydenhartman10@yahoo.com> | 2025-03-18 16:02:28 -0400 | 
|---|---|---|
| committer | Gunther6070 <haydenhartman10@yahoo.com> | 2025-03-18 16:02:28 -0400 | 
| commit | 2348497b5dd6bca85473e409e092aa897d5a6a7f (patch) | |
| tree | 133a51b5964f28fc2961a56dc34543618bddce25 /ufund-ui | |
| parent | 53cc8e1cf75468c9d270443627ee8f71db57ea59 (diff) | |
| parent | 9d90b2a29b1f47b6271fd9ea87989a4195cf5ee6 (diff) | |
| download | JellySolutions-2348497b5dd6bca85473e409e092aa897d5a6a7f.tar.gz JellySolutions-2348497b5dd6bca85473e409e092aa897d5a6a7f.tar.bz2 JellySolutions-2348497b5dd6bca85473e409e092aa897d5a6a7f.zip  | |
Merge branch 'funding_basket' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b into funding_basket
Diffstat (limited to 'ufund-ui')
| -rw-r--r-- | ufund-ui/src/app/components/funding-basket/funding-basket.component.html | 20 | ||||
| -rw-r--r-- | ufund-ui/src/app/components/funding-basket/funding-basket.component.ts | 53 | 
2 files changed, 59 insertions, 14 deletions
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 b8633b8..30c3167 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 @@ -9,7 +9,7 @@      <h2>There are no needs in the basket</h2>  </div> -<table class="needs" *ngIf="this.usersService.getBasket().getValue().length != 0"> +<table class="needs" id="funding-basket" *ngIf="this.usersService.getBasket().getValue().length != 0">      <thead>          <tr>              <th class="need"></th> @@ -18,20 +18,14 @@      <tbody>          <tr *ngFor="let need of usersService.getBasket().getValue()">              <td> -                <a routerLink="/need/{{need.id}}"> -                    {{need.name}} -                </a> +                <a routerLink="/need/{{need.id}}">{{need.name}}</a>                  <p>Goal: {{need.maxGoal}}</p>                  <p>Current: {{need.current}}</p> -                <p>How much to Contribute: <input type="number" #contribution></p> -                <div> -                <!-- <button type="button" class="addNeed" title="add need" -                (click)="addNeed(need)">Add Need</button> --> -                </div> +                <p>How much to Contribute: <input type="number" placeholder="insert value" min="0" id={{need.id}} class="contribution"></p>                  <br>                  <div> -                <button type="button" class="removeNeed" title="delete need" -                (click)="this.usersService.removeNeed(need.id)">Remove Need</button> +                    <button type="button" class="removeNeed" title="delete need" +                    (click)="this.usersService.removeNeed(need.id)">Remove Need</button>                  </div>              </td>          </tr> @@ -39,5 +33,7 @@  </table>  <br>  <div> -    <button type="submit" class="checkout" title="checkout">Checkout</button> +    <p *ngIf="!isValid">Invalid input in funding basket!</p> +    <button type="submit" class="checkout" title="checkout" (click)="checkout()">Checkout</button> +    <span *ngIf="statusText">{{statusText | async}}</span>  </div>
\ No newline at end of file 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 061e3fa..7f086ec 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 @@ -1,11 +1,11 @@ -import {Component, OnInit} from '@angular/core'; +import {Component, Input, OnInit, ViewChild} from '@angular/core';  import {User} from '../../models/User';  import { UsersService } from '../../services/users.service';  import { Need } from '../../models/Need';  import { NeedListComponent } from '../need-list/need-list.component';  import { Router } from '@angular/router';  import { CupboardService } from '../../services/cupboard.service'; -import { BehaviorSubject, firstValueFrom } from 'rxjs'; +import { BehaviorSubject, catchError, firstValueFrom, Observable } from 'rxjs';  @Component({      selector: 'app-funding-basket', @@ -14,6 +14,7 @@ import { BehaviorSubject, firstValueFrom } from 'rxjs';      styleUrl: './funding-basket.component.css'  })  export class FundingBasketComponent implements OnInit { +  statusText: any;    constructor(      private router: Router, @@ -21,6 +22,9 @@ export class FundingBasketComponent implements OnInit {      protected usersService: UsersService    ) {} +  @ViewChild("contribution") contribution?: Input; +  @Input() isValid: boolean = true; +    // this is for login rerouting    ngOnInit(): void {      if (!this.usersService.getCurrentUser()) { @@ -32,6 +36,51 @@ export class FundingBasketComponent implements OnInit {      // this.usersService.removeNeed(); <- call this to remove    } +  async checkout() { +    this.isValid = true; +    for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) { +      let contribution = c as HTMLInputElement; +      console.log(contribution.value, contribution.id); +      contribution.setAttribute("style",""); +      if ( contribution.value == '' || contribution.valueAsNumber < 0) { +        this.isValid = false; +        contribution.setAttribute("style","color: #ff0000"); +      } +    } +    if (this.isValid) { +      for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) { +        let contribution = c as HTMLInputElement; +        let need = await firstValueFrom(this.cupboardService.getNeed(+contribution.id)); +        need.current +=+ contribution.value; +        console.log(need); +        this.usersService.removeNeed(need.id); +        this.cupboardService.updateNeed(need.id, need) +                    .pipe(catchError((ex, r) => { +                        console.log(ex.status); +                        if (ex.status == 500) { +                            this.statusText.next("Fields cannot be blank"); +                        } else if (ex.status == 400) { +                            this.statusText.next("Goal must be greater than 0"); +                        } else { +                            this.statusText.next("Error on creating need"); +                        } +                        return new Observable<string>(); +                    })) +                    .subscribe( +                        (result) => { +                            if (result) { +                                console.log("need updated successfully"); +                                //this.needList?.refresh() +                            } else { +                                console.log("need update failed"); +                            } +                        } +         +                    ); +      } +    } +  } +  }  | 
