2024-01-14 02:12:19 +00:00
|
|
|
<template>
|
2024-01-14 06:20:21 +00:00
|
|
|
<div class="ingredient-add-box">
|
|
|
|
|
<p class="ingredient-line">
|
|
|
|
|
<ingredient-line :ingredient="ingredient"
|
|
|
|
|
:show-expanded="true"
|
|
|
|
|
@update-ingredient="updateIngredient"
|
|
|
|
|
@update-product-link="updateProduct"
|
|
|
|
|
@delete-item="deleteIngredient" />
|
|
|
|
|
</p>
|
|
|
|
|
<button @click="addIngredient(ingredient)">Add</button>
|
2024-01-14 02:12:19 +00:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import IngredientLine from './IngredientLine.vue';
|
|
|
|
|
import data from '@/data.js'
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'IngredientAddBox',
|
|
|
|
|
components: { IngredientLine },
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
ingredient: {
|
|
|
|
|
name: '',
|
|
|
|
|
quantity: '',
|
|
|
|
|
unit: '',
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
addIngredient() {
|
|
|
|
|
this.$emit('add-ingredient', this.ingredient);
|
|
|
|
|
this.ingredient = {
|
|
|
|
|
name: '',
|
|
|
|
|
quantity: '',
|
|
|
|
|
unit: '',
|
2024-01-14 06:20:21 +00:00
|
|
|
link: ''
|
2024-01-14 02:12:19 +00:00
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
updateProduct(ingredient, product_link) {
|
|
|
|
|
data.parseProduct(ingredient, product_link).then(product => {
|
|
|
|
|
ingredient.product = product
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
updateIngredient(ingredient, line) {
|
|
|
|
|
data.parseIngredients([line]).then(function(newIngredients) {
|
|
|
|
|
const newIngredient = newIngredients[0];
|
|
|
|
|
ingredient.line = line;
|
|
|
|
|
ingredient.name = newIngredient.name;
|
|
|
|
|
ingredient.quantity = newIngredient.quantity;
|
|
|
|
|
ingredient.unit = newIngredient.unit;
|
|
|
|
|
ingredient.preparation = newIngredient.preparation;
|
|
|
|
|
if (newIngredient.product) {
|
|
|
|
|
ingredient.product = newIngredient.product;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2024-01-14 06:20:21 +00:00
|
|
|
|
|
|
|
|
.ingredient-add-box {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ingredient-line {
|
|
|
|
|
flex: 1;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-14 02:12:19 +00:00
|
|
|
</style>
|