Skip to content

Commit

Permalink
improved shopping
Browse files Browse the repository at this point in the history
  • Loading branch information
vabene1111 committed Dec 28, 2024
1 parent a4548ab commit 6fc0780
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
30 changes: 22 additions & 8 deletions vue3/src/components/dialogs/ShoppingLineItemDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,25 @@
</v-btn>
</v-col>
<v-col class="pt-0">
<v-btn height="80px" color="success" density="compact" size="small" @click="addEntryForFood()" block stacked>
<i class="fa-solid fa-plus fa-2x mb-2"></i>
{{ $t('Add') }}
<v-btn height="80px" color="error" density="compact" size="small" @click="deleteAllEntries()" block stacked>
<i class="fa-solid fa-trash fa-2x mb-2"></i>
{{ $t('Delete_All') }}
</v-btn>
</v-col>
</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">
<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-title>
<b>
{{ e.amount }}
{{ $n(e.amount) }}
<span v-if="e.unit">{{ e.unit.name }}</span>
</b>
{{ e.food.name }}
Expand Down Expand Up @@ -110,7 +115,7 @@ import {ErrorMessageType, useMessageStore} from "@/stores/MessageStore";
const {mobile} = useDisplay()
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
Expand Down Expand Up @@ -152,13 +157,22 @@ function addEntryForFood() {
food: shoppingListFood.value?.food,
unit: null,
amount: 1,
} as ShoppingListEntry, false).then((r: ShoppingListEntry|undefined) => {
if(r != undefined){
} as ShoppingListEntry, false).then((r: ShoppingListEntry | undefined) => {
if (r != undefined) {
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>

<style scoped>
Expand Down
10 changes: 8 additions & 2 deletions vue3/src/components/display/ShoppingListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@

</v-list>
</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-window v-model="currentTab">
Expand Down Expand Up @@ -180,7 +185,8 @@
<template #append>
<v-btn icon color="delete">
<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>
</template>
</v-list-item>
Expand Down Expand Up @@ -346,7 +352,7 @@ function autoSyncLoop() {
/**
* delete shopping list recipe
*/
function deleteListRecipe(slr: ShoppingListRecipe){
function deleteListRecipe(slr: ShoppingListRecipe) {
let api = new ApiApi()
api.apiShoppingListRecipeDestroy({id: slr.id!}).then(r => {
Expand Down

0 comments on commit 6fc0780

Please sign in to comment.