mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-02 04:39:54 -05:00
@@ -279,12 +279,26 @@
|
||||
:create_date="mealplan_default_date"
|
||||
@reload-meal-types="refreshMealTypes"
|
||||
></meal-plan-edit-modal>
|
||||
<auto-meal-plan-modal
|
||||
:modal_title="'Auto create meal plan'"
|
||||
:current_period="current_period"
|
||||
@create-plan="doAutoPlan"
|
||||
></auto-meal-plan-modal>
|
||||
|
||||
<div class="row d-none d-lg-block">
|
||||
<div class="col-12 float-right">
|
||||
<button class="btn btn-success shadow-none" @click="createEntryClick(new Date())"><i
|
||||
class="fas fa-calendar-plus"></i> {{ $t("Create") }}
|
||||
</button>
|
||||
<button class="btn btn-primary shadow-none" @click="createAutoPlan(new Date())"><i
|
||||
class="fas fa-calendar-plus"></i> {{ $t("Auto_Planner") }}
|
||||
</button>
|
||||
<button class="btn btn-primary shadow-none" @click="deleteAll()"><i
|
||||
class="fas fa-calendar-plus"></i> {{ "DEBUG:deleteAll" }}
|
||||
</button>
|
||||
<button class="btn btn-primary shadow-none" @click="refreshEntries()"><i
|
||||
class="fas fa-calendar-plus"></i> {{ "DEBUG:RefreshMeals" }}
|
||||
</button>
|
||||
<a class="btn btn-primary shadow-none" :href="iCalUrl"><i class="fas fa-download"></i>
|
||||
{{ $t("Export_To_ICal") }}
|
||||
</a>
|
||||
@@ -297,6 +311,7 @@
|
||||
<a class="dropdown-item" @click="createEntryClick(new Date())"><i
|
||||
class="fas fa-calendar-plus fa-fw"></i> {{ $t("Create") }}</a>
|
||||
</template>
|
||||
|
||||
</bottom-navigation-bar>
|
||||
</div>
|
||||
</template>
|
||||
@@ -322,6 +337,8 @@ import {CalendarView, CalendarMathMixin} from "vue-simple-calendar/src/component
|
||||
import {ApiApiFactory} from "@/utils/openapi/api"
|
||||
import BottomNavigationBar from "@/components/BottomNavigationBar.vue";
|
||||
import {useMealPlanStore} from "@/stores/MealPlanStore";
|
||||
import axios from "axios";
|
||||
import AutoMealPlanModal from "@/components/AutoMealPlanModal";
|
||||
|
||||
const {makeToast} = require("@/utils/utils")
|
||||
|
||||
@@ -334,6 +351,7 @@ let SETTINGS_COOKIE_NAME = "mealplan_settings"
|
||||
export default {
|
||||
name: "MealPlanView",
|
||||
components: {
|
||||
AutoMealPlanModal,
|
||||
MealPlanEditModal,
|
||||
MealPlanCard,
|
||||
CalendarView,
|
||||
@@ -347,6 +365,16 @@ export default {
|
||||
mixins: [CalendarMathMixin, ApiMixin, ResolveUrlMixin],
|
||||
data: function () {
|
||||
return {
|
||||
AutoPlan: {
|
||||
meal_types: [],
|
||||
keywords: [[]],
|
||||
servings: 1,
|
||||
date: Date.now(),
|
||||
startDay: null,
|
||||
endDay: null,
|
||||
shared: [],
|
||||
addshopping: false
|
||||
},
|
||||
showDate: new Date(),
|
||||
plan_entries: [],
|
||||
recipe_viewed: {},
|
||||
@@ -656,6 +684,39 @@ export default {
|
||||
this.$bvModal.show(`id_meal_plan_edit_modal`)
|
||||
})
|
||||
|
||||
},
|
||||
createAutoPlan() {
|
||||
this.$bvModal.show(`autoplan-modal`)
|
||||
},
|
||||
async autoPlanThread(autoPlan, mealTypeIndex) {
|
||||
let apiClient = new ApiApiFactory()
|
||||
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,
|
||||
"addshopping": autoPlan.addshopping
|
||||
}
|
||||
await apiClient.createAutoPlanViewSet(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: {
|
||||
|
||||
Reference in New Issue
Block a user