summaryrefslogtreecommitdiff
path: root/recipeBuddy/src/app/shopping-cart/shopping-cart.component.ts
blob: b60a63cc5d59271a1f34ae367e2e6dd3a3fdbb94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { Component, OnInit } from '@angular/core';
import { MatSelectModule } from '@angular/material/select';
import { MatDividerModule } from '@angular/material/divider';
import { BackendService } from '../REST_service/backend.service';
import { FormsModule } from '@angular/forms';
import { Recipe } from '../DataModels/recipe';
import { Ingredient } from '../DataModels/ingredient';





@Component({
  selector: 'shopping-cart.component',
  templateUrl: './shopping-cart.component.html',
  styleUrls: ['./shopping-cart.component.css']
})
export class ShoppingCartComponent implements OnInit {
	
  recipes: Recipe[] = [];
  ingredients : Ingredient[] = [];
  units: string[] = [];
  amounts: number[] = [];
  types: string[] = [];
  rIDs: number[] = [];



  constructor( private restService: BackendService) {

	  this.restService.getRecipes().subscribe( 
		res => {
		  var i: number; 
		  for(i = 0; i < res.length; i++) {
			this.restService.getRecipe(res[i]).subscribe(
				res2 => {
          for (var j = 0; j < res2.ingredients.length; j++) {
            res2.ingredients[j]["checked"] = false;
            res2.ingredients[j]["cart_index"] = -1;
          }
					this.recipes.push(res2)
				});
			}
	    });
	  
  }
  
  

  ngOnInit() {
  }

  addAll(): void {

  }
  addRecipe(id: number): void {
	
  }
  addIngredient(ing: Ingredient): void {
    ing.checked = !ing.checked;
    if (ing.checked){
      this.ingredients.push(ing);
      ing.cart_index = this.ingredients.length - 1;
    } else {
      this.ingredients.splice(ing.cart_index, 1);
      for(var i = 0; i < this.ingredients.length; i++) {
        this.ingredients[i].cart_index = i;
      }
  }

  }
  printList(): void {
  }
}