1
0
mirror of https://github.com/TandoorRecipes/recipes.git synced 2026-01-11 00:58:32 -05:00

update Recipe Search, Edit and View to work with updated API

This commit is contained in:
smilerz
2024-04-29 13:06:00 -05:00
parent ce9c469acc
commit 748db37a1b
5 changed files with 1416 additions and 1421 deletions

View File

@@ -1149,11 +1149,9 @@ export default {
this.recipe.properties = this.recipe.properties.filter(p => p.id !== recipe_property.id)
},
searchKeywords: function (query) {
let apiFactory = new ApiApiFactory()
this.keywords_loading = true
apiFactory
.listKeywords(query, undefined, undefined, 1, this.options_limit)
this.genericAPI(this.Models.KEYWORD, this.Actions.LIST, {'query': query, 'page': 1, 'pageSize': this.options_limit})
.then((response) => {
this.keywords = response.data.results
this.keywords_loading = false
@@ -1163,13 +1161,10 @@ export default {
})
},
searchFiles: function (query) {
let apiFactory = new ApiApiFactory()
this.files_loading = true
apiFactory
.listUserFiles({query: {query: query}})
this.genericAPI(this.Models.USERFILE, this.Actions.LIST, {'query': query})
.then((response) => {
this.files = response.data
this.files = response.data.results
this.files_loading = false
})
.catch((err) => {
@@ -1188,11 +1183,9 @@ export default {
})
},
searchUnits: function (query) {
let apiFactory = new ApiApiFactory()
this.units_loading = true
apiFactory
.listUnits(query, 1, this.options_limit)
this.genericAPI(this.Models.UNIT, this.Actions.LIST, {'query': query, 'page': 1, 'pageSize': this.options_limit})
.then((response) => {
this.units = response.data.results
let unique_units = this.units.map(u => u.name)
@@ -1212,11 +1205,9 @@ export default {
})
},
searchFoods: _debounce(function (query) {
let apiFactory = new ApiApiFactory()
this.foods_loading = true
apiFactory
.listFoods(query, undefined, undefined, 1, this.options_limit)
this.genericAPI(this.Models.FOOD, this.Actions.LIST, {'query': query, 'page': 1, 'pageSize': this.options_limit})
.then((response) => {
this.foods = response.data.results
let unique_foods = this.foods.map(f => f.name)

View File

@@ -878,7 +878,6 @@ import GenericMultiselect from "@/components/GenericMultiselect"
import MealPlanEditModal from "@/components/MealPlanEditModal.vue"
import RecipeCard from "@/components/RecipeCard"
import { useMealPlanStore } from "@/stores/MealPlanStore"
import { ApiApiFactory } from "@/utils/openapi/api"
import { ApiMixin, ResolveUrlMixin, StandardToasts, ToastMixin } from "@/utils/utils"
Vue.use(VueCookies)
@@ -1127,10 +1126,6 @@ export default {
this.loadMealPlan()
this.refreshData(false)
})
let apiClient = new ApiApiFactory()
apiClient.retrieveSpace(window.ACTIVE_SPACE_ID).then((r) => {
this.use_plural = r.data.use_plural
})
this.$i18n.locale = window.CUSTOM_LOCALE
moment.locale(window.CUSTOM_LOCALE)
this.debug = localStorage.getItem("DEBUG") == "True" || false

View File

@@ -87,11 +87,11 @@
<script>
const { ApiApiFactory } = require("@/utils/openapi/api")
import { ResolveUrlMixin } from "@/utils/utils"
import { ApiMixin, ResolveUrlMixin } from "@/utils/utils"
export default {
name: "RecipeSwitcher",
mixins: [ResolveUrlMixin],
mixins: [ApiMixin, ResolveUrlMixin],
props: {
recipe: { type: Number, default: undefined },
},
@@ -179,9 +179,9 @@ export default {
// TODO move to utility function moment is in maintenance mode https://momentjs.com/docs/
var tzoffset = new Date().getTimezoneOffset() * 60000 //offset in milliseconds
let today = new Date(Date.now() - tzoffset).toISOString().split("T")[0]
return apiClient.listMealPlans(today, today).then((result) => {
return this.genericAPI(this.Models.MEAL_PLAN, this.Actions.LIST, {'fromDate': today, 'toDate': today}).then((result) => {
let promises = []
result.data.forEach((mealplan) => {
result.data.results.forEach((mealplan) => {
this.planned_recipes.push({ ...mealplan?.recipe, servings: mealplan?.servings })
const serving_factor = (mealplan?.servings ?? mealplan?.recipe?.servings ?? 1) / (mealplan?.recipe?.servings ?? 1)
promises.push(

View File

@@ -1,6 +1,7 @@
import { ApiApiFactory } from "@/utils/openapi/api"
import { StandardToasts } from "@/utils/utils"
import { defineStore } from "pinia"
import {ApiApiFactory} from "@/utils/openapi/api"
import {ApiMixin, StandardToasts} from "@/utils/utils"
import {Models, Actions} from "@/utils/models"
import {defineStore} from "pinia"
import Vue from "vue"
const _STORE_ID = "meal_plan_store"
@@ -50,9 +51,9 @@ export const useMealPlanStore = defineStore(_STORE_ID, {
if (this.currently_updating == null || (this.currently_updating[0] !== from_date || this.currently_updating[1] !== to_date)) {
this.currently_updating = [from_date, to_date] // certainly no perfect check but better than nothing
let apiClient = new ApiApiFactory()
apiClient.listMealPlans(from_date, to_date).then((r) => {
r.data.forEach((p) => {
let GenericAPI = ApiMixin.methods.genericAPI
GenericAPI(Models.MEAL_PLAN, Actions.LIST, {'fromDate': from_date, 'toDate': to_date}).then((r) => {
r.data.results.forEach((p) => {
Vue.set(this.plans, p.id, p)
})
this.currently_updating = null

File diff suppressed because it is too large Load Diff