diff options
author | John Molakvoæ <skjnldsv@protonmail.com> | 2023-04-27 11:15:48 +0200 |
---|---|---|
committer | John Molakvoæ <skjnldsv@protonmail.com> | 2023-07-05 16:20:33 +0200 |
commit | a0597da460f10245c3081dc263857bb575eaeda0 (patch) | |
tree | e8fdb08b638926b1f976b32a5c0c503a5f93fae2 /apps/files | |
parent | f029c8bd82e94479fef047f1147d025a523bcba7 (diff) | |
download | nextcloud-server-a0597da460f10245c3081dc263857bb575eaeda0.tar.gz nextcloud-server-a0597da460f10245c3081dc263857bb575eaeda0.zip |
feat(files): sort favorites first
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files')
-rw-r--r-- | apps/files/lib/Service/UserConfig.php | 8 | ||||
-rw-r--r-- | apps/files/src/store/userconfig.ts | 1 | ||||
-rw-r--r-- | apps/files/src/views/FilesList.vue | 13 | ||||
-rw-r--r-- | apps/files/src/views/Settings.vue | 4 |
4 files changed, 23 insertions, 3 deletions
diff --git a/apps/files/lib/Service/UserConfig.php b/apps/files/lib/Service/UserConfig.php index e405b02c07a..c39719ae8ed 100644 --- a/apps/files/lib/Service/UserConfig.php +++ b/apps/files/lib/Service/UserConfig.php @@ -41,6 +41,12 @@ class UserConfig { 'default' => false, 'allowed' => [true, false], ], + [ + // Whether to sort favorites first in the list or not + 'key' => 'sort_favorites_first', + 'default' => true, + 'allowed' => [true, false], + ], ]; protected IConfig $config; @@ -133,7 +139,7 @@ class UserConfig { $userConfigs = array_map(function(string $key) use ($userId) { $value = $this->config->getUserValue($userId, Application::APP_ID, $key, $this->getDefaultConfigValue($key)); // If the default is expected to be a boolean, we need to cast the value - if (is_bool($this->getDefaultConfigValue($key))) { + if (is_bool($this->getDefaultConfigValue($key)) && is_string($value)) { return $value === '1'; } return $value; diff --git a/apps/files/src/store/userconfig.ts b/apps/files/src/store/userconfig.ts index 42821951dbf..a5b049f197f 100644 --- a/apps/files/src/store/userconfig.ts +++ b/apps/files/src/store/userconfig.ts @@ -31,6 +31,7 @@ import { emit, subscribe } from '@nextcloud/event-bus' const userConfig = loadState('files', 'config', { show_hidden: false, crop_image_previews: true, + sort_favorites_first: true, }) as UserConfig export const useUserConfigStore = function() { diff --git a/apps/files/src/views/FilesList.vue b/apps/files/src/views/FilesList.vue index f2a20c18f28..8b42cfe6133 100644 --- a/apps/files/src/views/FilesList.vue +++ b/apps/files/src/views/FilesList.vue @@ -78,6 +78,7 @@ import Vue from 'vue' import { useFilesStore } from '../store/files.ts' import { usePathsStore } from '../store/paths.ts' import { useSelectionStore } from '../store/selection.ts' +import { useUserConfigStore } from '../store/userconfig.ts' import { useViewConfigStore } from '../store/viewConfig.ts' import BreadCrumbs from '../components/BreadCrumbs.vue' import FilesListVirtual from '../components/FilesListVirtual.vue' @@ -103,14 +104,16 @@ export default Vue.extend({ ], setup() { - const pathsStore = usePathsStore() const filesStore = useFilesStore() + const pathsStore = usePathsStore() const selectionStore = useSelectionStore() + const userConfigStore = useUserConfigStore() const viewConfigStore = useViewConfigStore() return { filesStore, pathsStore, selectionStore, + userConfigStore, viewConfigStore, } }, @@ -123,6 +126,10 @@ export default Vue.extend({ }, computed: { + userConfig() { + return this.userConfigStore.userConfig + }, + /** @return {Navigation} */ currentView() { return this.$navigation.active @@ -179,11 +186,13 @@ export default Vue.extend({ return orderBy( [...(this.currentFolder?._children || []).map(this.getNode).filter(file => file)], [ + // 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 v => v[this.sortingMode], - // Fallback to name + // Finally, fallback to name v => v.basename, ], this.isAscSorting ? ['asc', 'asc', 'asc'] : ['desc', 'desc', 'desc'], diff --git a/apps/files/src/views/Settings.vue b/apps/files/src/views/Settings.vue index efd9f8cad22..82580d7c504 100644 --- a/apps/files/src/views/Settings.vue +++ b/apps/files/src/views/Settings.vue @@ -26,6 +26,10 @@ @update:open="onClose"> <!-- Settings API--> <NcAppSettingsSection id="settings" :title="t('files', 'Files settings')"> + <NcCheckboxRadioSwitch :checked="userConfig.sort_favorites_first" + @update:checked="setConfig('sort_favorites_first', $event)"> + {{ t('files', 'Sort favorites first') }} + </NcCheckboxRadioSwitch> <NcCheckboxRadioSwitch :checked="userConfig.show_hidden" @update:checked="setConfig('show_hidden', $event)"> {{ t('files', 'Show hidden files') }} |