implement related recipes on home page

This commit is contained in:
smilerz
2021-12-22 15:23:16 -06:00
parent 2d01a2af47
commit 67e4c88be7
4 changed files with 50 additions and 35 deletions

View File

@@ -65,7 +65,6 @@ def test_related_mixed_space(request, recipe, u1_s2):
reverse(RELATED_URL, args={recipe.id})).content)) == 0
# TODO add tests for mealplan related when thats added
# TODO if/when related recipes includes multiple levels (related recipes of related recipes) add the following tests
# -- step recipes included in step recipes
# -- step recipes included in food recipes

View File

@@ -229,7 +229,6 @@ def test_shopping_recipe_mixed_authors(u1_s1, u2_s1):
assert len(json.loads(u2_s1.get(reverse(SHOPPING_LIST_URL)).content)) == 0
# TODO test adding recipe with ingredients that are not food
@pytest.mark.parametrize("recipe", [{'steps__ingredients__header': 1}], indirect=['recipe'])
def test_shopping_with_header_ingredient(u1_s1, recipe):
# with scope(space=recipe.space):

View File

@@ -1,5 +1,6 @@
<template>
<div id="app" style="margin-bottom: 4vh">
<RecipeSwitcher mode="mealplan" />
<div class="row">
<div class="col-12 col-xl-8 col-lg-10 offset-xl-2 offset-lg-1">
<div class="row">
@@ -244,6 +245,7 @@ import RecipeCard from "@/components/RecipeCard"
import GenericMultiselect from "@/components/GenericMultiselect"
import Treeselect from "@riophae/vue-treeselect"
import "@riophae/vue-treeselect/dist/vue-treeselect.css"
import RecipeSwitcher from "@/components/Buttons/RecipeSwitcher"
Vue.use(BootstrapVue)
@@ -252,7 +254,7 @@ let SETTINGS_COOKIE_NAME = "search_settings"
export default {
name: "RecipeSearchView",
mixins: [ResolveUrlMixin, ApiMixin],
components: { GenericMultiselect, RecipeCard, Treeselect },
components: { GenericMultiselect, RecipeCard, Treeselect, RecipeSwitcher },
data() {
return {
// this.Models and this.Actions inherited from ApiMixin

View File

@@ -34,9 +34,11 @@
<script>
const { ApiApiFactory } = require("@/utils/openapi/api")
import { ResolveUrlMixin } from "@/utils/utils"
export default {
name: "RecipeSwitcher",
mixins: [ResolveUrlMixin],
props: {
recipe: { type: Number, default: undefined },
name: { type: String, default: undefined },
@@ -64,7 +66,14 @@ export default {
},
mounted() {
this.recipes = []
switch (this.mode) {
case "recipe":
this.loadRecipes()
break
case "mealplan":
this.loadMealPlans()
break
}
},
methods: {
@@ -74,7 +83,8 @@ export default {
this.$emit("switch", recipe)
break
case "mealplan":
console.log("navigate to", recipe)
console.log("navigate to")
window.location.href = this.resolveDjangoUrl("view_recipe", recipe.id)
break
default:
console.log(this.mode, " isn't defined.")
@@ -82,7 +92,7 @@ export default {
},
loadRecipes: function () {
let apiClient = new ApiApiFactory()
let today = new Date(Date.now()).toISOString().split("T")[0]
apiClient
.relatedRecipe(this.recipe, { query: { levels: 2 } })
// get related recipes and save them for later
@@ -91,6 +101,12 @@ export default {
})
// get all recipes for today
.then(() => {
this.loadMealPlans()
})
},
loadMealPlans: function () {
let apiClient = new ApiApiFactory()
let today = new Date(Date.now()).toISOString().split("T")[0]
apiClient
.listMealPlans({
query: {
@@ -124,7 +140,6 @@ export default {
return Promise.all(promises)
})
})
})
},
},
}