8
8
<div class =' meta' >
9
9
<h2 >{{ $store.state.recipe.name }}</h2 >
10
10
<div class =" details" >
11
- <p v-if =" keywords.length" >
12
- <ul v-if =" keywords.length" >
13
- <RecipeKeyword v-for =" (keyword,idx) in keywords" :key =" 'keyw'+idx" :name =" keyword" :title =" t('cookbook', 'Search recipes with this keyword')" v-on:keyword-clicked =" keywordClicked(keyword)" />
11
+ <p v-if =" recipe. keywords.length" >
12
+ <ul v-if =" recipe. keywords.length" >
13
+ <RecipeKeyword v-for =" (keyword,idx) in recipe. keywords" :key =" 'keyw'+idx" :name =" keyword" :title =" t('cookbook', 'Search recipes with this keyword')" v-on:keyword-clicked =" keywordClicked(keyword)" />
14
14
</ul >
15
15
</p >
16
16
17
17
<p class =" dates" >
18
18
<span v-if =" showCreatedDate" class =" date" :title =" t('cookbook', 'Date created')" >
19
19
<span class =" icon-calendar-dark date-icon" />
20
- <span class =" date-text" >{{ dateCreated }}</span >
20
+ <span class =" date-text" >{{ recipe. dateCreated }}</span >
21
21
</span >
22
22
<span v-if =" showModifiedDate" class =" date" :title =" t('cookbook', 'Last modified')" >
23
23
<span class =" icon-rename date-icon" />
24
- <span class =" date-text" >{{ dateModified }}</span >
24
+ <span class =" date-text" >{{ recipe. dateModified }}</span >
25
25
</span >
26
26
</p >
27
27
32
32
<p ><strong >{{ t('cookbook', 'Servings') }}: </strong >{{ $store.state.recipe.recipeYield }}</p >
33
33
</div >
34
34
<div class =" times" >
35
- <RecipeTimer v-if =" timerPrep" :value =" timerPrep" :phase =" 'prep'" :timer =" false" :label =" 'Preparation time'" />
36
- <RecipeTimer v-if =" timerCook" :value =" timerCook" :phase =" 'prep'" :timer =" true" :label =" 'Cooking time'" />
37
- <RecipeTimer v-if =" timerTotal" :value =" timerTotal" :phase =" 'total'" :timer =" false" :label =" 'Total time'" />
35
+ <RecipeTimer v-if =" recipe. timerPrep" :value =" recipe. timerPrep" :phase =" 'prep'" :timer =" false" :label =" 'Preparation time'" />
36
+ <RecipeTimer v-if =" recipe. timerCook" :value =" recipe. timerCook" :phase =" 'prep'" :timer =" true" :label =" 'Cooking time'" />
37
+ <RecipeTimer v-if =" recipe. timerTotal" :value =" recipe. timerTotal" :phase =" 'total'" :timer =" false" :label =" 'Total time'" />
38
38
</div >
39
39
</div >
40
40
</div >
43
43
<section >
44
44
<aside >
45
45
<section >
46
- <h3 v-if =" ingredients.length" >{{ t('cookbook', 'Ingredients') }}</h3 >
47
- <ul v-if =" ingredients.length" >
48
- <RecipeIngredient v-for =" (ingredient,idx) in ingredients" :key =" 'ingr'+idx" :ingredient =" ingredient" :recipeIngredientsHaveSubgroups =" recipeIngredientsHaveSubgroups" />
46
+ <h3 v-if =" recipe. ingredients.length" >{{ t('cookbook', 'Ingredients') }}</h3 >
47
+ <ul v-if =" recipe. ingredients.length" >
48
+ <RecipeIngredient v-for =" (ingredient,idx) in recipe. ingredients" :key =" 'ingr'+idx" :ingredient =" ingredient" :recipeIngredientsHaveSubgroups =" recipeIngredientsHaveSubgroups" />
49
49
</ul >
50
50
</section >
51
51
52
52
<section >
53
- <h3 v-if =" tools.length" >{{ t('cookbook', 'Tools') }}</h3 >
54
- <ul v-if =" tools.length" >
55
- <RecipeTool v-for =" (tool,idx) in tools" :key =" 'tool'+idx" :tool =" tool" />
53
+ <h3 v-if =" recipe. tools.length" >{{ t('cookbook', 'Tools') }}</h3 >
54
+ <ul v-if =" recipe. tools.length" >
55
+ <RecipeTool v-for =" (tool,idx) in recipe. tools" :key =" 'tool'+idx" :tool =" tool" />
56
56
</ul >
57
57
</section >
58
58
59
59
<section v-if =" showNutritions" >
60
60
<h3 >{{ t('cookbook', 'Nutrition Information') }}</h3 >
61
61
<ul class =" nutrition-items" >
62
- <recipe-nutrition-info-item v-if =" ('servingSize' in nutrition) && !isNullOrEmpty(nutrition['servingSize'])" :title =" t('cookbook', 'Serving Size')" :data =" nutrition['servingSize']" />
63
- <recipe-nutrition-info-item v-if =" ('calories' in nutrition) && !isNullOrEmpty(nutrition['calories'])" :title =" t('cookbook', 'Energy')" :data =" nutrition['calories']" />
64
- <recipe-nutrition-info-item v-if =" ('sugarContent' in nutrition) && !isNullOrEmpty(nutrition['sugarContent'])" :title =" t('cookbook', 'Sugar')" :data =" nutrition['sugarContent']" />
65
- <recipe-nutrition-info-item v-if =" ('carbohydrateContent' in nutrition) && !isNullOrEmpty(nutrition['carbohydrateContent'])" :title =" t('cookbook', 'Carbohydrate')" :data =" nutrition['carbohydrateContent']" />
66
- <recipe-nutrition-info-item v-if =" ('cholesterolContent' in nutrition) && !isNullOrEmpty(nutrition['cholesterolContent'])" :title =" t('cookbook', 'Cholesterol')" :data =" nutrition['cholesterolContent']" />
67
- <recipe-nutrition-info-item v-if =" ('fiberContent' in nutrition) && !isNullOrEmpty(nutrition['fiberContent'])" :title =" t('cookbook', 'Fiber')" :data =" nutrition['fiberContent']" />
68
- <recipe-nutrition-info-item v-if =" ('proteinContent' in nutrition) && !isNullOrEmpty(nutrition['proteinContent'])" :title =" t('cookbook', 'Protein')" :data =" nutrition['proteinContent']" />
69
- <recipe-nutrition-info-item v-if =" ('sodiumContent' in nutrition) && !isNullOrEmpty(nutrition['sodiumContent'])" :title =" t('cookbook', 'Sodium')" :data =" nutrition['sodiumContent']" />
70
- <recipe-nutrition-info-item v-if =" ('fatContent' in nutrition) && !isNullOrEmpty(nutrition['fatContent'])" :title =" t('cookbook', 'Fat total')" :data =" nutrition['fatContent']" />
71
- <recipe-nutrition-info-item v-if =" ('saturatedFatContent' in nutrition) && !isNullOrEmpty(nutrition['saturatedFatContent'])" :title =" t('cookbook', 'Saturated Fat')" :data =" nutrition['saturatedFatContent']" />
72
- <recipe-nutrition-info-item v-if =" ('unsaturatedFatContent' in nutrition) && !isNullOrEmpty(nutrition['unsaturatedFatContent'])" :title =" t('cookbook', 'Unsaturated Fat')" :data =" nutrition['unsaturatedFatContent']" />
73
- <recipe-nutrition-info-item v-if =" ('transFatContent' in nutrition) && !isNullOrEmpty(nutrition['transFatContent'])" :title =" t('cookbook', 'Trans Fat')" :data =" nutrition['transFatContent']" />
62
+ <recipe-nutrition-info-item v-if =" ('servingSize' in recipe. nutrition) && !isNullOrEmpty(recipe. nutrition['servingSize'])" :title =" t('cookbook', 'Serving Size')" :data =" recipe. nutrition['servingSize']" />
63
+ <recipe-nutrition-info-item v-if =" ('calories' in recipe. nutrition) && !isNullOrEmpty(recipe. nutrition['calories'])" :title =" t('cookbook', 'Energy')" :data =" recipe. nutrition['calories']" />
64
+ <recipe-nutrition-info-item v-if =" ('sugarContent' in recipe. nutrition) && !isNullOrEmpty(recipe. nutrition['sugarContent'])" :title =" t('cookbook', 'Sugar')" :data =" recipe. nutrition['sugarContent']" />
65
+ <recipe-nutrition-info-item v-if =" ('carbohydrateContent' in recipe. nutrition) && !isNullOrEmpty(recipe. nutrition['carbohydrateContent'])" :title =" t('cookbook', 'Carbohydrate')" :data =" recipe. nutrition['carbohydrateContent']" />
66
+ <recipe-nutrition-info-item v-if =" ('cholesterolContent' in recipe. nutrition) && !isNullOrEmpty(recipe. nutrition['cholesterolContent'])" :title =" t('cookbook', 'Cholesterol')" :data =" recipe. nutrition['cholesterolContent']" />
67
+ <recipe-nutrition-info-item v-if =" ('fiberContent' in recipe. nutrition) && !isNullOrEmpty(recipe. nutrition['fiberContent'])" :title =" t('cookbook', 'Fiber')" :data =" recipe. nutrition['fiberContent']" />
68
+ <recipe-nutrition-info-item v-if =" ('proteinContent' in recipe. nutrition) && !isNullOrEmpty(recipe. nutrition['proteinContent'])" :title =" t('cookbook', 'Protein')" :data =" recipe. nutrition['proteinContent']" />
69
+ <recipe-nutrition-info-item v-if =" ('sodiumContent' in recipe. nutrition) && !isNullOrEmpty(recipe. nutrition['sodiumContent'])" :title =" t('cookbook', 'Sodium')" :data =" recipe. nutrition['sodiumContent']" />
70
+ <recipe-nutrition-info-item v-if =" ('fatContent' in recipe. nutrition) && !isNullOrEmpty(recipe. nutrition['fatContent'])" :title =" t('cookbook', 'Fat total')" :data =" recipe. nutrition['fatContent']" />
71
+ <recipe-nutrition-info-item v-if =" ('saturatedFatContent' in recipe. nutrition) && !isNullOrEmpty(recipe. nutrition['saturatedFatContent'])" :title =" t('cookbook', 'Saturated Fat')" :data =" recipe. nutrition['saturatedFatContent']" />
72
+ <recipe-nutrition-info-item v-if =" ('unsaturatedFatContent' in recipe. nutrition) && !isNullOrEmpty(recipe. nutrition['unsaturatedFatContent'])" :title =" t('cookbook', 'Unsaturated Fat')" :data =" recipe. nutrition['unsaturatedFatContent']" />
73
+ <recipe-nutrition-info-item v-if =" ('transFatContent' in recipe. nutrition) && !isNullOrEmpty(recipe. nutrition['transFatContent'])" :title =" t('cookbook', 'Trans Fat')" :data =" recipe. nutrition['transFatContent']" />
74
74
</ul >
75
75
</section >
76
76
</aside >
77
- <main v-if =" instructions.length" >
77
+ <main v-if =" recipe. instructions.length" >
78
78
<h3 >{{ t('cookbook', 'Instructions') }}</h3 >
79
79
<ol class =" instructions" >
80
- <RecipeInstruction v-for =" (instruction,idx) in instructions" :key =" 'instr'+idx" :instruction =" instruction" />
80
+ <RecipeInstruction v-for =" (instruction,idx) in recipe. instructions" :key =" 'instr'+idx" :instruction =" instruction" />
81
81
</ol >
82
82
</main >
83
83
</section >
@@ -111,33 +111,93 @@ export default {
111
111
},
112
112
data () {
113
113
return {
114
- headerPrefix: " ## " ,
115
- // Own properties
116
- ingredients: [],
117
- instructions: [],
118
- keywords: [],
119
- timerCook: null ,
120
- timerPrep: null ,
121
- timerTotal: null ,
122
- tools: [],
123
- dateCreated: null ,
124
- dateModified: null ,
125
- nutrition: null
114
+ headerPrefix: " ## "
126
115
}
127
116
},
128
117
computed: {
118
+ recipe : function () {
119
+ let recipe = {
120
+ ingredients: [],
121
+ instructions: [],
122
+ keywords: [],
123
+ timerCook: null ,
124
+ timerPrep: null ,
125
+ timerTotal: null ,
126
+ tools: [],
127
+ dateCreated: null ,
128
+ dateModified: null ,
129
+ nutrition: null
130
+ }
131
+
132
+ if (this .$store .state .recipe .recipeIngredient ) {
133
+ recipe .ingredients = Object .values (this .$store .state .recipe .recipeIngredient )
134
+ }
135
+
136
+ if (this .$store .state .recipe .recipeInstructions ) {
137
+ recipe .instructions = Object .values (this .$store .state .recipe .recipeInstructions )
138
+ }
139
+
140
+ if (this .$store .state .recipe .keywords ) {
141
+ recipe .keywords = String (this .$store .state .recipe .keywords ).split (' ,' )
142
+ }
143
+
144
+ if (this .$store .state .recipe .cookTime ) {
145
+ let cookT = this .$store .state .recipe .cookTime .match (/ PT(\d +? )H(\d +? )M/ )
146
+ recipe .timerCook = { hours: parseInt (cookT[1 ]), minutes: parseInt (cookT[2 ]) }
147
+ }
148
+
149
+ if (this .$store .state .recipe .prepTime ) {
150
+ let prepT = this .$store .state .recipe .prepTime .match (/ PT(\d +? )H(\d +? )M/ )
151
+ recipe .timerPrep = { hours: parseInt (prepT[1 ]), minutes: parseInt (prepT[2 ]) }
152
+ }
153
+
154
+ if (this .$store .state .recipe .totalTime ) {
155
+ let totalT = this .$store .state .recipe .totalTime .match (/ PT(\d +? )H(\d +? )M/ )
156
+ recipe .timerTotal = { hours: parseInt (totalT[1 ]), minutes: parseInt (totalT[2 ]) }
157
+ }
158
+
159
+ if (this .$store .state .recipe .tool ) {
160
+ recipe .tools = this .$store .state .recipe .tool
161
+ }
162
+
163
+ if (this .$store .state .recipe .dateCreated ) {
164
+ let date = this .parseDateTime (this .$store .state .recipe .dateCreated )
165
+ recipe .dateCreated = (date != null ? date .format (' L, LT' ).toString () : null )
166
+ }
167
+
168
+ if (this .$store .state .recipe .dateModified ) {
169
+ let date = this .parseDateTime (this .$store .state .recipe .dateModified )
170
+ recipe .dateModified = (date != null ? date .format (' L, LT' ).toString () : null )
171
+ }
172
+ if (this .$store .state .recipe .nutrition ) {
173
+ if ( this .$store .state .recipe .nutrition instanceof Array ) {
174
+ this .$store .state .recipe .nutrition = {}
175
+ }
176
+ } else {
177
+ this .$store .state .recipe .nutrition = {}
178
+ }
179
+ recipe .nutrition = this .$store .state .recipe .nutrition
180
+
181
+ return recipe
182
+ },
129
183
recipeIngredientsHaveSubgroups : function () {
130
- if (this .ingredients && this .ingredients .length > 0 ) {
131
- for (let idx = 0 ; idx < this .ingredients .length ; ++ idx) {
132
- if (this .ingredients [idx].startsWith (this .headerPrefix )) {
184
+ if (this .recipe . ingredients && this . recipe .ingredients .length > 0 ) {
185
+ for (let idx = 0 ; idx < this .recipe . ingredients .length ; ++ idx) {
186
+ if (this .recipe . ingredients [idx].startsWith (this .headerPrefix )) {
133
187
return true
134
188
}
135
189
}
136
190
}
137
191
return false
138
192
},
193
+ showCreatedDate : function () {
194
+ if (! this .recipe .dateCreated ) {
195
+ return false
196
+ }
197
+ return true
198
+ },
139
199
showModifiedDate : function () {
140
- if (! this .dateModified ) {
200
+ if (! this .recipe . dateModified ) {
141
201
return false
142
202
}
143
203
else if ( this .$store .state .recipe .dateCreated
@@ -148,13 +208,10 @@ export default {
148
208
}
149
209
return true
150
210
},
151
- showCreatedDate : function () {
152
- if (! this .dateCreated ) {
153
- return false
154
- }
155
- return true
156
- },
157
- showNutritions : function () { return this .nutrition && ! (this .nutrition instanceof Array ) && Object .keys (this .nutrition ).length > 0 }
211
+ showNutritions : function () {
212
+ return this .recipe .nutrition && ! (this .recipe .nutrition instanceof Array )
213
+ && Object .keys (this .recipe .nutrition ).length > 0
214
+ }
158
215
},
159
216
methods: {
160
217
isNullOrEmpty : function (str ) {
@@ -203,55 +260,6 @@ export default {
203
260
// Store recipe data in vuex
204
261
$this .$store .dispatch (' setRecipe' , { recipe: recipe })
205
262
206
- if ($this .$store .state .recipe .recipeIngredient ) {
207
- $this .ingredients = Object .values ($this .$store .state .recipe .recipeIngredient )
208
- }
209
-
210
- if ($this .$store .state .recipe .recipeInstructions ) {
211
- $this .instructions = Object .values ($this .$store .state .recipe .recipeInstructions )
212
- }
213
-
214
- if ($this .$store .state .recipe .keywords ) {
215
- $this .keywords = String ($this .$store .state .recipe .keywords ).split (' ,' )
216
- }
217
-
218
- if ($this .$store .state .recipe .cookTime ) {
219
- let cookT = $this .$store .state .recipe .cookTime .match (/ PT(\d +? )H(\d +? )M/ )
220
- $this .timerCook = { hours: parseInt (cookT[1 ]), minutes: parseInt (cookT[2 ]) }
221
- }
222
-
223
- if ($this .$store .state .recipe .prepTime ) {
224
- let prepT = $this .$store .state .recipe .prepTime .match (/ PT(\d +? )H(\d +? )M/ )
225
- $this .timerPrep = { hours: parseInt (prepT[1 ]), minutes: parseInt (prepT[2 ]) }
226
- }
227
-
228
- if ($this .$store .state .recipe .totalTime ) {
229
- let totalT = $this .$store .state .recipe .totalTime .match (/ PT(\d +? )H(\d +? )M/ )
230
- $this .timerTotal = { hours: parseInt (totalT[1 ]), minutes: parseInt (totalT[2 ]) }
231
- }
232
-
233
- if ($this .$store .state .recipe .tool ) {
234
- $this .tools = $this .$store .state .recipe .tool
235
- }
236
-
237
- if ($this .$store .state .recipe .dateCreated ) {
238
- let date = $this .parseDateTime ($this .$store .state .recipe .dateCreated )
239
- $this .dateCreated = (date != null ? date .format (' L, LT' ).toString () : null )
240
- }
241
-
242
- if ($this .$store .state .recipe .dateModified ) {
243
- let date = $this .parseDateTime ($this .$store .state .recipe .dateModified )
244
- $this .dateModified = (date != null ? date .format (' L, LT' ).toString () : null )
245
- }
246
- if ($this .$store .state .recipe .nutrition ) {
247
- if ( $this .$store .state .recipe .nutrition instanceof Array ) {
248
- $this .$store .state .recipe .nutrition = {}
249
- }
250
- } else {
251
- $this .$store .state .recipe .nutrition = {}
252
- }
253
- $this .nutrition = $this .$store .state .recipe .nutrition
254
-
255
263
// Always set the active page last!
256
264
$this .$store .dispatch (' setPage' , { page: ' recipe' })
257
265
})
0 commit comments