mirror of
https://we.phorge.it/source/phorge.git
synced 2025-04-02 15:38:18 +02:00
Summary: Adds a right-hand-side application menu, based roughly on `frame_v3.png`. This has the same icon as the left menu until we get real design in, but is functionally reasonable. Test Plan: {F26170} {F26169} Reviewers: chad Reviewed By: chad CC: aran Maniphest Tasks: T1960 Differential Revision: https://secure.phabricator.com/D4061
357 lines
9.2 KiB
PHP
357 lines
9.2 KiB
PHP
<?php
|
|
|
|
final class PhabricatorMainMenuView extends AphrontView {
|
|
|
|
private $user;
|
|
private $defaultSearchScope;
|
|
private $controller;
|
|
private $applicationMenu;
|
|
|
|
|
|
public function setApplicationMenu(PhabricatorMenuView $application_menu) {
|
|
$this->applicationMenu = $application_menu;
|
|
return $this;
|
|
}
|
|
|
|
public function getApplicationMenu() {
|
|
return $this->applicationMenu;
|
|
}
|
|
|
|
public function setController(PhabricatorController $controller) {
|
|
$this->controller = $controller;
|
|
return $this;
|
|
}
|
|
|
|
public function getController() {
|
|
return $this->controller;
|
|
}
|
|
|
|
public function setDefaultSearchScope($default_search_scope) {
|
|
$this->defaultSearchScope = $default_search_scope;
|
|
return $this;
|
|
}
|
|
|
|
public function getDefaultSearchScope() {
|
|
return $this->defaultSearchScope;
|
|
}
|
|
|
|
public function setUser(PhabricatorUser $user) {
|
|
$this->user = $user;
|
|
return $this;
|
|
}
|
|
|
|
public function getUser() {
|
|
return $this->user;
|
|
}
|
|
|
|
public function render() {
|
|
$user = $this->user;
|
|
|
|
require_celerity_resource('phabricator-main-menu-view');
|
|
|
|
$header_id = celerity_generate_unique_node_id();
|
|
$menus = array();
|
|
|
|
$group = new PhabricatorMainMenuGroupView();
|
|
$group->addClass('phabricator-main-menu-group-logo');
|
|
$group->setCollapsible(false);
|
|
|
|
$group->appendChild(
|
|
phutil_render_tag(
|
|
'a',
|
|
array(
|
|
'class' => 'phabricator-main-menu-logo',
|
|
'href' => '/',
|
|
),
|
|
''));
|
|
|
|
if (PhabricatorEnv::getEnvConfig('notification.enabled') &&
|
|
$user->isLoggedIn()) {
|
|
list($menu, $dropdown) = $this->renderNotificationMenu();
|
|
$group->appendChild($menu);
|
|
$menus[] = $dropdown;
|
|
}
|
|
|
|
$group->appendChild(
|
|
javelin_render_tag(
|
|
'a',
|
|
array(
|
|
'class' => 'phabricator-main-menu-expand-button',
|
|
'sigil' => 'jx-toggle-class',
|
|
'meta' => array(
|
|
'map' => array(
|
|
$header_id => 'phabricator-core-menu-expand',
|
|
),
|
|
),
|
|
),
|
|
''));
|
|
$logo = $group->render();
|
|
|
|
$phabricator_menu = $this->renderPhabricatorMenu();
|
|
// $menus[] = $this->renderApplicationMenu();
|
|
|
|
|
|
|
|
|
|
$actions = '';
|
|
|
|
$application_menu = $this->getApplicationMenu();
|
|
if ($application_menu) {
|
|
$application_menu->addClass('phabricator-dark-menu');
|
|
$application_menu->addClass('phabricator-application-menu');
|
|
}
|
|
|
|
return phutil_render_tag(
|
|
'div',
|
|
array(
|
|
'class' => 'phabricator-main-menu',
|
|
'id' => $header_id,
|
|
),
|
|
self::renderSingleView(
|
|
array(
|
|
$this->renderPhabricatorMenuButton($header_id),
|
|
$this->renderApplicationMenuButton($header_id),
|
|
$this->renderPhabricatorLogo(),
|
|
$alerts,
|
|
$phabricator_menu,
|
|
$application_menu,
|
|
))).
|
|
self::renderSingleView($menus);
|
|
}
|
|
|
|
private function renderSearch() {
|
|
$user = $this->user;
|
|
|
|
$result = null;
|
|
|
|
$keyboard_config = array(
|
|
'helpURI' => '/help/keyboardshortcut/',
|
|
);
|
|
|
|
if ($user->isLoggedIn()) {
|
|
$search = new PhabricatorMainMenuSearchView();
|
|
$search->setUser($user);
|
|
$search->setScope($this->getDefaultSearchScope());
|
|
$result = $search;
|
|
|
|
$pref_shortcut = PhabricatorUserPreferences::PREFERENCE_SEARCH_SHORTCUT;
|
|
if ($user->loadPreferences()->getPreference($pref_shortcut, true)) {
|
|
$keyboard_config['searchID'] = $search->getID();
|
|
}
|
|
}
|
|
|
|
Javelin::initBehavior('phabricator-keyboard-shortcuts', $keyboard_config);
|
|
|
|
if ($result) {
|
|
$result = id(new PhabricatorMenuItemView())
|
|
->addClass('phabricator-main-menu-search')
|
|
->appendChild($result);
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
private function renderPhabricatorMenuButton($header_id) {
|
|
return javelin_render_tag(
|
|
'a',
|
|
array(
|
|
'class' => 'phabricator-main-menu-expand-button '.
|
|
'phabricator-expand-core-menu',
|
|
'sigil' => 'jx-toggle-class',
|
|
'meta' => array(
|
|
'map' => array(
|
|
$header_id => 'phabricator-core-menu-expanded',
|
|
),
|
|
),
|
|
),
|
|
'');
|
|
}
|
|
|
|
public function renderApplicationMenuButton($header_id) {
|
|
return javelin_render_tag(
|
|
'a',
|
|
array(
|
|
'class' => 'phabricator-main-menu-expand-button '.
|
|
'phabricator-expand-application-menu',
|
|
'sigil' => 'jx-toggle-class',
|
|
'meta' => array(
|
|
'map' => array(
|
|
$header_id => 'phabricator-application-menu-expanded',
|
|
),
|
|
),
|
|
),
|
|
'');
|
|
}
|
|
|
|
private function renderPhabricatorMenu() {
|
|
$user = $this->getUser();
|
|
$controller = $this->getController();
|
|
|
|
$applications = PhabricatorApplication::getAllInstalledApplications();
|
|
$applications = msort($applications, 'getName');
|
|
|
|
$core = array();
|
|
$more = array();
|
|
$actions = array();
|
|
|
|
$group_core = PhabricatorApplication::GROUP_CORE;
|
|
foreach ($applications as $application) {
|
|
if ($application->shouldAppearInLaunchView()) {
|
|
$item = id(new PhabricatorMenuItemView())
|
|
->setName($application->getName())
|
|
->setHref($application->getBaseURI());
|
|
if ($application->getApplicationGroup() == $group_core) {
|
|
$core[] = $item;
|
|
} else {
|
|
$more[] = $item;
|
|
}
|
|
}
|
|
|
|
$app_actions = $application->buildMainMenuItems($user, $controller);
|
|
foreach ($app_actions as $action) {
|
|
$actions[] = $action;
|
|
}
|
|
}
|
|
|
|
|
|
$view = new PhabricatorMenuView();
|
|
$view->addClass('phabricator-dark-menu');
|
|
$view->addClass('phabricator-core-menu');
|
|
|
|
$search = $this->renderSearch();
|
|
$view->appendChild($search);
|
|
|
|
if ($core) {
|
|
$view->addMenuItem(
|
|
id(new PhabricatorMenuItemView())
|
|
->addClass('phabricator-core-item-device')
|
|
->setType(PhabricatorMenuItemView::TYPE_LABEL)
|
|
->setName(pht('Core Applications')));
|
|
foreach ($core as $item) {
|
|
$item->addClass('phabricator-core-item-device');
|
|
$view->addMenuItem($item);
|
|
}
|
|
}
|
|
|
|
if ($actions) {
|
|
$actions = msort($actions, 'getSortOrder');
|
|
$view->addMenuItem(
|
|
id(new PhabricatorMenuItemView())
|
|
->addClass('phabricator-core-item-device')
|
|
->setType(PhabricatorMenuItemView::TYPE_LABEL)
|
|
->setName(pht('Actions')));
|
|
foreach ($actions as $action) {
|
|
$icon = $action->getIcon();
|
|
if ($icon) {
|
|
$classes = array(
|
|
'phabricator-core-menu-icon',
|
|
'autosprite',
|
|
);
|
|
|
|
if ($action->getSelected()) {
|
|
$classes[] = 'main-menu-item-icon-'.$icon.'-selected';
|
|
} else {
|
|
$classes[] = 'main-menu-item-icon-'.$icon;
|
|
}
|
|
|
|
$action->appendChild(
|
|
phutil_render_tag(
|
|
'span',
|
|
array(
|
|
'class' => implode(' ', $classes),
|
|
),
|
|
''));
|
|
}
|
|
$view->addMenuItem($action);
|
|
}
|
|
}
|
|
|
|
if ($more) {
|
|
$view->addMenuItem(
|
|
id(new PhabricatorMenuItemView())
|
|
->addClass('phabricator-core-item-device')
|
|
->setType(PhabricatorMenuItemView::TYPE_LABEL)
|
|
->setName(pht('More Applications')));
|
|
foreach ($more as $item) {
|
|
$item->addClass('phabricator-core-item-device');
|
|
$view->addMenuItem($item);
|
|
}
|
|
}
|
|
|
|
|
|
return $view;
|
|
}
|
|
|
|
private function renderNotificationMenu() {
|
|
$user = $this->user;
|
|
|
|
require_celerity_resource('phabricator-notification-css');
|
|
require_celerity_resource('phabricator-notification-menu-css');
|
|
require_celerity_resource('sprite-menu-css');
|
|
|
|
$count_id = celerity_generate_unique_node_id();
|
|
$dropdown_id = celerity_generate_unique_node_id();
|
|
$bubble_id = celerity_generate_unique_node_id();
|
|
|
|
$count_number = id(new PhabricatorFeedStoryNotification())
|
|
->countUnread($user);
|
|
|
|
if ($count_number > 999) {
|
|
$count_number = "\xE2\x88\x9E";
|
|
}
|
|
|
|
$count_tag = phutil_render_tag(
|
|
'span',
|
|
array(
|
|
'id' => $count_id,
|
|
'class' => 'phabricator-main-menu-alert-count'
|
|
),
|
|
phutil_escape_html($count_number));
|
|
|
|
$icon_tag = phutil_render_tag(
|
|
'span',
|
|
array(
|
|
'class' => 'sprite-menu phabricator-main-menu-alert-icon',
|
|
),
|
|
'');
|
|
|
|
$container_classes = array(
|
|
'phabricator-main-menu-alert-bubble',
|
|
'sprite-menu',
|
|
'alert-notifications',
|
|
);
|
|
if ($count_number) {
|
|
$container_classes[] = 'alert-unread';
|
|
}
|
|
|
|
$bubble_tag = phutil_render_tag(
|
|
'a',
|
|
array(
|
|
'href' => '/notification/',
|
|
'class' => implode(' ', $container_classes),
|
|
'id' => $bubble_id,
|
|
),
|
|
$icon_tag.$count_tag);
|
|
|
|
Javelin::initBehavior(
|
|
'aphlict-dropdown',
|
|
array(
|
|
'bubbleID' => $bubble_id,
|
|
'countID' => $count_id,
|
|
'dropdownID' => $dropdown_id,
|
|
));
|
|
|
|
$notification_dropdown = javelin_render_tag(
|
|
'div',
|
|
array(
|
|
'id' => $dropdown_id,
|
|
'class' => 'phabricator-notification-menu',
|
|
'sigil' => 'phabricator-notification-menu',
|
|
'style' => 'display: none;',
|
|
),
|
|
'');
|
|
|
|
return array($bubble_tag, $notification_dropdown);
|
|
}
|
|
|
|
}
|