diff --git a/src/components/shopping/FullShoppingListPage.vue b/src/components/shopping/FullShoppingListPage.vue
new file mode 100644
index 0000000..2b48751
--- /dev/null
+++ b/src/components/shopping/FullShoppingListPage.vue
@@ -0,0 +1,82 @@
+
+ Full shopping list
+ Included Meals
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/components/shopping/FullShoppingPage.vue b/src/components/shopping/FullShoppingPage.vue
deleted file mode 100644
index d5ccc32..0000000
--- a/src/components/shopping/FullShoppingPage.vue
+++ /dev/null
@@ -1,64 +0,0 @@
-
- Full shopping list
- Included Meals
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/components/shopping/MealSelectionList.vue b/src/components/shopping/MealSelectionList.vue
index d0d0fc8..be5e754 100644
--- a/src/components/shopping/MealSelectionList.vue
+++ b/src/components/shopping/MealSelectionList.vue
@@ -4,7 +4,7 @@
-
+
@@ -138,6 +138,14 @@ export default {
this.$emit('meal-unselected', meal);
}
},
+ isChecked(meal) {
+ for (const checkedMeal of this.checked) {
+ if (checkedMeal.id === meal.id) {
+ return true;
+ }
+ }
+ return false;
+ }
}
}
diff --git a/src/components/shopping/MyShoppingPage.vue b/src/components/shopping/MyShoppingPage.vue
index 7fcba4d..0f2345a 100644
--- a/src/components/shopping/MyShoppingPage.vue
+++ b/src/components/shopping/MyShoppingPage.vue
@@ -1,6 +1,7 @@
My Shopping List
+ Full Shopping List
diff --git a/src/components/shopping/shopping.js b/src/components/shopping/shopping.js
index 6fabd0e..535eb79 100644
--- a/src/components/shopping/shopping.js
+++ b/src/components/shopping/shopping.js
@@ -13,6 +13,20 @@ export function mealToShoppingListSources(meal) {
return sources;
}
+export function requestsToSources(requests) {
+ const sources = [];
+ for (const request of requests) {
+ if (request.ingredient) {
+ sources.push(request);
+ }
+ else if (request.meal) {
+ sources.push(...mealToShoppingListSources(request.meal));
+ }
+ }
+
+ return sources;
+}
+
export function removeMealFromShoppingListSources(sources, meal) {
return sources.filter(source => source.meal?.id !== meal.id);
}
diff --git a/src/data.js b/src/data.js
index 2298982..c331d3a 100644
--- a/src/data.js
+++ b/src/data.js
@@ -1,13 +1,17 @@
const BASE_URL = window.location.href.replace(/^(http:\/\/[^/:]+).*/, "$1:8000")
+function fixMealDates(meals) {
+ for (const meal of meals) {
+ meal.meal_date = new Date(meal.meal_date);
+ }
+}
+
let user = null;
export default {
async getMeals(from, to) {
const response = await fetch(BASE_URL + "/meals?from=" + from.toISOString() + "&to=" + to.toISOString());
const meals = await response.json();
- for (const meal of meals) {
- meal.meal_date = new Date(meal.meal_date);
- }
+ fixMealDates(meals);
return meals.sort((a, b) => a.meal_date - b.meal_date);
},
@@ -137,11 +141,11 @@ export default {
return await response.json();
},
async getMyShoppingList() {
- const response = await fetch(BASE_URL + "/shopping/current/me", { credentials: "include" });
+ const response = await fetch(BASE_URL + "/shopping/current/me/ingredients", { credentials: "include" });
return await response.json();
},
async saveMyShoppingList(list) {
- const response = await fetch(BASE_URL + "/shopping/current/me", {
+ const response = await fetch(BASE_URL + "/shopping/current/me/ingredients", {
method: "POST",
credentials: "include",
headers: {
@@ -158,6 +162,30 @@ export default {
},
async getCurrentShoppingList() {
const response = await fetch(BASE_URL + "/shopping/current");
+ const lst = await response.json();
+ fixMealDates(lst.requests.map(request => request.meal).filter(meal => meal));
+ return lst;
+ },
+ async requestMeal(meal_id) {
+ const response = await fetch(BASE_URL + `/shopping/current/meals/me`, {
+ method: "POST",
+ credentials: "include",
+ headers: {
+ "Content-Type": "application/json"
+ },
+ body: JSON.stringify({ meal_id }),
+ });
+
+ const result = await response.json();
+ fixMealDates([result.meal]);
+ return result;
+ },
+ async unrequestMeal(meal_id) {
+ const response = await fetch(BASE_URL + `/shopping/current/meals/${encodeURIComponent(meal_id)}`, {
+ method: "DELETE",
+ credentials: "include",
+ });
+
return await response.json();
}
}
\ No newline at end of file
diff --git a/src/main.js b/src/main.js
index 5515f38..4d692de 100644
--- a/src/main.js
+++ b/src/main.js
@@ -7,6 +7,7 @@ import LoginPage from './components/LoginPage.vue'
import RecipesPage from './components/recipes/RecipesPage.vue'
import MealPlanPage from './components/meals/MealPlanPage.vue'
import MyShoppingPage from './components/shopping/MyShoppingPage.vue'
+import FullShoppingListPage from './components/shopping/FullShoppingListPage.vue'
import EditMealPage from './components/meals/EditMealPage.vue'
import EditRecipePage from './components/recipes/EditRecipePage.vue'
@@ -18,6 +19,7 @@ const routes = [
{ path: '/mealplan', component: MealPlanPage },
{ path: '/login', component: LoginPage },
{ path: '/shopping', component: MyShoppingPage },
+ { path: '/shopping/:id', component: FullShoppingListPage, props : true },
{ path: '/recipes', component: RecipesPage },
{ path: '/recipes/add', component: EditRecipePage },
{ path: '/recipes/:id', component: EditRecipePage, props: true },