Allowed for null products, move ingredient spreading server-side #2
2 changed files with 16 additions and 7 deletions
|
|
@ -43,7 +43,7 @@
|
||||||
<!-- Display 'Stocked', 'Purchased' and 'Cancel' buttons in a vertical stack fixed to the bottom of the screen when any elements are selected -->
|
<!-- Display 'Stocked', 'Purchased' and 'Cancel' buttons in a vertical stack fixed to the bottom of the screen when any elements are selected -->
|
||||||
<div class="footer-buttons" v-if="selected.length">
|
<div class="footer-buttons" v-if="selected.length">
|
||||||
<p v-if="selected.length === 1">
|
<p v-if="selected.length === 1">
|
||||||
Mark '{{ selected[0].product.name }}' as
|
Mark '{{ selected[0].product?.name ?? selected[0].name }}' as
|
||||||
</p>
|
</p>
|
||||||
<p v-else>
|
<p v-else>
|
||||||
Mark {{ selected.length }} items as
|
Mark {{ selected.length }} items as
|
||||||
|
|
@ -150,7 +150,13 @@ async function saveShoppingList(outstandingItemGroups) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await data.purchaseItems(items);
|
return await data.purchaseShoppingList(items);
|
||||||
|
}
|
||||||
|
|
||||||
|
const groupsMatch = (a, b) => {
|
||||||
|
if (a.product != b.product) return false;
|
||||||
|
if (a.name && a.name === b.name) return true;
|
||||||
|
return a.product.id === b.product.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
@ -169,7 +175,7 @@ export default {
|
||||||
const to = new Date();
|
const to = new Date();
|
||||||
to.setDate(to.getDate() + 7);
|
to.setDate(to.getDate() + 7);
|
||||||
|
|
||||||
return { from, to, shoppingList: null, includedMeals: [], selected: [], showPurchased: false }
|
return { from, to, shoppingList: null, selected: [], showPurchased: false }
|
||||||
},
|
},
|
||||||
async beforeMount() {
|
async beforeMount() {
|
||||||
this.loadData();
|
this.loadData();
|
||||||
|
|
@ -193,6 +199,9 @@ export default {
|
||||||
});
|
});
|
||||||
|
|
||||||
return Object.values(meals).filter(m => !m.purchase_date).sort((a, b) => a.suggested_date - b.suggested_date);
|
return Object.values(meals).filter(m => !m.purchase_date).sort((a, b) => a.suggested_date - b.suggested_date);
|
||||||
|
},
|
||||||
|
includedMeals() {
|
||||||
|
return this.shoppingList?.requested_meals.map(m => m.meal) ?? [];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -226,14 +235,14 @@ export default {
|
||||||
this.$router.push(`/shopping/${shoppingList.id}`);
|
this.$router.push(`/shopping/${shoppingList.id}`);
|
||||||
},
|
},
|
||||||
toggleSelect(item) {
|
toggleSelect(item) {
|
||||||
const index = this.selected.findIndex(i => i === item);
|
const index = this.selected.findIndex(i => groupsMatch(i, item));
|
||||||
if (index === -1)
|
if (index === -1)
|
||||||
this.selected.push(item);
|
this.selected.push(item);
|
||||||
else
|
else
|
||||||
this.selected.splice(index, 1);
|
this.selected.splice(index, 1);
|
||||||
},
|
},
|
||||||
isSelected(item) {
|
isSelected(item) {
|
||||||
return this.selected.some(i => i === item);
|
return this.selected.some(i => groupsMatch(i, item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -267,14 +267,14 @@ export default {
|
||||||
|
|
||||||
return lst;
|
return lst;
|
||||||
},
|
},
|
||||||
async purchaseItems(completed_requests) {
|
async purchaseShoppingList(completed_requests) {
|
||||||
const response = await fetch(BASE_URL + "/shopping/", {
|
const response = await fetch(BASE_URL + "/shopping/", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ completed_requests }),
|
body: JSON.stringify({ items: completed_requests }),
|
||||||
});
|
});
|
||||||
|
|
||||||
const lst = await response.json();
|
const lst = await response.json();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue