From 365d78a6a7884b21fe588df9d502240c4c52bf05 Mon Sep 17 00:00:00 2001 From: schencej Date: Tue, 10 Dec 2019 22:22:35 -0500 Subject: added funcitonality to cook-page --- .../src/app/cook-page/cook-page.component.ts | 69 +++++++++++++--------- 1 file changed, 41 insertions(+), 28 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 f114634..9dfc605 100644 --- a/recipeBuddy/src/app/cook-page/cook-page.component.ts +++ b/recipeBuddy/src/app/cook-page/cook-page.component.ts @@ -6,7 +6,7 @@ import {RecipePassService} from '../recipePass/recipe-pass.service' @Component({ selector: 'app-cook-page', templateUrl: './cook-page.component.html', - styleUrls: ['./cook-page.component.css'], + styleUrls: ['./cook-page.component.css'] }) export class CookPageComponent implements OnInit { steps: Step[]; @@ -14,35 +14,42 @@ export class CookPageComponent implements OnInit { firstStep: boolean = true; lastStep: boolean = false; + servingSize: number; previousStep: string; currentStep: string; nextStep: string; timeLeft: number; + timeHoursFirst: number; + timeHoursSecond: number; + timeMinutesFirst: number; + timeMinutesSecond: number; + timeSecondsFirst: number; + timeSecondsSecond: number; + timerInterval; constructor(private recipePass: RecipePassService){} ngOnInit() { - this.getSteps(); + var recipe: Recipe = this.recipePass.getRecipe(); + this.steps = recipe.steps; + this.servingSize = recipe.servingSize; 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; + this.currentStep = this.steps[this.stepNum-1].instructions; + if(this.steps.length > 1) + this.nextStep = this.steps[this.stepNum].instructions; + else + this.lastStep = true; +// this.timeLeft = this.steps[this.stepNum-1].timer; + this.timeLeft = 88888; + this.timeHoursFirst = Math.floor(this.timeLeft/3600/10); + this.timeHoursSecond = Math.floor(this.timeLeft/3600%10); + this.timeMinutesFirst = Math.floor(this.timeLeft%3600/60/10); + this.timeMinutesSecond = Math.floor(this.timeLeft%3600/60%10); + this.timeSecondsFirst = Math.floor(this.timeLeft%3600%60/10); + this.timeSecondsSecond = Math.floor(this.timeLeft%3600%60%10); } next(): void { @@ -52,11 +59,11 @@ export class CookPageComponent implements OnInit { if(this.stepNum == this.steps.length) { this.lastStep = true; } else { - this.nextStep = this.steps[this.stepNum].getInstruction(); + this.nextStep = this.steps[this.stepNum].instructions; } - this.previousStep = this.steps[this.stepNum-2].getInstruction(); - this.currentStep = this.steps[this.stepNum-1].getInstruction(); - this.timeLeft = this.steps[this.stepNum-1].getTimer(); + this.previousStep = this.steps[this.stepNum-2].instructions; + this.currentStep = this.steps[this.stepNum-1].instructions; + this.timeLeft = this.steps[this.stepNum-1].timer; } previous(): void { @@ -66,24 +73,30 @@ export class CookPageComponent implements OnInit { if(this.stepNum == 1) { this.firstStep = true; } else { - this.previousStep = this.steps[this.stepNum-2].getInstruction(); + this.previousStep = this.steps[this.stepNum-2].instructions; } - this.currentStep = this.steps[this.stepNum-1].getInstruction(); - this.nextStep = this.steps[this.stepNum].getInstruction(); - this.timeLeft = this.steps[this.stepNum-1].getTimer(); + this.currentStep = this.steps[this.stepNum-1].instructions; + this.nextStep = this.steps[this.stepNum].instructions; + this.timeLeft = this.steps[this.stepNum-1].timer; } hasTimer(): boolean { - if(this.steps[this.stepNum - 1].getTimer() > 0) + if(this.steps[this.stepNum-1].timer > 0) return true; else return false; } startTimer(): void { + console.log("timerStarted"); this.timerInterval = setInterval(() => { if(this.timeLeft > 0) { - this.timeLeft --; + this.timeHoursFirst = Math.floor(this.timeLeft/3600/10); + this.timeHoursSecond = Math.floor(this.timeLeft/3600%10); + this.timeMinutesFirst = Math.floor(this.timeLeft%3600/60/10); + this.timeMinutesSecond = Math.floor(this.timeLeft%3600/60%10); + this.timeSecondsFirst = Math.floor(this.timeLeft%3600%60/10); + this.timeSecondsSecond = Math.floor(this.timeLeft%3600%60%10); } else { clearInterval(this.timerInterval); -- cgit v1.1 From 34ceddd42d6e44f57f4697a254533872c53f4844 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Tue, 10 Dec 2019 19:34:30 -0500 Subject: Revert steps.instructions -> step.instruction For compatibility with backend JSON. --- recipeBuddy/src/app/cook-page/cook-page.component.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 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 9dfc605..3def7db 100644 --- a/recipeBuddy/src/app/cook-page/cook-page.component.ts +++ b/recipeBuddy/src/app/cook-page/cook-page.component.ts @@ -37,9 +37,9 @@ export class CookPageComponent implements OnInit { this.steps = recipe.steps; this.servingSize = recipe.servingSize; this.stepNum = 1; - this.currentStep = this.steps[this.stepNum-1].instructions; + this.currentStep = this.steps[this.stepNum-1].instruction; if(this.steps.length > 1) - this.nextStep = this.steps[this.stepNum].instructions; + this.nextStep = this.steps[this.stepNum].instruction; else this.lastStep = true; // this.timeLeft = this.steps[this.stepNum-1].timer; @@ -59,10 +59,10 @@ export class CookPageComponent implements OnInit { if(this.stepNum == this.steps.length) { this.lastStep = true; } else { - this.nextStep = this.steps[this.stepNum].instructions; + this.nextStep = this.steps[this.stepNum].instruction; } - this.previousStep = this.steps[this.stepNum-2].instructions; - this.currentStep = this.steps[this.stepNum-1].instructions; + this.previousStep = this.steps[this.stepNum-2].instruction; + this.currentStep = this.steps[this.stepNum-1].instruction; this.timeLeft = this.steps[this.stepNum-1].timer; } @@ -73,10 +73,10 @@ export class CookPageComponent implements OnInit { if(this.stepNum == 1) { this.firstStep = true; } else { - this.previousStep = this.steps[this.stepNum-2].instructions; + this.previousStep = this.steps[this.stepNum-2].instruction; } - this.currentStep = this.steps[this.stepNum-1].instructions; - this.nextStep = this.steps[this.stepNum].instructions; + this.currentStep = this.steps[this.stepNum-1].instruction; + this.nextStep = this.steps[this.stepNum].instruction; this.timeLeft = this.steps[this.stepNum-1].timer; } -- cgit v1.1 From b0bd782b6ff20ff874afc9ebf0b8ab9274ea2a09 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Tue, 10 Dec 2019 19:43:32 -0500 Subject: Fix removes testing value for timeLeft on step-card --- recipeBuddy/src/app/cook-page/cook-page.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 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 3def7db..a3a1dfe 100644 --- a/recipeBuddy/src/app/cook-page/cook-page.component.ts +++ b/recipeBuddy/src/app/cook-page/cook-page.component.ts @@ -42,8 +42,8 @@ export class CookPageComponent implements OnInit { this.nextStep = this.steps[this.stepNum].instruction; else this.lastStep = true; -// this.timeLeft = this.steps[this.stepNum-1].timer; - this.timeLeft = 88888; + + this.timeLeft = this.steps[this.stepNum-1].timer; this.timeHoursFirst = Math.floor(this.timeLeft/3600/10); this.timeHoursSecond = Math.floor(this.timeLeft/3600%10); this.timeMinutesFirst = Math.floor(this.timeLeft%3600/60/10); -- cgit v1.1