Skip to content

Commit

Permalink
enh: add filtering in views for multi selection
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Steffens <florian.steffens@nextcloud.com>
  • Loading branch information
Florian Steffens committed Jan 24, 2024
1 parent 25d220e commit 6a3893f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion lib/Db/Row2Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,21 @@ private function getFilterExpression(IQueryBuilder $qb, Column $column, string $
case 'ends-with':
return $qb2->andWhere($qb->expr()->like('value', $qb->createNamedParameter($this->db->escapeLikeParameter($value).'%', $paramType)));
case 'contains':
if ($column->getType() === 'selection' && $column->getSubtype() === 'multi') {
$value = str_replace(['"', '\''], '', $value);
return $qb2->andWhere($qb2->expr()->orX(
$qb->expr()->like('value', $qb->createNamedParameter('['.$this->db->escapeLikeParameter($value).']')),
$qb->expr()->like('value', $qb->createNamedParameter('['.$this->db->escapeLikeParameter($value).',%')),
$qb->expr()->like('value', $qb->createNamedParameter('%,'.$this->db->escapeLikeParameter($value).']%')),
$qb->expr()->like('value', $qb->createNamedParameter('%,'.$this->db->escapeLikeParameter($value).',%'))
));
}
return $qb2->andWhere($qb->expr()->like('value', $qb->createNamedParameter('%'.$this->db->escapeLikeParameter($value).'%', $paramType)));
case 'is-equal':
if ($column->getType() === 'selection' && $column->getSubtype() === 'multi') {
$value = str_replace(['"', '\''], '', $value);
return $qb2->andWhere($qb->expr()->eq('value', $qb->createNamedParameter('['.$this->db->escapeLikeParameter($value).']', $paramType)));
}
return $qb2->andWhere($qb->expr()->eq('value', $qb->createNamedParameter($value, $paramType)));
case 'is-greater-than':
return $qb2->andWhere($qb->expr()->gt('value', $qb->createNamedParameter($value, $paramType)));
Expand Down Expand Up @@ -366,7 +379,7 @@ private function getMetaFilterExpression(IQueryBuilder $qb, int $columnId, strin
/**
* @param string $operator
* @param IQueryBuilder $qb
* @param string $column
* @param string $columnName
* @param mixed $value
* @param mixed $paramType
* @return string
Expand Down
4 changes: 2 additions & 2 deletions src/shared/components/ncTable/mixins/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const Filters = {
Contains: new Filter({
id: FilterIds.Contains,
label: t('tables', 'Contains'),
goodFor: [ColumnTypes.TextLine, ColumnTypes.TextLong, ColumnTypes.TextLink, ColumnTypes.TextRich],
goodFor: [ColumnTypes.TextLine, ColumnTypes.TextLong, ColumnTypes.TextLink, ColumnTypes.TextRich, ColumnTypes.SelectionMulti],
incompatibleWith: [FilterIds.IsEmpty, FilterIds.IsEqual],
}),
BeginsWith: new Filter({
Expand All @@ -68,7 +68,7 @@ export const Filters = {
id: FilterIds.IsEqual,
label: t('tables', 'Is equal'),
shortLabel: '=',
goodFor: [ColumnTypes.TextLine, ColumnTypes.Number, ColumnTypes.SelectionCheck, ColumnTypes.TextLink, ColumnTypes.NumberStars, ColumnTypes.NumberProgress, ColumnTypes.DatetimeDate, ColumnTypes.DatetimeTime, ColumnTypes.Datetime, ColumnTypes.Selection],
goodFor: [ColumnTypes.TextLine, ColumnTypes.Number, ColumnTypes.SelectionCheck, ColumnTypes.TextLink, ColumnTypes.NumberStars, ColumnTypes.NumberProgress, ColumnTypes.DatetimeDate, ColumnTypes.DatetimeTime, ColumnTypes.Datetime, ColumnTypes.Selection, ColumnTypes.SelectionMulti],
incompatibleWith: [FilterIds.IsEmpty, FilterIds.IsEqual, FilterIds.BeginsWith, FilterIds.EndsWith, FilterIds.Contains, FilterIds.IsGreaterThan, FilterIds.IsGreaterThanOrEqual, FilterIds.IsLowerThan, FilterIds.IsLowerThanOrEqual],
}),
IsGreaterThan: new Filter({
Expand Down

0 comments on commit 6a3893f

Please sign in to comment.