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