Skip to content

Commit 40e7699

Browse files
Merge pull request #362 from seyfeb/bugfix/showItemForRecipesWithUnassignedCategory
Allow selecting recipes with unassigned category
2 parents 2a3ce12 + bc4b8d4 commit 40e7699

File tree

3 files changed

+47
-18
lines changed

3 files changed

+47
-18
lines changed

lib/Db/RecipeDb.php

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,13 @@ public function findAllKeywords(string $user_id) {
139139
public function findAllCategories(string $user_id) {
140140
$qb = $this->db->getQueryBuilder();
141141

142-
$qb->select('k.name')
143-
->selectAlias($qb->createFunction('COUNT(k.recipe_id)'), 'recipe_count')
144-
->from(self::DB_TABLE_CATEGORIES, 'k')
145-
->where('user_id = :user AND k.name != \'\'')
146-
->groupBy('k.name')
147-
->orderBy('k.name');
142+
// Get all named categories
143+
$qb->select('c.name')
144+
->selectAlias($qb->createFunction('COUNT(c.recipe_id)'), 'recipe_count')
145+
->from(self::DB_TABLE_CATEGORIES, 'c')
146+
->where('user_id = :user')
147+
->groupBy('c.name')
148+
->orderBy('c.name');
148149
$qb->setParameter('user', $user_id, TYPE::STRING);
149150

150151
$cursor = $qb->execute();
@@ -153,6 +154,7 @@ public function findAllCategories(string $user_id) {
153154

154155
$qb = $this->db->getQueryBuilder();
155156

157+
// Get count of recipes without category
156158
$qb->select($qb->createFunction('COUNT(1) as cnt'))
157159
->from(self::DB_TABLE_RECIPES, 'r')
158160
->leftJoin(
@@ -177,7 +179,7 @@ public function findAllCategories(string $user_id) {
177179
'name' => '*',
178180
'recipe_count' => $row['cnt']
179181
);
180-
182+
181183
$result = array_unique($result, SORT_REGULAR);
182184
$result = array_filter($result);
183185

@@ -186,21 +188,45 @@ public function findAllCategories(string $user_id) {
186188

187189
/**
188190
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
191+
*
192+
* Using '_' as a placeholder for recipes w/o category
189193
*/
190194
public function getRecipesByCategory(string $category, string $user_id) {
191195
$qb = $this->db->getQueryBuilder();
192196

193-
$qb->select(['r.recipe_id', 'r.name'])
194-
->from(self::DB_TABLE_CATEGORIES, 'k')
195-
->where('k.name = :category')
196-
->andWhere('k.user_id = :user')
197-
->setParameter('category', $category, TYPE::STRING)
198-
->setParameter('user', $user_id, TYPE::STRING);
199-
200-
$qb->join('k', self::DB_TABLE_RECIPES, 'r', 'k.recipe_id = r.recipe_id');
197+
if ($category != '_')
198+
{
199+
$qb->select(['r.recipe_id', 'r.name'])
200+
->from(self::DB_TABLE_CATEGORIES, 'k')
201+
->where('k.name = :category')
202+
->andWhere('k.user_id = :user')
203+
->setParameter('category', $category, TYPE::STRING)
204+
->setParameter('user', $user_id, TYPE::STRING);
205+
206+
$qb->join('k', self::DB_TABLE_RECIPES, 'r', 'k.recipe_id = r.recipe_id');
201207

202-
$qb->groupBy(['r.name', 'r.recipe_id']);
203-
$qb->orderBy('r.name');
208+
$qb->groupBy(['r.name', 'r.recipe_id']);
209+
$qb->orderBy('r.name');
210+
}
211+
else
212+
{
213+
214+
$qb->select(['r.recipe_id', 'r.name'])
215+
->from(self::DB_TABLE_RECIPES, 'r')
216+
->leftJoin(
217+
'r',
218+
self::DB_TABLE_CATEGORIES,
219+
'c',
220+
$qb->expr()->andX(
221+
'r.user_id = c.user_id',
222+
'r.recipe_id = c.recipe_id'
223+
)
224+
)
225+
->where(
226+
$qb->expr()->eq('r.user_id', $qb->expr()->literal($user_id)),
227+
$qb->expr()->isNull('c.name')
228+
);
229+
}
204230

205231
$cursor = $qb->execute();
206232
$result = $cursor->fetchAll();

src/components/AppControls.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</Breadcrumb>
1414
<!-- SEARCH PAGE -->
1515
<Breadcrumb v-if="isSearch" class="not-link" :title="searchTitle" :disableDrop="true" />
16-
<Breadcrumb v-if="isSearch && $route.params.value" class="active" :title="$route.params.value" :disableDrop="true" />
16+
<Breadcrumb v-if="isSearch && $route.params.value" class="active" :title="$route.params.value=='_'?'None':$route.params.value" :disableDrop="true" />
1717
<!-- RECIPE PAGES -->
1818
<!-- Edit recipe -->
1919
<Breadcrumb v-if="isEdit" class="not-link" :title="t('cookbook', 'Edit recipe')" :disableDrop="true" />

src/components/AppNavi.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<AppNavigationItem :title="t('cookbook', 'All recipes')" icon="icon-category-organization" :to="'/'">
2323
<AppNavigationCounter slot="counter">{{ totalRecipeCount }}</AppNavigationCounter>
2424
</AppNavigationItem>
25+
<AppNavigationItem :title="t('cookbook', 'Uncategorized recipes')" icon="icon-category-organization" :to="'/category/_/'">
26+
<AppNavigationCounter slot="counter">{{ uncatRecipes }}</AppNavigationCounter>
27+
</AppNavigationItem>
2528
<AppNavigationItem v-for="(cat,idx) in categories"
2629
:key="cat+idx"
2730
:ref="'app-navi-cat-'+idx"

0 commit comments

Comments
 (0)