enable food property deletion

This commit is contained in:
vabene1111
2025-03-20 21:33:51 +01:00
parent 4a13cc63ae
commit c36eaf934f

View File

@@ -64,7 +64,7 @@
</td> </td>
<td v-for="p in food.properties" v-bind:key="`${food.id}_${p.propertyType.id}`"> <td v-for="p in food.properties" v-bind:key="`${food.id}_${p.propertyType.id}`">
<v-text-field type="number" v-model="p.propertyAmount" density="compact" hide-details v-if="p.propertyAmount != null" @change="updateFood(food)" <v-text-field type="number" v-model="p.propertyAmount" density="compact" hide-details v-if="p.propertyAmount != null" @change="updateFood(food)"
:loading="food.loading"></v-text-field> :loading="food.loading" @click:clear="deleteFoodProperty(p, food)" clearable></v-text-field>
<v-btn variant="outlined" color="create" block v-if="p.propertyAmount == null" @click="p.propertyAmount = 0"> <v-btn variant="outlined" color="create" block v-if="p.propertyAmount == null" @click="p.propertyAmount = 0">
<v-icon icon="$create"></v-icon> <v-icon icon="$create"></v-icon>
</v-btn> </v-btn>
@@ -263,6 +263,28 @@ function buildFoodProperties(food: Food) {
return food return food
} }
/**
* deletes the given property either on client or also on server if it has an id
* @param p
* @param food
*/
function deleteFoodProperty(p: Property, food: Food & { loading?: boolean } ){
let api = new ApiApi()
if(p.id){
food.loading = true
api.apiPropertyDestroy({id: p.id}).then(r => {
p.propertyAmount = null
}).catch(err => {
useMessageStore().addError(ErrorMessageType.DELETE_ERROR, err)
}).finally(() => {
food.loading = false
})
} else {
p.propertyAmount = null
}
}
/** /**
* update food * update food
* @param food * @param food