Merge pull request #1538 from smilerz/feature/paste_ingredients

paste list of ingredients
This commit is contained in:
vabene1111 2022-02-17 10:54:25 +01:00 committed by GitHub
commit f77b45725b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 2 deletions

View File

@ -12,6 +12,7 @@ from django.contrib.auth.models import Group
from django.contrib.auth.password_validation import validate_password
from django.core.exceptions import ValidationError
from django.db.models import Avg, Q, Sum
from django.db.models.functions import Lower
from django.http import HttpResponseRedirect, JsonResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse, reverse_lazy

View File

@ -210,6 +210,18 @@
<b-button pill variant="primary" size="sm" class="ml-1" @click="step.file_visible = true" v-if="!step.file_visible">
<i class="fas fa-plus-circle"></i> {{ $t("File") }}
</b-button>
<b-button
pill
variant="primary"
size="sm"
class="ml-1"
@click="
paste_step = step.id
$bvModal.show('id_modal_paste_ingredients')
"
>
<i class="fas fa-plus-circle"></i> {{ $t("paste_ingredients") }}
</b-button>
</div>
</div>
@ -516,6 +528,17 @@
</draggable>
</b-modal>
<!-- modal for pasting list of ingredients -->
<b-modal
id="id_modal_paste_ingredients"
v-bind:title="$t('ingredient_list')"
@ok="appendIngredients"
@cancel="paste_ingredients = paste_step = undefined"
@close="paste_ingredients = paste_step = undefined"
>
<b-form-textarea id="paste_ingredients" v-model="paste_ingredients" :placeholder="$t('paste_ingredients_placeholder')" rows="10"></b-form-textarea>
</b-modal>
<!-- form to create files on the fly -->
<generic-modal-form :model="Models.USERFILE" :action="Actions.CREATE" :show="show_file_create" @finish-action="fileCreated" />
</div>
@ -574,7 +597,8 @@ export default {
recipes_loading: false,
message: "",
options_limit: 25,
paste_ingredients: undefined,
paste_step: undefined,
show_file_create: false,
step_for_file_create: undefined,
}
@ -942,6 +966,29 @@ export default {
energy: function () {
return energyHeading()
},
appendIngredients: function () {
let ing_list = this.paste_ingredients.split(/\r?\n/)
let step = this.recipe.steps.findIndex((x) => x.id == this.paste_step)
let order = Math.max(...this.recipe.steps[step].ingredients.map((x) => x.order), -1) + 1
this.recipe.steps[step].ingredients_visible = true
ing_list.forEach((ing) => {
if (ing.trim() !== "") {
this.genericPostAPI("api_ingredient_from_string", { text: ing }).then((result) => {
let unit = null
if (result.data.unit !== "") {
unit = { name: result.data.unit }
}
this.recipe.steps[step].ingredients.splice(order, 0, {
amount: result.data.amount,
unit: unit,
food: { name: result.data.food },
note: result.data.note,
})
})
order++
}
})
},
},
}
</script>

View File

@ -296,5 +296,8 @@
"food_recipe_help": "Linking a recipe here will include the linked recipe in any other recipe that use this food",
"Foods": "Foods",
"review_shopping": "Review shopping entries before saving",
"view_recipe": "View Recipe"
"view_recipe": "View Recipe",
"paste_ingredients_placeholder": "Paste ingredient list here...",
"paste_ingredients": "Paste Ingredients",
"ingredient_list": "Ingredient List"
}