diff --git a/vue3/src/components/display/ShoppingListView.vue b/vue3/src/components/display/ShoppingListView.vue index 1cfd01280..1ff3daf05 100644 --- a/vue3/src/components/display/ShoppingListView.vue +++ b/vue3/src/components/display/ShoppingListView.vue @@ -25,9 +25,12 @@ + + + - + @@ -37,6 +40,7 @@ + @@ -79,7 +83,7 @@ - + Auto Sync Debug @@ -92,24 +96,24 @@ - + Sync Queue Debug Length: {{ useShoppingStore().itemCheckSyncQueue.length }}
- Has Failed Items: {{ useShoppingStore().hasFailedItems()}} + Has Failed Items: {{ useShoppingStore().hasFailedItems() }} {{ i }}
- + Undo Debug - {{ i.type }} {{ i.entries.flatMap(e => e.food.name)}} + {{ i.type }} {{ i.entries.flatMap(e => e.food.name) }} @@ -167,8 +171,8 @@ const shoppingLineItemDialogFood = ref({} as IShoppingListFood) * VSelect items for shopping list grouping options with localized names */ const groupingOptionsItems = computed(() => { - let items = [] - Object.keys(ShoppingGroupingOptions).forEach(x => { + let items: any[] = [] + Object.values(ShoppingGroupingOptions).forEach(x => { items.push({'title': t(x), 'value': x}) }) return items diff --git a/vue3/src/components/settings/AccountSettings.vue b/vue3/src/components/settings/AccountSettings.vue index 78ed2a354..9c8973a19 100644 --- a/vue3/src/components/settings/AccountSettings.vue +++ b/vue3/src/components/settings/AccountSettings.vue @@ -19,6 +19,12 @@
{{ $t('Social_Authentication') }}
+ +

{{ $t('DeviceSettings') }}

+

{{$t('DeviceSettingsHelp')}}

+ + {{$t('Reset')}} + diff --git a/vue3/src/stores/ShoppingStore.ts b/vue3/src/stores/ShoppingStore.ts index f6cc59dc9..4c49496ce 100644 --- a/vue3/src/stores/ShoppingStore.ts +++ b/vue3/src/stores/ShoppingStore.ts @@ -49,9 +49,17 @@ export const useShoppingStore = defineStore(_STORE_ID, () => { * group by selected grouping key */ const getEntriesByGroup = computed(() => { + //TODO why is this called many times on each auto sync + console.log('running getEntriesByGroup') let structure = {} as IShoppingList structure.categories = new Map + if (useUserPreferenceStore().deviceSettings.shopping_selected_grouping === ShoppingGroupingOptions.CATEGORY && useUserPreferenceStore().deviceSettings.shopping_selected_supermarket != null) { + useUserPreferenceStore().deviceSettings.shopping_selected_supermarket.categoryToSupermarket.forEach(cTS => { + structure.categories.set(cTS.category.name, {'name': cTS.category.name, 'foods': new Map} as IShoppingListCategory) + }) + } + let orderedStructure = [] as IShoppingListCategory[] // build structure @@ -98,7 +106,6 @@ export const useShoppingStore = defineStore(_STORE_ID, () => { }) // ordering - if (structure.categories.has(UNDEFINED_CATEGORY)) { orderedStructure.push(structure.categories.get(UNDEFINED_CATEGORY)) structure.categories.delete(UNDEFINED_CATEGORY) @@ -108,25 +115,6 @@ export const useShoppingStore = defineStore(_STORE_ID, () => { orderedStructure.push(category) }) - // TODO implement ordering - // if (useUserPreferenceStore().device_settings.shopping_selected_grouping === this.GROUP_CATEGORY && 'useUserPreferenceStore().device_settings.shopping_selected_supermarket' !== null) { - // for (let c of useUserPreferenceStore().device_settings.shopping_selected_supermarket.category_to_supermarket) { - // if (c.category.name in structure) { - // ordered_structure.push(structure[c.category.name]) - // Vue.delete(structure, c.category.name) - // } - // } - // if (!useUserPreferenceStore().device_settings.shopping_show_selected_supermarket_only) { - // for (let i in structure) { - // ordered_structure.push(structure[i]) - // } - // } - // } else { - // for (let i in structure) { - // ordered_structure.push(structure[i]) - // } - // } - return orderedStructure }) @@ -205,21 +193,18 @@ export const useShoppingStore = defineStore(_STORE_ID, () => { */ function autoSync() { if (!currentlyUpdating.value && autoSyncHasFocus.value && !hasFailedItems()) { - console.log('running autosync') - currentlyUpdating.value = true const api = new ApiApi() api.apiShoppingListEntryList({updatedAfter: autoSyncLastTimestamp.value}).then((r) => { - console.log('received auto sync response ', r) autoSyncLastTimestamp.value = r.timestamp! r.results.forEach((e) => { + console.log('updating entry by auto sync ', e) entries.value.set(e.id!, e) }) currentlyUpdating.value = false }).catch((err: any) => { - console.warn('auto sync failed', err) currentlyUpdating.value = false }) } @@ -302,15 +287,16 @@ export const useShoppingStore = defineStore(_STORE_ID, () => { // convenience methods /** - * function to set entry to its proper place in the data structure to perform grouping - * @param {{}} structure datastructure - * @param {*} entry entry to place - * @param {*} group group to place entry into (must be of ShoppingListStore.GROUP_XXX/dot notation of entry property) - * @returns {{}} datastructure including entry + * puts an entry into the appropriate group of the IShoppingList datastructure + * if a group does not yet exist and the sorting is not set to category with selected supermarket only, it will be created + * @param structure + * @param entry */ - function updateEntryInStructure(structure: IShoppingList, entry: ShoppingListEntry, group: ShoppingGroupingOptions) { + function updateEntryInStructure(structure: IShoppingList, entry: ShoppingListEntry) { let groupingKey = UNDEFINED_CATEGORY + let group = useUserPreferenceStore().deviceSettings.shopping_selected_grouping + if (group == ShoppingGroupingOptions.CATEGORY && entry.food != null && entry.food.supermarketCategory != null) { groupingKey = entry.food?.supermarketCategory?.name } else if (group == ShoppingGroupingOptions.CREATED_BY) { @@ -319,16 +305,19 @@ export const useShoppingStore = defineStore(_STORE_ID, () => { groupingKey = entry.recipeMealplan.recipeName } - if (!structure.categories.has(groupingKey)) { + if (!structure.categories.has(groupingKey) && !(group == ShoppingGroupingOptions.CATEGORY && useUserPreferenceStore().deviceSettings.shopping_show_selected_supermarket_only)) { structure.categories.set(groupingKey, {'name': groupingKey, 'foods': new Map} as IShoppingListCategory) } - if (!structure.categories.get(groupingKey).foods.has(entry.food.id)) { - structure.categories.get(groupingKey).foods.set(entry.food.id, { - food: entry.food, - entries: new Map - } as IShoppingListFood) + if (structure.categories.has(groupingKey)) { + if (!structure.categories.get(groupingKey).foods.has(entry.food.id)) { + structure.categories.get(groupingKey).foods.set(entry.food.id, { + food: entry.food, + entries: new Map + } as IShoppingListFood) + } + structure.categories.get(groupingKey).foods.get(entry.food.id).entries.set(entry.id, entry) } - structure.categories.get(groupingKey).foods.get(entry.food.id).entries.set(entry.id, entry) + return structure } @@ -371,19 +360,18 @@ export const useShoppingStore = defineStore(_STORE_ID, () => { itemCheckSyncQueue.value.forEach((entry, index) => { entry['status'] = ((entry['status'] === 'waiting') ? 'syncing' : 'syncing_failed_before') - let p = api.apiShoppingListEntryBulkCreate({shoppingListEntryBulk: entry}, {}).then((r) => { + let p = api.apiShoppingListEntryBulkCreate({shoppingListEntryBulk: entry}, {}).then((r) => { entry.ids.forEach(id => { let e = entries.value.get(id) e.updatedAt = r.timestamp entries.value.set(id, e) }) - itemCheckSyncQueue.value.splice(index,1) + itemCheckSyncQueue.value.splice(index, 1) }).catch((err) => { if (err.code === "ERR_NETWORK" || err.code === "ECONNABORTED") { entry['status'] = 'waiting_failed_before' } else { - itemCheckSyncQueue.value.splice(index,1) - console.error('Failed API call for entry ', entry) + itemCheckSyncQueue.value.splice(index, 1) useMessageStore().addError(ErrorMessageType.UPDATE_ERROR, err) } }) diff --git a/vue3/src/stores/UserPreferenceStore.ts b/vue3/src/stores/UserPreferenceStore.ts index f522bd317..7672a998a 100644 --- a/vue3/src/stores/UserPreferenceStore.ts +++ b/vue3/src/stores/UserPreferenceStore.ts @@ -113,6 +113,13 @@ export const useUserPreferenceStore = defineStore('user_preference_store', () => }) } + /** + * resets all device settings to their default value + */ + function resetDeviceSettings(){ + deviceSettings.value = new DeviceSettings() + } + // always load user settings on first initialization of store loadUserSettings() // always load server settings on first initialization of store @@ -120,7 +127,7 @@ export const useUserPreferenceStore = defineStore('user_preference_store', () => // always load active space on first initialization of store loadActiveSpace() - return {deviceSettings, userSettings, serverSettings, activeSpace, loadUserSettings, loadServerSettings, updateUserSettings, switchSpace} + return {deviceSettings, userSettings, serverSettings, activeSpace, loadUserSettings, loadServerSettings, updateUserSettings, switchSpace, resetDeviceSettings} }) // enable hot reload for store