summaryrefslogtreecommitdiff
path: root/recipeBuddy/src/app/pre-cook-pop-up/pre-cook-pop-up.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'recipeBuddy/src/app/pre-cook-pop-up/pre-cook-pop-up.component.ts')
-rw-r--r--recipeBuddy/src/app/pre-cook-pop-up/pre-cook-pop-up.component.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/recipeBuddy/src/app/pre-cook-pop-up/pre-cook-pop-up.component.ts b/recipeBuddy/src/app/pre-cook-pop-up/pre-cook-pop-up.component.ts
new file mode 100644
index 0000000..208993f
--- /dev/null
+++ b/recipeBuddy/src/app/pre-cook-pop-up/pre-cook-pop-up.component.ts
@@ -0,0 +1,46 @@
+import { Component, OnInit } from '@angular/core';
+import { RecipePassService } from '../recipePass/recipe-pass.service';
+import { Recipe } from '../DataModels/recipe';
+import { Ingredient } from '../DataModels/ingredient';
+import { BackendService } from '../REST_service/backend.service';
+import { Router } from '@angular/router';
+
+@Component({
+ selector: 'app-pre-cook-pop-up',
+ templateUrl: './pre-cook-pop-up.component.html',
+ styleUrls: ['./pre-cook-pop-up.component.css']
+// providers: [RecipePassService]
+})
+export class PreCookPopUpComponent implements OnInit {
+
+ cookedRecipe: Recipe;
+ newSize: number;
+ originalAmounts: number[] = [];
+ originalSize: number;
+
+ constructor(private recipePass: RecipePassService, private backend: BackendService, private router: Router) { }
+
+ ngOnInit() {
+ this.backend.getRecipe(15).subscribe(res =>
+ {
+ console.log(res);
+ this.cookedRecipe = res;
+ this.originalSize = this.cookedRecipe.servingSize;
+ for(var _i = 0; _i < this.cookedRecipe.ingredients.length; _i++) {
+ this.originalAmounts[_i] = this.cookedRecipe.ingredients[_i].amount;
+ }
+ });
+ }
+
+ updateRecipe(event: any) {
+ if(event.target.value) {
+ this.newSize = parseInt(event.target.value);
+ for(var _i = 0; _i < this.cookedRecipe.ingredients.length; _i++) {
+ this.cookedRecipe.ingredients[_i].amount = Math.round(this.originalAmounts[_i] * (this.newSize / this.originalSize));
+ }
+
+ this.cookedRecipe.servingSize = this.newSize;
+ this.recipePass.setRecipe(this.cookedRecipe);
+ }
+ }
+}