diff options
| author | Akash Keshav <112591754+domesticchores@users.noreply.github.com> | 2025-03-18 15:49:08 -0400 | 
|---|---|---|
| committer | Akash Keshav <112591754+domesticchores@users.noreply.github.com> | 2025-03-18 15:49:08 -0400 | 
| commit | cd9dfcec9e7ae9fe6f08b61927b16cf76b8bcef7 (patch) | |
| tree | 8459fea69c0a20150479c65443991927e6aef6cf /ufund-ui/src | |
| parent | 080f7ce14770dd8b6bc893160afd357fada883b2 (diff) | |
| download | JellySolutions-cd9dfcec9e7ae9fe6f08b61927b16cf76b8bcef7.tar.gz JellySolutions-cd9dfcec9e7ae9fe6f08b61927b16cf76b8bcef7.tar.bz2 JellySolutions-cd9dfcec9e7ae9fe6f08b61927b16cf76b8bcef7.zip  | |
debug of checkout. -ak
Diffstat (limited to '')
| -rw-r--r-- | ufund-ui/src/app/components/funding-basket/funding-basket.component.html | 19 | ||||
| -rw-r--r-- | ufund-ui/src/app/components/funding-basket/funding-basket.component.ts | 28 | 
2 files changed, 34 insertions, 13 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..178a2cd 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,6 @@  </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>  </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..a7a38b8 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,4 +1,4 @@ -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'; @@ -21,6 +21,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 +35,29 @@ 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')!) { +      var 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')!) { +        var contribution = c as HTMLInputElement; +        var need = await firstValueFrom(this.cupboardService.getNeed(+contribution.id)); +        need.current +=+ contribution.value; +        console.log(need); +        this.cupboardService.updateNeed(+contribution.id, need); +        this.usersService.removeNeed(+contribution.id); +      } +    } +  } +  }  | 
