59 lines
1.6 KiB
Vue
59 lines
1.6 KiB
Vue
|
|
<template>
|
||
|
|
<div>
|
||
|
|
<ingredient-line :ingredient="ingredient"
|
||
|
|
@update-ingredient="updateIngredient"
|
||
|
|
@update-product-link="updateProduct"
|
||
|
|
@delete-item="deleteIngredient" />
|
||
|
|
</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: '',
|
||
|
|
};
|
||
|
|
},
|
||
|
|
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>
|
||
|
|
</style>
|