From 6d4f09445533965289662892f37c56335145ef20 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Wed, 10 Jan 2024 06:51:34 +0800 Subject: [PATCH] number scaler component and changing entry amount --- .../ShoppingListView/ShoppingListView.vue | 57 +++----------- vue/src/components/NumberScalerComponent.vue | 74 +++++++++++++++++++ vue/src/components/ShoppingLineItem.vue | 7 +- vue/src/locales/en.json | 1 + 4 files changed, 92 insertions(+), 47 deletions(-) create mode 100644 vue/src/components/NumberScalerComponent.vue diff --git a/vue/src/apps/ShoppingListView/ShoppingListView.vue b/vue/src/apps/ShoppingListView/ShoppingListView.vue index b998ffe2..2e39cd82 100644 --- a/vue/src/apps/ShoppingListView/ShoppingListView.vue +++ b/vue/src/apps/ShoppingListView/ShoppingListView.vue @@ -108,29 +108,11 @@ {{ r.recipe_name }} - - - 2 - - - - {{ - r.servings - }} - - - - 2 - - + @@ -488,11 +470,13 @@ import {Workbox} from 'workbox-window'; import BottomNavigationBar from "@/components/BottomNavigationBar.vue"; import {useShoppingListStore} from "@/stores/ShoppingListStore"; import {useUserPreferenceStore} from "@/stores/UserPreferenceStore"; +import NumberScalerComponent from "@/components/NumberScalerComponent.vue"; export default { name: "ShoppingListView", mixins: [ApiMixin, ResolveUrlMixin], components: { + NumberScalerComponent, ShoppingLineItem, GenericMultiselect, @@ -741,39 +725,22 @@ export default { * change number of servings of a shopping list recipe * backend handles scaling of associated entries * @param recipe recipe to update - * @param mode mode to change servings + * @param servings number of servings to set recipe to */ - updateServings(recipe, mode) { - if (mode === 'half') { - recipe.servings = recipe.servings / 2 - } - if (mode === 'multiply') { - recipe.servings = recipe.servings * 2 - } - if (mode === 'add') { - recipe.servings++ - } - if (mode === 'sub') { - recipe.servings-- - } - if (mode === 'prompt') { - let servings = prompt(this.$t('Servings'), recipe.servings); - if (servings !== null && servings !== "" && !isNaN(servings) && !isNaN(parseFloat(servings))) { - recipe.servings = parseFloat(servings) - } else { - console.log('Invalid input in servings prompt', servings) - } - } - - if (recipe.servings > 0 && recipe.servings !== "") { + updateServings(recipe, servings) { + if (servings > 0 && servings !== "") { let api = new ApiApiFactory() + useShoppingListStore().currently_updating = true api.partialUpdateShoppingListRecipe(recipe.shopping_list_recipe_id, { id: recipe.shopping_list_recipe_id, - servings: recipe.servings + servings: servings }).then(() => { + useShoppingListStore().currently_updating = false useShoppingListStore().refreshFromAPI() + }).catch((err) => { + useShoppingListStore().currently_updating = false + StandardToasts.makeStandardToast(this, StandardToasts.FAIL_UPDATE, err) }) - return recipe.servings } }, diff --git a/vue/src/components/NumberScalerComponent.vue b/vue/src/components/NumberScalerComponent.vue new file mode 100644 index 00000000..8e9c9579 --- /dev/null +++ b/vue/src/components/NumberScalerComponent.vue @@ -0,0 +1,74 @@ + + + + + + \ No newline at end of file diff --git a/vue/src/components/ShoppingLineItem.vue b/vue/src/components/ShoppingLineItem.vue index 3c21da14..7490e5d0 100644 --- a/vue/src/components/ShoppingLineItem.vue +++ b/vue/src/components/ShoppingLineItem.vue @@ -57,7 +57,7 @@ - {{ food.name }} + {{e.amount}} {{e.unit?.name}} {{ food.name }}
{{ e.recipe_mealplan.recipe_name }} ({{ @@ -76,6 +76,8 @@
+ +
@@ -97,6 +99,7 @@ import {useMealPlanStore} from "@/stores/MealPlanStore"; import {useShoppingListStore} from "@/stores/ShoppingListStore"; import {ApiApiFactory} from "@/utils/openapi/api"; import {useUserPreferenceStore} from "@/stores/UserPreferenceStore"; +import NumberScalerComponent from "@/components/NumberScalerComponent.vue"; Vue.use(BootstrapVue) @@ -104,7 +107,7 @@ Vue.use(BootstrapVue) export default { name: "ShoppingLineItem", mixins: [ApiMixin], - components: {}, + components: {NumberScalerComponent}, props: { entries: {type: Object,}, }, diff --git a/vue/src/locales/en.json b/vue/src/locales/en.json index 46bdeff8..abb63510 100644 --- a/vue/src/locales/en.json +++ b/vue/src/locales/en.json @@ -96,6 +96,7 @@ "base_unit": "Base Unit", "base_amount": "Base Amount", "Datatype": "Datatype", + "Input": "Input", "Number of Objects": "Number of Objects", "Add_Step": "Add Step", "Keywords": "Keywords",