Merge branch 'feature/vue3' of https://github.com/vabene1111/recipes into feature/vue3

This commit is contained in:
vabene1111
2025-06-19 17:36:44 +02:00
3 changed files with 36 additions and 31 deletions

View File

@@ -48,7 +48,7 @@ class FoodPropertyHelper:
found_property = False
# if food has a value for the given property type (no matter if conversion is possible)
has_property_value = False
if i.food.properties_food_amount == 0 or i.food.properties_food_unit is None: # if food is configured incorrectly
if i.food.properties_food_amount == 0 or i.food.properties_food_unit is None and not (i.amount == 0 or i.no_amount): # if food is configured incorrectly
computed_properties[pt.id]['food_values'][i.food.id] = {'id': i.food.id, 'food': {'id': i.food.id, 'name': i.food.name}, 'value': None}
computed_properties[pt.id]['missing_value'] = True
else:
@@ -62,7 +62,7 @@ class FoodPropertyHelper:
computed_properties[pt.id]['food_values'] = self.add_or_create(
computed_properties[p.property_type.id]['food_values'], c.food.id, (c.amount / i.food.properties_food_amount) * p.property_amount, c.food)
if not found_property:
if i.amount == 0: # don't count ingredients without an amount as missing
if i.amount == 0 or i.no_amount: # don't count ingredients without an amount as missing
computed_properties[pt.id]['missing_value'] = computed_properties[pt.id]['missing_value'] or False # don't override if another food was already missing
computed_properties[pt.id]['food_values'][i.food.id] = {'id': i.food.id, 'food': {'id': i.food.id, 'name': i.food.name}, 'value': 0}
else:

View File

@@ -44,7 +44,7 @@
<v-list-item border v-for="fv in dialogProperty.foodValues" :key="`${dialogProperty.id}_${fv.id}`">
<template #prepend>
<v-progress-circular size="55" width="5" :model-value="(fv.value/dialogProperty.propertyAmountTotal)*100"
:color="colorScale((fv.value/dialogProperty.propertyAmountTotal)*100)" v-if="fv.value != null">
:color="colorScale((fv.value/dialogProperty.propertyAmountTotal)*100)" v-if="fv.value != null && dialogProperty.propertyAmountTotal > 0">
{{ Math.round((fv.value / dialogProperty.propertyAmountTotal) * 100) }}%
</v-progress-circular>
<v-progress-circular size="55" width="5" v-if="fv.value == null">?</v-progress-circular>

View File

@@ -1,5 +1,6 @@
<template>
<v-text-field :label="$t('Shopping_input_placeholder')" density="compact" @keyup.enter="addIngredient()" v-model="ingredientInput" :loading="props.loading" hide-detail v-if="!useUserPreferenceStore().deviceSettings.shopping_input_autocomplete"s>
<v-text-field :label="$t('Shopping_input_placeholder')" density="compact" @keyup.enter="addIngredient()" v-model="ingredientInput" :loading="props.loading" hide-detail
v-if="!useUserPreferenceStore().deviceSettings.shopping_input_autocomplete" s>
<template #append>
<v-btn
density="comfortable"
@@ -36,7 +37,7 @@
import {PropType, ref} from "vue";
import {ApiApi, Food, IngredientString, MealPlan, ShoppingListEntry, ShoppingListRecipe} from "@/openapi";
import {ApiApi, Food, IngredientString, MealPlan, ShoppingListEntry, ShoppingListRecipe, Unit} from "@/openapi";
import {useShoppingStore} from "@/stores/ShoppingStore";
import {ErrorMessageType, MessageType, useMessageStore} from "@/stores/MessageStore";
import Multiselect from "@vueform/multiselect";
@@ -60,32 +61,36 @@ const loading = ref(false)
/**
* add new ingredient from ingredient text input
*/
function addIngredient() {
function addIngredient(amount: number, unit: Unit|null, food: Food|null) {
let sle = {
amount: Math.max(amount, 1),
unit: unit,
food: food,
} as ShoppingListEntry
console.log('adding SLR ? ', props.mealPlan)
if (props.mealPlan) {
console.log('yes')
sle.mealplanId = props.mealPlan.id
}
useShoppingStore().createObject(sle, true).finally(() => {
loading.value = false
})
ingredientInput.value = ''
ingredientInputIcon.value = 'fa-solid fa-check'
setTimeout(() => {
ingredientInputIcon.value = 'fa-solid fa-plus'
}, 1000)
}
function parseIngredient() {
const api = new ApiApi()
loading.value = true
api.apiIngredientFromStringCreate({ingredientString: {text: ingredientInput.value} as IngredientString}).then(r => {
let sle = {
amount: Math.max(r.amount, 1),
unit: r.unit,
food: r.food,
} as ShoppingListEntry
console.log('adding SLR ? ', props.mealPlan)
if (props.mealPlan) {
console.log('yes')
sle.mealplanId = props.mealPlan.id
}
useShoppingStore().createObject(sle, true).finally(() => {
loading.value = false
})
ingredientInput.value = ''
ingredientInputIcon.value = 'fa-solid fa-check'
setTimeout(() => {
ingredientInputIcon.value = 'fa-solid fa-plus'
}, 1000)
addIngredient(r.amount, r.unit, r.food)
}).catch(err => {
useMessageStore().addError(ErrorMessageType.CREATE_ERROR, err)
loading.value = false
@@ -99,14 +104,14 @@ function createObject(object: any, select$: Multiselect) {
ingredientModelInput.value = {} as Food
select$.close()
select$.clearSearch()
addIngredient()
parseIngredient()
return false
}
function selectObject(foodId: number, food: Food, select$: Multiselect) {
ingredientInput.value = food.name
//ingredientInput.value = food.name
ingredientModelInput.value = {} as Food
addIngredient()
addIngredient(1, null, food)
return false
}
@@ -118,7 +123,7 @@ function search(query: string) {
loading.value = true
let api = new ApiApi()
return api.apiFoodList({query: query, page: 1, pageSize: 25}).then(r => {
return api.apiFoodList({query: query, page: 1, pageSize: 25}).then(r => {
return r.results
}).catch((err: any) => {
useMessageStore().addError(ErrorMessageType.FETCH_ERROR, err)