refactor IngredientComponent, move shopping logic to card
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div>
|
||||
<b-modal :id="`shopping_${this.modal_id}`" hide-footer @show="loadRecipe">
|
||||
<b-modal :id="`shopping_${this.modal_id}`" @show="loadRecipe">
|
||||
<template v-slot:modal-title
|
||||
><h4>{{ $t("Add_Servings_to_Shopping", { servings: recipe_servings }) }}</h4></template
|
||||
>
|
||||
@ -16,10 +16,11 @@
|
||||
:recipe="recipe.id"
|
||||
:ingredient_factor="ingredient_factor"
|
||||
:servings="recipe_servings"
|
||||
:show_shopping="true"
|
||||
:add_shopping_mode="true"
|
||||
:recipe_list="list_recipe"
|
||||
:header="false"
|
||||
@add-to-shopping="addShopping($event)"
|
||||
@starting-cart="add_shopping = $event"
|
||||
/>
|
||||
</b-collapse>
|
||||
<!-- eslint-disable vue/no-v-for-template-key-on-child -->
|
||||
@ -34,10 +35,11 @@
|
||||
:recipe="r.recipe.id"
|
||||
:ingredient_factor="ingredient_factor"
|
||||
:servings="recipe_servings"
|
||||
:show_shopping="true"
|
||||
:add_shopping_mode="true"
|
||||
:recipe_list="list_recipe"
|
||||
:header="false"
|
||||
@add-to-shopping="addShopping($event)"
|
||||
@starting-cart="add_shopping = [...add_shopping, ...$event]"
|
||||
/>
|
||||
</b-collapse>
|
||||
</b-card>
|
||||
@ -46,18 +48,20 @@
|
||||
</b-card>
|
||||
</div>
|
||||
|
||||
<b-input-group class="my-3">
|
||||
<b-input-group-prepend is-text>
|
||||
{{ $t("Servings") }}
|
||||
</b-input-group-prepend>
|
||||
<template #modal-footer="">
|
||||
<b-input-group class="mr-3">
|
||||
<b-input-group-prepend is-text>
|
||||
{{ $t("Servings") }}
|
||||
</b-input-group-prepend>
|
||||
|
||||
<b-form-spinbutton min="1" v-model="recipe_servings" inline style="height: 3em"></b-form-spinbutton>
|
||||
<b-form-spinbutton min="1" v-model="recipe_servings" inline style="height: 3em"></b-form-spinbutton>
|
||||
|
||||
<b-input-group-append>
|
||||
<b-button variant="secondary" @click="$bvModal.hide(`shopping_${modal_id}`)">{{ $t("Cancel") }} </b-button>
|
||||
<b-button variant="success" @click="saveShopping">{{ $t("Save") }} </b-button>
|
||||
</b-input-group-append>
|
||||
</b-input-group>
|
||||
<b-input-group-append>
|
||||
<b-button variant="secondary" @click="$bvModal.hide(`shopping_${modal_id}`)">{{ $t("Cancel") }} </b-button>
|
||||
<b-button variant="success" @click="saveShopping">{{ $t("Save") }} </b-button>
|
||||
</b-input-group-append>
|
||||
</b-input-group>
|
||||
</template>
|
||||
</b-modal>
|
||||
</div>
|
||||
</template>
|
||||
@ -81,6 +85,7 @@ export default {
|
||||
servings: { type: Number, default: undefined },
|
||||
modal_id: { required: true, type: Number },
|
||||
mealplan: { type: Number, default: undefined },
|
||||
list_recipe: { type: Number, default: undefined },
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
@ -121,14 +126,6 @@ export default {
|
||||
this.steps = result.data.steps
|
||||
// ALERT: this will all break if ingredients are re-used between recipes
|
||||
// ALERT: this also doesn't quite work right if the same recipe appears multiple time in the related recipes
|
||||
this.add_shopping = [
|
||||
...this.add_shopping,
|
||||
...this.steps
|
||||
.map((x) => x.ingredients)
|
||||
.flat()
|
||||
.filter((x) => !x?.food?.food_onhand)
|
||||
.map((x) => x.id),
|
||||
]
|
||||
if (!this.recipe_servings) {
|
||||
this.recipe_servings = result.data?.servings
|
||||
}
|
||||
@ -155,18 +152,20 @@ export default {
|
||||
})
|
||||
return Promise.all(promises)
|
||||
})
|
||||
.then(() => {
|
||||
this.add_shopping = [
|
||||
...this.add_shopping,
|
||||
...this.related_recipes
|
||||
.map((x) => x.steps)
|
||||
.flat()
|
||||
.map((x) => x.ingredients)
|
||||
.flat()
|
||||
.filter((x) => !x.food.override_ignore)
|
||||
.map((x) => x.id),
|
||||
]
|
||||
})
|
||||
// .then(() => {
|
||||
// if (!this.list_recipe) {
|
||||
// this.add_shopping = [
|
||||
// ...this.add_shopping,
|
||||
// ...this.related_recipes
|
||||
// .map((x) => x.steps)
|
||||
// .flat()
|
||||
// .map((x) => x.ingredients)
|
||||
// .flat()
|
||||
// .filter((x) => !x.food.override_ignore)
|
||||
// .map((x) => x.id),
|
||||
// ]
|
||||
// }
|
||||
// })
|
||||
})
|
||||
},
|
||||
addShopping: function (e) {
|
||||
@ -183,6 +182,7 @@ export default {
|
||||
ingredients: this.add_shopping,
|
||||
servings: this.recipe_servings,
|
||||
mealplan: this.mealplan,
|
||||
list_recipe: this.list_recipe,
|
||||
}
|
||||
let apiClient = new ApiApiFactory()
|
||||
apiClient
|
||||
|
Reference in New Issue
Block a user