-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
moment(m.date).isSame(moment_date, 'day'))})
+ grid.push({date: moment_date, date_label: moment_date.format('DD.MM'), plan_entries: this.meal_plan_store.plans.filter((m) => moment(m.date).isSame(moment_date, 'day'))})
}
return grid
@@ -1169,6 +1175,9 @@ export default {
})
return sort_order
},
+ isMobile: function () { //TODO move to central helper
+ return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
+ }
},
mounted() {
@@ -1306,21 +1315,26 @@ export default {
return [...new Map(data.map((item) => [key(item), item])).values()]
},
loadMealPlan: function () {
- if (this.ui.show_meal_plan) {
- let params = {
- options: {
- query: {
- from_date: moment().format("YYYY-MM-DD"),
- to_date: moment().add(this.ui.meal_plan_days, "days").format("YYYY-MM-DD"),
- },
- },
- }
- this.genericAPI(this.Models.MEAL_PLAN, this.Actions.LIST, params).then((result) => {
- this.meal_plans = result.data
- })
- } else {
- this.meal_plans = []
- }
+ console.log('loadMealpLan')
+ this.meal_plan_store = useMealPlanStore()
+ this.meal_plan_store.refreshFromAPI(moment().format("YYYY-MM-DD"), moment().add(this.ui.meal_plan_days, "days").format("YYYY-MM-DD"))
+
+
+ // if (this.ui.show_meal_plan) {
+ // let params = {
+ // options: {
+ // query: {
+ // from_date: moment().format("YYYY-MM-DD"),
+ // to_date: moment().add(this.ui.meal_plan_days, "days").format("YYYY-MM-DD"),
+ // },
+ // },
+ // }
+ // this.genericAPI(this.Models.MEAL_PLAN, this.Actions.LIST, params).then((result) => {
+ // this.meal_plans = result.data
+ // })
+ // } else {
+ // this.meal_plans = []
+ // }
},
genericSelectChanged: function (obj) {
if (obj.var.includes("::")) {
diff --git a/vue/src/components/RecipeContextMenu.vue b/vue/src/components/RecipeContextMenu.vue
index c57d64b5..eb770203 100644
--- a/vue/src/components/RecipeContextMenu.vue
+++ b/vue/src/components/RecipeContextMenu.vue
@@ -106,6 +106,7 @@ import ShoppingModal from "@/components/Modals/ShoppingModal"
import moment from "moment"
import Vue from "vue"
import {ApiApiFactory} from "@/utils/openapi/api"
+import {useMealPlanStore} from "@/stores/MealPlanStore";
Vue.prototype.moment = moment
@@ -191,6 +192,7 @@ export default {
apiClient
.createMealPlan(entry)
.then((result) => {
+ useMealPlanStore().plans.push(result.data)
this.$bvModal.hide(`modal-meal-plan_${this.modal_id}`)
if (reviewshopping) {
this.mealplan = result.data.id
diff --git a/vue/src/stores/MealPlanStore.js b/vue/src/stores/MealPlanStore.js
new file mode 100644
index 00000000..d3f2b8a1
--- /dev/null
+++ b/vue/src/stores/MealPlanStore.js
@@ -0,0 +1,40 @@
+import {defineStore} from 'pinia'
+import {ApiApiFactory} from "@/utils/openapi/api";
+import moment from "moment/moment";
+
+
+const _STORE_ID = 'meal_plan_store'
+
+/*
+* 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: [] //TODO convert to dict and add translation functions for easy editing
+ }),
+ getters: {
+ plan_list() {
+ let plan_list = []
+ for (let key in this.plans) {
+ plan_list.push(this.plans[key]);
+ }
+ }
+ },
+ actions: {
+ refreshFromAPI(from_date, to_date) {
+ let options = {
+ query: {
+ from_date: from_date,
+ to_date: to_date,
+ },
+ }
+
+ let apiClient = new ApiApiFactory()
+
+ apiClient.listMealPlans(options).then(r => {
+ this.plans = r.data
+ })
+ },
+ },
+})
\ No newline at end of file