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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { FormBuilder } from '@angular/forms';
import { FormArray } from '@angular/forms';
import { Recipe } from '../DataModels/recipe';
import { Ingredient } from '../DataModels/ingredient'
import { Step } from '../DataModels/step';
import { BackendService } from '../REST_service/backend.service';
@Component({
selector: 'app-add-recipe',
templateUrl: './add-recipe.component.html',
styleUrls: ['./add-recipe.component.css']
})
export class AddRecipeComponent {
recipeForm = this.fb.group({
recipeName: [''],
desc: [''],
ingredients: this.fb.array([
this.fb.group({
ingrName: [''],
amount: [''],
units: ['']
})
]),
steps: this.fb.array([
this.fb.group({
instruct: [''],
timer: ['']
})
]),
servingSize: [''],
cookTime: [''],
tags: [''],
photos: ['']
});
constructor(private fb: FormBuilder,
private restService: BackendService
) { }
ngOnInit() {
}
get ingredients() {
return this.recipeForm.get('ingredients') as FormArray;
}
addIngredient() {
this.ingredients.push(
this.fb.group({
ingrName: [''],
amount: [''],
units: ['']
})
);
}
get steps() {
return this.recipeForm.get('steps') as FormArray;
}
addStep() {
this.steps.push(
this.fb.group({
instruct: [''],
timer: ['']
})
);
}
onSubmit() {
console.log('In Submit')
var formData = this.recipeForm.value;
var ingredients = []
var i;
for (i = 0; i < formData.ingredients.length; i++) {
ingredients.push(new Ingredient(formData.ingredients[0].ingrName,
formData.ingredients[0].amount,
formData.ingredients[0].unit,
""
));
}
var steps = []
for (i = 0; i < formData.ingredients.length; i++) {
steps.push(new Step(formData.steps[0].instruct,
formData.steps[0].timer
));
}
var recipe = new Recipe (0, //id
formData.recipeName, //name
formData.desc, //description
ingredients, //ingredients
steps, //steps
formData.servingSize, //servingSize
formData.cookTime, //cookTime
0, //timesCooked
0, //rating
formData.tags, //tags
formData.photos //photos
);
console.log(JSON.stringify(recipe))
}
}
|