From 161b1a1b2c3023da26388719cf962039742de350 Mon Sep 17 00:00:00 2001 From: schencej Date: Mon, 9 Dec 2019 17:38:03 -0500 Subject: added additional functionality to cook page --- .../src/app/cook-page/cook-page.component.ts | 78 ++++++++++++++++------ 1 file changed, 56 insertions(+), 22 deletions(-) (limited to 'recipeBuddy/src/app/cook-page/cook-page.component.ts') diff --git a/recipeBuddy/src/app/cook-page/cook-page.component.ts b/recipeBuddy/src/app/cook-page/cook-page.component.ts index 51a4c67..f114634 100644 --- a/recipeBuddy/src/app/cook-page/cook-page.component.ts +++ b/recipeBuddy/src/app/cook-page/cook-page.component.ts @@ -1,17 +1,20 @@ import {Component, OnInit} from '@angular/core'; +import {Recipe} from '../DataModels/recipe'; +import {Step} from '../DataModels/step'; +import {RecipePassService} from '../recipePass/recipe-pass.service' -/** - * @title Card with multiple sections - */ @Component({ selector: 'app-cook-page', templateUrl: './cook-page.component.html', styleUrls: ['./cook-page.component.css'], }) export class CookPageComponent implements OnInit { - step: number; - instructions: string[] = ["Cut the bread", "Toast the bread", "Warm the butter", "Apply butter to bread", "Enjoy"]; - timers: number[] = [5,60,30,0,0]; + steps: Step[]; + stepNum: number; + + firstStep: boolean = true; + lastStep: boolean = false; + previousStep: string; currentStep: string; nextStep: string; @@ -19,30 +22,62 @@ export class CookPageComponent implements OnInit { timerInterval; + constructor(private recipePass: RecipePassService){} + ngOnInit() { - this.step = 1; - this.previousStep = ""; - this.currentStep = this.instructions[this.step-1]; - this.nextStep = this.instructions[this.step]; - this.timeLeft = this.timers[this.step-1]; + this.getSteps(); + this.stepNum = 1; + this.currentStep = this.steps[this.stepNum-1].getInstruction(); + this.nextStep = this.steps[this.stepNum].getInstruction(); + this.timeLeft = this.steps[this.stepNum-1].getTimer(); + } + + getSteps(): void { +/** +* var recipe: Recipe; +* recipe = this.recipePass.getRecipe(); +* this.steps = recipe.getSteps(); +*/ + var tmpSteps: Step[] = []; + tmpSteps[0] = new Step("Cut the bread", 0); + tmpSteps[1] = new Step("Warm the butter", 5); + tmpSteps[2] = new Step("Enjoy", 0); + this.steps = tmpSteps; } next(): void { + this.firstStep = false; clearInterval(this.timerInterval); - this.step++; - this.previousStep = this.instructions[this.step-2]; - this.currentStep = this.instructions[this.step-1]; - this.nextStep = this.instructions[this.step]; - this.timeLeft = this.timers[this.step-1]; + this.stepNum++; + if(this.stepNum == this.steps.length) { + this.lastStep = true; + } else { + this.nextStep = this.steps[this.stepNum].getInstruction(); + } + this.previousStep = this.steps[this.stepNum-2].getInstruction(); + this.currentStep = this.steps[this.stepNum-1].getInstruction(); + this.timeLeft = this.steps[this.stepNum-1].getTimer(); } previous(): void { + this.lastStep = false; clearInterval(this.timerInterval); - this.step--; - this.previousStep = this.instructions[this.step-2]; - this.currentStep = this.instructions[this.step-1]; - this.nextStep = this.instructions[this.step]; - this.timeLeft = this.timers[this.step-1]; + this.stepNum--; + if(this.stepNum == 1) { + this.firstStep = true; + } else { + this.previousStep = this.steps[this.stepNum-2].getInstruction(); + } + this.currentStep = this.steps[this.stepNum-1].getInstruction(); + this.nextStep = this.steps[this.stepNum].getInstruction(); + this.timeLeft = this.steps[this.stepNum-1].getTimer(); + } + + hasTimer(): boolean { + if(this.steps[this.stepNum - 1].getTimer() > 0) + return true; + else + return false; } startTimer(): void { @@ -56,4 +91,3 @@ export class CookPageComponent implements OnInit { }, 1000) } } - -- cgit v1.1