diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index a3c868789fcc3..785705e9c8d46 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -2185,11 +2185,22 @@ } if (persist && OC.getCurrentUser().uid) { - $.post(OC.generateUrl('/apps/files/api/v1/sorting'), { - // Compatibility with new files-to-vue API - mode: sort === 'name' ? 'basename' : sort, - direction: direction, - view: 'files' + $.ajax({ + type: 'PUT', + url: OC.generateUrl('apps/files/api/v1/views/files/sorting_mode'), + contentType: 'application/json', + data: JSON.stringify({ + // Compatibility with new files-to-vue API + value: sort === 'name' ? 'basename' : sort, + }) + }); + $.ajax({ + type: 'PUT', + url: OC.generateUrl('apps/files/api/v1/views/files/sorting_direction'), + contentType: 'application/json', + data: JSON.stringify({ + value: direction, + }) }); } }, diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 01f85a7c93971..a5886ba8d805a 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -228,7 +228,7 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal $this->initialState->provideInitialState('favoriteFolders', $favElements['folders'] ?? []); // File sorting user config - $filesSortingConfig = json_decode($this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'), true); + $filesSortingConfig = $this->viewConfig->getConfigs(); $this->initialState->provideInitialState('filesSortingConfig', $filesSortingConfig); // render the container content for every navigation item @@ -274,8 +274,8 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal $params['ownerDisplayName'] = $storageInfo['ownerDisplayName'] ?? ''; $params['isPublic'] = false; $params['allowShareWithLink'] = $this->shareManager->shareApiAllowLinks() ? 'yes' : 'no'; - $params['defaultFileSorting'] = $filesSortingConfig['files']['mode'] ?? 'basename'; - $params['defaultFileSortingDirection'] = $filesSortingConfig['files']['direction'] ?? 'asc'; + $params['defaultFileSorting'] = $filesSortingConfig['files']['sorting_mode'] ?? 'basename'; + $params['defaultFileSortingDirection'] = $filesSortingConfig['files']['sorting_direction'] ?? 'asc'; $params['showgridview'] = $this->config->getUserValue($userId, 'files', 'show_grid', false); $showHidden = (bool) $this->config->getUserValue($userId, 'files', 'show_hidden', false); $params['showHiddenFiles'] = $showHidden ? 1 : 0; diff --git a/cypress/e2e/files.cy.ts b/cypress/e2e/files.cy.ts index 7b3a4ff7a56f9..e4f1f2e53384e 100644 --- a/cypress/e2e/files.cy.ts +++ b/cypress/e2e/files.cy.ts @@ -34,4 +34,24 @@ describe('Login with a new user and open the files app', function() { cy.visit('/apps/files') cy.get('.files-fileList tr').should('contain', 'welcome.txt') }) + + it('should save the last file list sorting', function() { + cy.intercept('PUT', /api\/v1\/views\/files\/sorting_direction$/).as('sorting_direction') + + cy.visit('/apps/files') + // default to sorting by name + cy.get('.files-filestable th.column-name .sort-indicator').should('be.visible') + // change to size + cy.get('.files-filestable th').contains('Size').click() + // size sorting should be active + cy.get('.files-filestable th.column-name .sort-indicator').should('not.be.visible') + cy.get('.files-filestable th.column-size .sort-indicator').should('be.visible') + cy.wait('@sorting_direction') + + // Re-visit + cy.visit('/apps/files') + // now sorting by name should be disabled and sorting by size should be enabled + cy.get('.files-filestable th.column-name .sort-indicator').should('not.be.visible') + cy.get('.files-filestable th.column-size .sort-indicator').should('be.visible') + }) })