mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-07 07:08:03 -05:00
updated auto meal plan to start at the current day, and exclude a meal plan if it has no keywords. Added debug buttons to help with testing.
This commit is contained in:
@@ -293,6 +293,12 @@
|
|||||||
<button class="btn btn-primary shadow-none" @click="createAutoPlan(new Date())"><i
|
<button class="btn btn-primary shadow-none" @click="createAutoPlan(new Date())"><i
|
||||||
class="fas fa-calendar-plus"></i> {{ $t("Auto_Planner") }}
|
class="fas fa-calendar-plus"></i> {{ $t("Auto_Planner") }}
|
||||||
</button>
|
</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>
|
<a class="btn btn-primary shadow-none" :href="iCalUrl"><i class="fas fa-download"></i>
|
||||||
{{ $t("Export_To_ICal") }}
|
{{ $t("Export_To_ICal") }}
|
||||||
</a>
|
</a>
|
||||||
@@ -680,55 +686,34 @@ export default {
|
|||||||
createAutoPlan() {
|
createAutoPlan() {
|
||||||
this.$bvModal.show(`autoplan-modal`)
|
this.$bvModal.show(`autoplan-modal`)
|
||||||
},
|
},
|
||||||
async autoPlanThread(date, dateOffset, meal_type, keywords, servings, mealTypesKey) {
|
async autoPlanThread(autoPlan, mealTypeIndex) {
|
||||||
|
|
||||||
let apiClient = new ApiApiFactory()
|
let apiClient = new ApiApiFactory()
|
||||||
let currentEntry = Object.assign({}, this.options.entryEditing)
|
let data = {
|
||||||
currentEntry.date = moment(date).add(dateOffset, "d").format("YYYY-MM-DD")
|
"start_date" : moment(autoPlan.startDay).format("YYYY-MM-DD"),
|
||||||
currentEntry.servings = servings
|
"end_date" : moment(autoPlan.endDay).format("YYYY-MM-DD"),
|
||||||
await Promise.all([
|
"meal_type_id" : autoPlan.meal_types[mealTypeIndex].id,
|
||||||
currentEntry.recipe = await this.randomRecipe(keywords[mealTypesKey]).then((result) => {
|
"keywords" : autoPlan.keywords[mealTypeIndex],
|
||||||
return result
|
"servings" : autoPlan.servings,
|
||||||
}),
|
"shared" : autoPlan.shared
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
await apiClient.createAutoPlanViewSet(data)
|
||||||
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) => {
|
|
||||||
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
getMealType(id) {
|
async doAutoPlan(autoPlan) {
|
||||||
let url = `/api/meal-type/${id}`
|
for (let i = 0; i < autoPlan.meal_types.length; i++) {
|
||||||
return axios.get(url).then((response) => {
|
if (autoPlan.keywords[i].length === 0) continue
|
||||||
return response.data
|
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: {
|
directives: {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
:initial_selection="AutoPlan.keywords[meal_type]"
|
:initial_selection="AutoPlan.keywords[meal_type]"
|
||||||
:parent_variable="`${k}`"
|
:parent_variable="`${k}`"
|
||||||
:model="Models.KEYWORD"
|
:model="Models.KEYWORD"
|
||||||
:placeholder="$t('Keywords')"
|
:placeholder="$t('Keywords, leave blank to exclude meal type')"
|
||||||
:limit="50"
|
:limit="50"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -35,9 +35,9 @@
|
|||||||
|
|
||||||
<div class="">
|
<div class="">
|
||||||
<div class="row m-3 mb-0">
|
<div class="row m-3 mb-0">
|
||||||
<b-form-datepicker class="col" :value-as-date="true" :value="current_period.periodStart" @input="updateStartDay"></b-form-datepicker>
|
<b-form-datepicker class="col" :value-as-date="true" :value="AutoPlan.startDay" @input="updateStartDay"></b-form-datepicker>
|
||||||
<div class="col"></div>
|
<div class="col"></div>
|
||||||
<b-form-datepicker class="col" :value-as-date="true" :value="current_period.periodEnd" @input="updateEndDay"></b-form-datepicker>
|
<b-form-datepicker class="col" :value-as-date="true" :value="AutoPlan.endDay" @input="updateEndDay"></b-form-datepicker>
|
||||||
</div>
|
</div>
|
||||||
<div class="row align-top m-3 mt-0">
|
<div class="row align-top m-3 mt-0">
|
||||||
<small tabindex="-1" class="col align-text-top text-muted">{{ $t("Start Day") }}</small>
|
<small tabindex="-1" class="col align-text-top text-muted">{{ $t("Start Day") }}</small>
|
||||||
@@ -102,7 +102,7 @@ export default {
|
|||||||
this.refreshMealTypes()
|
this.refreshMealTypes()
|
||||||
|
|
||||||
this.AutoPlan.servings = 1
|
this.AutoPlan.servings = 1
|
||||||
this.AutoPlan.startDay = this.current_period.periodStart
|
this.AutoPlan.startDay = new Date()
|
||||||
this.AutoPlan.endDay = this.current_period.periodEnd
|
this.AutoPlan.endDay = this.current_period.periodEnd
|
||||||
},
|
},
|
||||||
sortMealTypes() {
|
sortMealTypes() {
|
||||||
@@ -148,7 +148,6 @@ export default {
|
|||||||
},
|
},
|
||||||
updateStartDay(date){
|
updateStartDay(date){
|
||||||
this.AutoPlan.startDay = date
|
this.AutoPlan.startDay = date
|
||||||
console.log(date)
|
|
||||||
},
|
},
|
||||||
updateEndDay(date){
|
updateEndDay(date){
|
||||||
this.AutoPlan.endDay = date
|
this.AutoPlan.endDay = date
|
||||||
|
|||||||
Reference in New Issue
Block a user