From da4abcfce2bc6168cc6ff8933cc30b7864293d66 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Sun, 1 Dec 2024 14:46:31 +0100 Subject: [PATCH] shopping recipe scaling --- .../components/display/ShoppingListView.vue | 49 ++++++++++++++----- .../components/inputs/NumberScalerDialog.vue | 22 ++++----- 2 files changed, 49 insertions(+), 22 deletions(-) diff --git a/vue3/src/components/display/ShoppingListView.vue b/vue3/src/components/display/ShoppingListView.vue index 081297c30..d7c689f60 100644 --- a/vue3/src/components/display/ShoppingListView.vue +++ b/vue3/src/components/display/ShoppingListView.vue @@ -105,7 +105,7 @@ @@ -147,7 +147,10 @@ Undo Debug - {{ i.type }} {{ i.entries.flatMap(e => e.food.name) }} + {{ i.type }} {{ + i.entries.flatMap((e: ShoppingListEntry) => e.food.name) + }} + @@ -162,17 +165,21 @@ {{ $t('Recipes') }} - - {{ $t('Add_to_Shopping') }} - - - {{ $t('Recipes') }} - {{ r.recipeName }} + + + {{ r.recipeName }} + @@ -204,8 +211,8 @@ import {computed, onMounted, ref} from "vue"; import {useShoppingStore} from "@/stores/ShoppingStore"; -import {ApiApi, Food, IngredientString, ShoppingListEntry, Supermarket, SupermarketCategory, Unit} from "@/openapi"; -import {ErrorMessageType, useMessageStore} from "@/stores/MessageStore"; +import {ApiApi, Food, IngredientString, ShoppingListEntry, ShoppingListRecipe, Supermarket, Unit} from "@/openapi"; +import {ErrorMessageType, PreparedMessage, useMessageStore} from "@/stores/MessageStore"; import ShoppingLineItem from "@/components/display/ShoppingLineItem.vue"; import {useUserPreferenceStore} from "@/stores/UserPreferenceStore"; import ModelSelect from "@/components/inputs/ModelSelect.vue"; @@ -292,6 +299,26 @@ function isCategoryVisible(category: IShoppingListCategory) { return entryCount > 0 } +/** + * update the number of servings for an embedded recipe and with it the ShoppingListEntry amounts + * @param recipe ShoppingListRecipe to update + * @param servings number of servings to set the recipe to + */ +function updateRecipeServings(recipe: ShoppingListRecipe, servings: number) { + let api = new ApiApi() + useShoppingStore().currentlyUpdating = true + + recipe.servings = servings + api.apiShoppingListRecipeUpdate({id: recipe.id!, shoppingListRecipe: recipe}).then(r => { + useShoppingStore().currentlyUpdating = false + useShoppingStore().refreshFromAPI() + useMessageStore().addPreparedMessage(PreparedMessage.UPDATE_SUCCESS) + }).catch(err => { + useMessageStore().addError(ErrorMessageType.UPDATE_ERROR, err) + useShoppingStore().currentlyUpdating = false + }) +} + /** * run the autosync function in a loop */ diff --git a/vue3/src/components/inputs/NumberScalerDialog.vue b/vue3/src/components/inputs/NumberScalerDialog.vue index c5c540e38..5331fdb4c 100644 --- a/vue3/src/components/inputs/NumberScalerDialog.vue +++ b/vue3/src/components/inputs/NumberScalerDialog.vue @@ -1,13 +1,7 @@ @@ -38,7 +35,10 @@ import {VNumberInput} from 'vuetify/labs/VNumberInput' import VClosableCardTitle from "@/components/dialogs/VClosableCardTitle.vue"; //TODO remove once component is out of labs const emit = defineEmits({ - change(payload: { number: number }) { + change(payload: number) { + return payload + }, + confirm(payload: number) { return payload } }) @@ -76,8 +76,8 @@ function updateNumber(operation: string) { if (operation === 'sub') { mutable_number.value = props.number - 1 } - console.log(operation, mutable_number.value) - emit('change', {number: mutable_number.value}) + + emit('change', mutable_number.value) }