diff --git a/cookbook/serializer.py b/cookbook/serializer.py
index 1aea41051..f353a4c79 100644
--- a/cookbook/serializer.py
+++ b/cookbook/serializer.py
@@ -651,7 +651,7 @@ class IngredientSimpleSerializer(WritableNestedModelSerializer):
uch = UnitConversionHelper(self.context['request'].space)
conversions = []
for c in uch.get_conversions(obj):
- conversions.append({'food': c.food.name, 'unit': c.unit.name , 'amount': c.amount}) # TODO do formatting in helper
+ conversions.append({'food': c.food.name, 'unit': c.unit.name, 'amount': c.amount}) # TODO do formatting in helper
return conversions
else:
return []
@@ -726,7 +726,7 @@ class StepRecipeSerializer(WritableNestedModelSerializer):
class UnitConversionSerializer(WritableNestedModelSerializer):
base_unit = UnitSerializer()
converted_unit = UnitSerializer()
- food = FoodSerializer(allow_null=True)
+ food = FoodSerializer(allow_null=True, required=False)
base_amount = CustomDecimalField()
converted_amount = CustomDecimalField()
@@ -740,7 +740,7 @@ class UnitConversionSerializer(WritableNestedModelSerializer):
fields = ('id', 'base_amount', 'base_unit', 'converted_amount', 'converted_unit', 'food')
-class NutritionTypeSerializer(serializers.ModelSerializer):
+class FoodPropertyTypeSerializer(serializers.ModelSerializer):
def create(self, validated_data):
validated_data['space'] = self.context['request'].space
return super().create(validated_data)
@@ -750,6 +750,22 @@ class NutritionTypeSerializer(serializers.ModelSerializer):
fields = ('id', 'name', 'icon', 'unit', 'description')
+class FoodPropertySerializer(UniqueFieldsMixin, WritableNestedModelSerializer):
+ property_type = FoodPropertyTypeSerializer()
+ food = FoodSimpleSerializer()
+ unit = UnitSerializer()
+ # TODO prevent updates
+
+ def create(self, validated_data):
+ validated_data['space'] = self.context['request'].space
+ return super().create(validated_data)
+
+ class Meta:
+ model = FoodProperty
+ fields = ('id', 'food_amount', 'food_unit', 'food', 'property_amount', 'property_type')
+ read_only_fields = ('id',)
+
+
class NutritionInformationSerializer(serializers.ModelSerializer):
carbohydrates = CustomDecimalField()
fats = CustomDecimalField()
diff --git a/cookbook/templates/base.html b/cookbook/templates/base.html
index 7036ef40a..59c174207 100644
--- a/cookbook/templates/base.html
+++ b/cookbook/templates/base.html
@@ -269,6 +269,33 @@
+
+
+
diff --git a/cookbook/views/api.py b/cookbook/views/api.py
index e562005fe..6717ec324 100644
--- a/cookbook/views/api.py
+++ b/cookbook/views/api.py
@@ -92,7 +92,7 @@ from cookbook.serializer import (AutomationSerializer, BookmarkletImportListSeri
SyncLogSerializer, SyncSerializer, UnitSerializer,
UserFileSerializer, UserSerializer, UserPreferenceSerializer,
UserSpaceSerializer, ViewLogSerializer, AccessTokenSerializer, FoodSimpleSerializer,
- RecipeExportSerializer, UnitConversionSerializer, NutritionTypeSerializer)
+ RecipeExportSerializer, UnitConversionSerializer, FoodPropertyTypeSerializer)
from cookbook.views.import_export import get_integration
from recipes import settings
@@ -971,7 +971,7 @@ class UnitConversionViewSet(viewsets.ModelViewSet):
class NutritionTypeViewSet(viewsets.ModelViewSet):
queryset = FoodPropertyType.objects
- serializer_class = NutritionTypeSerializer
+ serializer_class = FoodPropertyTypeSerializer
permission_classes = [CustomIsUser & CustomTokenHasReadWriteScope]
def get_queryset(self):
diff --git a/vue/src/apps/TestView/TestView.vue b/vue/src/apps/TestView/TestView.vue
index 28bc4d662..bfc4300fa 100644
--- a/vue/src/apps/TestView/TestView.vue
+++ b/vue/src/apps/TestView/TestView.vue
@@ -1,43 +1,133 @@
-
-
-
-
-
-
-
-
- |
-
- {{ p.icon }} {{ p.name }}
- |
- {{ p.total_value }} {{ p.unit }} |
-
-
-
-
-
+
+
+
{{ food.name }} {{ food.plural_name }}
+
-
-
- {{ selected_property.description }}
-
-
- | {{ f.food }} |
- {{ f.value }} {{ selected_property.unit }} |
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ $t('Properties') }} {{ food.name }}
+
-
+
+
+
+
+
+
+
+
+
+ {{ $t('OnHand') }}
+
+
+
+ {{ $t('Ignore_Shopping') }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{
+ $t('substitute_siblings')
+ }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ $t('reset_children') }}
+
+
+ {{ $t('Save') }}
+
+
+
+
@@ -49,8 +139,9 @@ import {BootstrapVue} from "bootstrap-vue"
import "bootstrap-vue/dist/bootstrap-vue.css"
import {ApiApiFactory} from "@/utils/openapi/api";
-
-import {ApiMixin} from "@/utils/utils";
+import RecipeCard from "@/components/RecipeCard.vue";
+import GenericMultiselect from "@/components/GenericMultiselect.vue";
+import {ApiMixin, StandardToasts} from "@/utils/utils";
Vue.use(BootstrapVue)
@@ -59,31 +150,48 @@ Vue.use(BootstrapVue)
export default {
name: "TestView",
mixins: [ApiMixin],
- components: {},
+ components: {
+ GenericMultiselect
+ },
data() {
return {
- recipe: undefined,
- selected_property: undefined,
+ food: undefined,
+ food_properties: [],
}
},
- computed: {
- show_modal: function () {
- return this.selected_property !== undefined
- },
- },
mounted() {
this.$i18n.locale = window.CUSTOM_LOCALE
let apiClient = new ApiApiFactory()
- apiClient.retrieveRecipe('1').then((r) => {
- this.recipe = r.data
+ apiClient.retrieveFood('1').then((r) => {
+ this.food = r.data
})
+ apiClient.listFoodPropertyTypes().then((r) => {
+ r.data.forEach((fp) => {
+ this.food_properties.push({
+ 'food_amount': 0,
+ 'food_unit': null,
+ 'food': this.food,
+ 'property_amount': 0,
+ 'property_type': fp,
+ })
+ })
+ })
+ },
+ methods: {
+ updateFood: function () {
+ let apiClient = new ApiApiFactory()
+ apiClient.updateFood(this.food.id, this.food).then((r) => {
+ this.food = r.data
+ StandardToasts.makeStandardToast(this, StandardToasts.SUCCESS_UPDATE)
+ }).catch(err => {
+ StandardToasts.makeStandardToast(this, StandardToasts.FAIL_UPDATE, err)
+ })
+ }
},
- methods: {},
}
diff --git a/vue/src/components/FoodPropertyViewComponent.vue b/vue/src/components/FoodPropertyViewComponent.vue
index fb3d23c73..0d1d0d18e 100644
--- a/vue/src/components/FoodPropertyViewComponent.vue
+++ b/vue/src/components/FoodPropertyViewComponent.vue
@@ -2,8 +2,8 @@
-
-
Properties
+
+
{{$t('Properties')}}
diff --git a/vue/src/locales/en.json b/vue/src/locales/en.json
index 2828e747f..269a10ade 100644
--- a/vue/src/locales/en.json
+++ b/vue/src/locales/en.json
@@ -168,6 +168,7 @@
"create_title": "New {type}",
"edit_title": "Edit {type}",
"Name": "Name",
+ "Properties": "Properties",
"Type": "Type",
"Description": "Description",
"Recipe": "Recipe",
diff --git a/vue/src/utils/models.js b/vue/src/utils/models.js
index 185035585..7df27fa5e 100644
--- a/vue/src/utils/models.js
+++ b/vue/src/utils/models.js
@@ -595,7 +595,7 @@ export class Models {
form_field: true,
type: "text",
field: "converted_amount",
- label: "base_amount",
+ label: "converted_amount",
placeholder: "",
},
converted_unit: {