From 3c3050c76f86c7a8cc2f217f9305cb1051e0eca0 Mon Sep 17 00:00:00 2001 From: John Molakvoæ Date: Fri, 24 Mar 2023 09:41:40 +0100 Subject: feat(files): implement sorting per view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- apps/files/src/components/FilesListHeader.vue | 90 +++++++++++++++++++-------- 1 file changed, 64 insertions(+), 26 deletions(-) (limited to 'apps/files/src/components/FilesListHeader.vue') diff --git a/apps/files/src/components/FilesListHeader.vue b/apps/files/src/components/FilesListHeader.vue index 1fe6d230a20..0ee7298ee95 100644 --- a/apps/files/src/components/FilesListHeader.vue +++ b/apps/files/src/components/FilesListHeader.vue @@ -21,22 +21,18 @@ --> @@ -67,6 +62,7 @@ import { mapState } from 'pinia' import { translate } from '@nextcloud/l10n' import MenuDown from 'vue-material-design-icons/MenuDown.vue' import MenuUp from 'vue-material-design-icons/MenuUp.vue' +import NcButton from '@nextcloud/vue/dist/Components/NcButton.js' import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js' import Vue from 'vue' @@ -75,15 +71,13 @@ import { useSelectionStore } from '../store/selection' import { useSortingStore } from '../store/sorting' import logger from '../logger.js' import Navigation from '../services/Navigation' - -Vue.config.performance = true +import FilesListHeaderButton from './FilesListHeaderButton.vue' export default Vue.extend({ name: 'FilesListHeader', components: { - MenuDown, - MenuUp, + FilesListHeaderButton, NcCheckboxRadioSwitch, }, @@ -110,7 +104,7 @@ export default Vue.extend({ }, computed: { - ...mapState(useSortingStore, ['defaultFileSorting', 'defaultFileSortingDirection']), + ...mapState(useSortingStore, ['filesSortingConfig']), /** @return {Navigation} */ currentView() { @@ -153,9 +147,37 @@ export default Vue.extend({ selectedFiles() { return this.selectionStore.selected }, + + sortingMode() { + return this.sortingStore.getSortingMode(this.currentView.id) + || this.currentView.defaultSortKey + || 'basename' + }, + isAscSorting() { + return this.sortingStore.isAscSorting(this.currentView.id) === true + }, }, methods: { + classForColumn(column) { + return { + 'files-list__column': true, + 'files-list__column--sortable': !!column.sort, + 'files-list__row-column-custom': true, + [`files-list__row-${this.currentView.id}-${column.id}`]: true, + } + }, + + sortAriaLabel(column) { + const direction = this.isAscSorting + ? this.t('files', 'ascending') + : this.t('files', 'descending') + return this.t('files', 'Sort list by {column} ({direction})', { + column, + direction, + }) + }, + onToggleAll(selected) { if (selected) { const selection = this.nodes.map(node => node.attributes.fileid.toString()) @@ -169,12 +191,19 @@ export default Vue.extend({ toggleSortBy(key) { // If we're already sorting by this key, flip the direction - if (this.defaultFileSorting === key) { - this.sortingStore.toggleSortingDirection() + if (this.sortingMode === key) { + this.sortingStore.toggleSortingDirection(this.currentView.id) return } // else sort ASC by this new key - this.sortingStore.setFileSorting(key) + this.sortingStore.setSortingBy(key, this.currentView.id) + }, + + toggleSortByCustomColumn(column) { + if (!column.sort) { + return + } + this.toggleSortBy(column.id) }, t: translate, @@ -183,6 +212,15 @@ export default Vue.extend({ -- cgit v1.2.3