Mark meal as complete
This commit is contained in:
parent
0bcd05acc9
commit
da61a2daa3
3 changed files with 21 additions and 5 deletions
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
<ul class="actions" v-if="selectedMeal == meal">
|
||||
<li><router-link class="nav-link" :to="`/meals/${selectedMeal.id}`" active-class="active">Edit Meal</router-link></li>
|
||||
<li><a @click="markConsumed">Mark Consumed</a></li>
|
||||
<li><a @click="deleteSelectedMeal" class="button">Remove</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
|
@ -98,7 +99,7 @@ export default {
|
|||
}
|
||||
},
|
||||
async beforeMount() {
|
||||
const meals = await data.getMeals(this.from, this.to)
|
||||
const meals = await data.getUpcomingMeals(this.from, this.to)
|
||||
this.meals = meals;
|
||||
},
|
||||
methods: {
|
||||
|
|
@ -106,6 +107,10 @@ export default {
|
|||
await data.deleteMeal(this.selectedMeal.id);
|
||||
this.meals = this.meals.filter(m => m.id !== this.selectedMeal.id);
|
||||
this.selectedMeal = null;
|
||||
},
|
||||
async markConsumed() {
|
||||
await data.markMealConsumed(this.selectedMeal.id);
|
||||
this.meals = this.meals.filter(m => m.id !== this.selectedMeal.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ export default {
|
|||
return { from, to, availableMeals: [], shoppingList: null, includedMeals: [], listByProduct: [], stockTaking: false, productsToShow: []}
|
||||
},
|
||||
async beforeMount() {
|
||||
const allMeals = await data.getMeals(this.from, this.to);
|
||||
const allMeals = await data.getUpcomingMeals(this.from, this.to);
|
||||
this.availableMeals = allMeals.filter(m => !m.purchase_date);
|
||||
this.shoppingList = await data.getCurrentShoppingList();
|
||||
},
|
||||
|
|
|
|||
17
src/data.js
17
src/data.js
|
|
@ -1,7 +1,7 @@
|
|||
const BASE_URL = window.location.href.replace(/^(http:\/\/[^/:]+).*/, "$1:8000")
|
||||
|
||||
const datesToFix = {
|
||||
Meal: { fields: [ "suggested_date", "purchase_date" ] },
|
||||
Meal: { fields: [ "suggested_date", "purchase_date", "consumed_date" ] },
|
||||
ShoppingList: { fields: [ "created_date", "purchased_date" ], dependants: l => ({ ShoppingListResult: l.results, ShoppingListRequest: l.requests }) },
|
||||
ShoppingListResult: { fields: [ "found_date", "created_date" ], },
|
||||
ShoppingListRequest: { fields: [ "created_date" ], dependants: r => ({ Meal: r.meal }) },
|
||||
|
|
@ -43,8 +43,19 @@ const fixDates = (obj, type) => {
|
|||
|
||||
let user = null;
|
||||
export default {
|
||||
async getMeals(from, to) {
|
||||
const response = await fetch(BASE_URL + "/meals?from=" + from.toISOString() + "&to=" + to.toISOString());
|
||||
async markMealConsumed(meal_id) {
|
||||
const response = await fetch(BASE_URL + `/meals/${encodeURIComponent(meal_id)}/consumed`, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
});
|
||||
|
||||
const meal = await response.json();
|
||||
fixDates(meal, "Meal");
|
||||
|
||||
return meal;
|
||||
},
|
||||
async getUpcomingMeals(from, to) {
|
||||
const response = await fetch(BASE_URL + "/meals/upcoming?from=" + from.toISOString() + "&to=" + to.toISOString());
|
||||
const meals = await response.json();
|
||||
fixDates(meals, "Meal");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue