diff --git a/vue/src/apps/MealPlanView/MealPlanView.vue b/vue/src/apps/MealPlanView/MealPlanView.vue index c0d027a59..9e34cb718 100644 --- a/vue/src/apps/MealPlanView/MealPlanView.vue +++ b/vue/src/apps/MealPlanView/MealPlanView.vue @@ -293,6 +293,12 @@ + + {{ $t("Export_To_ICal") }} @@ -680,55 +686,34 @@ export default { createAutoPlan() { this.$bvModal.show(`autoplan-modal`) }, - async autoPlanThread(date, dateOffset, meal_type, keywords, servings, mealTypesKey) { - + async autoPlanThread(autoPlan, mealTypeIndex) { let apiClient = new ApiApiFactory() - let currentEntry = Object.assign({}, this.options.entryEditing) - currentEntry.date = moment(date).add(dateOffset, "d").format("YYYY-MM-DD") - currentEntry.servings = servings - await Promise.all([ - currentEntry.recipe = await this.randomRecipe(keywords[mealTypesKey]).then((result) => { - return result - }), - currentEntry.shared = await apiClient.listUserPreferences().then((result) => { - return result.data[0].plan_share - }), - currentEntry.meal_type = await this.getMealType(meal_type[mealTypesKey].id).then((result) => { - return result - }) - ]) - currentEntry.title = currentEntry.recipe.name - this.createEntry(currentEntry) - }, - doAutoPlan(autoPlan) { - let dayInMilliseconds = (86400000) - let numberOfDays = ((autoPlan.endDay - autoPlan.startDay) / dayInMilliseconds) + 1 - - for (const mealTypesKey in autoPlan.meal_types) { - for (let dateOffset = 0; dateOffset < numberOfDays; dateOffset++) { - this.autoPlanThread(autoPlan.startDay, dateOffset, autoPlan.meal_types, autoPlan.keywords, autoPlan.servings, mealTypesKey) - } + let data = { + "start_date" : moment(autoPlan.startDay).format("YYYY-MM-DD"), + "end_date" : moment(autoPlan.endDay).format("YYYY-MM-DD"), + "meal_type_id" : autoPlan.meal_types[mealTypeIndex].id, + "keywords" : autoPlan.keywords[mealTypeIndex], + "servings" : autoPlan.servings, + "shared" : autoPlan.shared } - }, - randomRecipe(keywords) { - let url = "/api/recipe/?query=" - for (const keywordsKey in keywords) { - let keyword = keywords[keywordsKey] - url += `&keywords_and=${keyword.id}` - } - return axios.get(url).then((response) => { - let result = response.data - let count = result.count - return result.results[Math.floor(Math.random() * count)] - }).catch((err) => { + await apiClient.createAutoPlanViewSet(data) - }) }, - getMealType(id) { - let url = `/api/meal-type/${id}` - return axios.get(url).then((response) => { - return response.data - }) + async doAutoPlan(autoPlan) { + for (let i = 0; i < autoPlan.meal_types.length; i++) { + if (autoPlan.keywords[i].length === 0) continue + await this.autoPlanThread(autoPlan, i) + } + this.refreshEntries() + }, + refreshEntries(){//todo Remove method + let date = this.current_period + useMealPlanStore().refreshFromAPI(moment(date.periodStart).format("YYYY-MM-DD"), moment(date.periodEnd).format("YYYY-MM-DD")) + }, + deleteAll(){//todo Remove method, only used in debugging + for (let i = 0; i < useMealPlanStore().plan_list.length; i++) { + useMealPlanStore().deleteObject(useMealPlanStore().plan_list[i]) + } } }, directives: { diff --git a/vue/src/components/AutoMealPlanModal.vue b/vue/src/components/AutoMealPlanModal.vue index 339427aa7..2d8084b33 100644 --- a/vue/src/components/AutoMealPlanModal.vue +++ b/vue/src/components/AutoMealPlanModal.vue @@ -21,7 +21,7 @@ :initial_selection="AutoPlan.keywords[meal_type]" :parent_variable="`${k}`" :model="Models.KEYWORD" - :placeholder="$t('Keywords')" + :placeholder="$t('Keywords, leave blank to exclude meal type')" :limit="50" /> @@ -35,9 +35,9 @@
- +
- +
{{ $t("Start Day") }} @@ -102,7 +102,7 @@ export default { this.refreshMealTypes() this.AutoPlan.servings = 1 - this.AutoPlan.startDay = this.current_period.periodStart + this.AutoPlan.startDay = new Date() this.AutoPlan.endDay = this.current_period.periodEnd }, sortMealTypes() { @@ -148,7 +148,6 @@ export default { }, updateStartDay(date){ this.AutoPlan.startDay = date - console.log(date) }, updateEndDay(date){ this.AutoPlan.endDay = date