improved shopping

This commit is contained in:
vabene1111
2024-12-28 15:24:07 +01:00
parent a4548abc19
commit 6fc078090a
2 changed files with 30 additions and 10 deletions

View File

@@ -35,20 +35,25 @@
</v-btn> </v-btn>
</v-col> </v-col>
<v-col class="pt-0"> <v-col class="pt-0">
<v-btn height="80px" color="success" density="compact" size="small" @click="addEntryForFood()" block stacked> <v-btn height="80px" color="error" density="compact" size="small" @click="deleteAllEntries()" block stacked>
<i class="fa-solid fa-plus fa-2x mb-2"></i> <i class="fa-solid fa-trash fa-2x mb-2"></i>
{{ $t('Add') }} {{ $t('Delete_All') }}
</v-btn> </v-btn>
</v-col> </v-col>
</v-row> </v-row>
<v-label class="mt-3">{{ $t('Entries') }}</v-label> <div class="mt-2">
<v-label class="mt-3">{{ $t('Entries') }}</v-label>
<v-btn color="success" class="float-right" @click="addEntryForFood()">
<v-icon icon="$create"></v-icon>
</v-btn>
</div>
<v-list density="compact"> <v-list density="compact">
<template v-for="[i, e] in shoppingListFood.entries" :key="e.id"> <template v-for="[i, e] in shoppingListFood.entries" :key="e.id">
<v-list-item border class="mt-1" :class="{'cursor-pointer': !e.recipeMealplan}"> <v-list-item border class="mt-1" :class="{'cursor-pointer': !e.recipeMealplan}">
<v-list-item-title> <v-list-item-title>
<b> <b>
{{ e.amount }} {{ $n(e.amount) }}
<span v-if="e.unit">{{ e.unit.name }}</span> <span v-if="e.unit">{{ e.unit.name }}</span>
</b> </b>
{{ e.food.name }} {{ e.food.name }}
@@ -110,7 +115,7 @@ import {ErrorMessageType, useMessageStore} from "@/stores/MessageStore";
const {mobile} = useDisplay() const {mobile} = useDisplay()
const showDialog = defineModel<Boolean>() const showDialog = defineModel<Boolean>()
const shoppingListFood = defineModel<IShoppingListFood>('shoppingListFood') const shoppingListFood = defineModel<IShoppingListFood>('shoppingListFood', {required: true})
/** /**
* returns a flat list of entries for the given shopping list food * returns a flat list of entries for the given shopping list food
@@ -152,13 +157,22 @@ function addEntryForFood() {
food: shoppingListFood.value?.food, food: shoppingListFood.value?.food,
unit: null, unit: null,
amount: 1, amount: 1,
} as ShoppingListEntry, false).then((r: ShoppingListEntry|undefined) => { } as ShoppingListEntry, false).then((r: ShoppingListEntry | undefined) => {
if(r != undefined){ if (r != undefined) {
shoppingListFood.value?.entries.set(r.id!, r) shoppingListFood.value?.entries.set(r.id!, r)
} }
}) })
} }
/**
* delete all shopping list entries for the given shopping list food
*/
function deleteAllEntries() {
shoppingListFood.value.entries.forEach(e => {
useShoppingStore().deleteObject(e, true)
})
}
</script> </script>
<style scoped> <style scoped>

View File

@@ -61,6 +61,11 @@
</v-list> </v-list>
</v-menu> </v-menu>
<v-btn height="100%" rounded="0" variant="plain" @click="useShoppingStore().undoChange()">
<i class="fa-solid fa-arrow-rotate-left"></i>
</v-btn>
</v-tabs> </v-tabs>
<v-window v-model="currentTab"> <v-window v-model="currentTab">
@@ -180,7 +185,8 @@
<template #append> <template #append>
<v-btn icon color="delete"> <v-btn icon color="delete">
<v-icon icon="$delete"></v-icon> <v-icon icon="$delete"></v-icon>
<delete-confirm-dialog :object-name="r.recipeName" :model-name="$t('ShoppingListRecipe')" @delete="deleteListRecipe(r)"></delete-confirm-dialog> <delete-confirm-dialog :object-name="r.recipeName" :model-name="$t('ShoppingListRecipe')"
@delete="deleteListRecipe(r)"></delete-confirm-dialog>
</v-btn> </v-btn>
</template> </template>
</v-list-item> </v-list-item>
@@ -346,7 +352,7 @@ function autoSyncLoop() {
/** /**
* delete shopping list recipe * delete shopping list recipe
*/ */
function deleteListRecipe(slr: ShoppingListRecipe){ function deleteListRecipe(slr: ShoppingListRecipe) {
let api = new ApiApi() let api = new ApiApi()
api.apiShoppingListRecipeDestroy({id: slr.id!}).then(r => { api.apiShoppingListRecipeDestroy({id: slr.id!}).then(r => {