mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-07 15:18:20 -05:00
lots of shopping list improvements
This commit is contained in:
@@ -14,7 +14,7 @@ import {
|
||||
} from "@/types/Shopping";
|
||||
import {ErrorMessageType, useMessageStore} from "@/stores/MessageStore";
|
||||
import {useUserPreferenceStore} from "@/stores/UserPreferenceStore";
|
||||
import {isDelayed} from "@/utils/logic_utils";
|
||||
import {isDelayed, isEntryVisible} from "@/utils/logic_utils";
|
||||
import {DateTime} from "luxon";
|
||||
|
||||
const _STORE_ID = "shopping_store"
|
||||
@@ -194,9 +194,11 @@ export const useShoppingStore = defineStore(_STORE_ID, () => {
|
||||
let requestParameters = {pageSize: 50, page: 1} as ApiShoppingListEntryListRequest
|
||||
if (mealPlanId) {
|
||||
requestParameters.mealplan = mealPlanId
|
||||
} else {
|
||||
// only clear local entries when not given a meal plan to not accidentally filter the shopping list
|
||||
entries.value = new Map<number, ShoppingListEntry>
|
||||
}
|
||||
|
||||
entries.value = new Map<number, ShoppingListEntry>
|
||||
recLoadShoppingListEntries(requestParameters)
|
||||
|
||||
api.apiSupermarketCategoryList().then(r => {
|
||||
@@ -217,23 +219,23 @@ export const useShoppingStore = defineStore(_STORE_ID, () => {
|
||||
* recursively load shopping list entries from paginated api
|
||||
* @param requestParameters
|
||||
*/
|
||||
function recLoadShoppingListEntries(requestParameters: ApiShoppingListEntryListRequest){
|
||||
function recLoadShoppingListEntries(requestParameters: ApiShoppingListEntryListRequest) {
|
||||
let api = new ApiApi()
|
||||
api.apiShoppingListEntryList(requestParameters).then((r) => {
|
||||
r.results.forEach((e) => {
|
||||
entries.value.set(e.id!, e)
|
||||
})
|
||||
if(r.next){
|
||||
requestParameters.page = requestParameters.page + 1
|
||||
recLoadShoppingListEntries(requestParameters)
|
||||
} else {
|
||||
currentlyUpdating.value = false
|
||||
initialized.value = true
|
||||
}
|
||||
}).catch((err) => {
|
||||
currentlyUpdating.value = false
|
||||
useMessageStore().addError(ErrorMessageType.FETCH_ERROR, err)
|
||||
r.results.forEach((e) => {
|
||||
entries.value.set(e.id!, e)
|
||||
})
|
||||
if (r.next) {
|
||||
requestParameters.page = requestParameters.page + 1
|
||||
recLoadShoppingListEntries(requestParameters)
|
||||
} else {
|
||||
currentlyUpdating.value = false
|
||||
initialized.value = true
|
||||
}
|
||||
}).catch((err) => {
|
||||
currentlyUpdating.value = false
|
||||
useMessageStore().addError(ErrorMessageType.FETCH_ERROR, err)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -321,7 +323,7 @@ export const useShoppingStore = defineStore(_STORE_ID, () => {
|
||||
let recipes = [] as ShoppingListRecipe[]
|
||||
|
||||
entries.value.forEach(e => {
|
||||
if (e.listRecipe != null && recipes.findIndex(x => x.id == e.listRecipe) == -1) {
|
||||
if (e.listRecipe != null && recipes.findIndex(x => x.id == e.listRecipe) == -1 && isEntryVisible(e, useUserPreferenceStore().deviceSettings)) {
|
||||
recipes.push(e.listRecipeData)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@ import {ErrorMessageType, PreparedMessage, useMessageStore} from "@/stores/Messa
|
||||
import {ApiApi, ServerSettings, Space, Supermarket, UserPreference, UserSpace} from "@/openapi";
|
||||
import {ShoppingGroupingOptions} from "@/types/Shopping";
|
||||
import {computed, ComputedRef} from "vue";
|
||||
import {DeviceSettings} from "@/types/settings";
|
||||
|
||||
const DEVICE_SETTINGS_KEY = 'TANDOOR_DEVICE_SETTINGS'
|
||||
const USER_PREFERENCE_KEY = 'TANDOOR_USER_PREFERENCE'
|
||||
@@ -11,31 +12,11 @@ const SERVER_SETTINGS_KEY = 'TANDOOR_SERVER_SETTINGS'
|
||||
const ACTIVE_SPACE_KEY = 'TANDOOR_ACTIVE_SPACE'
|
||||
const USER_SPACES_KEY = 'TANDOOR_USER_SPACES'
|
||||
|
||||
class DeviceSettings {
|
||||
shopping_show_checked_entries = false
|
||||
shopping_show_delayed_entries = false
|
||||
shopping_show_selected_supermarket_only = false
|
||||
shopping_selected_grouping = ShoppingGroupingOptions.CATEGORY
|
||||
shopping_selected_supermarket: Supermarket | null = null
|
||||
shopping_item_info_created_by = false
|
||||
shopping_item_info_mealplan = true
|
||||
shopping_item_info_recipe = true
|
||||
shopping_show_debug = false
|
||||
|
||||
mealplan_displayPeriod = 'week'
|
||||
mealplan_displayPeriodCount = 3
|
||||
mealplan_startingDayOfWeek = 1
|
||||
mealplan_displayWeekNumbers = true
|
||||
|
||||
general_tableItemsPerPage = 10
|
||||
general_closedHelpAlerts: String[] = []
|
||||
}
|
||||
|
||||
export const useUserPreferenceStore = defineStore('user_preference_store', () => {
|
||||
/**
|
||||
* settings only saved on device to allow per device customization
|
||||
*/
|
||||
let deviceSettings = useStorage(DEVICE_SETTINGS_KEY, new DeviceSettings(), localStorage, {mergeDefaults: true})
|
||||
let deviceSettings = useStorage(DEVICE_SETTINGS_KEY, getDefaultDeviceSettings(), localStorage, {mergeDefaults: true})
|
||||
/**
|
||||
* database user settings, cache in local storage in case application is started offline
|
||||
*/
|
||||
@@ -140,7 +121,7 @@ export const useUserPreferenceStore = defineStore('user_preference_store', () =>
|
||||
function switchSpace(space: Space) {
|
||||
let api = new ApiApi()
|
||||
|
||||
api.apiSwitchActiveSpaceRetrieve({spaceId: space.id}).then(r => {
|
||||
api.apiSwitchActiveSpaceRetrieve({spaceId: space.id!}).then(r => {
|
||||
loadActiveSpace()
|
||||
location.reload()
|
||||
}).catch(err => {
|
||||
@@ -152,7 +133,32 @@ export const useUserPreferenceStore = defineStore('user_preference_store', () =>
|
||||
* resets all device settings to their default value
|
||||
*/
|
||||
function resetDeviceSettings() {
|
||||
deviceSettings.value = new DeviceSettings()
|
||||
deviceSettings.value = getDefaultDeviceSettings()
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a default device settings object
|
||||
*/
|
||||
function getDefaultDeviceSettings(): DeviceSettings {
|
||||
return {
|
||||
shopping_show_checked_entries: false,
|
||||
shopping_show_delayed_entries: false,
|
||||
shopping_show_selected_supermarket_only: false,
|
||||
shopping_selected_grouping: ShoppingGroupingOptions.CATEGORY,
|
||||
shopping_selected_supermarket: null,
|
||||
shopping_item_info_created_by: false,
|
||||
shopping_item_info_mealplan: true,
|
||||
shopping_item_info_recipe: true,
|
||||
shopping_show_debug: false,
|
||||
|
||||
mealplan_displayPeriod: 'week',
|
||||
mealplan_displayPeriodCount: 3,
|
||||
mealplan_startingDayOfWeek: 1,
|
||||
mealplan_displayWeekNumbers: true,
|
||||
|
||||
general_tableItemsPerPage: 10,
|
||||
general_closedHelpAlerts: [],
|
||||
}
|
||||
}
|
||||
|
||||
// always load settings on first initialization of store
|
||||
|
||||
Reference in New Issue
Block a user