diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-07-13 09:57:54 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-07-13 09:57:54 +0200 |
commit | e1a2bb9d69bf1aeba6362672c6b161bb96ad8a48 (patch) | |
tree | 3184d27752e692b96e70e957b6b58cba495892ed | |
parent | 6f45607f57c55550808824ffdeebbf10353a2554 (diff) | |
download | nextcloud-server-e1a2bb9d69bf1aeba6362672c6b161bb96ad8a48.tar.gz nextcloud-server-e1a2bb9d69bf1aeba6362672c6b161bb96ad8a48.zip |
Fix fav quickaccess ressource addition
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
-rw-r--r-- | apps/files/appinfo/app.php | 26 | ||||
-rw-r--r-- | apps/files/js/tagsplugin.js | 33 | ||||
-rw-r--r-- | apps/files/lib/Controller/ViewController.php | 123 |
3 files changed, 87 insertions, 95 deletions
diff --git a/apps/files/appinfo/app.php b/apps/files/appinfo/app.php index a7ce4e18306..dfff7f6f464 100644 --- a/apps/files/appinfo/app.php +++ b/apps/files/appinfo/app.php @@ -40,27 +40,27 @@ $templateManager->registerTemplate('application/vnd.oasis.opendocument.text', 'c $templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods'); \OCA\Files\App::getNavigationManager()->add([ - 'id' => 'files', + 'id' => 'files', 'appname' => 'files', - 'script' => 'list.php', - 'order' => 0, - 'name' => $l->t('All files'), + 'script' => 'list.php', + 'order' => 0, + 'name' => $l->t('All files') ]); \OCA\Files\App::getNavigationManager()->add([ - 'id' => 'recent', + 'id' => 'recent', 'appname' => 'files', - 'script' => 'recentlist.php', - 'order' => 2, - 'name' => $l->t('Recent'), + 'script' => 'recentlist.php', + 'order' => 2, + 'name' => $l->t('Recent') ]); \OCA\Files\App::getNavigationManager()->add([ - 'id' => 'favorites', - 'appname' => 'files', - 'script' => 'simplelist.php', - 'order' => 5, - 'name' => $l->t('Favorites'), + 'id' => 'favorites', + 'appname' => 'files', + 'script' => 'simplelist.php', + 'order' => 5, + 'name' => $l->t('Favorites'), 'expandedState' => 'show_Quick_Access' ]); diff --git a/apps/files/js/tagsplugin.js b/apps/files/js/tagsplugin.js index bc1396b5104..4ce6604384d 100644 --- a/apps/files/js/tagsplugin.js +++ b/apps/files/js/tagsplugin.js @@ -68,29 +68,22 @@ * @param {String} appfolder folder to be removed */ function removeFavoriteFromList (appfolder) { - var quickAccessList = 'sublist-favorites'; - var collapsibleButtonId = 'button-collapse-favorites'; var listULElements = document.getElementById(quickAccessList); if (!listULElements) { return; } - var listLIElements = listULElements.getElementsByTagName('li'); var apppath=appfolder; if(appfolder.startsWith("//")){ apppath=appfolder.substring(1, appfolder.length); } - for (var i = 0; i <= listLIElements.length - 1; i++) { - if (listLIElements[i].getElementsByTagName('a')[0].href.endsWith("dir=" + apppath)) { - listLIElements[i].remove(); - } - } + $(listULElements).find('[data-dir="' + apppath + '"]').remove(); if (listULElements.childElementCount === 0) { - var collapsibleButton = document.getElementById("button-collapse-favorites"); - collapsibleButton.style.display = 'none'; + var collapsibleButton = $(listULElements).parent().find('button.collapse'); + collapsibleButton.hide(); $("#button-collapse-parent-favorites").removeClass('collapsible'); } } @@ -102,7 +95,6 @@ */ function addFavoriteToList (appfolder) { var quickAccessList = 'sublist-favorites'; - var collapsibleButtonId = 'button-collapse-favorites'; var listULElements = document.getElementById(quickAccessList); if (!listULElements) { return; @@ -110,13 +102,13 @@ var listLIElements = listULElements.getElementsByTagName('li'); var appName = appfolder.substring(appfolder.lastIndexOf("/") + 1, appfolder.length); - var apppath=appfolder; + var apppath = appfolder; if(appfolder.startsWith("//")){ - apppath=appfolder.substring(1, appfolder.length); + apppath = appfolder.substring(1, appfolder.length); } - var url=OC.generateUrl('/apps/files/?dir=')+apppath; - + var url = OC.generateUrl('/apps/files/?dir=' + apppath + '&view=files'); + var innerTagA = document.createElement('A'); innerTagA.setAttribute("href", url); @@ -125,7 +117,9 @@ var length = listLIElements.length + 1; var innerTagLI = document.createElement('li'); - innerTagLI.setAttribute("data-id", url); + innerTagLI.setAttribute("data-id", apppath.replace('/', '-')); + innerTagLI.setAttribute("data-dir", apppath); + innerTagLI.setAttribute("data-view", 'files'); innerTagLI.setAttribute("class", "nav-" + appName); innerTagLI.setAttribute("folderpos", length.toString()); innerTagLI.appendChild(innerTagA); @@ -134,10 +128,9 @@ if (data === "dir") { if (listULElements.childElementCount <= 0) { listULElements.appendChild(innerTagLI); - var collapsibleButton = document.getElementById(collapsibleButtonId); - collapsibleButton.style.display = ''; - - $("#button-collapse-parent-favorites").addClass('collapsible'); + var collapsibleButton = $(listULElements).parent().find('button.collapse'); + collapsibleButton.show(); + $(listULElements).parent().addClass('collapsible'); } else { listLIElements[listLIElements.length - 1].after(innerTagLI); } diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 063d16c62d7..0a13af32331 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -33,6 +33,8 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\TemplateResponse; +use OCP\App\IAppManager; +use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\IConfig; @@ -41,8 +43,6 @@ use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUserSession; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use OCP\Files\Folder; -use OCP\App\IAppManager; use Symfony\Component\EventDispatcher\GenericEvent; /** @@ -73,27 +73,27 @@ class ViewController extends Controller { protected $activityHelper; public function __construct(string $appName, - IRequest $request, - IURLGenerator $urlGenerator, - IL10N $l10n, - IConfig $config, - EventDispatcherInterface $eventDispatcherInterface, - IUserSession $userSession, - IAppManager $appManager, - IRootFolder $rootFolder, - Helper $activityHelper + IRequest $request, + IURLGenerator $urlGenerator, + IL10N $l10n, + IConfig $config, + EventDispatcherInterface $eventDispatcherInterface, + IUserSession $userSession, + IAppManager $appManager, + IRootFolder $rootFolder, + Helper $activityHelper ) { parent::__construct($appName, $request); - $this->appName = $appName; - $this->request = $request; - $this->urlGenerator = $urlGenerator; - $this->l10n = $l10n; - $this->config = $config; + $this->appName = $appName; + $this->request = $request; + $this->urlGenerator = $urlGenerator; + $this->l10n = $l10n; + $this->config = $config; $this->eventDispatcher = $eventDispatcherInterface; - $this->userSession = $userSession; - $this->appManager = $appManager; - $this->rootFolder = $rootFolder; - $this->activityHelper = $activityHelper; + $this->userSession = $userSession; + $this->appManager = $appManager; + $this->rootFolder = $rootFolder; + $this->activityHelper = $activityHelper; } /** @@ -102,8 +102,8 @@ class ViewController extends Controller { * @return string */ protected function renderScript($appName, $scriptName) { - $content = ''; - $appPath = \OC_App::getAppPath($appName); + $content = ''; + $appPath = \OC_App::getAppPath($appName); $scriptPath = $appPath . '/' . $scriptName; if (file_exists($scriptPath)) { // TODO: sanitize path / script name ? @@ -112,6 +112,7 @@ class ViewController extends Controller { $content = ob_get_contents(); @ob_end_clean(); } + return $content; } @@ -123,6 +124,7 @@ class ViewController extends Controller { */ protected function getStorageInfo() { $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false); + return \OC_Helper::getStorageInfo('/', $dirInfo); } @@ -171,21 +173,21 @@ class ViewController extends Controller { $favoritesSublistArray = Array(); $navBarPositionPosition = 6; - $currentCount = 0; + $currentCount = 0; foreach ($favElements['folders'] as $dir) { - $id = substr($dir, strrpos($dir, '/') + 1, strlen($dir)); - $link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']); + $id = substr($dir, strrpos($dir, '/') + 1, strlen($dir)); + $link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']); $sortingValue = ++$currentCount; - $element = [ - 'id' => str_replace('/', '-', $dir), - 'view' => 'files', - 'href' => $link, - 'dir' => $dir, - 'order' => $navBarPositionPosition, - 'folderPosition' => $sortingValue, - 'name' => $id, - 'icon' => 'files', + $element = [ + 'id' => str_replace('/', '-', $dir), + 'view' => 'files', + 'href' => $link, + 'dir' => $dir, + 'order' => $navBarPositionPosition, + 'folderPosition' => $sortingValue, + 'name' => $id, + 'icon' => 'files', 'quickaccesselement' => 'true' ]; @@ -193,19 +195,16 @@ class ViewController extends Controller { $navBarPositionPosition++; } - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); - // transform the favorites entry in menu + // add the favorites entry in menu $navItems['favorites']['sublist'] = $favoritesSublistArray; $navItems['favorites']['classes'] = $collapseClasses; - // parse every menu and add the expandedState user value foreach ($navItems as $key => $item) { if (isset($item['expandedState'])) { - $defaultValue = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1'; - $navItems[$key]['defaultExpandedState'] = $defaultValue; + $navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1'; } } @@ -237,34 +236,34 @@ class ViewController extends Controller { $subcontent = $this->renderScript($subitem['appname'], $subitem['script']); } $contentItems[$subitem['id']] = [ - 'id' => $subitem['id'], - 'content' =>$subcontent + 'id' => $subitem['id'], + 'content' => $subcontent ]; } } $contentItems[$item['id']] = [ - 'id' => $item['id'], - 'content' =>$content + 'id' => $item['id'], + 'content' => $content ]; } $event = new GenericEvent(null, ['hiddenFields' => []]); $this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts', $event); - $params = []; - $params['usedSpacePercent'] = (int)$storageInfo['relative']; - $params['owner'] = $storageInfo['owner']; - $params['ownerDisplayName'] = $storageInfo['ownerDisplayName']; - $params['isPublic'] = false; - $params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); - $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); + $params = []; + $params['usedSpacePercent'] = (int) $storageInfo['relative']; + $params['owner'] = $storageInfo['owner']; + $params['ownerDisplayName'] = $storageInfo['ownerDisplayName']; + $params['isPublic'] = false; + $params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); + $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc'); - $showHidden = (bool)$this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); - $params['showHiddenFiles'] = $showHidden ? 1 : 0; - $params['fileNotFound'] = $fileNotFound ? 1 : 0; - $params['appNavigation'] = $nav; - $params['appContents'] = $contentItems; - $params['hiddenFields'] = $event->getArgument('hiddenFields'); + $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); + $params['showHiddenFiles'] = $showHidden ? 1 : 0; + $params['fileNotFound'] = $fileNotFound ? 1 : 0; + $params['appNavigation'] = $nav; + $params['appContents'] = $contentItems; + $params['hiddenFields'] = $event->getArgument('hiddenFields'); $response = new TemplateResponse( $this->appName, @@ -275,7 +274,6 @@ class ViewController extends Controller { $policy->addAllowedFrameDomain('\'self\''); $response->setContentSecurityPolicy($policy); - return $response; } @@ -287,14 +285,14 @@ class ViewController extends Controller { * @throws \OCP\Files\NotFoundException */ private function showFile($fileId) { - $uid = $this->userSession->getUser()->getUID(); + $uid = $this->userSession->getUser()->getUID(); $baseFolder = $this->rootFolder->getUserFolder($uid); - $files = $baseFolder->getById($fileId); - $params = []; + $files = $baseFolder->getById($fileId); + $params = []; if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { - $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); - $files = $baseFolder->getById($fileId); + $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); + $files = $baseFolder->getById($fileId); $params['view'] = 'trashbin'; } @@ -309,6 +307,7 @@ class ViewController extends Controller { // and scroll to the entry $params['scrollto'] = $file->getName(); } + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); } throw new \OCP\Files\NotFoundException(); |