load RecipeFilter cookbook entries
This commit is contained in:
@ -25,10 +25,11 @@ class RecipeSearch():
|
||||
def __init__(self, request, **params):
|
||||
self._request = request
|
||||
self._queryset = None
|
||||
if filter := params.get('filter', None):
|
||||
try:
|
||||
self._params = {**json.loads(CustomFilter.objects.get(id=filter).search)}
|
||||
except CustomFilter.DoesNotExist:
|
||||
if f := params.get('filter', None):
|
||||
filter = CustomFilter.objects.filter(id=f, space=self._request.space).filter(Q(created_by=self._request.user) | Q(shared=self._request.user)).first()
|
||||
if filter:
|
||||
self._params = {**json.loads(filter.search)}
|
||||
else:
|
||||
self._params = {**(params or {})}
|
||||
else:
|
||||
self._params = {**(params or {})}
|
||||
@ -116,9 +117,7 @@ class RecipeSearch():
|
||||
self.unit_filters(units=self._units)
|
||||
self.string_filters(string=self._string)
|
||||
self._makenow_filter()
|
||||
|
||||
# self._queryset = self._queryset.distinct() # TODO 2x check. maybe add filter of recipe__in after orderby
|
||||
return self._queryset.filter(space=self._request.space).order_by(*self.orderby)
|
||||
return self._queryset.filter(space=self._request.space).distinct().order_by(*self.orderby)
|
||||
|
||||
def _sort_includes(self, *args):
|
||||
for x in args:
|
||||
|
@ -58,13 +58,13 @@ import "bootstrap-vue/dist/bootstrap-vue.css"
|
||||
import { ApiApiFactory } from "@/utils/openapi/api"
|
||||
import CookbookSlider from "@/components/CookbookSlider"
|
||||
import LoadingSpinner from "@/components/LoadingSpinner"
|
||||
import { StandardToasts } from "@/utils/utils"
|
||||
import { StandardToasts, ApiMixin } from "@/utils/utils"
|
||||
|
||||
Vue.use(BootstrapVue)
|
||||
|
||||
export default {
|
||||
name: "CookbookView",
|
||||
mixins: [],
|
||||
mixins: [ApiMixin],
|
||||
components: { LoadingSpinner, CookbookSlider },
|
||||
data() {
|
||||
return {
|
||||
@ -105,8 +105,24 @@ export default {
|
||||
let apiClient = new ApiApiFactory()
|
||||
|
||||
this.current_book = book
|
||||
const book_contents = this.cookbooks.filter((b) => {
|
||||
return b.id == book
|
||||
})[0]
|
||||
|
||||
apiClient.listRecipeBookEntrys({ query: { book: book } }).then((result) => {
|
||||
this.recipes = result.data
|
||||
if (book_contents.filter) {
|
||||
var promises = []
|
||||
var page = 1
|
||||
this.appendRecipeFilter(page, book_contents).then((count) => {
|
||||
while (count.total > 0) {
|
||||
page++
|
||||
promises.push(this.appendRecipeFilter(page, book_contents))
|
||||
count.total = count.total - count.page
|
||||
}
|
||||
Promise.all(promises).then()
|
||||
})
|
||||
}
|
||||
this.loading = false
|
||||
})
|
||||
},
|
||||
@ -124,6 +140,22 @@ export default {
|
||||
StandardToasts.makeStandardToast(StandardToasts.FAIL_CREATE)
|
||||
})
|
||||
},
|
||||
appendRecipeFilter: function (page, book) {
|
||||
let params = { page: page, options: { query: { filter: book.filter.id } } }
|
||||
return this.genericAPI(this.Models.RECIPE, this.Actions.LIST, params).then((results) => {
|
||||
let recipes = results.data.results.map((x) => {
|
||||
return {
|
||||
id: x.id,
|
||||
book: book.id,
|
||||
book_content: book,
|
||||
recipe: x.id,
|
||||
recipe_content: x,
|
||||
}
|
||||
})
|
||||
this.recipes.push(...recipes)
|
||||
return { total: results.data.count - results.data.results.length, page: results.data.results.length }
|
||||
})
|
||||
},
|
||||
},
|
||||
directives: {
|
||||
hover: {
|
||||
|
@ -817,6 +817,7 @@ export default {
|
||||
this.meal_plans.forEach((x) => mealPlans.push(x.recipe.id))
|
||||
this.recipes = this.recipes.filter((recipe) => !mealPlans.includes(recipe.id))
|
||||
}
|
||||
console.log(result.data)
|
||||
})
|
||||
.then(() => {
|
||||
this.$nextTick(function () {
|
||||
@ -1065,14 +1066,15 @@ export default {
|
||||
},
|
||||
saveSearch: function () {
|
||||
let filtername = window.prompt(this.$t("save_filter"), this.$t("filter_name"))
|
||||
let search = this.buildParams(false)
|
||||
;["page", "pageSize"].forEach((key) => {
|
||||
delete search[key]
|
||||
})
|
||||
let params = {
|
||||
name: filtername,
|
||||
search: JSON.stringify(this.buildParams(false)),
|
||||
search: JSON.stringify(search),
|
||||
}
|
||||
let delete_keys = ["page", "pageSize"]
|
||||
delete_keys.forEach((key) => {
|
||||
delete params.search[key]
|
||||
})
|
||||
|
||||
this.genericAPI(this.Models.CUSTOM_FILTER, this.Actions.CREATE, params)
|
||||
.then((result) => {
|
||||
this.search.search_filter = result.data
|
||||
|
@ -318,7 +318,7 @@
|
||||
"asc": "Ascending",
|
||||
"desc": "Descending",
|
||||
"date_viewed": "Last Viewed",
|
||||
"date_cooked": "Last Cooked",
|
||||
"last_cooked": "Last Cooked",
|
||||
"times_cooked": "Times Cooked",
|
||||
"date_created": "Date Created",
|
||||
"show_sortby": "Show Sort By",
|
||||
|
@ -3134,21 +3134,18 @@ export interface UserPreference {
|
||||
* @memberof UserPreference
|
||||
*/
|
||||
shopping_add_onhand?: boolean;
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> created CustomFilter model and api
|
||||
/**
|
||||
*
|
||||
* @type {boolean}
|
||||
* @memberof UserPreference
|
||||
*/
|
||||
left_handed?: boolean;
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> complex keyword filters
|
||||
=======
|
||||
>>>>>>> created CustomFilter model and api
|
||||
/**
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof UserPreference
|
||||
*/
|
||||
food_children_exist?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user