diff --git a/cookbook/helper/recipe_search.py b/cookbook/helper/recipe_search.py index ef080a351..1846f2e85 100644 --- a/cookbook/helper/recipe_search.py +++ b/cookbook/helper/recipe_search.py @@ -222,13 +222,16 @@ class RecipeSearch(): def rating_filter(self, rating=None): if rating is None: return - rating = int(rating) + lessthan = '-' in rating + # TODO make ratings a settings user-only vs all-users self._queryset = self._queryset.annotate(rating=Round(Avg(Case(When(cooklog__created_by=self._request.user, then='cooklog__rating'), default=Value(0))))) if rating == 0: self._queryset = self._queryset.filter(rating=0) + elif lessthan: + self._queryset = self._queryset.filter(rating__lte=int(rating[1:])) else: - self._queryset = self._queryset.filter(rating__gte=rating) + self._queryset = self._queryset.filter(rating__gte=int(rating)) def internal_filter(self): self._queryset = self._queryset.filter(internal=True) diff --git a/vue/src/apps/RecipeSearchView/RecipeSearchView.vue b/vue/src/apps/RecipeSearchView/RecipeSearchView.vue index 269b9d651..b95e79e60 100644 --- a/vue/src/apps/RecipeSearchView/RecipeSearchView.vue +++ b/vue/src/apps/RecipeSearchView/RecipeSearchView.vue @@ -143,10 +143,10 @@
- + - + {{ $t("or") }} {{ $t("and") }} @@ -365,17 +365,24 @@ export default { advanced_search_visible: false, search_input: "", search_internal: false, - search_keywords: [], + search_keywords: [ + { items: [], operator: true }, + { items: [], operator: true }, + { items: [], operator: true }, + { items: [], operator: true }, + ], search_foods: [], search_books: [], search_units: [], search_ratings: undefined, + search_rating_gte: true, search_keywords_or: true, search_foods_or: true, search_books_or: true, search_units_or: true, pagination_page: 1, expert_mode: false, + keyword_fields: 1, }, ui: { show_meal_plan: true, @@ -412,6 +419,12 @@ export default { return ` (${x})` } } + let label = "" + if (this.search.search_rating_gte) { + label = this.$t("and_up") + } else { + label = this.$t("and_down") + } return [ { id: 5, label: "⭐⭐⭐⭐⭐" + ratingCount(this.facets.Ratings?.["5.0"] ?? 0) }, { id: 4, label: "⭐⭐⭐⭐ " + this.$t("and_up") + ratingCount(this.facets.Ratings?.["4.0"] ?? 0) }, @@ -436,7 +449,7 @@ export default { let urlParams = new URLSearchParams(window.location.search) if (urlParams.has("keyword")) { - this.search.search_keywords = [] + this.search.search_keywords[0].items = [] this.facets.Keywords = [] for (let x of urlParams.getAll("keyword")) { let initial_keyword = { id: Number.parseInt(x), name: "loading..." } @@ -503,8 +516,7 @@ export default { this.refreshData(false) }, "ui.tree_select": function () { - if (this.ui.tree_select && !this.facets?.Keywords && !this.facets?.Foods) { - console.log("i changed to true") + if (this.ui.tree_select && (!this.facets?.Keywords || !this.facets?.Foods)) { this.getFacets(this.facets?.hash) } }, @@ -520,10 +532,11 @@ export default { methods: { // this.genericAPI inherited from ApiMixin refreshData: function (random) { + console.log(this.search.search_keywords) this.random_search = random let params = { query: this.search.search_input, - keywords: this.search.search_keywords.map(function (A) { + keywords: this.search.search_keywords[0].items.map(function (A) { return A?.["id"] ?? A }), foods: this.search.search_foods.map(function (A) { @@ -549,6 +562,7 @@ export default { if (!this.searchFiltered) { params.options = { query: { last_viewed: this.ui.recently_viewed } } } + // console.log(params, this.search.search_keywords[0], this.search.search_keywords[0].items) this.genericAPI(this.Models.RECIPE, this.Actions.LIST, params) .then((result) => { window.scrollTo(0, 0) @@ -593,13 +607,19 @@ export default { } }, genericSelectChanged: function (obj) { - this.search[obj.var] = obj.val + if (obj.var.includes("::")) { + let x = obj.var.split("::") + this.search[x[0]][x[1]].items = obj.val + } else { + this.search[obj.var] = obj.val + } + this.refreshData(false) }, resetSearch: function () { this.search.search_input = "" this.search.search_internal = false - this.search.search_keywords = [] + this.search.search_keywords[0].items = [] this.search.search_foods = [] this.search.search_books = [] this.search.search_units = [] @@ -665,7 +685,7 @@ export default { buildParams: function () { let params = { query: this.search.search_input, - keywords: this.search.search_keywords, + keywords: this.search.search_keywords[0].items, foods: this.search.search_foods, rating: this.search.search_ratings, books: this.search.search_books.map(function (A) { @@ -686,16 +706,17 @@ export default { }, searchFiltered: function (ignore_string = false) { let filtered = - this.search?.search_keywords?.length === 0 && + this.search?.search_keywords[0].items?.length === 0 && this.search?.search_foods?.length === 0 && this.search?.search_books?.length === 0 && // this.settings?.pagination_page === 1 && !this.random_search && this.search?.search_ratings === undefined + if (ignore_string) { - return filtered + return !filtered } else { - return filtered && this.search?.search_input === "" + return !filtered && this.search?.search_input !== "" } }, }, diff --git a/vue/src/locales/en.json b/vue/src/locales/en.json index 527bd3a3b..7166bebf1 100644 --- a/vue/src/locales/en.json +++ b/vue/src/locales/en.json @@ -165,6 +165,7 @@ "Create_New_Unit": "Add New Unit", "Create_New_Meal_Type": "Add New Meal Type", "and_up": "& Up", + "and_down": "& Down", "Instructions": "Instructions", "Unrated": "Unrated", "Automate": "Automate",