From 48c3c2b00dc5ebe36c291630ac8ff7c07d98a291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=9B=BD=E7=92=87?= <37972689+YangGuoXuan-0503@users.noreply.github.com> Date: Sun, 8 Sep 2024 11:32:02 +0800 Subject: [PATCH] feat: metadata gallery view (#380) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 杨国璇 --- repo_metadata/view_data_sql.py | 52 +++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/repo_metadata/view_data_sql.py b/repo_metadata/view_data_sql.py index b787ea66..d66fff2e 100644 --- a/repo_metadata/view_data_sql.py +++ b/repo_metadata/view_data_sql.py @@ -996,31 +996,26 @@ def _get_column_by_name(self, col_name): def _sort_2_sql(self): condition_sorts = self.view.get('sorts', []) - if not condition_sorts: - return f' ORDER BY \ - `{self.table.columns.parent_dir.name}` ASC, \ - `{self.table.columns.is_dir.name}` DESC, \ - `{self.table.columns.file_name.name}` ASC' - order_header = 'ORDER BY ' clauses = [] - for sort in condition_sorts: - column_key = sort.get('column_key', '') - column_name = sort.get('column_name', '') - sort_type = sort.get('sort_type', 'DESC') == 'up' and 'ASC' or 'DESC' - column = self._get_column_by_key(column_key) - if not column: - column = self._get_column_by_name(column_name) + if condition_sorts: + for sort in condition_sorts: + column_key = sort.get('column_key', '') + column_name = sort.get('column_name', '') + sort_type = sort.get('sort_type', 'DESC') == 'up' and 'ASC' or 'DESC' + column = self._get_column_by_key(column_key) if not column: - if column_key in ['_ctime', '_mtime']: - order_condition = '%s %s' % (column_key, sort_type) - clauses.append(order_condition) - continue - else: - continue - - order_condition = '`%s` %s' % (column.get('name'), sort_type) - clauses.append(order_condition) + column = self._get_column_by_name(column_name) + if not column: + if column_key in ['_ctime', '_mtime']: + order_condition = '%s %s' % (column_key, sort_type) + clauses.append(order_condition) + continue + else: + continue + + order_condition = '`%s` %s' % (column.get('name'), sort_type) + clauses.append(order_condition) if not clauses: return f' ORDER BY \ `{self.table.columns.parent_dir.name}` ASC, \ @@ -1080,7 +1075,8 @@ def _basic_filters_sql(self): filters = [] for filter_item in basic_filters: - if filter_item.get('column_key') == '_is_dir': + column_key = filter_item.get('column_key') + if column_key == '_is_dir': filter_term = filter_item.get('filter_term', 'all') if filter_term == 'file': filter_item['filter_term'] = False @@ -1090,6 +1086,16 @@ def _basic_filters_sql(self): filters.append(filter_item) else: continue + if column_key == '_file_type': + filter_term = filter_item.get('filter_term', 'picture') + if filter_term == 'picture': + filter_item['filter_term'] = '_picture' + elif filter_term == 'video': + filter_item['filter_term'] = '_video' + else: + filter_item['filter_predicate'] = 'is_any_of' + filter_item['filter_term'] = ['_picture', '_video'] + filters.append(filter_item) else: filters.append(filter_item)