Merge pull request #2808 from smilerz/add_mealtype_filter

add ability to filter meal plans based on type
This commit is contained in:
vabene1111
2023-12-20 15:55:09 +01:00
committed by GitHub
5 changed files with 134 additions and 3855 deletions

View File

@ -1,10 +1,9 @@
<template>
<div v-if="recipes !== {}">
<div id="switcher" class="align-center">
<i class="btn btn-primary fas fa-receipt fa-xl fa-fw shadow-none btn-circle" v-b-toggle.related-recipes/>
<i class="btn btn-primary fas fa-receipt fa-xl fa-fw shadow-none btn-circle" v-b-toggle.related-recipes />
</div>
<b-sidebar id="related-recipes" backdrop right bottom no-header shadow="sm" style="z-index: 10000"
@shown="updatePinnedRecipes()">
<b-sidebar id="related-recipes" backdrop right bottom no-header shadow="sm" style="z-index: 10000" @shown="updatePinnedRecipes()">
<template #default="{ hide }">
<div class="d-flex flex-column justify-content-end h-100 p-3 align-items-end">
<h5>{{ $t("Planned") }} <i class="fas fa-calendar fa-fw"></i></h5>
@ -19,7 +18,7 @@
hide()
"
href="javascript:void(0);"
>{{ r.name }}</a
>{{ r.name }}</a
>
</div>
</div>
@ -36,8 +35,7 @@
<div v-for="r in pinned_recipes" :key="`pin${r.id}`">
<b-row class="pb-1 pt-1">
<b-col cols="2">
<a href="javascript:void(0)" @click="unPinRecipe(r)" class="text-muted"><i
class="fas fa-times"></i></a>
<a href="javascript:void(0)" @click="unPinRecipe(r)" class="text-muted"><i class="fas fa-times"></i></a>
</b-col>
<b-col cols="10">
<a
@ -47,7 +45,7 @@
"
href="javascript:void(0);"
class="align-self-end"
>{{ r.name }}
>{{ r.name }}
</a>
</b-col>
</b-row>
@ -69,7 +67,7 @@
hide()
"
href="javascript:void(0);"
>{{ r.name }}</a
>{{ r.name }}</a
>
</div>
</div>
@ -88,14 +86,14 @@
</template>
<script>
const {ApiApiFactory} = require("@/utils/openapi/api")
import {ResolveUrlMixin} from "@/utils/utils"
const { ApiApiFactory } = require("@/utils/openapi/api")
import { ResolveUrlMixin } from "@/utils/utils"
export default {
name: "RecipeSwitcher",
mixins: [ResolveUrlMixin],
props: {
recipe: {type: Number, default: undefined},
recipe: { type: Number, default: undefined },
},
data() {
return {
@ -160,14 +158,16 @@ export default {
// get related recipes and save them for later
if (this.$parent.recipe) {
this.related_recipes = [this.$parent.recipe]
return apiClient.relatedRecipe(this.$parent.recipe.id, {
query: {
levels: 2,
format: "json"
}
}).then((result) => {
this.related_recipes = this.related_recipes.concat(result.data)
})
return apiClient
.relatedRecipe(this.$parent.recipe.id, {
query: {
levels: 2,
format: "json",
},
})
.then((result) => {
this.related_recipes = this.related_recipes.concat(result.data)
})
}
},
loadPinnedRecipes: function () {
@ -179,16 +179,16 @@ 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({query: {from_date: today, to_date: today}}).then((result) => {
return apiClient.listMealPlans(today, today).then((result) => {
let promises = []
result.data.forEach((mealplan) => {
this.planned_recipes.push({...mealplan?.recipe, servings: mealplan?.servings})
this.planned_recipes.push({ ...mealplan?.recipe, servings: mealplan?.servings })
const serving_factor = (mealplan?.servings ?? mealplan?.recipe?.servings ?? 1) / (mealplan?.recipe?.servings ?? 1)
promises.push(
apiClient.relatedRecipe(mealplan?.recipe?.id, {query: {levels: 2}}).then((r) => {
apiClient.relatedRecipe(mealplan?.recipe?.id, { query: { levels: 2 } }).then((r) => {
// scale all recipes to mealplan servings
r.data = r.data.map((x) => {
return {...x, factor: serving_factor}
return { ...x, factor: serving_factor }
})
this.planned_recipes = [...this.planned_recipes, ...r.data]
})
@ -220,7 +220,6 @@ export default {
z-index: 9000;
}
@media (max-width: 991.98px) {
#switcher .btn-circle {
position: fixed;

View File

@ -1,14 +1,14 @@
import {defineStore} from 'pinia'
import {ApiApiFactory} from "@/utils/openapi/api";
const _STORE_ID = 'meal_plan_store'
const _LOCAL_STORAGE_KEY = 'MEAL_PLAN_CLIENT_SETTINGS'
import { ApiApiFactory } from "@/utils/openapi/api"
import { StandardToasts } from "@/utils/utils"
import { defineStore } from "pinia"
import Vue from "vue"
import {StandardToasts} from "@/utils/utils";
const _STORE_ID = "meal_plan_store"
const _LOCAL_STORAGE_KEY = "MEAL_PLAN_CLIENT_SETTINGS"
/*
* test store to play around with pinia and see if it can work for my usecases
* dont trust that all mealplans are in store as there is no cache validation logic, its just a shared data holder
* */
* test store to play around with pinia and see if it can work for my usecases
* dont trust that all mealplans are in store as there is no cache validation logic, its just a shared data holder
* */
export const useMealPlanStore = defineStore(_STORE_ID, {
state: () => ({
plans: {},
@ -19,7 +19,7 @@ export const useMealPlanStore = defineStore(_STORE_ID, {
plan_list: function () {
let plan_list = []
for (let key in this.plans) {
plan_list.push(this.plans[key]);
plan_list.push(this.plans[key])
}
return plan_list
},
@ -35,7 +35,7 @@ export const useMealPlanStore = defineStore(_STORE_ID, {
servings: 1,
shared: [],
title: "",
title_placeholder: 'Title', // meal plan edit modal should be improved to not need this
title_placeholder: "Title", // meal plan edit modal should be improved to not need this
}
},
client_settings: function () {
@ -43,22 +43,15 @@ export const useMealPlanStore = defineStore(_STORE_ID, {
this.settings = this.loadClientSettings()
}
return this.settings
}
},
},
actions: {
refreshFromAPI(from_date, to_date) {
if (this.currently_updating !== [from_date, to_date]) {
this.currently_updating = [from_date, to_date] // certainly no perfect check but better than nothing
let options = {
query: {
from_date: from_date,
to_date: to_date,
},
}
let apiClient = new ApiApiFactory()
apiClient.listMealPlans(options).then(r => {
apiClient.listMealPlans(from_date, to_date).then((r) => {
r.data.forEach((p) => {
Vue.set(this.plans, p.id, p)
})
@ -68,31 +61,40 @@ export const useMealPlanStore = defineStore(_STORE_ID, {
},
createObject(object) {
let apiClient = new ApiApiFactory()
return apiClient.createMealPlan(object).then(r => {
//StandardToasts.makeStandardToast(this, StandardToasts.SUCCESS_CREATE)
Vue.set(this.plans, r.data.id, r.data)
return r
}).catch(err => {
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_CREATE, err)
})
return apiClient
.createMealPlan(object)
.then((r) => {
//StandardToasts.makeStandardToast(this, StandardToasts.SUCCESS_CREATE)
Vue.set(this.plans, r.data.id, r.data)
return r
})
.catch((err) => {
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_CREATE, err)
})
},
updateObject(object) {
let apiClient = new ApiApiFactory()
return apiClient.updateMealPlan(object.id, object).then(r => {
//StandardToasts.makeStandardToast(this, StandardToasts.SUCCESS_UPDATE)
Vue.set(this.plans, object.id, object)
}).catch(err => {
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_UPDATE, err)
})
return apiClient
.updateMealPlan(object.id, object)
.then((r) => {
//StandardToasts.makeStandardToast(this, StandardToasts.SUCCESS_UPDATE)
Vue.set(this.plans, object.id, object)
})
.catch((err) => {
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_UPDATE, err)
})
},
deleteObject(object) {
let apiClient = new ApiApiFactory()
return apiClient.destroyMealPlan(object.id).then(r => {
//StandardToasts.makeStandardToast(this, StandardToasts.SUCCESS_DELETE)
Vue.delete(this.plans, object.id)
}).catch(err => {
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_DELETE, err)
})
return apiClient
.destroyMealPlan(object.id)
.then((r) => {
//StandardToasts.makeStandardToast(this, StandardToasts.SUCCESS_DELETE)
Vue.delete(this.plans, object.id)
})
.catch((err) => {
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_DELETE, err)
})
},
updateClientSettings(settings) {
this.settings = settings
@ -110,6 +112,6 @@ export const useMealPlanStore = defineStore(_STORE_ID, {
} else {
return JSON.parse(s)
}
}
},
},
})
})

File diff suppressed because it is too large Load Diff