From 6f45607f57c55550808824ffdeebbf10353a2554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Fri, 13 Jul 2018 09:33:57 +0200 Subject: [PATCH] Upgraded navigation submenu management and api + created sharing submenu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- apps/files/appinfo/app.php | 41 +++++----- apps/files/appinfo/routes.php | 11 +-- apps/files/css/files.scss | 3 +- apps/files/js/navigation.js | 26 ++----- apps/files/lib/Controller/ApiController.php | 33 ++++----- apps/files/lib/Controller/ViewController.php | 55 ++++++++------ apps/files/templates/appnavigation.php | 21 ++++-- apps/files_sharing/appinfo/app.php | 78 ++++++++++---------- lib/private/NavigationManager.php | 4 +- 9 files changed, 135 insertions(+), 137 deletions(-) diff --git a/apps/files/appinfo/app.php b/apps/files/appinfo/app.php index fbe33fb54f..a7ce4e1830 100644 --- a/apps/files/appinfo/app.php +++ b/apps/files/appinfo/app.php @@ -39,24 +39,29 @@ $templateManager->registerTemplate('application/vnd.oasis.opendocument.presentat $templateManager->registerTemplate('application/vnd.oasis.opendocument.text', 'core/templates/filetemplates/template.odt'); $templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods'); -\OCA\Files\App::getNavigationManager()->add(function () use ($l) { - return [ - 'id' => 'files', - 'appname' => 'files', - 'script' => 'list.php', - 'order' => 0, - 'name' => $l->t('All files'), - ]; -}); +\OCA\Files\App::getNavigationManager()->add([ + 'id' => 'files', + 'appname' => 'files', + 'script' => 'list.php', + 'order' => 0, + 'name' => $l->t('All files'), +]); -\OCA\Files\App::getNavigationManager()->add(function () use ($l) { - return [ - 'id' => 'recent', - 'appname' => 'files', - 'script' => 'recentlist.php', - 'order' => 2, - 'name' => $l->t('Recent'), - ]; -}); +\OCA\Files\App::getNavigationManager()->add([ + 'id' => 'recent', + 'appname' => 'files', + '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'), + 'expandedState' => 'show_Quick_Access' +]); \OCP\Util::connectHook('\OCP\Config', 'js', '\OCA\Files\App', 'extendJsConfig'); diff --git a/apps/files/appinfo/routes.php b/apps/files/appinfo/routes.php index a9d8ba0a1b..44663d185d 100644 --- a/apps/files/appinfo/routes.php +++ b/apps/files/appinfo/routes.php @@ -77,14 +77,9 @@ $application->registerRoutes( 'verb' => 'GET', ], [ - 'name' => 'API#showQuickAccess', - 'url' => '/api/v1/quickaccess/set/showList', - 'verb' => 'GET', - ], - [ - 'name' => 'API#getShowQuickAccess', - 'url' => '/api/v1/quickaccess/get/showList', - 'verb' => 'GET', + 'name' => 'API#toggleShowFolder', + 'url' => '/api/v1/toggleShowFolder/{key}', + 'verb' => 'POST' ], [ 'name' => 'API#getShowQuickaccessSettings', diff --git a/apps/files/css/files.scss b/apps/files/css/files.scss index 24ecbf399e..79dc2a26eb 100644 --- a/apps/files/css/files.scss +++ b/apps/files/css/files.scss @@ -93,7 +93,8 @@ background-image: url('../img/star.svg?v=1'); } .nav-icon-sharingin, -.nav-icon-sharingout { +.nav-icon-sharingout, +.nav-icon-shareoverview { background-image: url('../img/share.svg?v=1'); } .nav-icon-sharinglinks { diff --git a/apps/files/js/navigation.js b/apps/files/js/navigation.js index d4fa06cb45..8ce976a6f5 100644 --- a/apps/files/js/navigation.js +++ b/apps/files/js/navigation.js @@ -172,30 +172,18 @@ */ _onClickMenuButton: function (ev) { var $target = $(ev.target); + var $menu = $target.parent('li'); var itemId = $target.closest('button').attr('id'); var collapsibleToggles = []; var dotmenuToggles = []; - // The collapsibleToggles-Array consists of a list of Arrays. Every subarray must contain the Button to listen to at the 0th index, - // and the parent, which should be toggled at the first arrayindex. - collapsibleToggles.push(["#button-collapse-favorites", "#button-collapse-parent-favorites"]); - - // The dotmenuToggles-Array consists of a list of Arrays. Every subarray must contain the Button to listen to at the 0th index, - // and the parent, which should be toggled at the first arrayindex. - dotmenuToggles.push(["#dotmenu-button-favorites", "dotmenu-content-favorites"]); - - collapsibleToggles.forEach(function foundToggle (item) { - if (item[0] === ("#" + itemId)) { - $(item[1]).toggleClass('open'); - var show = 1; - if (!$(item[1]).hasClass('open')) { - show = 0; - } - $.get(OC.generateUrl("/apps/files/api/v1/quickaccess/set/showList"), {show: show}, function (data, status) { - }); - } - }); + if ($menu.hasClass('collapsible') && $menu.data('expandedstate')) { + $menu.toggleClass('open'); + var show = $menu.hasClass('open') ? 1 : 0; + var key = $menu.data('expandedstate'); + $.post(OC.generateUrl("/apps/files/api/v1/toggleShowFolder/" + key), {show: show}); + } dotmenuToggles.forEach(function foundToggle (item) { if (item[0] === ("#" + itemId)) { diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index aae1bec2e7..fd63d54515 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -291,29 +291,28 @@ class ApiController extends Controller { } /** - * Toggle default for showing/hiding QuickAccess folder + * Toggle default for showing/hiding xxx folder * * @NoAdminRequired * - * @param bool $show + * @param bool $show + * @param bool $key the key of the folder * * @return Response */ - public function showQuickAccess($show) { - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', (int)$show); - return new Response(); - } - - /** - * Toggle default for showing/hiding QuickAccess folder - * - * @NoAdminRequired - * - * @return String - */ - public function getShowQuickAccess() { - - return $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', 0); + public function toggleShowFolder(int $show, string $key) { + // 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, (int)$show); + return new Response(); + } + } + $response = new Response(); + $response->setStatus(Http::STATUS_FORBIDDEN); + return $response; } /** diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index f240e04c72..063d16c62d 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -156,6 +156,7 @@ class ViewController extends Controller { $user = $this->userSession->getUser()->getUID(); + // Get all the user favorites to create a submenu try { $favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID()); } catch (\RuntimeException $e) { @@ -193,27 +194,20 @@ class ViewController extends Controller { } - // show_Quick_Access stored as string - $defaultExpandedState = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', '0') === '1'; - - \OCA\Files\App::getNavigationManager()->add( - [ - 'id' => 'favorites', - 'appname' => 'files', - 'script' => 'simplelist.php', - 'classes' => $collapseClasses, - 'order' => 5, - 'name' => $this->l10n->t('Favorites'), - 'sublist' => $favoritesSublistArray, - 'defaultExpandedState' => $defaultExpandedState, - 'enableMenuButton' => 0, - ] - ); - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); - usort($navItems, function ($item1, $item2) { - return $item1['order'] - $item2['order']; - }); + + // transform 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; + } + } $nav->assign('navigationItems', $navItems); @@ -235,10 +229,23 @@ class ViewController extends Controller { if (isset($item['script'])) { $content = $this->renderScript($item['appname'], $item['script']); } - $contentItem = []; - $contentItem['id'] = $item['id']; - $contentItem['content'] = $content; - $contentItems[] = $contentItem; + // parse submenus + if (isset($item['sublist'])) { + foreach ($item['sublist'] as $subitem) { + $subcontent = ''; + if (isset($subitem['script'])) { + $subcontent = $this->renderScript($subitem['appname'], $subitem['script']); + } + $contentItems[$subitem['id']] = [ + 'id' => $subitem['id'], + 'content' =>$subcontent + ]; + } + } + $contentItems[$item['id']] = [ + 'id' => $item['id'], + 'content' =>$content + ]; } $event = new GenericEvent(null, ['hiddenFields' => []]); diff --git a/apps/files/templates/appnavigation.php b/apps/files/templates/appnavigation.php index 0b9ac66590..04bcc57700 100644 --- a/apps/files/templates/appnavigation.php +++ b/apps/files/templates/appnavigation.php @@ -66,21 +66,26 @@ function NavigationListElements($item, $l, $pinned) { strpos($item['classes'], 'pinned') !== false ? $pinned++ : ''; ?> -
  • id="button-collapse-parent-" - data-id="" data-dir="" data-view="" - class="nav- open" +
  • data-dir="" + data-view="" + data-expandedstate="" + class="nav- + + + open" folderposition="" > + class="nav-icon- svg"> - +
      style="display: none"> + class="app-navigation-entry-utils" style="display: none">
      • diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 189c45426d..b7459d999d 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -50,56 +50,54 @@ $eventDispatcher->addListener( $config = \OC::$server->getConfig(); $shareManager = \OC::$server->getShareManager(); $userSession = \OC::$server->getUserSession(); +$l = \OC::$server->getL10N('files_sharing'); if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') { - \OCA\Files\App::getNavigationManager()->add(function () { - $l = \OC::$server->getL10N('files_sharing'); - return [ - 'id' => 'sharingin', - 'appname' => 'files_sharing', - 'script' => 'list.php', - 'order' => 15, - 'name' => $l->t('Shared with you'), - ]; - }); + + $sharingSublistArray = []; + + array_push($sharingSublistArray, [ + 'id' => 'sharingin', + 'appname' => 'files_sharing', + 'script' => 'list.php', + 'order' => 15, + 'name' => $l->t('Shared with you'), + ]); if (\OCP\Util::isSharingDisabledForUser() === false) { - \OCA\Files\App::getNavigationManager()->add(function () { - $l = \OC::$server->getL10N('files_sharing'); - return [ - 'id' => 'sharingout', - 'appname' => 'files_sharing', - 'script' => 'list.php', - 'order' => 16, - 'name' => $l->t('Shared with others'), - ]; - }); + array_push($sharingSublistArray, [ + 'id' => 'sharingout', + 'appname' => 'files_sharing', + 'script' => 'list.php', + 'order' => 16, + 'name' => $l->t('Shared with others'), + ]); // Check if sharing by link is enabled if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { - \OCA\Files\App::getNavigationManager()->add(function () { - $l = \OC::$server->getL10N('files_sharing'); - return [ - 'id' => 'sharinglinks', - 'appname' => 'files_sharing', - 'script' => 'list.php', - 'order' => 17, - 'name' => $l->t('Shared by link'), - ]; - }); + array_push($sharingSublistArray, [ + 'id' => 'sharinglinks', + 'appname' => 'files_sharing', + 'script' => 'list.php', + 'order' => 17, + 'name' => $l->t('Shared by link'), + ]); } } - \OCA\Files\App::getNavigationManager()->add(function () { - $l = \OC::$server->getL10N('files_sharing'); - return [ - 'id' => 'shareoverview', - 'appname' => 'files_sharing', - 'script' => 'list.php', - 'order' => 18, - 'name' => $l->t('Share overview'), - ]; - }); + // show_Quick_Access stored as string + $defaultExpandedState = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_sharing_menu', '0') === '1'; + + \OCA\Files\App::getNavigationManager()->add([ + 'id' => 'shareoverview', + 'appname' => 'files_sharing', + 'script' => 'list.php', + 'order' => 18, + 'name' => $l->t('Share overview'), + 'classes' => 'collapsible', + 'sublist' => $sharingSublistArray, + 'expandedState' => 'show_sharing_menu' + ]); \OCA\Files\App::getNavigationManager()->add(function () { diff --git a/lib/private/NavigationManager.php b/lib/private/NavigationManager.php index 1c764f9c1f..1874cd0e4f 100644 --- a/lib/private/NavigationManager.php +++ b/lib/private/NavigationManager.php @@ -100,7 +100,7 @@ class NavigationManager implements INavigationManager { if(!isset($entry['type'])) { $entry['type'] = 'link'; } - $this->entries[] = $entry; + $this->entries[$entry['id']] = $entry; } /** @@ -133,7 +133,7 @@ class NavigationManager implements INavigationManager { * @return array */ private function proceedNavigation(array $list): array { - usort($list, function($a, $b) { + uasort($list, function($a, $b) { if (isset($a['order']) && isset($b['order'])) { return ($a['order'] < $b['order']) ? -1 : 1; } else if (isset($a['order']) || isset($b['order'])) {