From 16d125a24384b86265308f4683fb13ee4d5a0681 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Sat, 4 Sep 2021 19:26:42 +0200 Subject: [PATCH] fixed search facets and sub recipe --- cookbook/helper/recipe_search.py | 15 +++++++-------- .../templates/forms/edit_internal_recipe.html | 8 +++++++- cookbook/views/api.py | 2 +- .../apps/RecipeSearchView/RecipeSearchView.vue | 1 + 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/cookbook/helper/recipe_search.py b/cookbook/helper/recipe_search.py index 3b4fd97e3..51e3d094a 100644 --- a/cookbook/helper/recipe_search.py +++ b/cookbook/helper/recipe_search.py @@ -51,7 +51,7 @@ def search_recipes(request, queryset, params): if search_new == 'true': queryset = ( queryset.annotate(new_recipe=Case( - When(created_at__gte=(datetime.now() - timedelta(days=7)), then=('pk')), default=Value(0),)) + When(created_at__gte=(datetime.now() - timedelta(days=7)), then=('pk')), default=Value(0), )) ) orderby += ['-new_recipe'] @@ -123,9 +123,9 @@ def search_recipes(request, queryset, params): # TODO add order by user settings - only do search rank and annotation if rank order is configured search_rank = ( - SearchRank('name_search_vector', search_query, cover_density=True) - + SearchRank('desc_search_vector', search_query, cover_density=True) - + SearchRank('steps__search_vector', search_query, cover_density=True) + SearchRank('name_search_vector', search_query, cover_density=True) + + SearchRank('desc_search_vector', search_query, cover_density=True) + + SearchRank('steps__search_vector', search_query, cover_density=True) ) queryset = queryset.filter(query_filter).annotate(rank=search_rank) orderby += ['-rank'] @@ -174,7 +174,6 @@ def search_recipes(request, queryset, params): return queryset - def get_facet(qs, request): # NOTE facet counts for tree models include self AND descendants facets = {} @@ -210,9 +209,9 @@ def get_facet(qs, request): # TODO add book facet facets['Books'] = [] facets['Recent'] = ViewLog.objects.filter( - created_by=request.user, space=request.space, - created_at__gte=datetime.now() - timedelta(days=14) # TODO make days of recent recipe a setting - ).values_list('recipe__pk', flat=True) + created_by=request.user, space=request.space, + created_at__gte=datetime.now() - timedelta(days=14) # TODO make days of recent recipe a setting + ).values_list('recipe__pk', flat=True) return facets diff --git a/cookbook/templates/forms/edit_internal_recipe.html b/cookbook/templates/forms/edit_internal_recipe.html index 4ba9235c4..ceb193b34 100644 --- a/cookbook/templates/forms/edit_internal_recipe.html +++ b/cookbook/templates/forms/edit_internal_recipe.html @@ -252,7 +252,6 @@ select-label="{% trans 'Select' %}" :id="'id_step_' + step.id + '_recipe'" :custom-label="opt => recipes.find(x => x.id == opt).name" - :multiple="false" :loading="recipes_loading" @search-change="searchRecipes"> @@ -615,6 +614,13 @@ this.$http.get("{% url 'api:recipe-detail' recipe.pk %}").then((response) => { this.recipe = response.data; this.loading = false + + //TODO workaround function until view is properly refactored, loads name of selected sub recipe so the input can find its label + this.recipe.steps.forEach(s => { + if (s.step_recipe != null) { + this.recipes.push(s.step_recipe_data) + } + }) }).catch((err) => { this.loading = false console.log(err) diff --git a/cookbook/views/api.py b/cookbook/views/api.py index 7288b78cd..a0b113fe0 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -486,7 +486,7 @@ class RecipePagination(PageNumberPagination): max_page_size = 100 def paginate_queryset(self, queryset, request, view=None): - self.facets = get_facet(queryset, request.query_params, request.space) + self.facets = get_facet(queryset, request) return super().paginate_queryset(queryset, request, view) def get_paginated_response(self, data): diff --git a/vue/src/apps/RecipeSearchView/RecipeSearchView.vue b/vue/src/apps/RecipeSearchView/RecipeSearchView.vue index 2eef60ae4..0d9fc41af 100644 --- a/vue/src/apps/RecipeSearchView/RecipeSearchView.vue +++ b/vue/src/apps/RecipeSearchView/RecipeSearchView.vue @@ -337,6 +337,7 @@ export default { this.$nextTick(function () { if (this.$cookies.isKey(SETTINGS_COOKIE_NAME)) { this.settings = Object.assign({}, this.settings, this.$cookies.get(SETTINGS_COOKIE_NAME)) + this.refreshData(false) } let urlParams = new URLSearchParams(window.location.search);