From d42c6dcce1ab5cb84130ff6c0e9787d8789dbd08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Thu, 25 Mar 2021 23:14:49 +0100 Subject: [PATCH] [pricelist] delete drink pictures --- .../pricelist/components/CalculationTable.vue | 63 +++++++++++++------ .../pricelist/components/DrinkTypes.vue | 12 ++-- src/plugins/pricelist/store.ts | 5 ++ 3 files changed, 54 insertions(+), 26 deletions(-) diff --git a/src/plugins/pricelist/components/CalculationTable.vue b/src/plugins/pricelist/components/CalculationTable.vue index 6632499..5e26945 100644 --- a/src/plugins/pricelist/components/CalculationTable.vue +++ b/src/plugins/pricelist/components/CalculationTable.vue @@ -59,23 +59,34 @@ @click="deleteDrink(drinks_props.row)" /> - + - - - - + + @@ -446,20 +457,31 @@ export default defineComponent({ }); drinkPic.value = undefined; } - + interface Row extends Drink { + expand: boolean; + } function savePicture(drink: Drink) { console.log('hier bin ich!!!', drinkPic.value); - if (drinkPic.value && drinkPic.value instanceof File) + drink.loading = true; + if (drinkPic.value && drinkPic.value instanceof File) { store .upload_drink_picture(drink, drinkPic.value) - .then(() => { - root?.$forceUpdate(); - }) .catch((response: Response) => { if (response && response.status == 400) { onPictureRejected(); } + }) + .finally(() => { + drink.loading = false; }); + } + } + + function deletePicture(drink: Row) { + drink.loading = true; + void store.delete_drink_picture(drink).finally(() => { + drink.loading = false; + }); } return { @@ -475,6 +497,7 @@ export default defineComponent({ showNewDrink, drinkPic, savePicture, + deletePicture, console, }; }, diff --git a/src/plugins/pricelist/components/DrinkTypes.vue b/src/plugins/pricelist/components/DrinkTypes.vue index 348cc74..3071aae 100644 --- a/src/plugins/pricelist/components/DrinkTypes.vue +++ b/src/plugins/pricelist/components/DrinkTypes.vue @@ -70,14 +70,14 @@ export default defineComponent({ label: 'Getränkeart', field: 'name', align: 'left', - sortable: true + sortable: true, }, { name: 'actions', label: 'Aktionen', field: 'actions', - align: 'right' - } + align: 'right', + }, ]; async function addType() { @@ -94,7 +94,7 @@ export default defineComponent({ try { await store.changeDrinkTypeName({ id: actualDrinkType.value.id, - name: newDrinkTypeName.value + name: newDrinkTypeName.value, }); } catch (e) {} discardChanges(); @@ -121,9 +121,9 @@ export default defineComponent({ actualDrinkType, newDrinkTypeName, discardChanges, - saveChanges + saveChanges, }; - } + }, }); diff --git a/src/plugins/pricelist/store.ts b/src/plugins/pricelist/store.ts index 0177ef2..1018e98 100644 --- a/src/plugins/pricelist/store.ts +++ b/src/plugins/pricelist/store.ts @@ -15,6 +15,7 @@ interface Drink extends Omit, 'volumes'> volumes: DrinkPriceVolume[]; cost_price_pro_volume: WritableComputedRef; _cost_price_pro_volume?: number; + loading: boolean; } class DrinkPriceVolume implements DrinkPriceVolume { @@ -80,6 +81,7 @@ class Drink { this.tags = tags; this.type = type; this.volumes = []; + this.loading = false; } } @@ -309,6 +311,9 @@ export const usePricelistStore = defineStore({ }, }); }, + async delete_drink_picture(drink: Drink) { + await api.delete(`pricelist/drinks/${drink.id}/picture`); + }, }, });