load RecipeFilter cookbook entries

This commit is contained in:
Chris Scoggins
2022-01-27 10:21:05 -06:00
parent c042ab08c7
commit 07d5ead128
5 changed files with 54 additions and 24 deletions

View File

@ -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: {

View File

@ -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

View File

@ -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",

View File

@ -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;
}
/**