mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-05 14:18:51 -05:00
working shopping list
This commit is contained in:
@@ -25,9 +25,12 @@
|
||||
<v-list-item>
|
||||
<v-select hide-details :items="groupingOptionsItems" v-model="useUserPreferenceStore().deviceSettings.shopping_selected_grouping" :label="$t('GroupBy')">
|
||||
</v-select>
|
||||
</v-list-item>
|
||||
<v-list-item v-if="useUserPreferenceStore().deviceSettings.shopping_selected_grouping == ShoppingGroupingOptions.CATEGORY">
|
||||
<v-switch color="primary" hide-details :label="$t('SupermarketCategoriesOnly')" v-model="useUserPreferenceStore().deviceSettings.shopping_show_selected_supermarket_only"></v-switch>
|
||||
</v-list-item>
|
||||
<v-list-item>
|
||||
<model-select model="Supermarket"></model-select>
|
||||
<model-select model="Supermarket" v-model="useUserPreferenceStore().deviceSettings.shopping_selected_supermarket"></model-select>
|
||||
</v-list-item>
|
||||
|
||||
<v-list-item>
|
||||
@@ -37,6 +40,7 @@
|
||||
<v-switch color="primary" hide-details :label="$t('ShowRecentlyCompleted')"
|
||||
v-model="useUserPreferenceStore().deviceSettings.shopping_show_checked_entries"></v-switch>
|
||||
</v-list-item>
|
||||
|
||||
</v-list>
|
||||
</v-menu>
|
||||
</v-tabs>
|
||||
@@ -79,7 +83,7 @@
|
||||
</v-row>
|
||||
|
||||
<v-row>
|
||||
<v-col cols="4">
|
||||
<v-col cols="12" md="4">
|
||||
<v-card>
|
||||
<v-card-title>Auto Sync Debug</v-card-title>
|
||||
<v-card-text>
|
||||
@@ -92,7 +96,7 @@
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</v-col>
|
||||
<v-col cols="4">
|
||||
<v-col cols="12" md="4">
|
||||
<v-card>
|
||||
<v-card-title>Sync Queue Debug</v-card-title>
|
||||
<v-card-text>
|
||||
@@ -104,7 +108,7 @@
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</v-col>
|
||||
<v-col cols="4">
|
||||
<v-col cols="12" md="4">
|
||||
<v-card>
|
||||
<v-card-title>Undo Debug</v-card-title>
|
||||
<v-card-text>
|
||||
@@ -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
|
||||
|
||||
@@ -19,6 +19,12 @@
|
||||
<br/>
|
||||
<v-btn color="primary" class="mt-1" href="/accounts/social/connections/" target="_blank">{{ $t('Social_Authentication') }}</v-btn>
|
||||
<br/>
|
||||
|
||||
<p class="text-h6 mt-3">{{ $t('DeviceSettings') }}</p>
|
||||
<p class="text-disabled">{{$t('DeviceSettingsHelp')}}</p>
|
||||
|
||||
<v-btn @click="useUserPreferenceStore().resetDeviceSettings()">{{$t('Reset')}}</v-btn>
|
||||
|
||||
</v-form>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -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<string, IShoppingListCategory>
|
||||
|
||||
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<number, IShoppingListFood>} 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,9 +305,10 @@ 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<number, IShoppingListFood>} as IShoppingListCategory)
|
||||
}
|
||||
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,
|
||||
@@ -329,6 +316,8 @@ export const useShoppingStore = defineStore(_STORE_ID, () => {
|
||||
} as IShoppingListFood)
|
||||
}
|
||||
structure.categories.get(groupingKey).foods.get(entry.food.id).entries.set(entry.id, entry)
|
||||
}
|
||||
|
||||
return structure
|
||||
}
|
||||
|
||||
@@ -383,7 +372,6 @@ export const useShoppingStore = defineStore(_STORE_ID, () => {
|
||||
entry['status'] = 'waiting_failed_before'
|
||||
} else {
|
||||
itemCheckSyncQueue.value.splice(index, 1)
|
||||
console.error('Failed API call for entry ', entry)
|
||||
useMessageStore().addError(ErrorMessageType.UPDATE_ERROR, err)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user