diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-03-16 13:03:41 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-16 13:03:41 -0600 |
commit | cd4ebe2777b268f916a5edbbbc49f65504a1e12b (patch) | |
tree | e3d5f10ec1e071bd1de2b4a85aa4ee3ae4503fb6 /lib | |
parent | 2a9d1a7147b5494d2c8dda15a9ab4f74527b4a97 (diff) | |
parent | b8ef61645522322486a055df40d3d773964de720 (diff) | |
download | nextcloud-server-cd4ebe2777b268f916a5edbbbc49f65504a1e12b.tar.gz nextcloud-server-cd4ebe2777b268f916a5edbbbc49f65504a1e12b.zip |
Merge pull request #3008 from nextcloud/appmenu-experiment
Show apps in header
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/TemplateLayout.php | 2 | ||||
-rw-r--r-- | lib/private/legacy/app.php | 83 |
2 files changed, 77 insertions, 8 deletions
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 f89f32f069a..c82d620882d 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -529,25 +529,76 @@ class OC_App { // This is private as well. It simply works, so don't ask for more details private static function proceedNavigation($list) { + $headerIconCount = 8; + if(OC_User::isAdminUser(OC_User::getUser())) { + $headerIconCount--; + } + usort($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'])) { + return isset($a['order']) ? -1 : 1; + } else { + return ($a['name'] < $b['name']) ? -1 : 1; + } + }); + + $activeAppIndex = -1; $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); - foreach ($list as &$navEntry) { + foreach ($list as $index => &$navEntry) { if ($navEntry['id'] == $activeApp) { $navEntry['active'] = true; + $activeAppIndex = $index; } else { $navEntry['active'] = false; } } unset($navEntry); - usort($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'])) { - return isset($a['order']) ? -1 : 1; + if($activeAppIndex > ($headerIconCount-1)) { + $active = $list[$activeAppIndex]; + $lastInHeader = $list[$headerIconCount-1]; + $list[$headerIconCount-1] = $active; + $list[$activeAppIndex] = $lastInHeader; + } + + foreach ($list as $index => &$navEntry) { + $navEntry['showInHeader'] = false; + if($index < $headerIconCount) { + $navEntry['showInHeader'] = true; + } + } + + + + return $list; + } + + public static function proceedAppNavigation($entries) { + $headerIconCount = 8; + if(OC_User::isAdminUser(OC_User::getUser())) { + $headerIconCount--; + } + $activeAppIndex = -1; + $list = self::proceedNavigation($entries); + + $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); + foreach ($list as $index => &$navEntry) { + if ($navEntry['id'] == $activeApp) { + $navEntry['active'] = true; + $activeAppIndex = $index; } else { - return ($a['name'] < $b['name']) ? -1 : 1; + $navEntry['active'] = false; } - }); + } + // move active item to last position + if($activeAppIndex > ($headerIconCount-1)) { + $active = $list[$activeAppIndex]; + $lastInHeader = $list[$headerIconCount-1]; + $list[$headerIconCount-1] = $active; + $list[$activeAppIndex] = $lastInHeader; + } + $list = array_slice($list, 0, $headerIconCount); return $list; } @@ -742,6 +793,22 @@ class OC_App { } /** + * 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 * * @return string |