From 7394cfc6400209fb2bc0cbc3c87cbf407f95d121 Mon Sep 17 00:00:00 2001 From: hay-kot Date: Tue, 30 Mar 2021 12:18:05 -0800 Subject: [PATCH] fix meal-plan filter --- .../src/components/MealPlan/MealPlanNew.vue | 35 +++++++++++-------- .../src/pages/Admin/MealPlanner/index.vue | 2 +- mealie/routes/recipe/all_recipe_routes.py | 6 ++-- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/frontend/src/components/MealPlan/MealPlanNew.vue b/frontend/src/components/MealPlan/MealPlanNew.vue index fcb087892..2b86afb9c 100644 --- a/frontend/src/components/MealPlan/MealPlanNew.vue +++ b/frontend/src/components/MealPlan/MealPlanNew.vue @@ -115,26 +115,17 @@ export default { }); } }, + groupSettings() { + this.buildMealStore(); + }, }, async mounted() { - let categories = Array.from(this.groupSettings, x => x.name); - this.items = await api.recipes.getAllByCategory(categories); - - if (this.items.length === 0) { - const keys = [ - "name", - "slug", - "image", - "description", - "dateAdded", - "rating", - ]; - this.items = await api.recipes.allByKeys(keys); - } + this.$store.dispatch("requestCurrentGroup"); }, computed: { groupSettings() { + console.log(this.$store.getters.getCurrentGroup); return this.$store.getters.getCurrentGroup; }, actualStartDate() { @@ -164,6 +155,22 @@ export default { }, methods: { + async buildMealStore() { + let categories = Array.from(this.groupSettings.categories, x => x.name); + this.items = await api.recipes.getAllByCategory(categories); + + if (this.items.length === 0) { + const keys = [ + "name", + "slug", + "image", + "description", + "dateAdded", + "rating", + ]; + this.items = await api.recipes.allByKeys(keys); + } + }, get_random(list) { const object = list[Math.floor(Math.random() * list.length)]; return object; diff --git a/frontend/src/pages/Admin/MealPlanner/index.vue b/frontend/src/pages/Admin/MealPlanner/index.vue index a391bd6c5..a1b953430 100644 --- a/frontend/src/pages/Admin/MealPlanner/index.vue +++ b/frontend/src/pages/Admin/MealPlanner/index.vue @@ -133,7 +133,7 @@ export default { }, computed: { categories() { - return this.$store.getters.getCategories; + return this.$store.getters.getAllCategories; }, isFlat() { return this.groupSettings.categories >= 1 ? true : false; diff --git a/mealie/routes/recipe/all_recipe_routes.py b/mealie/routes/recipe/all_recipe_routes.py index 761e081d2..659905483 100644 --- a/mealie/routes/recipe/all_recipe_routes.py +++ b/mealie/routes/recipe/all_recipe_routes.py @@ -1,8 +1,8 @@ from typing import List, Optional +from fastapi import APIRouter, Depends, Query from mealie.db.database import db from mealie.db.db_setup import generate_session -from fastapi import APIRouter, Depends, Query from mealie.schema.recipe import AllRecipeRequest from slugify import slugify from sqlalchemy.orm.session import Session @@ -75,7 +75,7 @@ def filter_by_category(categories: list, session: Session = Depends(generate_ses """ pass a list of categories and get a list of recipes associated with those categories """ # ! This should be refactored into a single database call, but I couldn't figure it out in_category = [db.categories.get(session, slugify(cat), limit=1) for cat in categories] - in_category = [cat.get("recipes") for cat in in_category if cat] + in_category = [cat.recipes for cat in in_category if cat] in_category = [item for sublist in in_category for item in sublist] return in_category @@ -85,6 +85,6 @@ async def filter_by_tags(tags: list, session: Session = Depends(generate_session """ pass a list of tags and get a list of recipes associated with those tags""" # ! This should be refactored into a single database call, but I couldn't figure it out in_tags = [db.tags.get(session, slugify(tag), limit=1) for tag in tags] - in_tags = [tag.get("recipes") for tag in in_tags] + in_tags = [tag.recipes for tag in in_tags] in_tags = [item for sublist in in_tags for item in sublist] return in_tags