mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 14:00:56 +01:00
Basic structure for MenuItem on Home
Summary: Ref T11957, builds out `/home/menu/` as a basic structure for adding/editing the homepage menu. Test Plan: visit `/home/menu/` and add items to global and personal. Not wired to anything. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T11957 Differential Revision: https://secure.phabricator.com/D17180
This commit is contained in:
parent
2941b34acb
commit
dfee1352e9
7 changed files with 240 additions and 0 deletions
|
@ -2820,9 +2820,14 @@ phutil_register_library_map(array(
|
|||
'PhabricatorHeraldContentSource' => 'applications/herald/contentsource/PhabricatorHeraldContentSource.php',
|
||||
'PhabricatorHighSecurityRequestExceptionHandler' => 'aphront/handler/PhabricatorHighSecurityRequestExceptionHandler.php',
|
||||
'PhabricatorHomeApplication' => 'applications/home/application/PhabricatorHomeApplication.php',
|
||||
'PhabricatorHomeConstants' => 'applications/home/constants/PhabricatorHomeConstants.php',
|
||||
'PhabricatorHomeController' => 'applications/home/controller/PhabricatorHomeController.php',
|
||||
'PhabricatorHomeMainController' => 'applications/home/controller/PhabricatorHomeMainController.php',
|
||||
'PhabricatorHomeManageProfileMenuItem' => 'applications/home/menuitem/PhabricatorHomeManageProfileMenuItem.php',
|
||||
'PhabricatorHomeMenuController' => 'applications/home/controller/PhabricatorHomeMenuController.php',
|
||||
'PhabricatorHomeMenuItemController' => 'applications/home/controller/PhabricatorHomeMenuItemController.php',
|
||||
'PhabricatorHomePreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorHomePreferencesSettingsPanel.php',
|
||||
'PhabricatorHomeProfileMenuEngine' => 'applications/home/engine/PhabricatorHomeProfileMenuEngine.php',
|
||||
'PhabricatorHomeQuickCreateController' => 'applications/home/controller/PhabricatorHomeQuickCreateController.php',
|
||||
'PhabricatorHovercardEngineExtension' => 'applications/search/engineextension/PhabricatorHovercardEngineExtension.php',
|
||||
'PhabricatorHovercardEngineExtensionModule' => 'applications/search/engineextension/PhabricatorHovercardEngineExtensionModule.php',
|
||||
|
@ -7861,9 +7866,14 @@ phutil_register_library_map(array(
|
|||
'PhabricatorHeraldContentSource' => 'PhabricatorContentSource',
|
||||
'PhabricatorHighSecurityRequestExceptionHandler' => 'PhabricatorRequestExceptionHandler',
|
||||
'PhabricatorHomeApplication' => 'PhabricatorApplication',
|
||||
'PhabricatorHomeConstants' => 'PhabricatorHomeController',
|
||||
'PhabricatorHomeController' => 'PhabricatorController',
|
||||
'PhabricatorHomeMainController' => 'PhabricatorHomeController',
|
||||
'PhabricatorHomeManageProfileMenuItem' => 'PhabricatorProfileMenuItem',
|
||||
'PhabricatorHomeMenuController' => 'PhabricatorHomeController',
|
||||
'PhabricatorHomeMenuItemController' => 'PhabricatorHomeController',
|
||||
'PhabricatorHomePreferencesSettingsPanel' => 'PhabricatorSettingsPanel',
|
||||
'PhabricatorHomeProfileMenuEngine' => 'PhabricatorProfileMenuEngine',
|
||||
'PhabricatorHomeQuickCreateController' => 'PhabricatorHomeController',
|
||||
'PhabricatorHovercardEngineExtension' => 'Phobject',
|
||||
'PhabricatorHovercardEngineExtensionModule' => 'PhabricatorConfigModule',
|
||||
|
|
|
@ -27,6 +27,11 @@ final class PhabricatorHomeApplication extends PhabricatorApplication {
|
|||
'/(?P<only>home)/' => 'PhabricatorHomeMainController',
|
||||
'/home/' => array(
|
||||
'create/' => 'PhabricatorHomeQuickCreateController',
|
||||
'menu/' => array(
|
||||
'' => 'PhabricatorHomeMenuController',
|
||||
'(?P<type>global|personal)/item/' => $this->getProfileMenuRouting(
|
||||
'PhabricatorHomeMenuItemController'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorHomeConstants
|
||||
extends PhabricatorHomeController {
|
||||
|
||||
const ITEM_LAUNCHER = 'home.launcher';
|
||||
const ITEM_MANAGE = 'home.manage.menu';
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorHomeMenuController extends PhabricatorHomeController {
|
||||
|
||||
public function shouldAllowPublic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
|
||||
$menu = id(new PHUIObjectItemListView())
|
||||
->setUser($viewer);
|
||||
|
||||
$menu->addItem(
|
||||
id(new PHUIObjectItemView())
|
||||
->setHeader(pht('Personal Menu Items'))
|
||||
->setHref($this->getApplicationURI('menu/personal/item/configure/'))
|
||||
->setImageURI($viewer->getProfileImageURI())
|
||||
->addAttribute(pht('Edit the menu for your personal account.')));
|
||||
|
||||
$icon = id(new PHUIIconView())
|
||||
->setIcon('fa-globe')
|
||||
->setBackground('bg-blue');
|
||||
|
||||
$menu->addItem(
|
||||
id(new PHUIObjectItemView())
|
||||
->setHeader(pht('Global Menu Items'))
|
||||
->setHref($this->getApplicationURI('menu/global/item/configure/'))
|
||||
->setImageIcon($icon)
|
||||
->addAttribute(pht('Edit the global default menu for all users.')));
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
$crumbs->addTextCrumb(pht('Manage'));
|
||||
$crumbs->setBorder(true);
|
||||
|
||||
$box = id(new PHUIObjectBoxView())
|
||||
->setObjectList($menu);
|
||||
|
||||
$header = id(new PHUIHeaderView())
|
||||
->setHeader(pht('Manage Home Menu'))
|
||||
->setHeaderIcon('fa-home');
|
||||
|
||||
$view = id(new PHUITwoColumnView())
|
||||
->setHeader($header)
|
||||
->setFooter(array(
|
||||
$box,
|
||||
));
|
||||
|
||||
return $this->newPage()
|
||||
->setTitle(pht('Manage Home Menu'))
|
||||
->setCrumbs($crumbs)
|
||||
->appendChild($view);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorHomeMenuItemController
|
||||
extends PhabricatorHomeController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $this->getViewer();
|
||||
$type = $request->getURIData('type');
|
||||
$custom_phid = null;
|
||||
if ($type == 'personal') {
|
||||
$custom_phid = $viewer->getPHID();
|
||||
}
|
||||
|
||||
$application = 'PhabricatorHomeApplication';
|
||||
$home_app = id(new PhabricatorApplicationQuery())
|
||||
->setViewer($viewer)
|
||||
->withClasses(array($application))
|
||||
->withInstalled(true)
|
||||
->executeOne();
|
||||
|
||||
$engine = id(new PhabricatorHomeProfileMenuEngine())
|
||||
->setProfileObject($home_app)
|
||||
->setCustomPHID($custom_phid)
|
||||
->setController($this);
|
||||
|
||||
return $engine->buildResponse();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorHomeProfileMenuEngine
|
||||
extends PhabricatorProfileMenuEngine {
|
||||
|
||||
protected function isMenuEngineConfigurable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getItemURI($path) {
|
||||
$object = $this->getProfileObject();
|
||||
$custom = $this->getCustomPHID();
|
||||
|
||||
if ($custom) {
|
||||
return "/home/menu/personal/item/{$path}";
|
||||
} else {
|
||||
return "/home/menu/global/item/{$path}";
|
||||
}
|
||||
}
|
||||
|
||||
protected function getBuiltinProfileItems($object) {
|
||||
$viewer = $this->getViewer();
|
||||
$items = array();
|
||||
$custom_phid = $this->getCustomPHID();
|
||||
|
||||
$applications = id(new PhabricatorApplicationQuery())
|
||||
->setViewer($viewer)
|
||||
->withInstalled(true)
|
||||
->withUnlisted(false)
|
||||
->withLaunchable(true)
|
||||
->execute();
|
||||
|
||||
foreach ($applications as $application) {
|
||||
if (!$application->isPinnedByDefault($viewer)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$properties = array(
|
||||
'name' => $application->getName(),
|
||||
'application' => $application->getPHID(),
|
||||
);
|
||||
|
||||
$items[] = $this->newItem()
|
||||
->setBuiltinKey($application->getPHID())
|
||||
->setMenuItemKey(PhabricatorApplicationProfileMenuItem::MENUITEMKEY)
|
||||
->setMenuItemProperties($properties);
|
||||
}
|
||||
|
||||
// Single Manage Item, switches URI based on admin/user
|
||||
$items[] = $this->newItem()
|
||||
->setBuiltinKey(PhabricatorHomeConstants::ITEM_MANAGE)
|
||||
->setMenuItemKey(
|
||||
PhabricatorHomeManageProfileMenuItem::MENUITEMKEY);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorHomeManageProfileMenuItem
|
||||
extends PhabricatorProfileMenuItem {
|
||||
|
||||
const MENUITEMKEY = 'home.manage.menu';
|
||||
|
||||
public function getMenuItemTypeName() {
|
||||
return pht('Manage Home Menu');
|
||||
}
|
||||
|
||||
private function getDefaultName() {
|
||||
return pht('Manage');
|
||||
}
|
||||
|
||||
public function canHideMenuItem(
|
||||
PhabricatorProfileMenuItemConfiguration $config) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function canMakeDefault(
|
||||
PhabricatorProfileMenuItemConfiguration $config) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDisplayName(
|
||||
PhabricatorProfileMenuItemConfiguration $config) {
|
||||
$name = $config->getMenuItemProperty('name');
|
||||
|
||||
if (strlen($name)) {
|
||||
return $name;
|
||||
}
|
||||
|
||||
return $this->getDefaultName();
|
||||
}
|
||||
|
||||
public function buildEditEngineFields(
|
||||
PhabricatorProfileMenuItemConfiguration $config) {
|
||||
return array(
|
||||
id(new PhabricatorTextEditField())
|
||||
->setKey('name')
|
||||
->setLabel(pht('Name'))
|
||||
->setPlaceholder($this->getDefaultName())
|
||||
->setValue($config->getMenuItemProperty('name')),
|
||||
);
|
||||
}
|
||||
|
||||
protected function newNavigationMenuItems(
|
||||
PhabricatorProfileMenuItemConfiguration $config) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
if ($viewer->isLoggedIn()) {
|
||||
$admin = $viewer->getIsAdmin();
|
||||
$name = $this->getDisplayName($config);
|
||||
$icon = 'fa-pencil';
|
||||
$href = '/home/menu/personal/item/configure/';
|
||||
if ($admin) {
|
||||
$href = '/home/menu/';
|
||||
}
|
||||
|
||||
$item = $this->newItem()
|
||||
->setHref($href)
|
||||
->setName($name)
|
||||
->setIcon($icon);
|
||||
}
|
||||
|
||||
return array(
|
||||
$item,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue