Skip to content

Commit

Permalink
filter by tags (#444)
Browse files Browse the repository at this point in the history
* filter by tags

* fix tags operator

* update link operator

* feat: update code

* feat: update code

---------

Co-authored-by: zhouwenxuan <[email protected]>
Co-authored-by: 杨国璇 <[email protected]>
  • Loading branch information
3 people authored Dec 25, 2024
1 parent 023d33c commit 4cdc0b9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
8 changes: 8 additions & 0 deletions repo_metadata/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ class FilterTermModifier(object):
THIS_YEAR = 'this_year'


class FormulaResultType(object):
NUMBER = 'number'
STRING = 'string'
DATE = 'date'
BOOL = 'bool'
ARRAY = 'array'


class DurationFormatsType(object):
H_MM = 'h:mm'
H_MM_SS = 'h:mm:ss'
Expand Down
50 changes: 48 additions & 2 deletions repo_metadata/view_data_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dateutil.relativedelta import relativedelta

from seafevents.repo_metadata.constants import FilterPredicateTypes, FilterTermModifier, PropertyTypes, \
DurationFormatsType, PrivatePropertyKeys, ViewType
DurationFormatsType, PrivatePropertyKeys, ViewType, FormulaResultType

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -839,6 +839,50 @@ def __init__(self, column, filter_item):
super(FileOperator, self).__init__(column, filter_item)


class ArrayOperator(object):

def __new__(cls, column, filter_item):
column_data = column.get('data', {})
column_name = column.get('name', '')
column_key = column.get('key', '')
if column_key == PrivatePropertyKeys.TAGS:
new_column = {
'name': column_name,
'type': PropertyTypes.TEXT,
}
return TextOperator(new_column, filter_item)

array_type, array_data = column_data.get('array_type', ''), column_data.get('array_data')
linked_column = {
'name': column_name,
'type': array_type,
'data': array_data
}

if array_type == FormulaResultType.STRING:
new_column = {
'name': column_name,
'type': PropertyTypes.TEXT,
}
return TextOperator(new_column, filter_item)

if array_type == FormulaResultType.BOOL:
new_column = {
'name': column_name,
'type': PropertyTypes.CHECKBOX,
}
return CheckBoxOperator(new_column, filter_item)

if array_type == PropertyTypes.SINGLE_SELECT:
return MultipleSelectOperator(linked_column, filter_item)

if array_type in [PropertyTypes.CREATOR, PropertyTypes.LAST_MODIFIER]:
return CollaboratorOperator(linked_column, filter_item)

operator = _get_operator_by_type(array_type)
return operator(linked_column, filter_item)


def _filter2sql(operator):
support_filter_predicates = operator.SUPPORT_FILTER_PREDICATE
filter_predicate = operator.filter_predicate
Expand Down Expand Up @@ -924,7 +968,6 @@ def _get_operator_by_type(column_type):
PropertyTypes.EMAIL,
PropertyTypes.GEOLOCATION,
PropertyTypes.FILE_NAME

]:
return TextOperator

Expand Down Expand Up @@ -967,6 +1010,9 @@ def _get_operator_by_type(column_type):
]:
return FileOperator

if column_type == PropertyTypes.LINK:
return ArrayOperator

return None


Expand Down

0 comments on commit 4cdc0b9

Please sign in to comment.