aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/lib/Controller
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2022-12-01 14:34:23 +0100
committerJohn Molakvoæ <skjnldsv@protonmail.com>2023-01-04 16:45:41 +0100
commit887c9e05de88f81ed6f0cb88bd185c05b1a22076 (patch)
tree5fdd405133148fdba12ff6ea6a8cd9e4f27007d2 /apps/files/lib/Controller
parent36b6a7c77199d17c0147fc27cd0cc54a2b7d5020 (diff)
downloadnextcloud-server-887c9e05de88f81ed6f0cb88bd185c05b1a22076.tar.gz
nextcloud-server-887c9e05de88f81ed6f0cb88bd185c05b1a22076.zip
Port Files navigation to vue
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files/lib/Controller')
-rw-r--r--apps/files/lib/Controller/ApiController.php22
-rw-r--r--apps/files/lib/Controller/ViewController.php41
2 files changed, 32 insertions, 31 deletions
diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php
index e29e81d6296..a87b4f9490a 100644
--- a/apps/files/lib/Controller/ApiController.php
+++ b/apps/files/lib/Controller/ApiController.php
@@ -346,18 +346,18 @@ class ApiController extends Controller {
* @throws \OCP\PreConditionNotMetException
*/
public function toggleShowFolder(int $show, string $key): Response {
- // ensure the edited key exists
- $navItems = \OCA\Files\App::getNavigationManager()->getAll();
- foreach ($navItems as $item) {
- // check if data is valid
- if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) {
- $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (string)$show);
- return new Response();
- }
+ if ($show !== 0 && $show !== 1) {
+ return new DataResponse([
+ 'message' => 'Invalid show value. Only 0 and 1 are allowed.'
+ ], Http::STATUS_BAD_REQUEST);
}
- $response = new Response();
- $response->setStatus(Http::STATUS_FORBIDDEN);
- return $response;
+
+ $userId = $this->userSession->getUser()->getUID();
+
+ // Set the new value and return it
+ // Using a prefix prevents the user from setting arbitrary keys
+ $this->config->setUserValue($userId, 'files', 'show_' . $key, (string)$show);
+ return new JSONResponse([$key => $show]);
}
/**
diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php
index 1da9814d7e8..63863b3e367 100644
--- a/apps/files/lib/Controller/ViewController.php
+++ b/apps/files/lib/Controller/ViewController.php
@@ -186,13 +186,14 @@ class ViewController extends Controller {
* @throws NotFoundException
*/
public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false, $openfile = null) {
- if ($fileid !== null && $dir === '') {
- try {
- return $this->redirectToFile($fileid);
- } catch (NotFoundException $e) {
- return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true]));
- }
- }
+
+ // if ($fileid !== null && $dir === '') {
+ // try {
+ // return $this->redirectToFile($fileid);
+ // } catch (NotFoundException $e) {
+ // return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true]));
+ // }
+ // }
$nav = new \OCP\Template('files', 'appnavigation', '');
@@ -205,11 +206,11 @@ class ViewController extends Controller {
// FIXME: Make non static
$storageInfo = $this->getStorageInfo();
- $user = $this->userSession->getUser()->getUID();
+ $userId = $this->userSession->getUser()->getUID();
// Get all the user favorites to create a submenu
try {
- $favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID());
+ $favElements = $this->activityHelper->getFavoriteFilePaths($userId);
} catch (\RuntimeException $e) {
$favElements['folders'] = [];
}
@@ -234,7 +235,7 @@ class ViewController extends Controller {
'order' => $navBarPositionPosition,
'folderPosition' => $sortingValue,
'name' => basename($favElement),
- 'icon' => 'files',
+ 'icon' => 'folder',
'quickaccesselement' => 'true'
];
@@ -248,11 +249,9 @@ class ViewController extends Controller {
$navItems['favorites']['sublist'] = $favoritesSublistArray;
$navItems['favorites']['classes'] = $collapseClasses;
- // parse every menu and add the expandedState user value
+ // parse every menu and add the expanded user value
foreach ($navItems as $key => $item) {
- if (isset($item['expandedState'])) {
- $navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1';
- }
+ $navItems[$key]['expanded'] = $this->config->getUserValue($userId, 'files', 'show_' . $item['id'], '0') === '1';
}
$nav->assign('navigationItems', $navItems);
@@ -267,10 +266,12 @@ class ViewController extends Controller {
$nav->assign('quota', $storageInfo['quota']);
$nav->assign('usage_relative', $storageInfo['relative']);
- $nav->assign('webdav_url', \OCP\Util::linkToRemote('dav/files/' . rawurlencode($user)));
+ $nav->assign('webdav_url', \OCP\Util::linkToRemote('dav/files/' . rawurlencode($userId)));
$contentItems = [];
+ $this->initialState->provideInitialState('navigation', $navItems);
+
// render the container content for every navigation item
foreach ($navItems as $item) {
$content = '';
@@ -314,12 +315,12 @@ class ViewController extends Controller {
$params['ownerDisplayName'] = $storageInfo['ownerDisplayName'] ?? '';
$params['isPublic'] = false;
$params['allowShareWithLink'] = $this->shareManager->shareApiAllowLinks() ? 'yes' : 'no';
- $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name');
- $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc');
- $params['showgridview'] = $this->config->getUserValue($user, 'files', 'show_grid', false);
- $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false);
+ $params['defaultFileSorting'] = $this->config->getUserValue($userId, 'files', 'file_sorting', 'name');
+ $params['defaultFileSortingDirection'] = $this->config->getUserValue($userId, 'files', 'file_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;
- $cropImagePreviews = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', true);
+ $cropImagePreviews = (bool) $this->config->getUserValue($userId, 'files', 'crop_image_previews', true);
$params['cropImagePreviews'] = $cropImagePreviews ? 1 : 0;
$params['fileNotFound'] = $fileNotFound ? 1 : 0;
$params['appNavigation'] = $nav;