mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-30 16:38:21 +01:00
Add a basic ProjectProfileMenuItem
Summary: Allows you to name and set a project as a menu item navigation element. Test Plan: Add a project, no name, see project. Remove. Add a project and give it a short name (bugs) and see project link. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D17021
This commit is contained in:
parent
de4d7e1b10
commit
f277de1d02
6 changed files with 135 additions and 1 deletions
|
@ -3476,6 +3476,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorProjectPointsProfileMenuItem' => 'applications/project/menuitem/PhabricatorProjectPointsProfileMenuItem.php',
|
'PhabricatorProjectPointsProfileMenuItem' => 'applications/project/menuitem/PhabricatorProjectPointsProfileMenuItem.php',
|
||||||
'PhabricatorProjectProfileController' => 'applications/project/controller/PhabricatorProjectProfileController.php',
|
'PhabricatorProjectProfileController' => 'applications/project/controller/PhabricatorProjectProfileController.php',
|
||||||
'PhabricatorProjectProfileMenuEngine' => 'applications/project/engine/PhabricatorProjectProfileMenuEngine.php',
|
'PhabricatorProjectProfileMenuEngine' => 'applications/project/engine/PhabricatorProjectProfileMenuEngine.php',
|
||||||
|
'PhabricatorProjectProfileMenuItem' => 'applications/search/menuitem/PhabricatorProjectProfileMenuItem.php',
|
||||||
'PhabricatorProjectProjectHasMemberEdgeType' => 'applications/project/edge/PhabricatorProjectProjectHasMemberEdgeType.php',
|
'PhabricatorProjectProjectHasMemberEdgeType' => 'applications/project/edge/PhabricatorProjectProjectHasMemberEdgeType.php',
|
||||||
'PhabricatorProjectProjectHasObjectEdgeType' => 'applications/project/edge/PhabricatorProjectProjectHasObjectEdgeType.php',
|
'PhabricatorProjectProjectHasObjectEdgeType' => 'applications/project/edge/PhabricatorProjectProjectHasObjectEdgeType.php',
|
||||||
'PhabricatorProjectProjectPHIDType' => 'applications/project/phid/PhabricatorProjectProjectPHIDType.php',
|
'PhabricatorProjectProjectPHIDType' => 'applications/project/phid/PhabricatorProjectProjectPHIDType.php',
|
||||||
|
@ -8613,6 +8614,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorProjectPointsProfileMenuItem' => 'PhabricatorProfileMenuItem',
|
'PhabricatorProjectPointsProfileMenuItem' => 'PhabricatorProfileMenuItem',
|
||||||
'PhabricatorProjectProfileController' => 'PhabricatorProjectController',
|
'PhabricatorProjectProfileController' => 'PhabricatorProjectController',
|
||||||
'PhabricatorProjectProfileMenuEngine' => 'PhabricatorProfileMenuEngine',
|
'PhabricatorProjectProfileMenuEngine' => 'PhabricatorProfileMenuEngine',
|
||||||
|
'PhabricatorProjectProfileMenuItem' => 'PhabricatorProfileMenuItem',
|
||||||
'PhabricatorProjectProjectHasMemberEdgeType' => 'PhabricatorEdgeType',
|
'PhabricatorProjectProjectHasMemberEdgeType' => 'PhabricatorEdgeType',
|
||||||
'PhabricatorProjectProjectHasObjectEdgeType' => 'PhabricatorEdgeType',
|
'PhabricatorProjectProjectHasObjectEdgeType' => 'PhabricatorEdgeType',
|
||||||
'PhabricatorProjectProjectPHIDType' => 'PhabricatorPHIDType',
|
'PhabricatorProjectProjectPHIDType' => 'PhabricatorPHIDType',
|
||||||
|
|
|
@ -73,7 +73,7 @@ abstract class PhabricatorProfileMenuEngine extends Phobject {
|
||||||
}
|
}
|
||||||
|
|
||||||
$item_id = $request->getURIData('itemID');
|
$item_id = $request->getURIData('itemID');
|
||||||
$item_list = $this->loadItems();
|
$item_list = $this->getItems();
|
||||||
|
|
||||||
$selected_item = null;
|
$selected_item = null;
|
||||||
if (strlen($item_id)) {
|
if (strlen($item_id)) {
|
||||||
|
@ -174,6 +174,18 @@ abstract class PhabricatorProfileMenuEngine extends Phobject {
|
||||||
->setBaseURI(new PhutilURI($this->getItemURI('')));
|
->setBaseURI(new PhutilURI($this->getItemURI('')));
|
||||||
|
|
||||||
$menu_items = $this->getItems();
|
$menu_items = $this->getItems();
|
||||||
|
$filtered_items = array();
|
||||||
|
foreach ($menu_items as $menu_item) {
|
||||||
|
if ($menu_item->isDisabled()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$filtered_items[] = $menu_item;
|
||||||
|
}
|
||||||
|
$filtered_groups = mgroup($filtered_items, 'getMenuItemKey');
|
||||||
|
foreach ($filtered_groups as $group) {
|
||||||
|
$first_item = head($group);
|
||||||
|
$first_item->willBuildNavigationItems($group);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($menu_items as $menu_item) {
|
foreach ($menu_items as $menu_item) {
|
||||||
if ($menu_item->isDisabled()) {
|
if ($menu_item->isDisabled()) {
|
||||||
|
|
|
@ -12,6 +12,8 @@ abstract class PhabricatorProfileMenuItem extends Phobject {
|
||||||
abstract protected function newNavigationMenuItems(
|
abstract protected function newNavigationMenuItems(
|
||||||
PhabricatorProfileMenuItemConfiguration $config);
|
PhabricatorProfileMenuItemConfiguration $config);
|
||||||
|
|
||||||
|
public function willBuildNavigationItems(array $items) {}
|
||||||
|
|
||||||
public function getMenuItemTypeIcon() {
|
public function getMenuItemTypeIcon() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorProjectProfileMenuItem
|
||||||
|
extends PhabricatorProfileMenuItem {
|
||||||
|
|
||||||
|
const MENUITEMKEY = 'project';
|
||||||
|
|
||||||
|
private $project;
|
||||||
|
|
||||||
|
public function getMenuItemTypeIcon() {
|
||||||
|
return 'fa-briefcase';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMenuItemTypeName() {
|
||||||
|
return pht('Project');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canAddToObject($object) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attachProject($project) {
|
||||||
|
$this->project = $project;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProject() {
|
||||||
|
$project = $this->project;
|
||||||
|
if (!$project) {
|
||||||
|
return null;
|
||||||
|
} else if ($project->isArchived()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function willBuildNavigationItems(array $items) {
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
$project_phids = array();
|
||||||
|
foreach ($items as $item) {
|
||||||
|
$project_phids[] = $item->getMenuItemProperty('project');
|
||||||
|
}
|
||||||
|
|
||||||
|
$projects = id(new PhabricatorProjectQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withPHIDs($project_phids)
|
||||||
|
->needImages(true)
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
$projects = mpull($projects, null, 'getPHID');
|
||||||
|
foreach ($items as $item) {
|
||||||
|
$project_phid = $item->getMenuItemProperty('project');
|
||||||
|
$project = idx($projects, $project_phid, null);
|
||||||
|
$item->getMenuItem()->attachProject($project);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDisplayName(
|
||||||
|
PhabricatorProfileMenuItemConfiguration $config) {
|
||||||
|
$project = $this->getProject();
|
||||||
|
if (!$project) {
|
||||||
|
return pht('(Restricted/Invalid Project)');
|
||||||
|
}
|
||||||
|
if (strlen($this->getName($config))) {
|
||||||
|
return $this->getName($config);
|
||||||
|
} else {
|
||||||
|
return $project->getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildEditEngineFields(
|
||||||
|
PhabricatorProfileMenuItemConfiguration $config) {
|
||||||
|
return array(
|
||||||
|
id(new PhabricatorTextEditField())
|
||||||
|
->setKey('name')
|
||||||
|
->setLabel(pht('Name'))
|
||||||
|
->setValue($this->getName($config)),
|
||||||
|
id(new PhabricatorDatasourceEditField())
|
||||||
|
->setKey('project')
|
||||||
|
->setLabel(pht('Project'))
|
||||||
|
->setDatasource(new PhabricatorProjectDatasource())
|
||||||
|
->setSingleValue($config->getMenuItemProperty('project')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getName(
|
||||||
|
PhabricatorProfileMenuItemConfiguration $config) {
|
||||||
|
return $config->getMenuItemProperty('name');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function newNavigationMenuItems(
|
||||||
|
PhabricatorProfileMenuItemConfiguration $config) {
|
||||||
|
|
||||||
|
$project = $this->getProject();
|
||||||
|
if (!$project) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$picture = $project->getProfileImageURI();
|
||||||
|
$name = $this->getDisplayName($config);
|
||||||
|
$href = $project->getURI();
|
||||||
|
|
||||||
|
$item = $this->newItem()
|
||||||
|
->setHref($href)
|
||||||
|
->setName($name)
|
||||||
|
->setProfileImage($picture);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
$item,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -66,6 +66,7 @@ final class PhabricatorProfileMenuItemConfigurationQuery
|
||||||
unset($page[$key]);
|
unset($page[$key]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
$item_type = clone $item_type;
|
||||||
$item->attachMenuItem($item_type);
|
$item->attachMenuItem($item_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,10 @@ final class PhabricatorProfileMenuItemConfiguration
|
||||||
return $this->getMenuItem()->shouldEnableForObject($object);
|
return $this->getMenuItem()->shouldEnableForObject($object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function willBuildNavigationItems(array $items) {
|
||||||
|
return $this->getMenuItem()->willBuildNavigationItems($items);
|
||||||
|
}
|
||||||
|
|
||||||
public function getSortKey() {
|
public function getSortKey() {
|
||||||
$order = $this->getMenuItemOrder();
|
$order = $this->getMenuItemOrder();
|
||||||
if ($order === null) {
|
if ($order === null) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue