diff options
author | John Molakvoæ <skjnldsv@protonmail.com> | 2023-03-24 09:41:40 +0100 |
---|---|---|
committer | John Molakvoæ <skjnldsv@protonmail.com> | 2023-04-06 14:49:31 +0200 |
commit | 3c3050c76f86c7a8cc2f217f9305cb1051e0eca0 (patch) | |
tree | d9656a549b1db4c7f3d37549713a6c96da616464 /apps/files/lib/Controller/ApiController.php | |
parent | 0b4da6117fff4d999cb492503a8b6fc04eb75f9d (diff) | |
download | nextcloud-server-3c3050c76f86c7a8cc2f217f9305cb1051e0eca0.tar.gz nextcloud-server-3c3050c76f86c7a8cc2f217f9305cb1051e0eca0.zip |
feat(files): implement sorting per view
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files/lib/Controller/ApiController.php')
-rw-r--r-- | apps/files/lib/Controller/ApiController.php | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index c7da9b2c118..808f0d555d0 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -281,20 +281,29 @@ class ApiController extends Controller { * * @param string $mode * @param string $direction - * @return Response + * @return JSONResponse * @throws \OCP\PreConditionNotMetException */ - public function updateFileSorting($mode, $direction) { - $allowedMode = ['basename', 'size', 'mtime']; + public function updateFileSorting($mode, string $direction = 'asc', string $view = 'files'): JSONResponse { $allowedDirection = ['asc', 'desc']; - if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) { - $response = new Response(); - $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY); - return $response; + if (!in_array($direction, $allowedDirection)) { + return new JSONResponse(['message' => 'Invalid direction parameter'], Http::STATUS_UNPROCESSABLE_ENTITY); } - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode); - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction); - return new Response(); + + $userId = $this->userSession->getUser()->getUID(); + + $sortingJson = $this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'); + $sortingConfig = json_decode($sortingJson, true) ?: []; + $sortingConfig[$view] = [ + 'mode' => $mode, + 'direction' => $direction, + ]; + + $this->config->setUserValue($userId, 'files', 'files_sorting_configs', json_encode($sortingConfig)); + return new JSONResponse([ + 'message' => 'ok', + 'data' => $sortingConfig, + ]); } /** |