diff --git a/cookbook/views/api.py b/cookbook/views/api.py index 5f01c401..41951f29 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -688,8 +688,11 @@ class RecipeViewSet(viewsets.ModelViewSet): obj = self.get_object() if obj.get_space() != request.space: raise PermissionDenied(detail='You do not have the required permission to perform this action', code=403) - qs = obj.get_related_recipes(levels=1) # TODO: make levels a user setting, included in request data?, keep solely in the backend? - # mealplans= TODO get todays mealplans + try: + levels = int(request.query_params.get('levels', 1)) + except (ValueError, TypeError): + levels = 1 + qs = obj.get_related_recipes(levels=levels) # TODO: make levels a user setting, included in request data?, keep solely in the backend? return Response(self.serializer_class(qs, many=True).data) diff --git a/vue/src/apps/RecipeView/RecipeView.vue b/vue/src/apps/RecipeView/RecipeView.vue index d87cd6a6..6cbc0976 100644 --- a/vue/src/apps/RecipeView/RecipeView.vue +++ b/vue/src/apps/RecipeView/RecipeView.vue @@ -5,6 +5,7 @@
+

{{ recipe.name }}

@@ -172,6 +173,7 @@ import IngredientsCard from "@/components/IngredientsCard" import StepComponent from "@/components/StepComponent" import KeywordsComponent from "@/components/KeywordsComponent" import NutritionComponent from "@/components/NutritionComponent" +import RecipeSwitcher from "@/components/Buttons/RecipeSwitcher" Vue.prototype.moment = moment @@ -192,6 +194,7 @@ export default { KeywordsComponent, LoadingSpinner, AddRecipeToBook, + RecipeSwitcher, }, computed: { ingredient_factor: function () { @@ -202,6 +205,7 @@ export default { return { loading: true, recipe: undefined, + rootrecipe: undefined, ingredient_count: 0, servings: 1, start_time: "", @@ -237,7 +241,7 @@ export default { this.start_time = moment().format("yyyy-MM-DDTHH:mm") } - this.recipe = recipe + this.recipe = this.rootrecipe = recipe this.loading = false }) }, @@ -253,6 +257,13 @@ export default { } } }, + quickSwitch: function (e) { + if (e === -1) { + this.recipe = this.rootrecipe + } else { + this.recipe = e + } + }, }, } diff --git a/vue/src/components/Buttons/RecipeSwitcher.vue b/vue/src/components/Buttons/RecipeSwitcher.vue new file mode 100644 index 00000000..73d062a9 --- /dev/null +++ b/vue/src/components/Buttons/RecipeSwitcher.vue @@ -0,0 +1,161 @@ + + + + + diff --git a/vue/src/locales/en.json b/vue/src/locales/en.json index 3c05bf82..7456063c 100644 --- a/vue/src/locales/en.json +++ b/vue/src/locales/en.json @@ -276,5 +276,7 @@ "csv_prefix_label": "List Prefix", "copy_markdown_table": "Copy as Markdown Table", "in_shopping": "In Shopping List", - "DelayUntil": "Delay Until" + "DelayUntil": "Delay Until", + "related_recipes": "Related Recipes", + "today_recipes": "Today's Recipes" }