improvements
This commit is contained in:
@ -134,7 +134,7 @@
|
||||
</div>
|
||||
|
||||
|
||||
<b-button variant="danger" @click="deleteRecipe(r.shopping_list_recipe_id)"><i
|
||||
<b-button variant="danger" @click="useShoppingListStore().deleteShoppingListRecipe(r.shopping_list_recipe_id)"><i
|
||||
class="fas fa-trash fa-fw"></i></b-button>
|
||||
</b-button-group>
|
||||
|
||||
@ -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: {
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
<b-form-group :label="$t('shopping_auto_sync')" :description="$t('shopping_auto_sync_desc')">
|
||||
<b-form-input type="range" :min="SHOPPING_MIN_AUTOSYNC_INTERVAL" max="60" step="1" v-model="useUserPreferenceStore().user_settings.shopping_auto_sync"
|
||||
@change="updateSettings(false)"></b-form-input>
|
||||
@change="updateSettings(false)" :disabled="useUserPreferenceStore().user_settings.shopping_auto_sync < 1"></b-form-input>
|
||||
<div class="text-center">
|
||||
<span v-if="useUserPreferenceStore().user_settings.shopping_auto_sync > 0">
|
||||
{{ Math.round(useUserPreferenceStore().user_settings.shopping_auto_sync) }}
|
||||
@ -24,7 +24,10 @@
|
||||
<span v-if="useUserPreferenceStore().user_settings.shopping_auto_sync < 1">{{ $t('Disable') }}</span>
|
||||
</div>
|
||||
<br/>
|
||||
<b-button class="btn btn-sm" @click="useUserPreferenceStore().user_settings.shopping_auto_sync = 0; updateSettings(false)">{{ $t('Disabled') }}</b-button>
|
||||
<b-button class="btn btn-sm" @click="useUserPreferenceStore().user_settings.shopping_auto_sync = 0; updateSettings(false)"
|
||||
v-if="useUserPreferenceStore().user_settings.shopping_auto_sync > 0">{{ $t('Disable') }}</b-button>
|
||||
<b-button class="btn btn-sm btn-success" @click="useUserPreferenceStore().user_settings.shopping_auto_sync = SHOPPING_MIN_AUTOSYNC_INTERVAL; updateSettings(false)"
|
||||
v-if="useUserPreferenceStore().user_settings.shopping_auto_sync < 1">{{ $t('Enable') }}</b-button>
|
||||
</b-form-group>
|
||||
|
||||
<b-form-group :description="$t('mealplan_autoadd_shopping_desc')">
|
||||
|
@ -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.",
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user