diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2023-11-16 19:59:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-16 19:59:56 +0100 |
commit | 82e08f1df35aaf519ba5bd92723e8d6e88f0a865 (patch) | |
tree | 220258823456adb101c3b190ec494a219d5e7efe /apps | |
parent | c9dc377ebcdda91d2e471a3c26c72ed94fecb9aa (diff) | |
parent | 7f462649dab1374fdb85d0fddb7535b7f278884d (diff) | |
download | nextcloud-server-82e08f1df35aaf519ba5bd92723e8d6e88f0a865.tar.gz nextcloud-server-82e08f1df35aaf519ba5bd92723e8d6e88f0a865.zip |
Merge pull request #41519 from nextcloud/fix/files-sorting
fix(files): Ensure folders and favorites are sorted first regardless of sorting mode
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/src/views/FilesList.vue | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/apps/files/src/views/FilesList.vue b/apps/files/src/views/FilesList.vue index 3bc4f27c2a2..0729e8a983a 100644 --- a/apps/files/src/views/FilesList.vue +++ b/apps/files/src/views/FilesList.vue @@ -218,6 +218,40 @@ export default Vue.extend({ }, /** + * Directory content sorting parameters + * Provided by an extra computed property for caching + */ + sortingParameters() { + const identifiers = [ + // 1: Sort favorites first if enabled + ...(this.userConfig.sort_favorites_first ? [v => v.attributes?.favorite !== 1] : []), + // 2: Sort folders first if sorting by name + ...(this.sortingMode === 'basename' ? [v => v.type !== 'folder'] : []), + // 3: Use sorting mode if NOT basename (to be able to use displayName too) + ...(this.sortingMode !== 'basename' ? [v => v[this.sortingMode]] : []), + // 4: Use displayName if available, fallback to name + v => v.attributes?.displayName || v.basename, + // 5: Finally, use basename if all previous sorting methods failed + v => v.basename, + ] + const orders = [ + // (for 1): always sort favorites before normal files + ...(this.userConfig.sort_favorites_first ? ['asc'] : []), + // (for 2): always sort folders before files + ...(this.sortingMode === 'basename' ? ['asc'] : []), + // (for 3): Reverse if sorting by mtime as mtime higher means edited more recent -> lower + ...(this.sortingMode === 'mtime' ? [this.isAscSorting ? 'desc' : 'asc'] : []), + // (also for 3 so make sure not to conflict with 2 and 3) + ...(this.sortingMode !== 'mtime' && this.sortingMode !== 'basename' ? [this.isAscSorting ? 'asc' : 'desc'] : []), + // for 4: use configured sorting direction + this.isAscSorting ? 'asc' : 'desc', + // for 5: use configured sorting direction + this.isAscSorting ? 'asc' : 'desc', + ] + return [identifiers, orders] as const + }, + + /** * The current directory contents. */ dirContentsSorted(): Node[] { @@ -234,24 +268,9 @@ export default Vue.extend({ return this.isAscSorting ? results : results.reverse() } - const identifiers = [ - // Sort favorites first if enabled - ...this.userConfig.sort_favorites_first ? [v => v.attributes?.favorite !== 1] : [], - // Sort folders first if sorting by name - ...this.sortingMode === 'basename' ? [v => v.type !== 'folder'] : [], - // Use sorting mode if NOT basename (to be able to use displayName too) - ...this.sortingMode !== 'basename' ? [v => v[this.sortingMode]] : [], - // Use displayName if available, fallback to name - v => v.attributes?.displayName || v.basename, - // Finally, use basename if all previous sorting methods failed - v => v.basename, - ] - const orders = new Array(identifiers.length).fill(this.isAscSorting ? 'asc' : 'desc') - return orderBy( [...this.dirContents], - identifiers, - orders, + ...this.sortingParameters, ) }, |