diff --git a/cookbook/views/views.py b/cookbook/views/views.py index 8a1462a2..6fefc11a 100644 --- a/cookbook/views/views.py +++ b/cookbook/views/views.py @@ -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 diff --git a/vue/src/apps/RecipeEditView/RecipeEditView.vue b/vue/src/apps/RecipeEditView/RecipeEditView.vue index 0bd118fa..14ccd0c3 100644 --- a/vue/src/apps/RecipeEditView/RecipeEditView.vue +++ b/vue/src/apps/RecipeEditView/RecipeEditView.vue @@ -210,6 +210,18 @@ {{ $t("File") }} + + {{ $t("paste_ingredients") }} + @@ -516,6 +528,17 @@ + + + + + @@ -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++ + } + }) + }, }, } diff --git a/vue/src/locales/en.json b/vue/src/locales/en.json index 9bf72a48..8942d03e 100644 --- a/vue/src/locales/en.json +++ b/vue/src/locales/en.json @@ -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" }