Differential D17239 Diff 41459 src/applications/people/engineextension/PeopleMainMenuBarExtension.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/people/engineextension/PeopleMainMenuBarExtension.php
- This file was copied from src/applications/home/application/PhabricatorHomeApplication.php.
<?php | <?php | ||||
final class PhabricatorHomeApplication extends PhabricatorApplication { | final class PeopleMainMenuBarExtension | ||||
extends PhabricatorMainMenuBarExtension { | |||||
const DASHBOARD_DEFAULT = 'dashboard:default'; | const MAINMENUBARKEY = 'user'; | ||||
public function getBaseURI() { | public function isExtensionEnabledForViewer(PhabricatorUser $viewer) { | ||||
return '/home/'; | return $viewer->isLoggedIn(); | ||||
} | } | ||||
public function getName() { | public function getExtensionOrder() { | ||||
return pht('Home'); | return 1200; | ||||
} | } | ||||
public function getShortDescription() { | public function buildMainMenus() { | ||||
return pht('Command Center'); | $viewer = $this->getViewer(); | ||||
} | $application = $this->getApplication(); | ||||
$dropdown_menu = $this->newDropdown($viewer, $application); | |||||
public function getIcon() { | |||||
return 'fa-home'; | |||||
} | |||||
public function getRoutes() { | |||||
return array( | |||||
'/' => 'PhabricatorHomeMainController', | |||||
'/(?P<only>home)/' => 'PhabricatorHomeMainController', | |||||
'/home/' => array( | |||||
'menu/' => array( | |||||
'' => 'PhabricatorHomeMenuController', | |||||
'(?P<type>global|personal)/item/' => $this->getProfileMenuRouting( | |||||
'PhabricatorHomeMenuItemController'), | |||||
), | |||||
), | |||||
); | |||||
} | |||||
public function isLaunchable() { | |||||
return false; | |||||
} | |||||
public function getApplicationOrder() { | |||||
return 9; | |||||
} | |||||
public function buildMainMenuExtraNodes( | |||||
PhabricatorUser $viewer, | |||||
PhabricatorController $controller = null) { | |||||
if (!$viewer->isLoggedIn()) { | |||||
return; | |||||
} | |||||
$image = $viewer->getProfileImageURI(); | |||||
$profile_image = id(new PHUIIconView()) | |||||
->setImage($image) | |||||
->setHeadSize(PHUIIconView::HEAD_SMALL); | |||||
if ($controller) { | |||||
$application = $controller->getCurrentApplication(); | |||||
} else { | |||||
$application = null; | |||||
} | |||||
$dropdown_menu = $this->renderUserDropdown($viewer, $application); | |||||
$menu_id = celerity_generate_unique_node_id(); | $menu_id = celerity_generate_unique_node_id(); | ||||
Javelin::initBehavior( | Javelin::initBehavior( | ||||
'user-menu', | 'user-menu', | ||||
array( | array( | ||||
'menuID' => $menu_id, | 'menuID' => $menu_id, | ||||
'menu' => $dropdown_menu->getDropdownMenuMetadata(), | 'menu' => $dropdown_menu->getDropdownMenuMetadata(), | ||||
)); | )); | ||||
return id(new PHUIButtonView()) | $image = $viewer->getProfileImageURI(); | ||||
$profile_image = id(new PHUIIconView()) | |||||
->setImage($image) | |||||
->setHeadSize(PHUIIconView::HEAD_SMALL); | |||||
$user_menu = id(new PHUIButtonView()) | |||||
->setID($menu_id) | ->setID($menu_id) | ||||
->setTag('a') | ->setTag('a') | ||||
->setHref('/p/'.$viewer->getUsername().'/') | ->setHref('/p/'.$viewer->getUsername().'/') | ||||
->setIcon($profile_image) | ->setIcon($profile_image) | ||||
->addClass('phabricator-core-user-menu') | ->addClass('phabricator-core-user-menu') | ||||
->setHasCaret(true) | ->setHasCaret(true) | ||||
->setNoCSS(true); | ->setNoCSS(true); | ||||
return array( | |||||
$user_menu, | |||||
); | |||||
} | } | ||||
private function renderUserDropdown( | private function newDropdown( | ||||
PhabricatorUser $viewer, | PhabricatorUser $viewer, | ||||
$application) { | $application) { | ||||
$person_to_show = id(new PHUIObjectItemView()) | $person_to_show = id(new PHUIObjectItemView()) | ||||
->setObjectName($viewer->getRealName()) | ->setObjectName($viewer->getRealName()) | ||||
->setSubHead($viewer->getUsername()) | ->setSubHead($viewer->getUsername()) | ||||
->setImageURI($viewer->getProfileImageURI()); | ->setImageURI($viewer->getProfileImageURI()); | ||||
$user_view = id(new PHUIObjectItemListView()) | $user_view = id(new PHUIObjectItemListView()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->setFlush(true) | ->setFlush(true) | ||||
->setSimple(true) | ->setSimple(true) | ||||
->addItem($person_to_show) | ->addItem($person_to_show) | ||||
->addClass('phabricator-core-user-profile-object'); | ->addClass('phabricator-core-user-profile-object'); | ||||
$view = id(new PhabricatorActionListView()) | $view = id(new PhabricatorActionListView()) | ||||
->setViewer($viewer); | ->setViewer($viewer); | ||||
// User Menu | |||||
$view->addAction( | $view->addAction( | ||||
id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
->appendChild($user_view)); | ->appendChild($user_view)); | ||||
$view->addAction( | $view->addAction( | ||||
id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
->setType(PhabricatorActionView::TYPE_DIVIDER)); | ->setType(PhabricatorActionView::TYPE_DIVIDER)); | ||||
$view->addAction( | $view->addAction( | ||||
id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
->setName(pht('Profile')) | ->setName(pht('Profile')) | ||||
->setHref('/p/'.$viewer->getUsername().'/')); | ->setHref('/p/'.$viewer->getUsername().'/')); | ||||
$view->addAction( | $view->addAction( | ||||
id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
->setName(pht('Settings')) | ->setName(pht('Settings')) | ||||
->setHref('/settings/user/'.$viewer->getUsername().'/')); | ->setHref('/settings/user/'.$viewer->getUsername().'/')); | ||||
$view->addAction( | $view->addAction( | ||||
id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
->setName(pht('Manage')) | ->setName(pht('Manage')) | ||||
->setHref('/people/manage/'.$viewer->getID().'/')); | ->setHref('/people/manage/'.$viewer->getID().'/')); | ||||
// Help Menus | |||||
if ($application) { | if ($application) { | ||||
$help_links = $application->getHelpMenuItems($viewer); | $help_links = $application->getHelpMenuItems($viewer); | ||||
if ($help_links) { | if ($help_links) { | ||||
foreach ($help_links as $link) { | foreach ($help_links as $link) { | ||||
$view->addAction($link); | $view->addAction($link); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Logout Menu | |||||
$view->addAction( | $view->addAction( | ||||
id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
->addSigil('logout-item') | ->addSigil('logout-item') | ||||
->setType(PhabricatorActionView::TYPE_DIVIDER)); | ->setType(PhabricatorActionView::TYPE_DIVIDER)); | ||||
$view->addAction( | $view->addAction( | ||||
id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
->setName(pht('Log Out %s', $viewer->getUsername())) | ->setName(pht('Log Out %s', $viewer->getUsername())) | ||||
Show All 9 Lines |