From 46cc3898ab0ae600d9df6cf4d5033053dcdada0b Mon Sep 17 00:00:00 2001 From: Michael Genson <71845777+michael-genson@users.noreply.github.com> Date: Fri, 30 Dec 2022 16:47:35 -0600 Subject: [PATCH] feat: Improved Recipe Scaling Support and Shopping List Recipe Refactor (#1847) * propogate scale changes to print view * fixed incorrect variable reference * refactored shopping list recipe routes cleaned up existing logic added support for recipe scaling * updated current revision * adding to shopping list respects UI recipe scale * added field annotations * added tests for recipe scaling * made column nullable and set to 1 during migration --- ...add_recipe_scale_to_shopping_list_item_.py | 29 +++ .../Domain/Recipe/RecipeActionMenu.vue | 5 + .../Domain/Recipe/RecipeContextMenu.vue | 6 +- .../Domain/Recipe/RecipePage/RecipePage.vue | 4 +- .../RecipePageParts/RecipePageHeader.vue | 5 + .../Domain/Recipe/RecipePrintView.vue | 6 +- frontend/lib/api/user/group-shopping-lists.ts | 4 +- mealie/db/models/group/shopping_list.py | 1 + .../groups/controller_shopping_lists.py | 18 +- mealie/schema/group/group_shopping_list.py | 14 ++ .../services/group_services/shopping_lists.py | 118 ++++++++---- .../test_group_shopping_lists.py | 181 +++++++++++++++++- .../backup_v2_tests/test_alchemy_exporter.py | 2 +- 13 files changed, 344 insertions(+), 49 deletions(-) create mode 100644 alembic/versions/2022-11-22-03.42.45_167eb69066ad_add_recipe_scale_to_shopping_list_item_.py diff --git a/alembic/versions/2022-11-22-03.42.45_167eb69066ad_add_recipe_scale_to_shopping_list_item_.py b/alembic/versions/2022-11-22-03.42.45_167eb69066ad_add_recipe_scale_to_shopping_list_item_.py new file mode 100644 index 00000000..42f508cd --- /dev/null +++ b/alembic/versions/2022-11-22-03.42.45_167eb69066ad_add_recipe_scale_to_shopping_list_item_.py @@ -0,0 +1,29 @@ +"""add recipe_scale to shopping list item ref + +Revision ID: 167eb69066ad +Revises: 1923519381ad +Create Date: 2022-11-22 03:42:45.494567 + +""" +import sqlalchemy as sa + +from alembic import op + +# revision identifiers, used by Alembic. +revision = "167eb69066ad" +down_revision = "1923519381ad" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column("shopping_list_item_recipe_reference", sa.Column("recipe_scale", sa.Float(), nullable=True)) + op.execute("UPDATE shopping_list_item_recipe_reference SET recipe_scale = 1") + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("shopping_list_item_recipe_reference", "recipe_scale") + # ### end Alembic commands ### diff --git a/frontend/components/Domain/Recipe/RecipeActionMenu.vue b/frontend/components/Domain/Recipe/RecipeActionMenu.vue index a0745335..b8447d5a 100644 --- a/frontend/components/Domain/Recipe/RecipeActionMenu.vue +++ b/frontend/components/Domain/Recipe/RecipeActionMenu.vue @@ -51,6 +51,7 @@ color="info" :card-menu="false" :recipe-id="recipe.id" + :recipe-scale="recipeScale" :use-items="{ delete: false, edit: false, @@ -105,6 +106,10 @@ export default defineComponent({ required: true, type: String, }, + recipeScale: { + type: Number, + default: 1, + }, open: { required: true, type: Boolean, diff --git a/frontend/components/Domain/Recipe/RecipeContextMenu.vue b/frontend/components/Domain/Recipe/RecipeContextMenu.vue index 475c119f..5ae36e4c 100644 --- a/frontend/components/Domain/Recipe/RecipeContextMenu.vue +++ b/frontend/components/Domain/Recipe/RecipeContextMenu.vue @@ -199,6 +199,10 @@ export default defineComponent({ required: true, type: String, }, + recipeScale: { + type: Number, + default: 1, + }, /** * Optional group ID prop that is only _required_ when the * public URL is requested. If the public URL button is pressed @@ -316,7 +320,7 @@ export default defineComponent({ } async function addRecipeToList(listId: string) { - const { data } = await api.shopping.lists.addRecipe(listId, props.recipeId); + const { data } = await api.shopping.lists.addRecipe(listId, props.recipeId, props.recipeScale); if (data) { alert.success(i18n.t("recipe.recipe-added-to-list") as string); state.shoppingListDialog = false; diff --git a/frontend/components/Domain/Recipe/RecipePage/RecipePage.vue b/frontend/components/Domain/Recipe/RecipePage/RecipePage.vue index 89028b89..f5ffb6dd 100644 --- a/frontend/components/Domain/Recipe/RecipePage/RecipePage.vue +++ b/frontend/components/Domain/Recipe/RecipePage/RecipePage.vue @@ -1,7 +1,7 @@