forked from mealie-recipes/mealie
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Structured Yields (mealie-recipes#4489)
Co-authored-by: Kuchenpirat <[email protected]>
- Loading branch information
1 parent
c8cd68b
commit 327da02
Showing
39 changed files
with
1,017 additions
and
550 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
alembic/versions/2024-10-23-15.50.59_b1020f328e98_add_recipe_yield_quantity.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"""add recipe yield quantity | ||
Revision ID: b1020f328e98 | ||
Revises: 3897397b4631 | ||
Create Date: 2024-10-23 15:50:59.888793 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from sqlalchemy import orm | ||
|
||
from alembic import op | ||
from mealie.db.models._model_utils.guid import GUID | ||
from mealie.services.scraper.cleaner import clean_yield | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "b1020f328e98" | ||
down_revision: str | None = "3897397b4631" | ||
branch_labels: str | tuple[str, ...] | None = None | ||
depends_on: str | tuple[str, ...] | None = None | ||
|
||
|
||
# Intermediate table definitions | ||
class SqlAlchemyBase(orm.DeclarativeBase): | ||
pass | ||
|
||
|
||
class RecipeModel(SqlAlchemyBase): | ||
__tablename__ = "recipes" | ||
|
||
id: orm.Mapped[GUID] = orm.mapped_column(GUID, primary_key=True, default=GUID.generate) | ||
recipe_yield: orm.Mapped[str | None] = orm.mapped_column(sa.String) | ||
recipe_yield_quantity: orm.Mapped[float] = orm.mapped_column(sa.Float, index=True, default=0) | ||
recipe_servings: orm.Mapped[float] = orm.mapped_column(sa.Float, index=True, default=0) | ||
|
||
|
||
def parse_recipe_yields(): | ||
bind = op.get_bind() | ||
session = orm.Session(bind=bind) | ||
|
||
for recipe in session.query(RecipeModel).all(): | ||
try: | ||
recipe.recipe_servings, recipe.recipe_yield_quantity, recipe.recipe_yield = clean_yield(recipe.recipe_yield) | ||
except Exception: | ||
recipe.recipe_servings = 0 | ||
recipe.recipe_yield_quantity = 0 | ||
|
||
session.commit() | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("recipes", schema=None) as batch_op: | ||
batch_op.add_column(sa.Column("recipe_yield_quantity", sa.Float(), nullable=False, server_default="0")) | ||
batch_op.create_index(batch_op.f("ix_recipes_recipe_yield_quantity"), ["recipe_yield_quantity"], unique=False) | ||
batch_op.add_column(sa.Column("recipe_servings", sa.Float(), nullable=False, server_default="0")) | ||
batch_op.create_index(batch_op.f("ix_recipes_recipe_servings"), ["recipe_servings"], unique=False) | ||
|
||
# ### end Alembic commands ### | ||
|
||
parse_recipe_yields() | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("recipes", schema=None) as batch_op: | ||
batch_op.drop_index(batch_op.f("ix_recipes_recipe_servings")) | ||
batch_op.drop_column("recipe_servings") | ||
batch_op.drop_index(batch_op.f("ix_recipes_recipe_yield_quantity")) | ||
batch_op.drop_column("recipe_yield_quantity") | ||
|
||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
frontend/components/Domain/Recipe/RecipePage/RecipePageParts/RecipePageInfoCard.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<template> | ||
<div> | ||
<div class="d-flex justify-end flex-wrap align-stretch"> | ||
<RecipePageInfoCardImage v-if="landscape" :recipe="recipe" /> | ||
<v-card | ||
:width="landscape ? '100%' : '50%'" | ||
flat | ||
class="d-flex flex-column justify-center align-center" | ||
> | ||
<v-card-text> | ||
<v-card-title class="headline pa-0 flex-column align-center"> | ||
{{ recipe.name }} | ||
<RecipeRating :key="recipe.slug" :value="recipe.rating" :recipe-id="recipe.id" :slug="recipe.slug" /> | ||
</v-card-title> | ||
<v-divider class="my-2" /> | ||
<SafeMarkdown :source="recipe.description" /> | ||
<v-divider /> | ||
<v-container class="d-flex flex-row flex-wrap justify-center align-center"> | ||
<div class="mx-5"> | ||
<v-row no-gutters class="mb-1"> | ||
<v-col v-if="recipe.recipeYieldQuantity || recipe.recipeYield" cols="12" class="d-flex flex-wrap justify-center"> | ||
<RecipeYield | ||
:yield-quantity="recipe.recipeYieldQuantity" | ||
:yield="recipe.recipeYield" | ||
:scale="recipeScale" | ||
/> | ||
</v-col> | ||
</v-row> | ||
<v-row no-gutters> | ||
<v-col cols="12" class="d-flex flex-wrap justify-center"> | ||
<RecipeLastMade | ||
v-if="isOwnGroup" | ||
:value="recipe.lastMade" | ||
:recipe="recipe" | ||
:class="true ? undefined : 'force-bottom'" | ||
/> | ||
</v-col> | ||
</v-row> | ||
</div> | ||
<div class="mx-5"> | ||
<RecipeTimeCard | ||
stacked | ||
container-class="d-flex flex-wrap justify-center" | ||
:prep-time="recipe.prepTime" | ||
:total-time="recipe.totalTime" | ||
:perform-time="recipe.performTime" | ||
/> | ||
</div> | ||
</v-container> | ||
</v-card-text> | ||
</v-card> | ||
<RecipePageInfoCardImage v-if="!landscape" :recipe="recipe" max-width="50%" class="my-auto" /> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { computed, defineComponent, useContext } from "@nuxtjs/composition-api"; | ||
import { useLoggedInState } from "~/composables/use-logged-in-state"; | ||
import RecipeRating from "~/components/Domain/Recipe/RecipeRating.vue"; | ||
import RecipeLastMade from "~/components/Domain/Recipe/RecipeLastMade.vue"; | ||
import RecipeTimeCard from "~/components/Domain/Recipe/RecipeTimeCard.vue"; | ||
import RecipeYield from "~/components/Domain/Recipe/RecipeYield.vue"; | ||
import RecipePageInfoCardImage from "~/components/Domain/Recipe/RecipePage/RecipePageParts/RecipePageInfoCardImage.vue"; | ||
import { Recipe } from "~/lib/api/types/recipe"; | ||
import { NoUndefinedField } from "~/lib/api/types/non-generated"; | ||
export default defineComponent({ | ||
components: { | ||
RecipeRating, | ||
RecipeLastMade, | ||
RecipeTimeCard, | ||
RecipeYield, | ||
RecipePageInfoCardImage, | ||
}, | ||
props: { | ||
recipe: { | ||
type: Object as () => NoUndefinedField<Recipe>, | ||
required: true, | ||
}, | ||
recipeScale: { | ||
type: Number, | ||
default: 1, | ||
}, | ||
landscape: { | ||
type: Boolean, | ||
required: true, | ||
}, | ||
}, | ||
setup() { | ||
const { $vuetify } = useContext(); | ||
const useMobile = computed(() => $vuetify.breakpoint.smAndDown); | ||
const { isOwnGroup } = useLoggedInState(); | ||
return { | ||
isOwnGroup, | ||
useMobile, | ||
}; | ||
} | ||
}); | ||
</script> |
Oops, something went wrong.