-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -691,9 +711,8 @@ export default {
*/
deleteRecipe: function (shopping_list_recipe_id) {
let api = new ApiApiFactory()
- //TODO properly integrate into store logic
api.destroyShoppingListRecipe(shopping_list_recipe_id).then((x) => {
- useShoppingListStore().refreshFromAPI()
+ useShoppingListStore().refreshFromAPI() //TODO only do partial refresh
}).catch((err) => {
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_DELETE, err)
})
@@ -841,16 +860,37 @@ export default {
/**
* change number of servings of a shopping list recipe
* backend handles scaling of associated entries
- * @param shopping_list_recipe_id shopping list recipe to update
- * @param servings number of servings to set shopping list recipe to
+ * @param recipe recipe to update
+ * @param mode mode to change servings
*/
- updateServings(shopping_list_recipe_id, servings) {
- if (servings !== 0 && servings !== "") {
- console.log('NEW SERVINGS', servings)
+ 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 !== "") {
let api = new ApiApiFactory()
- api.partialUpdateShoppingListRecipe(shopping_list_recipe_id, {id: shopping_list_recipe_id, servings: servings}).then(() => {
+ api.partialUpdateShoppingListRecipe(recipe.shopping_list_recipe_id, {id: recipe.shopping_list_recipe_id, servings: recipe.servings}).then(() => {
useShoppingListStore().refreshFromAPI()
})
+ return recipe.servings
}
},
deleteSupermarket(index) {
@@ -1100,10 +1140,8 @@ export default {
})
},
finishShopping() {
- this.add_recipe_servings = 1
this.new_recipe = {id: undefined}
- this.edit_recipe_list = undefined
- this.getShoppingList()
+ useShoppingListStore().refreshFromAPI() //TODO only do partial fetch
},
editRecipeList(e, r) {
this.new_recipe = {
diff --git a/vue/src/stores/ShoppingListStore.js b/vue/src/stores/ShoppingListStore.js
index c41425466b..e873974260 100644
--- a/vue/src/stores/ShoppingListStore.js
+++ b/vue/src/stores/ShoppingListStore.js
@@ -124,7 +124,6 @@ export const useShoppingListStore = defineStore(_STORE_ID, {
},
},
actions: {
- // TODO implement shopping list recipes
/**
* Retrieves all shopping related data (shopping list entries, supermarkets, supermarket categories and shopping list recipes) from API
*/
@@ -133,6 +132,8 @@ export const useShoppingListStore = defineStore(_STORE_ID, {
this.currently_updating = true
let apiClient = new ApiApiFactory()
apiClient.listShoppingListEntrys().then((r) => {
+ this.entries = {}
+
r.data.forEach((e) => {
Vue.set(this.entries, e.id, e)
})