From 2d01a2af47b4be071c9f62e547cec44001c03046 Mon Sep 17 00:00:00 2001 From: smilerz Date: Wed, 22 Dec 2021 14:43:00 -0600 Subject: [PATCH 1/6] implemented quick switch --- cookbook/views/api.py | 7 +- vue/src/apps/RecipeView/RecipeView.vue | 13 +- vue/src/components/Buttons/RecipeSwitcher.vue | 161 ++++++++++++++++++ vue/src/locales/en.json | 4 +- 4 files changed, 181 insertions(+), 4 deletions(-) create mode 100644 vue/src/components/Buttons/RecipeSwitcher.vue diff --git a/cookbook/views/api.py b/cookbook/views/api.py index 5f01c4013..41951f293 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 d87cd6a60..6cbc09762 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 000000000..73d062a99 --- /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 3c05bf828..7456063ca 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" } From 67e4c88be7608062a24d8a4cbaa9e3e39da46002 Mon Sep 17 00:00:00 2001 From: smilerz Date: Wed, 22 Dec 2021 15:23:16 -0600 Subject: [PATCH 2/6] implement related recipes on home page --- cookbook/tests/api/test_api_related_recipe.py | 1 - .../tests/api/test_api_shopping_recipe.py | 1 - .../RecipeSearchView/RecipeSearchView.vue | 4 +- vue/src/components/Buttons/RecipeSwitcher.vue | 79 +++++++++++-------- 4 files changed, 50 insertions(+), 35 deletions(-) diff --git a/cookbook/tests/api/test_api_related_recipe.py b/cookbook/tests/api/test_api_related_recipe.py index ce6221880..1a381ed5c 100644 --- a/cookbook/tests/api/test_api_related_recipe.py +++ b/cookbook/tests/api/test_api_related_recipe.py @@ -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 diff --git a/cookbook/tests/api/test_api_shopping_recipe.py b/cookbook/tests/api/test_api_shopping_recipe.py index 6b0630c8b..37ac53ba6 100644 --- a/cookbook/tests/api/test_api_shopping_recipe.py +++ b/cookbook/tests/api/test_api_shopping_recipe.py @@ -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): diff --git a/vue/src/apps/RecipeSearchView/RecipeSearchView.vue b/vue/src/apps/RecipeSearchView/RecipeSearchView.vue index 8efde72ab..9b7571fc8 100644 --- a/vue/src/apps/RecipeSearchView/RecipeSearchView.vue +++ b/vue/src/apps/RecipeSearchView/RecipeSearchView.vue @@ -1,5 +1,6 @@