fixed review shopping before save, improved meal plan edit modal independece
This commit is contained in:
parent
3c00e1ecdb
commit
c08c1d30ad
@ -44,9 +44,11 @@ class RecipeShoppingEditor():
|
|||||||
self.space = space
|
self.space = space
|
||||||
self._kwargs = {**kwargs}
|
self._kwargs = {**kwargs}
|
||||||
|
|
||||||
self.mealplan = self._kwargs.get('mealplan', None)
|
mealplan = self._kwargs.get('mealplan', None)
|
||||||
if type(self.mealplan) in [int, float]:
|
if type(mealplan) in [int, float]:
|
||||||
self.mealplan = MealPlan.objects.filter(id=self.mealplan, space=self.space)
|
self.mealplan = MealPlan.objects.filter(id=self.mealplan, space=self.space).first()
|
||||||
|
if type(mealplan) == dict:
|
||||||
|
self.mealplan = MealPlan.objects.filter(id=mealplan['id'], space=self.space).first()
|
||||||
self.id = self._kwargs.get('id', None)
|
self.id = self._kwargs.get('id', None)
|
||||||
|
|
||||||
self._shopping_list_recipe = self.get_shopping_list_recipe(self.id, self.created_by, self.space)
|
self._shopping_list_recipe = self.get_shopping_list_recipe(self.id, self.created_by, self.space)
|
||||||
@ -106,9 +108,8 @@ class RecipeShoppingEditor():
|
|||||||
if servings := kwargs.get('servings', None):
|
if servings := kwargs.get('servings', None):
|
||||||
self.servings = float(servings)
|
self.servings = float(servings)
|
||||||
|
|
||||||
if mealplan := kwargs.get('mealplan', None):
|
if mealplan := kwargs.get('mealplan', None): # it appears this code is never called just init is used, no time to validate
|
||||||
self.mealplan = mealplan
|
self.mealplan = MealPlan.objects.filter(id=mealplan['id'], space=self.space).fist()
|
||||||
self.recipe = mealplan.recipe
|
|
||||||
elif recipe := kwargs.get('recipe', None):
|
elif recipe := kwargs.get('recipe', None):
|
||||||
self.recipe = recipe
|
self.recipe = recipe
|
||||||
|
|
||||||
@ -195,7 +196,6 @@ class RecipeShoppingEditor():
|
|||||||
ShoppingListEntry.objects.filter(id__in=to_delete).delete()
|
ShoppingListEntry.objects.filter(id__in=to_delete).delete()
|
||||||
self._shopping_list_recipe = self.get_shopping_list_recipe(self.id, self.created_by, self.space)
|
self._shopping_list_recipe = self.get_shopping_list_recipe(self.id, self.created_by, self.space)
|
||||||
|
|
||||||
|
|
||||||
# # TODO refactor as class
|
# # TODO refactor as class
|
||||||
# def list_from_recipe(list_recipe=None, recipe=None, mealplan=None, servings=None, ingredients=None, created_by=None, space=None, append=False):
|
# def list_from_recipe(list_recipe=None, recipe=None, mealplan=None, servings=None, ingredients=None, created_by=None, space=None, append=False):
|
||||||
# """
|
# """
|
||||||
|
@ -204,6 +204,7 @@
|
|||||||
:entry="entryEditing"
|
:entry="entryEditing"
|
||||||
:modal_title="modal_title"
|
:modal_title="modal_title"
|
||||||
:edit_modal_show="edit_modal_show"
|
:edit_modal_show="edit_modal_show"
|
||||||
|
:create_date="edit_modal_default_date"
|
||||||
@reload-meal-types="refreshMealTypes"
|
@reload-meal-types="refreshMealTypes"
|
||||||
></meal-plan-edit-modal>
|
></meal-plan-edit-modal>
|
||||||
|
|
||||||
@ -322,29 +323,18 @@ export default {
|
|||||||
{text: this.$t("Year"), value: "year"},
|
{text: this.$t("Year"), value: "year"},
|
||||||
],
|
],
|
||||||
displayPeriodCount: [1, 2, 3],
|
displayPeriodCount: [1, 2, 3],
|
||||||
entryEditing: {
|
|
||||||
date: null,
|
|
||||||
id: -1,
|
|
||||||
meal_type: null,
|
|
||||||
note: "",
|
|
||||||
note_markdown: "",
|
|
||||||
recipe: null,
|
|
||||||
servings: 1,
|
|
||||||
shared: [],
|
|
||||||
title: "",
|
|
||||||
title_placeholder: this.$t("Title"),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
shopping_list: [],
|
shopping_list: [],
|
||||||
current_period: null,
|
current_period: null,
|
||||||
entryEditing: {},
|
entryEditing: null,
|
||||||
edit_modal_show: false,
|
edit_modal_show: false,
|
||||||
|
edit_modal_default_date: null,
|
||||||
ical_url: window.ICAL_URL,
|
ical_url: window.ICAL_URL,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
modal_title: function () {
|
modal_title: function () {
|
||||||
if (this.entryEditing.id === -1) {
|
if (this.entryEditing === null || this.entryEditing?.id === -1) {
|
||||||
return this.$t("Create_Meal_Plan_Entry")
|
return this.$t("Create_Meal_Plan_Entry")
|
||||||
} else {
|
} else {
|
||||||
return this.$t("Edit_Meal_Plan_Entry")
|
return this.$t("Edit_Meal_Plan_Entry")
|
||||||
@ -496,9 +486,11 @@ export default {
|
|||||||
this.showDate = d
|
this.showDate = d
|
||||||
},
|
},
|
||||||
createEntryClick(data) {
|
createEntryClick(data) {
|
||||||
this.entryEditing = this.options.entryEditing
|
this.edit_modal_default_date = moment(data).format("YYYY-MM-DD")
|
||||||
this.entryEditing.date = moment(data).format("YYYY-MM-DD")
|
this.entryEditing = null
|
||||||
|
this.$nextTick(function () {
|
||||||
this.$bvModal.show(`edit-modal`)
|
this.$bvModal.show(`edit-modal`)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
findEntry(id) {
|
findEntry(id) {
|
||||||
return useMealPlanStore().plan_list.filter((entry) => {
|
return useMealPlanStore().plan_list.filter((entry) => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<b-modal :id="modal_id" size="lg" :title="modal_title" hide-footer aria-label="" @show="showModal">
|
<b-modal :id="modal_id" size="lg" :title="modal_title" hide-footer aria-label="" @show="showModal">
|
||||||
<div class="row">
|
<div class="row" v-if="entryEditing !== null">
|
||||||
<div class="col col-md-12">
|
<div class="col col-md-12">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col col-md-12">
|
<div class="col col-md-12">
|
||||||
@ -125,7 +125,7 @@
|
|||||||
</b-modal>
|
</b-modal>
|
||||||
|
|
||||||
<shopping-modal :recipe="last_created_plan.recipe" :servings="last_created_plan.servings" :modal_id="999999"
|
<shopping-modal :recipe="last_created_plan.recipe" :servings="last_created_plan.servings" :modal_id="999999"
|
||||||
:mealplan="undefined" v-if="last_created_plan !== null && last_created_plan.recipe !== null"/>
|
:mealplan="last_created_plan" v-if="last_created_plan !== null && last_created_plan.recipe !== null"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
@ -152,7 +152,7 @@ export default {
|
|||||||
name: "MealPlanEditModal",
|
name: "MealPlanEditModal",
|
||||||
props: {
|
props: {
|
||||||
entry: Object,
|
entry: Object,
|
||||||
entryEditing_initial_servings: Number,
|
create_date: String,
|
||||||
modal_title: String,
|
modal_title: String,
|
||||||
modal_id: {
|
modal_id: {
|
||||||
type: String,
|
type: String,
|
||||||
@ -171,7 +171,7 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
entryEditing: {},
|
entryEditing: null,
|
||||||
missing_recipe: false,
|
missing_recipe: false,
|
||||||
missing_meal_type: false,
|
missing_meal_type: false,
|
||||||
default_plan_share: [],
|
default_plan_share: [],
|
||||||
@ -186,10 +186,6 @@ export default {
|
|||||||
entry: {
|
entry: {
|
||||||
handler() {
|
handler() {
|
||||||
this.entryEditing = Object.assign({}, this.entry)
|
this.entryEditing = Object.assign({}, this.entry)
|
||||||
|
|
||||||
if (this.entryEditing_initial_servings) {
|
|
||||||
this.entryEditing.servings = this.entryEditing_initial_servings
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
deep: true,
|
deep: true,
|
||||||
},
|
},
|
||||||
@ -204,9 +200,6 @@ export default {
|
|||||||
},
|
},
|
||||||
deep: true,
|
deep: true,
|
||||||
},
|
},
|
||||||
entryEditing_initial_servings: function (newVal) {
|
|
||||||
this.entryEditing.servings = newVal
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
mounted: function () {
|
mounted: function () {
|
||||||
useUserPreferenceStore().updateIfStaleOrEmpty()
|
useUserPreferenceStore().updateIfStaleOrEmpty()
|
||||||
@ -222,8 +215,18 @@ export default {
|
|||||||
this.mealplan_settings = Object.assign({}, this.mealplan_settings, this.$cookies.get(MEALPLAN_COOKIE_NAME))
|
this.mealplan_settings = Object.assign({}, this.mealplan_settings, this.$cookies.get(MEALPLAN_COOKIE_NAME))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.entry === null) {
|
||||||
|
this.entryEditing = useMealPlanStore().empty_meal_plan
|
||||||
|
} else {
|
||||||
|
this.entryEditing = this.entry
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.create_date) {
|
||||||
|
this.entryEditing.date = this.create_date
|
||||||
|
}
|
||||||
|
|
||||||
useUserPreferenceStore().getData().then(userPreference => {
|
useUserPreferenceStore().getData().then(userPreference => {
|
||||||
if (this.entry.id === -1) {
|
if (this.entryEditing.id === -1) {
|
||||||
this.entryEditing.shared = userPreference.plan_share
|
this.entryEditing.shared = userPreference.plan_share
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -248,9 +251,10 @@ export default {
|
|||||||
this.last_created_plan = r.data
|
this.last_created_plan = r.data
|
||||||
if (r.data.recipe && (this.mealplan_settings.addshopping || this.autoMealPlan) && this.mealplan_settings.reviewshopping) {
|
if (r.data.recipe && (this.mealplan_settings.addshopping || this.autoMealPlan) && this.mealplan_settings.reviewshopping) {
|
||||||
console.log('OPENING SHOPPING MODAL', this.$bvModal)
|
console.log('OPENING SHOPPING MODAL', this.$bvModal)
|
||||||
|
this.$nextTick(function () {
|
||||||
this.$bvModal.show(`shopping_999999`)
|
this.$bvModal.show(`shopping_999999`)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
//TODO cleanout entry editing without breaking default function from meal plan
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
console.log('CALLING UPDATE')
|
console.log('CALLING UPDATE')
|
||||||
|
@ -78,6 +78,7 @@ const {ApiApiFactory} = require("@/utils/openapi/api")
|
|||||||
import {StandardToasts} from "@/utils/utils"
|
import {StandardToasts} from "@/utils/utils"
|
||||||
import IngredientComponent from "@/components/IngredientComponent"
|
import IngredientComponent from "@/components/IngredientComponent"
|
||||||
import LoadingSpinner from "@/components/LoadingSpinner"
|
import LoadingSpinner from "@/components/LoadingSpinner"
|
||||||
|
import {useMealPlanStore} from "@/stores/MealPlanStore";
|
||||||
// import CustomInputSpinButton from "@/components/CustomInputSpinButton"
|
// import CustomInputSpinButton from "@/components/CustomInputSpinButton"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -88,7 +89,7 @@ export default {
|
|||||||
recipe: {required: true, type: Object},
|
recipe: {required: true, type: Object},
|
||||||
servings: {type: Number, default: undefined},
|
servings: {type: Number, default: undefined},
|
||||||
modal_id: {required: true, type: Number},
|
modal_id: {required: true, type: Number},
|
||||||
mealplan: {type: Number, default: undefined},
|
mealplan: {type: Object, default: undefined},
|
||||||
list_recipe: {type: Number, default: undefined},
|
list_recipe: {type: Number, default: undefined},
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
@ -169,6 +170,9 @@ export default {
|
|||||||
.then((result) => {
|
.then((result) => {
|
||||||
StandardToasts.makeStandardToast(this, StandardToasts.SUCCESS_CREATE)
|
StandardToasts.makeStandardToast(this, StandardToasts.SUCCESS_CREATE)
|
||||||
this.$emit("finish")
|
this.$emit("finish")
|
||||||
|
if (this.mealplan !== undefined && this.mealplan !== null){
|
||||||
|
useMealPlanStore().plans[this.mealplan.id].shopping = true
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_CREATE, err)
|
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_CREATE, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user