From a630e4629f2489e9d7678fbe6833cf926e2b968e Mon Sep 17 00:00:00 2001 From: Julius Haertl Date: Wed, 1 Mar 2017 23:04:27 +0100 Subject: Generate seperate menu list for header bar Signed-off-by: Julius Haertl --- lib/private/TemplateLayout.php | 2 ++ lib/private/legacy/app.php | 44 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) (limited to 'lib/private') diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index ccd53c9cafa..3f8c75adc84 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -76,6 +76,8 @@ class TemplateLayout extends \OC_Template { $this->assign( 'appid', $appId ); $navigation = \OC_App::getNavigation(); $this->assign( 'navigation', $navigation); + $navigation = \OC_App::getHeaderNavigation(); + $this->assign( 'headernavigation', $navigation); $settingsNavigation = \OC_App::getSettingsNavigation(); $this->assign( 'settingsnavigation', $settingsNavigation); foreach($navigation as $entry) { diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index 264e8f5fc60..1cc83888734 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -530,7 +530,6 @@ class OC_App { // This is private as well. It simply works, so don't ask for more details private static function proceedNavigation($list) { - usort($list, function($a, $b) { if (isset($a['order']) && isset($b['order'])) { return ($a['order'] < $b['order']) ? -1 : 1; @@ -552,13 +551,36 @@ class OC_App { } unset($navEntry); - // Move active app to the first position + + foreach ($list as $index => &$navEntry) { + $navEntry['showInHeader'] = false; + if($index < 4) { + $navEntry['showInHeader'] = true; + } + } + + return $list; + } + + public static function proceedAppNavigation($entries) { + $list = self::proceedNavigation($entries); + + $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); + foreach ($list as $index => &$navEntry) { + if ($navEntry['id'] == $activeApp) { + $navEntry['active'] = true; + $activeAppIndex = $index; + } else { + $navEntry['active'] = false; + } + } + $list = array_slice($list, 0, 4); + // move active item to last position if($activeAppIndex > 2) { $active = $list[$activeAppIndex]; unset($list[$activeAppIndex]); array_unshift($list, $active); } - return $list; } @@ -751,6 +773,22 @@ class OC_App { return $navigation; } + /** + * Returns the navigation inside the header bar + * + * @return array + * + * This function returns an array containing all entries added. The + * entries are sorted by the key 'order' ascending. Additional to the keys + * given for each app the following keys exist: + * - active: boolean, signals if the user is on this navigation entry + */ + public static function getHeaderNavigation() { + $entries = OC::$server->getNavigationManager()->getAll(); + $navigation = self::proceedAppNavigation($entries); + return $navigation; + } + /** * get the id of loaded app * -- cgit v1.2.3