added ability to order property types
This commit is contained in:
parent
17fa3c8d7c
commit
92d648c3a3
@ -34,7 +34,7 @@ class FoodPropertyHelper:
|
||||
caches['default'].set(CacheHelper(self.space).PROPERTY_TYPE_CACHE_KEY, property_types, 60 * 60) # cache is cleared on property type save signal so long duration is fine
|
||||
|
||||
for fpt in property_types:
|
||||
computed_properties[fpt.id] = {'id': fpt.id, 'name': fpt.name, 'icon': fpt.icon, 'description': fpt.description, 'unit': fpt.unit, 'food_values': {}, 'total_value': 0, 'missing_value': False}
|
||||
computed_properties[fpt.id] = {'id': fpt.id, 'name': fpt.name, 'icon': fpt.icon, 'description': fpt.description, 'unit': fpt.unit, 'order': fpt.order, 'food_values': {}, 'total_value': 0, 'missing_value': False}
|
||||
|
||||
uch = UnitConversionHelper(self.space)
|
||||
|
||||
|
18
cookbook/migrations/0198_propertytype_order.py
Normal file
18
cookbook/migrations/0198_propertytype_order.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.1.10 on 2023-08-24 09:25
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0197_step_show_ingredients_table_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='propertytype',
|
||||
name='order',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
]
|
@ -768,6 +768,7 @@ class PropertyType(models.Model, PermissionModelMixin):
|
||||
name = models.CharField(max_length=128)
|
||||
unit = models.CharField(max_length=64, blank=True, null=True)
|
||||
icon = models.CharField(max_length=16, blank=True, null=True)
|
||||
order = models.IntegerField(default=0)
|
||||
description = models.CharField(max_length=512, blank=True, null=True)
|
||||
category = models.CharField(max_length=64, choices=((NUTRITION, _('Nutrition')), (ALLERGEN, _('Allergen')), (PRICE, _('Price')), (GOAL, _('Goal')), (OTHER, _('Other'))), null=True, blank=True)
|
||||
open_data_slug = models.CharField(max_length=128, null=True, blank=True, default=None)
|
||||
@ -786,6 +787,7 @@ class PropertyType(models.Model, PermissionModelMixin):
|
||||
models.UniqueConstraint(fields=['space', 'name'], name='property_type_unique_name_per_space'),
|
||||
models.UniqueConstraint(fields=['space', 'open_data_slug'], name='property_type_unique_open_data_slug_per_space')
|
||||
]
|
||||
ordering = ('order',)
|
||||
|
||||
|
||||
class Property(models.Model, PermissionModelMixin):
|
||||
|
@ -528,7 +528,7 @@ class PropertyTypeSerializer(OpenDataModelMixin, WritableNestedModelSerializer,
|
||||
|
||||
class Meta:
|
||||
model = PropertyType
|
||||
fields = ('id', 'name', 'icon', 'unit', 'description', 'open_data_slug')
|
||||
fields = ('id', 'name', 'icon', 'unit', 'description', 'order', 'open_data_slug')
|
||||
|
||||
|
||||
class PropertySerializer(UniqueFieldsMixin, WritableNestedModelSerializer):
|
||||
@ -771,7 +771,7 @@ class StepSerializer(WritableNestedModelSerializer, ExtendedRecipeMixin):
|
||||
model = Step
|
||||
fields = (
|
||||
'id', 'name', 'instruction', 'ingredients', 'ingredients_markdown',
|
||||
'ingredients_vue', 'time', 'order', 'show_as_header', 'file', 'step_recipe',
|
||||
'ingredients_vue', 'time', 'order', 'show_as_header', 'file', 'step_recipe',
|
||||
'step_recipe_data', 'numrecipe', 'show_ingredients_table'
|
||||
)
|
||||
|
||||
@ -1002,7 +1002,6 @@ class MealPlanSerializer(SpacedModelSerializer, WritableNestedModelSerializer):
|
||||
|
||||
|
||||
class AutoMealPlanSerializer(serializers.Serializer):
|
||||
|
||||
start_date = serializers.DateField()
|
||||
end_date = serializers.DateField()
|
||||
meal_type_id = serializers.IntegerField()
|
||||
|
@ -131,6 +131,7 @@ export default {
|
||||
'property_amount_total': rp.property_amount * this.recipe.servings * (this.servings / this.recipe.servings),
|
||||
'missing_value': false,
|
||||
'unit': rp.property_type.unit,
|
||||
'type': rp.property_type,
|
||||
}
|
||||
)
|
||||
})
|
||||
@ -147,11 +148,23 @@ export default {
|
||||
'property_amount_total': fp.total_value * (this.servings / this.recipe.servings),
|
||||
'missing_value': fp.missing_value,
|
||||
'unit': fp.unit,
|
||||
'type': fp,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
return pt_list
|
||||
|
||||
function compare(a,b){
|
||||
if(a.type.order > b.type.order){
|
||||
return 1
|
||||
}
|
||||
if(a.type.order < b.type.order){
|
||||
return -1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
return pt_list.sort(compare)
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
|
@ -319,6 +319,7 @@
|
||||
"CategoryName": "Category Name",
|
||||
"SupermarketName": "Supermarket Name",
|
||||
"CategoryInstruction": "Drag categories to change the order categories appear in shopping list.",
|
||||
"OrderInformation": "Objects are ordered from small to large numbers.",
|
||||
"shopping_recent_days_desc": "Days of recent shopping list entries to display.",
|
||||
"shopping_recent_days": "Recent Days",
|
||||
"download_pdf": "Download PDF",
|
||||
|
@ -281,7 +281,7 @@ export class Models {
|
||||
apiName: "Unit",
|
||||
paginated: true,
|
||||
create: {
|
||||
params: [["name", "plural_name", "description", "base_unit","open_data_slug",]],
|
||||
params: [["name", "plural_name", "description", "base_unit", "open_data_slug",]],
|
||||
form: {
|
||||
show_help: true,
|
||||
name: {
|
||||
@ -711,7 +711,7 @@ export class Models {
|
||||
},
|
||||
},
|
||||
create: {
|
||||
params: [['name', 'icon', 'unit', 'description']],
|
||||
params: [['name', 'icon', 'unit', 'description','order']],
|
||||
form: {
|
||||
show_help: true,
|
||||
name: {
|
||||
@ -745,6 +745,15 @@ export class Models {
|
||||
placeholder: "",
|
||||
optional: true,
|
||||
},
|
||||
order: {
|
||||
form_field: true,
|
||||
type: "number",
|
||||
field: "order",
|
||||
label: "Order",
|
||||
placeholder: "",
|
||||
optional: true,
|
||||
helpt_text: "OrderInformation",
|
||||
},
|
||||
open_data_slug: {
|
||||
form_field: true,
|
||||
type: "text",
|
||||
|
Loading…
Reference in New Issue
Block a user