fixed formatting and minor bug causeing the start of the period to always be the current day.

This commit is contained in:
AquaticLava 2023-05-18 11:14:59 -06:00
parent 693b43af2e
commit 6c9227faac
2 changed files with 48 additions and 43 deletions

View File

@ -18,7 +18,7 @@
<excludeFolder url="file://$MODULE_DIR$/staticfiles" /> <excludeFolder url="file://$MODULE_DIR$/staticfiles" />
<excludeFolder url="file://$MODULE_DIR$/venv" /> <excludeFolder url="file://$MODULE_DIR$/venv" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="jdk" jdkName="Python 3.11 (recipes)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
<component name="TemplatesService"> <component name="TemplatesService">

View File

@ -290,6 +290,9 @@
<button class="btn btn-success shadow-none" @click="createEntryClick(new Date())"><i <button class="btn btn-success shadow-none" @click="createEntryClick(new Date())"><i
class="fas fa-calendar-plus"></i> {{ $t("Create") }} class="fas fa-calendar-plus"></i> {{ $t("Create") }}
</button> </button>
<button class="btn btn-primary shadow-none" @click="createAutoPlan(new Date())"><i
class="fas fa-calendar-plus"></i> {{ $t("Auto_Planner") }}
</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>
@ -302,11 +305,7 @@
<a class="dropdown-item" @click="createEntryClick(new Date())"><i <a class="dropdown-item" @click="createEntryClick(new Date())"><i
class="fas fa-calendar-plus fa-fw"></i> {{ $t("Create") }}</a> class="fas fa-calendar-plus fa-fw"></i> {{ $t("Create") }}</a>
</template> </template>
<div class="col-md-3 col-6 mb-1 mb-md-0">
<button class="btn btn-block btn-primary shadow-none" @click="createAutoPlan(new Date())">
{{ $t("Auto_Planner") }}
</button>
</div>
</bottom-navigation-bar> </bottom-navigation-bar>
</div> </div>
</template> </template>
@ -677,53 +676,59 @@ export default {
this.$bvModal.show(`id_meal_plan_edit_modal`) this.$bvModal.show(`id_meal_plan_edit_modal`)
}) })
} },
createAutoPlan() { createAutoPlan() {
this.$bvModal.show(`autoplan-modal`) this.$bvModal.show(`autoplan-modal`)
}, },
async autoPlanThread(date,dateOffset,meal_type,keywords,servings,mealTypesKey){ async autoPlanThread(date, dateOffset, meal_type, keywords, servings, mealTypesKey) {
let apiClient = new ApiApiFactory() let apiClient = new ApiApiFactory()
let currentEntry = Object.assign({}, this.options.entryEditing) let currentEntry = Object.assign({}, this.options.entryEditing)
currentEntry.date = moment(date).add(dateOffset,"d").format("YYYY-MM-DD") currentEntry.date = moment(date).add(dateOffset, "d").format("YYYY-MM-DD")
currentEntry.servings = servings currentEntry.servings = servings
await Promise.all([ await Promise.all([
currentEntry.recipe = await this.randomRecipe(keywords[mealTypesKey]).then((result)=>{return result}), currentEntry.recipe = await this.randomRecipe(keywords[mealTypesKey]).then((result) => {
currentEntry.shared = await apiClient.listUserPreferences().then((result) => {return result.data[0].plan_share}), return result
currentEntry.meal_type = await this.getMealType(meal_type[mealTypesKey].id).then((result)=>{return result}) }),
]) currentEntry.shared = await apiClient.listUserPreferences().then((result) => {
currentEntry.title = currentEntry.recipe.name return result.data[0].plan_share
this.createEntry(currentEntry) }),
}, currentEntry.meal_type = await this.getMealType(meal_type[mealTypesKey].id).then((result) => {
doAutoPlan(autoPlan){ return result
let dayInMilliseconds = (86400000) })
let numberOfDays = ((autoPlan.endDay - autoPlan.startDay)/dayInMilliseconds) + 1 ])
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 (const mealTypesKey in autoPlan.meal_types) {
for (let dateOffset = 0; dateOffset < numberOfDays; dateOffset++) { for (let dateOffset = 0; dateOffset < numberOfDays; dateOffset++) {
this.autoPlanThread(autoPlan.date, dateOffset, autoPlan.meal_types, autoPlan.keywords, autoPlan.servings, mealTypesKey) this.autoPlanThread(autoPlan.startDay, dateOffset, autoPlan.meal_types, autoPlan.keywords, autoPlan.servings, mealTypesKey)
} }
} }
}, },
randomRecipe(keywords) { randomRecipe(keywords) {
let url = "/api/recipe/?query=" let url = "/api/recipe/?query="
for (const keywordsKey in keywords) { for (const keywordsKey in keywords) {
let keyword = keywords[keywordsKey] let keyword = keywords[keywordsKey]
url += `&keywords_and=${keyword.id}` url += `&keywords_and=${keyword.id}`
} }
return axios.get(url).then((response) => { return axios.get(url).then((response) => {
let result = response.data let result = response.data
let count = result.count let count = result.count
return result.results[Math.floor(Math.random() * count)] return result.results[Math.floor(Math.random() * count)]
}).catch((err) => { }).catch((err) => {
}) })
}, },
getMealType(id) { getMealType(id) {
let url = `/api/meal-type/${id}` let url = `/api/meal-type/${id}`
return axios.get(url).then((response) => { return axios.get(url).then((response) => {
return response.data return response.data
}) })
} }
}, },
directives: { directives: {