improved paste ingredient function to retain order and add to correct step
This commit is contained in:
parent
5e4cac52d6
commit
16d0fc38f9
@ -308,7 +308,7 @@
|
|||||||
size="sm"
|
size="sm"
|
||||||
class="ml-1 mb-1 mb-md-0"
|
class="ml-1 mb-1 mb-md-0"
|
||||||
@click="
|
@click="
|
||||||
paste_step = step.id
|
paste_step = step
|
||||||
$bvModal.show('id_modal_paste_ingredients')
|
$bvModal.show('id_modal_paste_ingredients')
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
@ -581,12 +581,14 @@
|
|||||||
<i class="fas fa-copy"></i>
|
<i class="fas fa-copy"></i>
|
||||||
{{ $t("Copy") }}
|
{{ $t("Copy") }}
|
||||||
</button>
|
</button>
|
||||||
<button type="button" class="dropdown-item" v-if="index > 0"
|
<button type="button" class="dropdown-item"
|
||||||
|
v-if="index > 0"
|
||||||
@click="moveIngredient(step, ingredient, index-1)">
|
@click="moveIngredient(step, ingredient, index-1)">
|
||||||
<i class="fas fa-arrow-up"></i>
|
<i class="fas fa-arrow-up"></i>
|
||||||
{{ $t("Up") }}
|
{{ $t("Up") }}
|
||||||
</button>
|
</button>
|
||||||
<button type="button" class="dropdown-item" v-if="index !== step.ingredients.length - 1"
|
<button type="button" class="dropdown-item"
|
||||||
|
v-if="index !== step.ingredients.length - 1"
|
||||||
@click="moveIngredient(step, ingredient, index+1)">
|
@click="moveIngredient(step, ingredient, index+1)">
|
||||||
<i class="fas fa-arrow-down"></i>
|
<i class="fas fa-arrow-down"></i>
|
||||||
{{ $t("Down") }}
|
{{ $t("Down") }}
|
||||||
@ -721,7 +723,7 @@
|
|||||||
<b-modal
|
<b-modal
|
||||||
id="id_modal_paste_ingredients"
|
id="id_modal_paste_ingredients"
|
||||||
v-bind:title="$t('ingredient_list')"
|
v-bind:title="$t('ingredient_list')"
|
||||||
@ok="appendIngredients"
|
@ok="appendIngredients(paste_step)"
|
||||||
@cancel="paste_ingredients = paste_step = undefined"
|
@cancel="paste_ingredients = paste_step = undefined"
|
||||||
@close="paste_ingredients = paste_step = undefined"
|
@close="paste_ingredients = paste_step = undefined"
|
||||||
>
|
>
|
||||||
@ -1210,29 +1212,33 @@ export default {
|
|||||||
energy: function () {
|
energy: function () {
|
||||||
return energyHeading()
|
return energyHeading()
|
||||||
},
|
},
|
||||||
appendIngredients: function () {
|
appendIngredients: function (step) {
|
||||||
let ing_list = this.paste_ingredients.split(/\r?\n/)
|
let ing_list = this.paste_ingredients.split(/\r?\n/)
|
||||||
let step = this.recipe.steps.findIndex((x) => x.id == this.paste_step)
|
step.ingredients_visible = true
|
||||||
let order = Math.max(...this.recipe.steps[step].ingredients.map((x) => x.order), -1) + 1
|
let parsed_ing_list = []
|
||||||
this.recipe.steps[step].ingredients_visible = true
|
let promises = []
|
||||||
ing_list.forEach((ing) => {
|
ing_list.forEach((ing) => {
|
||||||
if (ing.trim() !== "") {
|
if (ing.trim() !== "") {
|
||||||
this.genericPostAPI("api_ingredient_from_string", {text: ing}).then((result) => {
|
promises.push(this.genericPostAPI("api_ingredient_from_string", {text: ing}).then((result) => {
|
||||||
let unit = null
|
let unit = null
|
||||||
if (result.data.unit !== "" && result.data.unit !== null) {
|
if (result.data.unit !== "" && result.data.unit !== null) {
|
||||||
unit = {name: result.data.unit}
|
unit = {name: result.data.unit}
|
||||||
}
|
}
|
||||||
this.recipe.steps[step].ingredients.splice(order, 0, {
|
parsed_ing_list.push({
|
||||||
amount: result.data.amount,
|
amount: result.data.amount,
|
||||||
unit: unit,
|
unit: unit,
|
||||||
food: {name: result.data.food},
|
food: {name: result.data.food},
|
||||||
note: result.data.note,
|
note: result.data.note,
|
||||||
original_text: ing,
|
original_text: ing,
|
||||||
})
|
})
|
||||||
})
|
}))
|
||||||
order++
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Promise.allSettled(promises).then(() => {
|
||||||
|
ing_list.forEach(ing => {
|
||||||
|
step.ingredients.push(parsed_ing_list.find(x => x.original_text === ing))
|
||||||
|
})
|
||||||
|
})
|
||||||
},
|
},
|
||||||
duplicateIngredient: function (step, ingredient, new_index) {
|
duplicateIngredient: function (step, ingredient, new_index) {
|
||||||
delete ingredient.id
|
delete ingredient.id
|
||||||
|
Loading…
Reference in New Issue
Block a user