Skip to content

Allow selecting recipes with unassigned category #362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 43 additions & 17 deletions lib/Db/RecipeDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,13 @@ public function findAllKeywords(string $user_id) {
public function findAllCategories(string $user_id) {
$qb = $this->db->getQueryBuilder();

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

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

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

// Get count of recipes without category
$qb->select($qb->createFunction('COUNT(1) as cnt'))
->from(self::DB_TABLE_RECIPES, 'r')
->leftJoin(
Expand All @@ -177,7 +179,7 @@ public function findAllCategories(string $user_id) {
'name' => '*',
'recipe_count' => $row['cnt']
);

$result = array_unique($result, SORT_REGULAR);
$result = array_filter($result);

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

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

$qb->select(['r.recipe_id', 'r.name'])
->from(self::DB_TABLE_CATEGORIES, 'k')
->where('k.name = :category')
->andWhere('k.user_id = :user')
->setParameter('category', $category, TYPE::STRING)
->setParameter('user', $user_id, TYPE::STRING);

$qb->join('k', self::DB_TABLE_RECIPES, 'r', 'k.recipe_id = r.recipe_id');
if ($category != '_')
{
$qb->select(['r.recipe_id', 'r.name'])
->from(self::DB_TABLE_CATEGORIES, 'k')
->where('k.name = :category')
->andWhere('k.user_id = :user')
->setParameter('category', $category, TYPE::STRING)
->setParameter('user', $user_id, TYPE::STRING);

$qb->join('k', self::DB_TABLE_RECIPES, 'r', 'k.recipe_id = r.recipe_id');

$qb->groupBy(['r.name', 'r.recipe_id']);
$qb->orderBy('r.name');
$qb->groupBy(['r.name', 'r.recipe_id']);
$qb->orderBy('r.name');
}
else
{

$qb->select(['r.recipe_id', 'r.name'])
->from(self::DB_TABLE_RECIPES, 'r')
->leftJoin(
'r',
self::DB_TABLE_CATEGORIES,
'c',
$qb->expr()->andX(
'r.user_id = c.user_id',
'r.recipe_id = c.recipe_id'
)
)
->where(
$qb->expr()->eq('r.user_id', $qb->expr()->literal($user_id)),
$qb->expr()->isNull('c.name')
);
}

$cursor = $qb->execute();
$result = $cursor->fetchAll();
Expand Down
2 changes: 1 addition & 1 deletion src/components/AppControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</Breadcrumb>
<!-- SEARCH PAGE -->
<Breadcrumb v-if="isSearch" class="not-link" :title="searchTitle" :disableDrop="true" />
<Breadcrumb v-if="isSearch && $route.params.value" class="active" :title="$route.params.value" :disableDrop="true" />
<Breadcrumb v-if="isSearch && $route.params.value" class="active" :title="$route.params.value=='_'?'None':$route.params.value" :disableDrop="true" />
<!-- RECIPE PAGES -->
<!-- Edit recipe -->
<Breadcrumb v-if="isEdit" class="not-link" :title="t('cookbook', 'Edit recipe')" :disableDrop="true" />
Expand Down
3 changes: 3 additions & 0 deletions src/components/AppNavi.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<AppNavigationItem :title="t('cookbook', 'All recipes')" icon="icon-category-organization" :to="'/'">
<AppNavigationCounter slot="counter">{{ totalRecipeCount }}</AppNavigationCounter>
</AppNavigationItem>
<AppNavigationItem :title="t('cookbook', 'Uncategorized recipes')" icon="icon-category-organization" :to="'/category/_/'">
<AppNavigationCounter slot="counter">{{ uncatRecipes }}</AppNavigationCounter>
</AppNavigationItem>
<AppNavigationItem v-for="(cat,idx) in categories"
:key="cat+idx"
:ref="'app-navi-cat-'+idx"
Expand Down