From 0f1a3ba5d86dc90fd1e8b475946b252287003ce8 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Mon, 29 Jan 2024 08:37:53 +0100 Subject: [PATCH] improvements --- .../ShoppingListView/ShoppingListView.vue | 22 +++++-------------- .../Settings/ShoppingSettingsComponent.vue | 7 ++++-- vue/src/locales/en.json | 1 + vue/src/stores/ShoppingListStore.js | 21 +++++++++++++++++- vue/src/stores/UserPreferenceStore.js | 4 ++-- vue/src/utils/utils.js | 2 +- 6 files changed, 34 insertions(+), 23 deletions(-) diff --git a/vue/src/apps/ShoppingListView/ShoppingListView.vue b/vue/src/apps/ShoppingListView/ShoppingListView.vue index 1a26d8872..7661a9fe7 100644 --- a/vue/src/apps/ShoppingListView/ShoppingListView.vue +++ b/vue/src/apps/ShoppingListView/ShoppingListView.vue @@ -134,7 +134,7 @@ - @@ -605,18 +605,7 @@ export default { }) } }, - /** - * delete shopping list recipe, associated entries are deleted automatically by database - * @param shopping_list_recipe_id id of shopping list recipe to delete - */ - deleteRecipe: function (shopping_list_recipe_id) { - let api = new ApiApiFactory() - api.destroyShoppingListRecipe(shopping_list_recipe_id).then((x) => { - useShoppingListStore().refreshFromAPI() //TODO only do partial refresh - }).catch((err) => { - StandardToasts.makeStandardToast(this, StandardToasts.FAIL_DELETE, err) - }) - }, + /** * change number of servings of a shopping list recipe * backend handles scaling of associated entries @@ -680,10 +669,9 @@ export default { * add new supermarket to list of supermarkets */ addSupermarket: function () { - // TODO integrate into store let api = new ApiApiFactory() api.createSupermarket({name: this.$t('Supermarket') + Math.floor(1000 + Math.random() * 9000)}).then((r) => { - this.shopping_list_store.supermarkets.push(r.data) + useShoppingListStore().supermarkets.push(r.data) this.new_supermarket.value = undefined }).catch((err) => { StandardToasts.makeStandardToast(this, StandardToasts.FAIL_CREATE, err) @@ -880,12 +868,12 @@ export default { }) }, /** - * called after adding a new recipe trough the shopping modal + * called after adding a new recipe through the shopping modal * cleanup and data refresh */ finishShopping() { this.new_recipe = {id: undefined} - useShoppingListStore().refreshFromAPI() //TODO only do partial fetch + useShoppingListStore().autosync() }, }, directives: { diff --git a/vue/src/components/Settings/ShoppingSettingsComponent.vue b/vue/src/components/Settings/ShoppingSettingsComponent.vue index 945e08664..f5a7da82b 100644 --- a/vue/src/components/Settings/ShoppingSettingsComponent.vue +++ b/vue/src/components/Settings/ShoppingSettingsComponent.vue @@ -13,7 +13,7 @@ + @change="updateSettings(false)" :disabled="useUserPreferenceStore().user_settings.shopping_auto_sync < 1">
{{ Math.round(useUserPreferenceStore().user_settings.shopping_auto_sync) }} @@ -24,7 +24,10 @@ {{ $t('Disable') }}

- {{ $t('Disabled') }} + {{ $t('Disable') }} + {{ $t('Enable') }}
diff --git a/vue/src/locales/en.json b/vue/src/locales/en.json index a1f49865b..79f9c96e9 100644 --- a/vue/src/locales/en.json +++ b/vue/src/locales/en.json @@ -503,6 +503,7 @@ "Reset": "Reset", "Disabled": "Disabled", "Disable": "Disable", + "Enable": "Enable", "Options": "Options", "Create Food": "Create Food", "create_food_desc": "Create a food and link it to this recipe.", diff --git a/vue/src/stores/ShoppingListStore.js b/vue/src/stores/ShoppingListStore.js index 1cdbbf25e..ac00635df 100644 --- a/vue/src/stores/ShoppingListStore.js +++ b/vue/src/stores/ShoppingListStore.js @@ -125,8 +125,12 @@ export const useShoppingListStore = defineStore(_STORE_ID, { return ordered_structure }, + /** + * flattened list of entries used for exporters + * kinda uncool but works for now + * @return {*[]} + */ get_flat_entries: function () { - //{amount: x.amount, unit: x.unit?.name ?? "", food: x.food?.name ?? ""} let items = [] for (let i in this.get_entries_by_group) { for (let f in this.get_entries_by_group[i]['foods']) { @@ -435,6 +439,21 @@ export const useShoppingListStore = defineStore(_STORE_ID, { this.deleteObject(this.entries[i]) } }, + deleteShoppingListRecipe(shopping_list_recipe_id) { + let api = new ApiApiFactory() + + for (let i in this.entries) { + if (this.entries[i].list_recipe === shopping_list_recipe_id) { + Vue.delete(this.entries, i) + } + } + + api.destroyShoppingListRecipe(shopping_list_recipe_id).then((x) => { + // no need to update anything, entries were already removed + }).catch((err) => { + StandardToasts.makeStandardToast(this, StandardToasts.FAIL_DELETE, err) + }) + }, /** * register the change to a set of entries to allow undoing it * throws an Error if the operation type is not known diff --git a/vue/src/stores/UserPreferenceStore.js b/vue/src/stores/UserPreferenceStore.js index 4dc9b2d5e..adc06ee43 100644 --- a/vue/src/stores/UserPreferenceStore.js +++ b/vue/src/stores/UserPreferenceStore.js @@ -95,10 +95,10 @@ export const useUserPreferenceStore = defineStore(_STORE_ID, { for (s in settings) { Vue.set(this.user_settings, s, settings[s]) } - //console.log(`loaded local user settings age ${((new Date().getTime()) - this.user_settings.locally_updated_at) / 1000} `) + console.log(`loaded local user settings age ${((new Date().getTime()) - this.user_settings.locally_updated_at) / 1000} `) } if (((new Date().getTime()) - this.user_settings.locally_updated_at) > _STALE_TIME_IN_MS || !allow_cached_results) { - //console.log('refreshing user settings from API') + console.log('refreshing user settings from API') let apiClient = new ApiApiFactory() apiClient.retrieveUserPreference(localStorage.getItem('USER_ID')).then(r => { for (s in r.data) { diff --git a/vue/src/utils/utils.js b/vue/src/utils/utils.js index b34396d44..cf1a5b3f5 100644 --- a/vue/src/utils/utils.js +++ b/vue/src/utils/utils.js @@ -131,7 +131,7 @@ export class StandardToasts { } - let DEBUG = localStorage.getItem("DEBUG") === "True" || always_show_errors + let DEBUG = (localStorage.getItem("DEBUG") === "True" || always_show_errors) && variant !== 'success' if (DEBUG){ console.log('ERROR ', err, JSON.stringify(err?.response?.data)) console.trace();