-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add file sorting capabilities and sorting GET api #27398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |||||
| namespace OCA\Files\Controller; | ||||||
|
|
||||||
| use OC\Files\Node\Node; | ||||||
| use OCA\Files\Capabilities; | ||||||
| use OCA\Files\Service\TagService; | ||||||
| use OCP\AppFramework\Controller; | ||||||
| use OCP\AppFramework\Http; | ||||||
|
|
@@ -267,12 +268,9 @@ public function getRecentFiles() { | |||||
| * @param string $mode | ||||||
| * @param string $direction | ||||||
| * @return Response | ||||||
| * @throws \OCP\PreConditionNotMetException | ||||||
| */ | ||||||
| public function updateFileSorting($mode, $direction) { | ||||||
| $allowedMode = ['name', 'size', 'mtime']; | ||||||
| $allowedDirection = ['asc', 'desc']; | ||||||
| if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) { | ||||||
| public function updateFileSorting($mode, $direction): Response { | ||||||
| if (!in_array($mode, Capabilities::SORTING_MODES) || !in_array($direction, Capabilities::SORTING_DIRECTIONS)) { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
for strict comparison |
||||||
| $response = new Response(); | ||||||
| $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY); | ||||||
| return $response; | ||||||
|
|
@@ -282,6 +280,23 @@ public function updateFileSorting($mode, $direction) { | |||||
| return new Response(); | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| /** | ||||||
| * Get the default sort mode | ||||||
| * | ||||||
| * @NoAdminRequired | ||||||
| * | ||||||
| * @return JSONResponse | ||||||
| */ | ||||||
| public function getFileSorting(): JSONResponse { | ||||||
| $file_sorting = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', Capabilities::SORTING_MODES[0]); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💥 if the user is not logged in. please do a null check on the result of |
||||||
| $file_sorting_direction = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', Capabilities::SORTING_DIRECTIONS[0]); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||||||
| return new JSONResponse([ | ||||||
| 'file_sorting' => $file_sorting, | ||||||
| 'file_sorting_direction' => $file_sorting_direction | ||||||
| ]); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Toggle default for showing/hiding hidden files | ||||||
| * | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use associative indices (probably event constants) to avoid messing with strings or meaningless numerical indices in the code.