persist servings changes
This commit is contained in:
@ -76,12 +76,12 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="my-auto">
|
<div class="my-auto">
|
||||||
<span class="text-primary"
|
<span class="text-primary">
|
||||||
><b
|
<b>
|
||||||
><template v-if="recipe.servings_text === ''">{{ $t("Servings") }}</template
|
<template v-if="recipe.servings_text === ''">{{ $t("Servings") }}</template>
|
||||||
><template v-else>{{ recipe.servings_text }}</template></b
|
<template v-else>{{ recipe.servings_text }}</template>
|
||||||
></span
|
</b>
|
||||||
>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -200,8 +200,8 @@ export default {
|
|||||||
ingredient_factor: function () {
|
ingredient_factor: function () {
|
||||||
return this.servings / this.recipe.servings
|
return this.servings / this.recipe.servings
|
||||||
},
|
},
|
||||||
title() {
|
ingredient_count() {
|
||||||
return this.recipe?.steps?.map((x) => x?.ingredients).flat()
|
return this.recipe?.steps.map((x) => x.ingredients).flat().length
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
@ -209,17 +209,20 @@ export default {
|
|||||||
loading: true,
|
loading: true,
|
||||||
recipe: undefined,
|
recipe: undefined,
|
||||||
rootrecipe: undefined,
|
rootrecipe: undefined,
|
||||||
ingredient_count: 0,
|
|
||||||
servings: 1,
|
servings: 1,
|
||||||
|
servings_cache: {},
|
||||||
start_time: "",
|
start_time: "",
|
||||||
share_uid: window.SHARE_UID,
|
share_uid: window.SHARE_UID,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
servings(newVal, oldVal) {
|
||||||
|
this.servings_cache[this.recipe.id] = this.servings
|
||||||
|
},
|
||||||
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.loadRecipe(window.RECIPE_ID)
|
this.loadRecipe(window.RECIPE_ID)
|
||||||
this.$i18n.locale = window.CUSTOM_LOCALE
|
this.$i18n.locale = window.CUSTOM_LOCALE
|
||||||
console.log(this.recipe)
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
loadRecipe: function (recipe_id) {
|
loadRecipe: function (recipe_id) {
|
||||||
@ -227,12 +230,9 @@ export default {
|
|||||||
if (window.USER_SERVINGS !== 0) {
|
if (window.USER_SERVINGS !== 0) {
|
||||||
recipe.servings = window.USER_SERVINGS
|
recipe.servings = window.USER_SERVINGS
|
||||||
}
|
}
|
||||||
this.servings = recipe.servings
|
|
||||||
|
|
||||||
let total_time = 0
|
let total_time = 0
|
||||||
for (let step of recipe.steps) {
|
for (let step of recipe.steps) {
|
||||||
this.ingredient_count += step.ingredients.length
|
|
||||||
|
|
||||||
for (let ingredient of step.ingredients) {
|
for (let ingredient of step.ingredients) {
|
||||||
this.$set(ingredient, "checked", false)
|
this.$set(ingredient, "checked", false)
|
||||||
}
|
}
|
||||||
@ -247,6 +247,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.recipe = this.rootrecipe = recipe
|
this.recipe = this.rootrecipe = recipe
|
||||||
|
this.servings = this.servings_cache[this.rootrecipe.id] = recipe.servings
|
||||||
this.loading = false
|
this.loading = false
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -265,8 +266,10 @@ export default {
|
|||||||
quickSwitch: function (e) {
|
quickSwitch: function (e) {
|
||||||
if (e === -1) {
|
if (e === -1) {
|
||||||
this.recipe = this.rootrecipe
|
this.recipe = this.rootrecipe
|
||||||
|
this.servings = this.servings_cache[this.rootrecipe?.id ?? 1]
|
||||||
} else {
|
} else {
|
||||||
this.recipe = e
|
this.recipe = e
|
||||||
|
this.servings = this.servings_cache?.[e.id] ?? e.servings
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -83,7 +83,6 @@ export default {
|
|||||||
this.$emit("switch", recipe)
|
this.$emit("switch", recipe)
|
||||||
break
|
break
|
||||||
case "mealplan":
|
case "mealplan":
|
||||||
console.log("navigate to")
|
|
||||||
window.location.href = this.resolveDjangoUrl("view_recipe", recipe.id)
|
window.location.href = this.resolveDjangoUrl("view_recipe", recipe.id)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
@ -117,14 +116,21 @@ export default {
|
|||||||
.then((result) => {
|
.then((result) => {
|
||||||
let promises = []
|
let promises = []
|
||||||
result.data.forEach((mealplan) => {
|
result.data.forEach((mealplan) => {
|
||||||
this.recipe_list.push(mealplan?.recipe)
|
this.recipe_list.push({ ...mealplan?.recipe, servings: mealplan?.servings })
|
||||||
|
const serving_factor = (mealplan?.servings ?? mealplan?.recipe?.servings ?? 1) / (mealplan?.recipe?.servings ?? 1)
|
||||||
promises.push(
|
promises.push(
|
||||||
apiClient.relatedRecipe(mealplan?.recipe?.id, { query: { levels: 2 } }).then((r) => {
|
apiClient.relatedRecipe(mealplan?.recipe?.id, { query: { levels: 2 } }).then((r) => {
|
||||||
|
// scale all recipes to mealplan servings
|
||||||
|
r.data = r.data.map((x) => {
|
||||||
|
return { ...x, factor: serving_factor }
|
||||||
|
})
|
||||||
this.recipe_list = [...this.recipe_list, ...r.data]
|
this.recipe_list = [...this.recipe_list, ...r.data]
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
return Promise.all(promises).then(() => {
|
return Promise.all(promises).then(() => {
|
||||||
|
console.log(this.recipe_list)
|
||||||
let promises = []
|
let promises = []
|
||||||
let dedup = []
|
let dedup = []
|
||||||
this.recipe_list.forEach((recipe) => {
|
this.recipe_list.forEach((recipe) => {
|
||||||
@ -132,6 +138,8 @@ export default {
|
|||||||
dedup.push(recipe.id)
|
dedup.push(recipe.id)
|
||||||
promises.push(
|
promises.push(
|
||||||
apiClient.retrieveRecipe(recipe.id).then((result) => {
|
apiClient.retrieveRecipe(recipe.id).then((result) => {
|
||||||
|
// scale all recipes to mealplan servings
|
||||||
|
result.data.servings = recipe?.servings ?? result.data.servings * (recipe?.factor ?? 1)
|
||||||
this.recipes.push(result.data)
|
this.recipes.push(result.data)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -108,7 +108,7 @@ export default {
|
|||||||
this.shop = false // don't check any boxes until user selects a shopping list to edit
|
this.shop = false // don't check any boxes until user selects a shopping list to edit
|
||||||
if (count_shopping_ingredient >= 1) {
|
if (count_shopping_ingredient >= 1) {
|
||||||
this.shopping_status = true // ingredient is in the shopping list - probably (but not definitely, this ingredient)
|
this.shopping_status = true // ingredient is in the shopping list - probably (but not definitely, this ingredient)
|
||||||
} else if (this.ingredient.food.shopping) {
|
} else if (this.ingredient?.food?.shopping) {
|
||||||
this.shopping_status = null // food is in the shopping list, just not for this ingredient/recipe
|
this.shopping_status = null // food is in the shopping list, just not for this ingredient/recipe
|
||||||
} else {
|
} else {
|
||||||
// food is not in any shopping list
|
// food is not in any shopping list
|
||||||
@ -123,7 +123,7 @@ export default {
|
|||||||
if (count_shopping_ingredient >= 1) {
|
if (count_shopping_ingredient >= 1) {
|
||||||
// ingredient is in this shopping list (not entirely sure how this could happen?)
|
// ingredient is in this shopping list (not entirely sure how this could happen?)
|
||||||
this.shopping_status = true
|
this.shopping_status = true
|
||||||
} else if (count_shopping_ingredient == 0 && this.ingredient.food.shopping) {
|
} else if (count_shopping_ingredient == 0 && this.ingredient?.food?.shopping) {
|
||||||
// food is in the shopping list, just not for this ingredient/recipe
|
// food is in the shopping list, just not for this ingredient/recipe
|
||||||
this.shopping_status = null
|
this.shopping_status = null
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user