From 40d1a9c3d0ecadf4678af772c232368e8c41d8c4 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Mon, 12 Feb 2024 20:36:33 +0100 Subject: [PATCH] Show the number of items per shopping list in the shopping lists dropdown (closes #2467) --- changelog/75_UNRELEASED_xxxx-xx-xx.md | 2 +- controllers/StockController.php | 2 +- migrations/0235.sql | 6 ++++++ views/shoppinglist.blade.php | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 migrations/0235.sql diff --git a/changelog/75_UNRELEASED_xxxx-xx-xx.md b/changelog/75_UNRELEASED_xxxx-xx-xx.md index 7396b76d..12c1770d 100644 --- a/changelog/75_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/75_UNRELEASED_xxxx-xx-xx.md @@ -17,7 +17,7 @@ ### Shopping list -- xxx +- The shopping lists dropdown on the shopping list page now also shows the number of items on the corresponding shopping list ### Recipes diff --git a/controllers/StockController.php b/controllers/StockController.php index 6fb49820..fecd6e80 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -397,7 +397,7 @@ class StockController extends BaseController 'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'), 'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'), 'missingProducts' => $this->getStockService()->GetMissingProducts(), - 'shoppingLists' => $this->getDatabase()->shopping_lists()->orderBy('name', 'COLLATE NOCASE'), + 'shoppingLists' => $this->getDatabase()->shopping_lists_view()->orderBy('name', 'COLLATE NOCASE'), 'selectedShoppingListId' => $listId, 'quantityUnitConversionsResolved' => $this->getDatabase()->cache__quantity_unit_conversions_resolved(), 'productUserfields' => $this->getUserfieldsService()->GetFields('products'), diff --git a/migrations/0235.sql b/migrations/0235.sql new file mode 100644 index 00000000..9d58eb1c --- /dev/null +++ b/migrations/0235.sql @@ -0,0 +1,6 @@ +CREATE VIEW shopping_lists_view +AS +SELECT + *, + (SELECT IFNULL(COUNT(*), 0) FROM shopping_list WHERE shopping_list_id = sl.id) AS item_count +FROM shopping_lists sl; diff --git a/views/shoppinglist.blade.php b/views/shoppinglist.blade.php index 33b785fd..cadc1b9c 100644 --- a/views/shoppinglist.blade.php +++ b/views/shoppinglist.blade.php @@ -45,7 +45,7 @@