diff --git a/cookbook/templates/shopping_list.html b/cookbook/templates/shopping_list.html
index 1254122ec..e0d672d1e 100644
--- a/cookbook/templates/shopping_list.html
+++ b/cookbook/templates/shopping_list.html
@@ -110,21 +110,23 @@
+
+
-
-
-
- | [[element.amount]] |
- [[element.unit.name]] |
- [[element.food.name]] |
-
-
- |
-
+
+
+ | [[element.amount]] |
+ [[element.unit.name]] |
+ [[element.food.name]] |
+
+
+ |
+
+
+
@@ -238,27 +240,41 @@
@@ -356,13 +372,27 @@
return cache
},
display_entries() {
- let entries = []
+ let categories = {
+ no_category: {
+ name: gettext('Uncategorized'),
+ entries: []
+ }
+ }
+
+ this.shopping_list.entries.forEach((e) => {
+ if (e.food.supermarket_category !== null) {
+ categories[e.food.supermarket_category.id] = {
+ name: e.food.supermarket_category.name,
+ entries: []
+ };
+ }
+ })
this.shopping_list.entries.forEach(element => {
let item = {}
Object.assign(item, element);
- let entry = this.findMergeEntry(entries, item)
+ let entry = this.findMergeEntry(categories, item)
if (entry !== undefined) {
entry.amount += item.amount * this.servings_cache[item.list_recipe]
entry.entries.push(item.id)
@@ -372,17 +402,24 @@
}
item.unit = ((element.unit !== undefined && element.unit !== null) ? element.unit : {'name': ''})
item.entries = [element.id]
- entries.push(item)
+ if (item.food.supermarket_category !== null) {
+ categories[item.food.supermarket_category.id].entries.push(item)
+ } else {
+ categories['no_category'].entries.push(item)
+ }
}
});
- return entries
+ return categories
},
export_text() {
let text = ''
- for (let e of this.display_entries.filter(item => item.checked === false)) {
- text += `${this.export_text_prefix}${e.amount} ${e.unit.name} ${e.food.name} \n`
+ for (let [i, c] of Object.entries(this.display_entries)) {
+ for (let e of c.entries.filter(item => item.checked === false)) {
+ text += `${this.export_text_prefix}${e.amount} ${e.unit.name} ${e.food.name} \n`
+ }
}
+
return text
}
},
@@ -416,16 +453,23 @@
this.searchUsers('')
},
methods: {
- findMergeEntry: function (entries, entry) {
- return entries.find(item => {
- if (entry.food.id === item.food.id) {
- if (entry.unit === null && item.unit === null) {
- return true
- } else if (entry.unit.id === item.unit.id) {
- return true
+ findMergeEntry: function (categories, entry) {
+ for (let [i, e] of Object.entries(categories)) {
+ let found_entry = e.entries.find(item => {
+ if (entry.food.id === item.food.id) {
+ if (entry.unit === null && item.unit === null) {
+ return true
+ } else if (entry.unit.id === item.unit.id) {
+ return true
+ }
}
+ })
+
+ if (found_entry !== undefined) {
+ return found_entry
}
- })
+ }
+ return undefined
},
updateOnlineStatus(e) {
const {