Skip to content

Commit

Permalink
feat(files): Provide folder tree folders state
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <[email protected]>
  • Loading branch information
Pytal committed Jul 25, 2024
1 parent 739106c commit e73ded9
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
namespace OCA\Files\Controller;

use OC\Files\FilenameValidator;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchQuery;
use OCA\Files\Activity\Helper;
use OCA\Files\AppInfo\Application;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
Expand All @@ -26,9 +28,11 @@
use OCP\AppFramework\Services\IInitialState;
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\Search\ISearchComparison;
use OCP\Files\Template\ITemplateManager;
use OCP\IConfig;
use OCP\IL10N;
Expand Down Expand Up @@ -160,6 +164,35 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
$favElements = [];
}

try {
$userFolder = $this->rootFolder->getUserFolder($userId);
$searchQuery = new SearchQuery(
new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE),
0,
0,
[],
$this->userSession->getUser(),
false,
);
/** @var Folder[] $folders */
$folders = $userFolder->search($searchQuery);
$folderTreeFolders = array_values(array_map(fn (Folder $folder) => [
'fileid' => $folder->getId(),
'displayname' => $folder->getName(),
'owner' => $folder->getOwner()?->getUID(),
'path' => $userFolder->getRelativePath($folder->getPath()),
'parentid' => $folder->getParentId(),
'mountType' => $folder->getMountPoint()->getMountType(),
'mime' => $folder->getMimetype(),
'size' => $folder->getSize(),
'mtime' => $folder->getMTime(),
'crtime' => $folder->getCreationTime(),
'permissions' => $folder->getPermissions(),
], $folders));
} catch (\RuntimeException $e) {
$folderTreeFolders = [];
}

// If the file doesn't exists in the folder and
// exists in only one occurrence, redirect to that file
// in the correct folder
Expand Down Expand Up @@ -190,6 +223,7 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
$this->initialState->provideInitialState('config', $this->userConfig->getConfigs());
$this->initialState->provideInitialState('viewConfigs', $this->viewConfig->getConfigs());
$this->initialState->provideInitialState('favoriteFolders', $favElements);
$this->initialState->provideInitialState('folderTreeFolders', $folderTreeFolders);

// File sorting user config
$filesSortingConfig = json_decode($this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'), true);
Expand Down

0 comments on commit e73ded9

Please sign in to comment.