fix meal-plan filter

This commit is contained in:
hay-kot 2021-03-30 12:18:05 -08:00
commit 7394cfc640
3 changed files with 25 additions and 18 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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