blob: f114634f93a0c970e3a32ea2138eb7b0172c63b8 (
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
import {Component, OnInit} from '@angular/core';
import {Recipe} from '../DataModels/recipe';
import {Step} from '../DataModels/step';
import {RecipePassService} from '../recipePass/recipe-pass.service'
@Component({
selector: 'app-cook-page',
templateUrl: './cook-page.component.html',
styleUrls: ['./cook-page.component.css'],
})
export class CookPageComponent implements OnInit {
steps: Step[];
stepNum: number;
firstStep: boolean = true;
lastStep: boolean = false;
previousStep: string;
currentStep: string;
nextStep: string;
timeLeft: number;
timerInterval;
constructor(private recipePass: RecipePassService){}
ngOnInit() {
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.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.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 {
this.timerInterval = setInterval(() => {
if(this.timeLeft > 0) {
this.timeLeft --;
}
else {
clearInterval(this.timerInterval);
}
}, 1000)
}
}
|