2016-01-12 19:27:39 +01:00
|
|
|
<?php
|
|
|
|
|
2016-12-11 18:00:44 +01:00
|
|
|
abstract class PhabricatorProfileMenuEngine extends Phobject {
|
2016-01-12 19:27:39 +01:00
|
|
|
|
|
|
|
private $viewer;
|
|
|
|
private $profileObject;
|
2017-01-07 05:12:57 +01:00
|
|
|
private $customPHID;
|
2016-12-11 19:08:26 +01:00
|
|
|
private $items;
|
|
|
|
private $defaultItem;
|
2016-01-13 00:06:43 +01:00
|
|
|
private $controller;
|
2016-01-19 19:35:32 +01:00
|
|
|
private $navigation;
|
2017-01-17 21:04:28 +01:00
|
|
|
private $showNavigation = true;
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
private $editMode;
|
2017-02-01 19:16:23 +01:00
|
|
|
private $pageClasses = array();
|
|
|
|
private $showContentCrumbs = true;
|
2017-01-17 21:04:28 +01:00
|
|
|
|
2017-01-17 21:46:05 +01:00
|
|
|
const ITEM_CUSTOM_DIVIDER = 'engine.divider';
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
const ITEM_MANAGE = 'item.configure';
|
|
|
|
|
|
|
|
const MODE_COMBINED = 'combined';
|
|
|
|
const MODE_GLOBAL = 'global';
|
|
|
|
const MODE_CUSTOM = 'custom';
|
2016-01-12 19:27:39 +01:00
|
|
|
|
|
|
|
public function setViewer(PhabricatorUser $viewer) {
|
|
|
|
$this->viewer = $viewer;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getViewer() {
|
|
|
|
return $this->viewer;
|
|
|
|
}
|
|
|
|
|
2016-01-14 14:59:25 +01:00
|
|
|
public function setProfileObject($profile_object) {
|
2016-01-12 19:27:39 +01:00
|
|
|
$this->profileObject = $profile_object;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getProfileObject() {
|
|
|
|
return $this->profileObject;
|
|
|
|
}
|
|
|
|
|
2017-01-07 05:12:57 +01:00
|
|
|
public function setCustomPHID($custom_phid) {
|
|
|
|
$this->customPHID = $custom_phid;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCustomPHID() {
|
|
|
|
return $this->customPHID;
|
|
|
|
}
|
|
|
|
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
private function getEditModeCustomPHID() {
|
|
|
|
$mode = $this->getEditMode();
|
|
|
|
|
|
|
|
switch ($mode) {
|
|
|
|
case self::MODE_CUSTOM:
|
|
|
|
$custom_phid = $this->getCustomPHID();
|
|
|
|
break;
|
|
|
|
case self::MODE_GLOBAL:
|
|
|
|
$custom_phid = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $custom_phid;
|
|
|
|
}
|
|
|
|
|
2016-01-13 00:06:43 +01:00
|
|
|
public function setController(PhabricatorController $controller) {
|
|
|
|
$this->controller = $controller;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getController() {
|
|
|
|
return $this->controller;
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
private function setDefaultItem(
|
|
|
|
PhabricatorProfileMenuItemConfiguration $default_item) {
|
|
|
|
$this->defaultItem = $default_item;
|
2016-01-22 14:33:21 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
public function getDefaultItem() {
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$this->getItems();
|
2016-12-11 19:08:26 +01:00
|
|
|
return $this->defaultItem;
|
2016-01-22 14:33:21 +01:00
|
|
|
}
|
|
|
|
|
2017-01-17 21:04:28 +01:00
|
|
|
public function setShowNavigation($show) {
|
|
|
|
$this->showNavigation = $show;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getShowNavigation() {
|
|
|
|
return $this->showNavigation;
|
|
|
|
}
|
|
|
|
|
2017-02-01 19:16:23 +01:00
|
|
|
public function addContentPageClass($class) {
|
|
|
|
$this->pageClasses[] = $class;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setShowContentCrumbs($show_content_crumbs) {
|
|
|
|
$this->showContentCrumbs = $show_content_crumbs;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getShowContentCrumbs() {
|
|
|
|
return $this->showContentCrumbs;
|
|
|
|
}
|
|
|
|
|
Allow menu items to render their own content; make Dashboard items render on-page
Summary:
Ref T11957. When you click a dashboard item, it now sends you to `/<app>/item/view/123/`, which renders the proper crumbs, navigation, etc., with the dashboard as page content.
This works as you'd expect in Projects:
{F2508568}
It's sliiiightly odd in Favorites since we nuke the nav menu, but seems basically fine?
{F2508571}
Test Plan:
- Created a dashboard panel on a project.
- Clicked it, saw it render.
- Made it the default panel, viewed project default screen, saw dashboard.
- Disabled every panel I could, still saw reasonable behavior (this is silly anyway).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11957
Differential Revision: https://secure.phabricator.com/D17255
2017-01-26 21:14:02 +01:00
|
|
|
abstract public function getItemURI($path);
|
2016-12-11 18:00:44 +01:00
|
|
|
abstract protected function isMenuEngineConfigurable();
|
2016-01-14 15:47:06 +01:00
|
|
|
|
2017-01-17 21:46:05 +01:00
|
|
|
abstract protected function getBuiltinProfileItems($object);
|
|
|
|
|
|
|
|
protected function getBuiltinCustomProfileItems(
|
|
|
|
$object,
|
|
|
|
$custom_phid) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
protected function getEditMode() {
|
|
|
|
return $this->editMode;
|
|
|
|
}
|
|
|
|
|
2016-01-13 00:06:43 +01:00
|
|
|
public function buildResponse() {
|
|
|
|
$controller = $this->getController();
|
|
|
|
|
|
|
|
$viewer = $controller->getViewer();
|
|
|
|
$this->setViewer($viewer);
|
|
|
|
|
|
|
|
$request = $controller->getRequest();
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$item_action = $request->getURIData('itemAction');
|
Allow menu items to render their own content; make Dashboard items render on-page
Summary:
Ref T11957. When you click a dashboard item, it now sends you to `/<app>/item/view/123/`, which renders the proper crumbs, navigation, etc., with the dashboard as page content.
This works as you'd expect in Projects:
{F2508568}
It's sliiiightly odd in Favorites since we nuke the nav menu, but seems basically fine?
{F2508571}
Test Plan:
- Created a dashboard panel on a project.
- Clicked it, saw it render.
- Made it the default panel, viewed project default screen, saw dashboard.
- Disabled every panel I could, still saw reasonable behavior (this is silly anyway).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11957
Differential Revision: https://secure.phabricator.com/D17255
2017-01-26 21:14:02 +01:00
|
|
|
if (!$item_action) {
|
|
|
|
$item_action = 'view';
|
|
|
|
}
|
2016-01-14 15:47:06 +01:00
|
|
|
|
2017-02-01 19:16:23 +01:00
|
|
|
$is_view = ($item_action == 'view');
|
|
|
|
|
2016-01-14 15:47:06 +01:00
|
|
|
// If the engine is not configurable, don't respond to any of the editing
|
|
|
|
// or configuration routes.
|
2016-12-11 18:00:44 +01:00
|
|
|
if (!$this->isMenuEngineConfigurable()) {
|
2017-02-01 19:16:23 +01:00
|
|
|
if (!$is_view) {
|
|
|
|
return new Aphront404Response();
|
2016-01-14 15:47:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$item_id = $request->getURIData('itemID');
|
2017-01-31 22:23:11 +01:00
|
|
|
|
|
|
|
// If we miss on the MenuEngine route, try the EditEngine route. This will
|
|
|
|
// be populated while editing items.
|
|
|
|
if (!$item_id) {
|
|
|
|
$item_id = $request->getURIData('id');
|
|
|
|
}
|
|
|
|
|
2016-12-15 23:22:42 +01:00
|
|
|
$item_list = $this->getItems();
|
2016-01-13 00:06:43 +01:00
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$selected_item = null;
|
|
|
|
if (strlen($item_id)) {
|
|
|
|
$item_id_int = (int)$item_id;
|
|
|
|
foreach ($item_list as $item) {
|
|
|
|
if ($item_id_int) {
|
|
|
|
if ((int)$item->getID() === $item_id_int) {
|
|
|
|
$selected_item = $item;
|
2016-01-13 00:06:43 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$builtin_key = $item->getBuiltinKey();
|
|
|
|
if ($builtin_key === (string)$item_id) {
|
|
|
|
$selected_item = $item;
|
2016-01-13 00:06:43 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Allow menu items to render their own content; make Dashboard items render on-page
Summary:
Ref T11957. When you click a dashboard item, it now sends you to `/<app>/item/view/123/`, which renders the proper crumbs, navigation, etc., with the dashboard as page content.
This works as you'd expect in Projects:
{F2508568}
It's sliiiightly odd in Favorites since we nuke the nav menu, but seems basically fine?
{F2508571}
Test Plan:
- Created a dashboard panel on a project.
- Clicked it, saw it render.
- Made it the default panel, viewed project default screen, saw dashboard.
- Disabled every panel I could, still saw reasonable behavior (this is silly anyway).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11957
Differential Revision: https://secure.phabricator.com/D17255
2017-01-26 21:14:02 +01:00
|
|
|
if (!$selected_item) {
|
2017-02-01 19:16:23 +01:00
|
|
|
if ($is_view) {
|
Allow menu items to render their own content; make Dashboard items render on-page
Summary:
Ref T11957. When you click a dashboard item, it now sends you to `/<app>/item/view/123/`, which renders the proper crumbs, navigation, etc., with the dashboard as page content.
This works as you'd expect in Projects:
{F2508568}
It's sliiiightly odd in Favorites since we nuke the nav menu, but seems basically fine?
{F2508571}
Test Plan:
- Created a dashboard panel on a project.
- Clicked it, saw it render.
- Made it the default panel, viewed project default screen, saw dashboard.
- Disabled every panel I could, still saw reasonable behavior (this is silly anyway).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11957
Differential Revision: https://secure.phabricator.com/D17255
2017-01-26 21:14:02 +01:00
|
|
|
$selected_item = $this->getDefaultItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
switch ($item_action) {
|
2016-01-13 00:06:43 +01:00
|
|
|
case 'view':
|
|
|
|
case 'info':
|
|
|
|
case 'hide':
|
2016-01-22 14:33:21 +01:00
|
|
|
case 'default':
|
2016-01-13 00:06:43 +01:00
|
|
|
case 'builtin':
|
2016-12-11 19:08:26 +01:00
|
|
|
if (!$selected_item) {
|
2016-01-13 00:06:43 +01:00
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
break;
|
2017-01-09 20:57:32 +01:00
|
|
|
case 'edit':
|
|
|
|
if (!$request->getURIData('id')) {
|
|
|
|
// If we continue along the "edit" pathway without an ID, we hit an
|
|
|
|
// unrelated exception because we can not build a new menu item out
|
|
|
|
// of thin air. For menus, new items are created via the "new"
|
|
|
|
// action. Just catch this case and 404 early since there's currently
|
|
|
|
// no clean way to make EditEngine aware of this.
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
break;
|
2016-01-13 00:06:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$navigation = $this->buildNavigation();
|
|
|
|
|
|
|
|
$crumbs = $controller->buildApplicationCrumbsForEditEngine();
|
Allow menu items to render their own content; make Dashboard items render on-page
Summary:
Ref T11957. When you click a dashboard item, it now sends you to `/<app>/item/view/123/`, which renders the proper crumbs, navigation, etc., with the dashboard as page content.
This works as you'd expect in Projects:
{F2508568}
It's sliiiightly odd in Favorites since we nuke the nav menu, but seems basically fine?
{F2508571}
Test Plan:
- Created a dashboard panel on a project.
- Clicked it, saw it render.
- Made it the default panel, viewed project default screen, saw dashboard.
- Disabled every panel I could, still saw reasonable behavior (this is silly anyway).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11957
Differential Revision: https://secure.phabricator.com/D17255
2017-01-26 21:14:02 +01:00
|
|
|
|
2017-02-01 19:16:23 +01:00
|
|
|
if (!$is_view) {
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$navigation->selectFilter(self::ITEM_MANAGE);
|
|
|
|
|
|
|
|
if ($selected_item) {
|
|
|
|
if ($selected_item->getCustomPHID()) {
|
|
|
|
$edit_mode = 'custom';
|
|
|
|
} else {
|
|
|
|
$edit_mode = 'global';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$edit_mode = $request->getURIData('itemEditMode');
|
|
|
|
}
|
|
|
|
|
2017-02-17 11:10:15 +01:00
|
|
|
$available_modes = $this->getViewerEditModes();
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
if ($available_modes) {
|
|
|
|
$available_modes = array_fuse($available_modes);
|
|
|
|
if (isset($available_modes[$edit_mode])) {
|
|
|
|
$this->editMode = $edit_mode;
|
|
|
|
} else {
|
|
|
|
if ($item_action != 'configure') {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
}
|
Allow menu items to render their own content; make Dashboard items render on-page
Summary:
Ref T11957. When you click a dashboard item, it now sends you to `/<app>/item/view/123/`, which renders the proper crumbs, navigation, etc., with the dashboard as page content.
This works as you'd expect in Projects:
{F2508568}
It's sliiiightly odd in Favorites since we nuke the nav menu, but seems basically fine?
{F2508571}
Test Plan:
- Created a dashboard panel on a project.
- Clicked it, saw it render.
- Made it the default panel, viewed project default screen, saw dashboard.
- Disabled every panel I could, still saw reasonable behavior (this is silly anyway).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11957
Differential Revision: https://secure.phabricator.com/D17255
2017-01-26 21:14:02 +01:00
|
|
|
}
|
2017-01-31 22:28:50 +01:00
|
|
|
$page_title = pht('Configure Menu');
|
|
|
|
} else {
|
|
|
|
$page_title = $selected_item->getDisplayName();
|
2017-01-17 21:04:28 +01:00
|
|
|
}
|
2016-01-13 00:06:43 +01:00
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
switch ($item_action) {
|
2016-01-13 00:06:43 +01:00
|
|
|
case 'view':
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$navigation->selectFilter($selected_item->getDefaultMenuItemKey());
|
Allow menu items to render their own content; make Dashboard items render on-page
Summary:
Ref T11957. When you click a dashboard item, it now sends you to `/<app>/item/view/123/`, which renders the proper crumbs, navigation, etc., with the dashboard as page content.
This works as you'd expect in Projects:
{F2508568}
It's sliiiightly odd in Favorites since we nuke the nav menu, but seems basically fine?
{F2508571}
Test Plan:
- Created a dashboard panel on a project.
- Clicked it, saw it render.
- Made it the default panel, viewed project default screen, saw dashboard.
- Disabled every panel I could, still saw reasonable behavior (this is silly anyway).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11957
Differential Revision: https://secure.phabricator.com/D17255
2017-01-26 21:14:02 +01:00
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$content = $this->buildItemViewContent($selected_item);
|
Allow menu items to render their own content; make Dashboard items render on-page
Summary:
Ref T11957. When you click a dashboard item, it now sends you to `/<app>/item/view/123/`, which renders the proper crumbs, navigation, etc., with the dashboard as page content.
This works as you'd expect in Projects:
{F2508568}
It's sliiiightly odd in Favorites since we nuke the nav menu, but seems basically fine?
{F2508571}
Test Plan:
- Created a dashboard panel on a project.
- Clicked it, saw it render.
- Made it the default panel, viewed project default screen, saw dashboard.
- Disabled every panel I could, still saw reasonable behavior (this is silly anyway).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11957
Differential Revision: https://secure.phabricator.com/D17255
2017-01-26 21:14:02 +01:00
|
|
|
$crumbs->addTextCrumb($selected_item->getDisplayName());
|
|
|
|
if (!$content) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
2016-01-13 00:06:43 +01:00
|
|
|
break;
|
|
|
|
case 'configure':
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$mode = $this->getEditMode();
|
|
|
|
if (!$mode) {
|
|
|
|
$crumbs->addTextCrumb(pht('Configure Menu'));
|
|
|
|
$content = $this->buildMenuEditModeContent();
|
|
|
|
} else {
|
|
|
|
if (count($available_modes) > 1) {
|
|
|
|
$crumbs->addTextCrumb(
|
|
|
|
pht('Configure Menu'),
|
|
|
|
$this->getItemURI('configure/'));
|
|
|
|
|
|
|
|
switch ($mode) {
|
|
|
|
case self::MODE_CUSTOM:
|
|
|
|
$crumbs->addTextCrumb(pht('Personal'));
|
|
|
|
break;
|
|
|
|
case self::MODE_GLOBAL:
|
|
|
|
$crumbs->addTextCrumb(pht('Global'));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$crumbs->addTextCrumb(pht('Configure Menu'));
|
|
|
|
}
|
|
|
|
$edit_list = $this->loadItems($mode);
|
|
|
|
$content = $this->buildItemConfigureContent($edit_list);
|
|
|
|
}
|
2016-01-13 00:06:43 +01:00
|
|
|
break;
|
2016-01-13 18:40:27 +01:00
|
|
|
case 'reorder':
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$mode = $this->getEditMode();
|
|
|
|
$edit_list = $this->loadItems($mode);
|
|
|
|
$content = $this->buildItemReorderContent($edit_list);
|
2016-01-13 18:40:27 +01:00
|
|
|
break;
|
2016-01-13 00:06:43 +01:00
|
|
|
case 'new':
|
2016-12-11 19:08:26 +01:00
|
|
|
$item_key = $request->getURIData('itemKey');
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$mode = $this->getEditMode();
|
|
|
|
$content = $this->buildItemNewContent($item_key, $mode);
|
2016-01-13 00:06:43 +01:00
|
|
|
break;
|
|
|
|
case 'builtin':
|
2016-12-11 19:08:26 +01:00
|
|
|
$content = $this->buildItemBuiltinContent($selected_item);
|
2016-01-13 00:06:43 +01:00
|
|
|
break;
|
2016-01-13 19:40:31 +01:00
|
|
|
case 'hide':
|
2016-12-11 19:08:26 +01:00
|
|
|
$content = $this->buildItemHideContent($selected_item);
|
2016-01-13 19:40:31 +01:00
|
|
|
break;
|
2016-01-22 14:33:21 +01:00
|
|
|
case 'default':
|
2017-02-02 16:37:53 +01:00
|
|
|
if (!$this->isMenuEnginePinnable()) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
2016-12-11 19:08:26 +01:00
|
|
|
$content = $this->buildItemDefaultContent(
|
|
|
|
$selected_item,
|
|
|
|
$item_list);
|
2016-01-22 14:33:21 +01:00
|
|
|
break;
|
2016-01-13 00:06:43 +01:00
|
|
|
case 'edit':
|
2016-12-11 19:08:26 +01:00
|
|
|
$content = $this->buildItemEditContent();
|
2016-01-13 00:06:43 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
2016-12-11 19:08:26 +01:00
|
|
|
'Unsupported item action "%s".',
|
|
|
|
$item_action));
|
2016-01-13 00:06:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($content instanceof AphrontResponse) {
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($content instanceof AphrontResponseProducerInterface) {
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
2016-12-12 17:35:22 +01:00
|
|
|
$crumbs->setBorder(true);
|
|
|
|
|
2017-01-17 21:04:28 +01:00
|
|
|
$page = $controller->newPage()
|
2017-01-31 22:28:50 +01:00
|
|
|
->setTitle($page_title)
|
2016-01-13 00:06:43 +01:00
|
|
|
->appendChild($content);
|
2017-01-17 21:04:28 +01:00
|
|
|
|
2017-02-01 19:16:23 +01:00
|
|
|
if (!$is_view || $this->getShowContentCrumbs()) {
|
|
|
|
$page->setCrumbs($crumbs);
|
|
|
|
}
|
|
|
|
|
2017-01-17 21:04:28 +01:00
|
|
|
if ($this->getShowNavigation()) {
|
|
|
|
$page->setNavigation($navigation);
|
|
|
|
}
|
Allow menu items to render their own content; make Dashboard items render on-page
Summary:
Ref T11957. When you click a dashboard item, it now sends you to `/<app>/item/view/123/`, which renders the proper crumbs, navigation, etc., with the dashboard as page content.
This works as you'd expect in Projects:
{F2508568}
It's sliiiightly odd in Favorites since we nuke the nav menu, but seems basically fine?
{F2508571}
Test Plan:
- Created a dashboard panel on a project.
- Clicked it, saw it render.
- Made it the default panel, viewed project default screen, saw dashboard.
- Disabled every panel I could, still saw reasonable behavior (this is silly anyway).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11957
Differential Revision: https://secure.phabricator.com/D17255
2017-01-26 21:14:02 +01:00
|
|
|
|
2017-02-01 19:16:23 +01:00
|
|
|
if ($is_view) {
|
|
|
|
foreach ($this->pageClasses as $class) {
|
|
|
|
$page->addClass($class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-17 21:04:28 +01:00
|
|
|
return $page;
|
2016-01-13 00:06:43 +01:00
|
|
|
}
|
|
|
|
|
2016-01-12 19:27:39 +01:00
|
|
|
public function buildNavigation() {
|
2016-01-19 19:35:32 +01:00
|
|
|
if ($this->navigation) {
|
|
|
|
return $this->navigation;
|
|
|
|
}
|
2016-01-12 19:27:39 +01:00
|
|
|
$nav = id(new AphrontSideNavFilterView())
|
2016-01-14 01:07:04 +01:00
|
|
|
->setIsProfileMenu(true)
|
2016-12-11 19:08:26 +01:00
|
|
|
->setBaseURI(new PhutilURI($this->getItemURI('')));
|
2016-01-12 19:27:39 +01:00
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$menu_items = $this->getItems();
|
2017-01-17 21:46:05 +01:00
|
|
|
|
2016-12-15 23:22:42 +01:00
|
|
|
$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);
|
|
|
|
}
|
2016-01-12 19:27:39 +01:00
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
foreach ($menu_items as $menu_item) {
|
|
|
|
if ($menu_item->isDisabled()) {
|
2016-01-13 19:40:31 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$items = $menu_item->buildNavigationMenuItems();
|
2016-01-12 19:27:39 +01:00
|
|
|
foreach ($items as $item) {
|
|
|
|
$this->validateNavigationMenuItem($item);
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
// If the item produced only a single item which does not otherwise
|
2016-01-12 19:27:39 +01:00
|
|
|
// have a key, try to automatically assign it a reasonable key. This
|
|
|
|
// makes selecting the correct item simpler.
|
|
|
|
|
|
|
|
if (count($items) == 1) {
|
|
|
|
$item = head($items);
|
|
|
|
if ($item->getKey() === null) {
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$default_key = $menu_item->getDefaultMenuItemKey();
|
|
|
|
$item->setKey($default_key);
|
2016-01-12 19:27:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$nav->addMenuItem($item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$nav->selectFilter(null);
|
|
|
|
|
2016-01-19 19:35:32 +01:00
|
|
|
$this->navigation = $nav;
|
|
|
|
return $this->navigation;
|
2016-01-12 19:27:39 +01:00
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
private function getItems() {
|
|
|
|
if ($this->items === null) {
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$this->items = $this->loadItems(self::MODE_COMBINED);
|
2016-01-12 19:27:39 +01:00
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
return $this->items;
|
2016-01-12 19:27:39 +01:00
|
|
|
}
|
|
|
|
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
private function loadItems($mode) {
|
2016-01-12 19:27:39 +01:00
|
|
|
$viewer = $this->getViewer();
|
2016-01-13 00:06:43 +01:00
|
|
|
$object = $this->getProfileObject();
|
2016-01-12 19:27:39 +01:00
|
|
|
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$items = $this->loadBuiltinProfileItems($mode);
|
2017-01-17 21:46:05 +01:00
|
|
|
|
|
|
|
$query = id(new PhabricatorProfileMenuItemConfigurationQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withProfilePHIDs(array($object->getPHID()));
|
|
|
|
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
switch ($mode) {
|
|
|
|
case self::MODE_GLOBAL:
|
2017-01-17 21:46:05 +01:00
|
|
|
$query->withCustomPHIDs(array(), true);
|
|
|
|
break;
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
case self::MODE_CUSTOM:
|
2017-01-17 21:46:05 +01:00
|
|
|
$query->withCustomPHIDs(array($this->getCustomPHID()), false);
|
|
|
|
break;
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
case self::MODE_COMBINED:
|
2017-01-17 21:46:05 +01:00
|
|
|
$query->withCustomPHIDs(array($this->getCustomPHID()), true);
|
|
|
|
break;
|
2017-01-07 05:12:57 +01:00
|
|
|
}
|
2016-01-13 00:06:43 +01:00
|
|
|
|
2017-01-17 21:46:05 +01:00
|
|
|
$stored_items = $query->execute();
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
foreach ($stored_items as $stored_item) {
|
|
|
|
$impl = $stored_item->getMenuItem();
|
2016-02-09 02:31:21 +01:00
|
|
|
$impl->setViewer($viewer);
|
Allow menu items to render their own content; make Dashboard items render on-page
Summary:
Ref T11957. When you click a dashboard item, it now sends you to `/<app>/item/view/123/`, which renders the proper crumbs, navigation, etc., with the dashboard as page content.
This works as you'd expect in Projects:
{F2508568}
It's sliiiightly odd in Favorites since we nuke the nav menu, but seems basically fine?
{F2508571}
Test Plan:
- Created a dashboard panel on a project.
- Clicked it, saw it render.
- Made it the default panel, viewed project default screen, saw dashboard.
- Disabled every panel I could, still saw reasonable behavior (this is silly anyway).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11957
Differential Revision: https://secure.phabricator.com/D17255
2017-01-26 21:14:02 +01:00
|
|
|
$impl->setEngine($this);
|
2016-02-09 02:31:21 +01:00
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
// Merge the stored items into the builtin items. If a builtin item has
|
2016-01-13 00:06:43 +01:00
|
|
|
// a stored version, replace the defaults with the stored changes.
|
2016-12-11 19:08:26 +01:00
|
|
|
foreach ($stored_items as $stored_item) {
|
|
|
|
if (!$stored_item->shouldEnableForObject($object)) {
|
2016-02-06 21:48:01 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$builtin_key = $stored_item->getBuiltinKey();
|
2016-01-13 00:06:43 +01:00
|
|
|
if ($builtin_key !== null) {
|
2016-01-22 14:33:21 +01:00
|
|
|
// If this builtin actually exists, replace the builtin with the
|
|
|
|
// stored configuration. Otherwise, we're just going to drop the
|
|
|
|
// stored config: it corresponds to an out-of-date or uninstalled
|
2016-12-11 19:08:26 +01:00
|
|
|
// item.
|
|
|
|
if (isset($items[$builtin_key])) {
|
|
|
|
$items[$builtin_key] = $stored_item;
|
2016-01-22 14:33:21 +01:00
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
2016-01-13 00:06:43 +01:00
|
|
|
} else {
|
2016-12-11 19:08:26 +01:00
|
|
|
$items[] = $stored_item;
|
2016-01-13 00:06:43 +01:00
|
|
|
}
|
|
|
|
}
|
2016-01-12 19:27:39 +01:00
|
|
|
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$items = $this->arrangeItems($items, $mode);
|
2016-01-22 14:33:21 +01:00
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
// Make sure exactly one valid item is marked as default.
|
2016-01-22 14:33:21 +01:00
|
|
|
$default = null;
|
|
|
|
$first = null;
|
2016-12-11 19:08:26 +01:00
|
|
|
foreach ($items as $item) {
|
|
|
|
if (!$item->canMakeDefault()) {
|
2016-01-22 14:33:21 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-02-02 16:37:53 +01:00
|
|
|
// If this engine doesn't support pinning items, don't respect any
|
|
|
|
// setting which might be present in the database.
|
|
|
|
if ($this->isMenuEnginePinnable()) {
|
|
|
|
if ($item->isDefault()) {
|
|
|
|
$default = $item;
|
|
|
|
break;
|
|
|
|
}
|
2016-01-22 14:33:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($first === null) {
|
2016-12-11 19:08:26 +01:00
|
|
|
$first = $item;
|
2016-01-22 14:33:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$default) {
|
|
|
|
$default = $first;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($default) {
|
2016-12-11 19:08:26 +01:00
|
|
|
$this->setDefaultItem($default);
|
2016-01-22 14:33:21 +01:00
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
return $items;
|
2016-01-12 19:27:39 +01:00
|
|
|
}
|
|
|
|
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
private function loadBuiltinProfileItems($mode) {
|
2016-01-12 19:27:39 +01:00
|
|
|
$object = $this->getProfileObject();
|
2017-01-17 21:46:05 +01:00
|
|
|
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
switch ($mode) {
|
|
|
|
case self::MODE_GLOBAL:
|
2017-01-17 21:46:05 +01:00
|
|
|
$builtins = $this->getBuiltinProfileItems($object);
|
|
|
|
break;
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
case self::MODE_CUSTOM:
|
2017-01-17 21:46:05 +01:00
|
|
|
$builtins = $this->getBuiltinCustomProfileItems(
|
|
|
|
$object,
|
|
|
|
$this->getCustomPHID());
|
|
|
|
break;
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
case self::MODE_COMBINED:
|
2017-01-17 21:46:05 +01:00
|
|
|
$builtins = array();
|
|
|
|
$builtins[] = $this->getBuiltinCustomProfileItems(
|
|
|
|
$object,
|
|
|
|
$this->getCustomPHID());
|
|
|
|
$builtins[] = $this->getBuiltinProfileItems($object);
|
|
|
|
$builtins = array_mergev($builtins);
|
|
|
|
break;
|
|
|
|
}
|
2016-01-12 19:27:39 +01:00
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$items = PhabricatorProfileMenuItem::getAllMenuItems();
|
2016-02-09 02:31:21 +01:00
|
|
|
$viewer = $this->getViewer();
|
2016-01-12 19:27:39 +01:00
|
|
|
|
|
|
|
$order = 1;
|
|
|
|
$map = array();
|
|
|
|
foreach ($builtins as $builtin) {
|
|
|
|
$builtin_key = $builtin->getBuiltinKey();
|
|
|
|
|
|
|
|
if (!$builtin_key) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
2016-12-11 19:08:26 +01:00
|
|
|
'Object produced a builtin item with no builtin item key! '.
|
|
|
|
'Builtin items must have a unique key.'));
|
2016-01-12 19:27:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($map[$builtin_key])) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
2016-12-11 19:08:26 +01:00
|
|
|
'Object produced two items with the same builtin key ("%s"). '.
|
|
|
|
'Each item must have a unique builtin key.',
|
2016-01-12 19:27:39 +01:00
|
|
|
$builtin_key));
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$item_key = $builtin->getMenuItemKey();
|
2016-01-12 19:27:39 +01:00
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$item = idx($items, $item_key);
|
|
|
|
if (!$item) {
|
2016-01-12 19:27:39 +01:00
|
|
|
throw new Exception(
|
|
|
|
pht(
|
2016-12-11 19:08:26 +01:00
|
|
|
'Builtin item ("%s") specifies a bad item key ("%s"); there '.
|
|
|
|
'is no corresponding item implementation available.',
|
2016-01-12 19:27:39 +01:00
|
|
|
$builtin_key,
|
2016-12-11 19:08:26 +01:00
|
|
|
$item_key));
|
2016-01-12 19:27:39 +01:00
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$item = clone $item;
|
|
|
|
$item->setViewer($viewer);
|
Allow menu items to render their own content; make Dashboard items render on-page
Summary:
Ref T11957. When you click a dashboard item, it now sends you to `/<app>/item/view/123/`, which renders the proper crumbs, navigation, etc., with the dashboard as page content.
This works as you'd expect in Projects:
{F2508568}
It's sliiiightly odd in Favorites since we nuke the nav menu, but seems basically fine?
{F2508571}
Test Plan:
- Created a dashboard panel on a project.
- Clicked it, saw it render.
- Made it the default panel, viewed project default screen, saw dashboard.
- Disabled every panel I could, still saw reasonable behavior (this is silly anyway).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11957
Differential Revision: https://secure.phabricator.com/D17255
2017-01-26 21:14:02 +01:00
|
|
|
$item->setEngine($this);
|
2016-02-09 02:31:21 +01:00
|
|
|
|
2016-01-12 19:27:39 +01:00
|
|
|
$builtin
|
2016-01-13 00:06:43 +01:00
|
|
|
->setProfilePHID($object->getPHID())
|
2016-12-11 19:08:26 +01:00
|
|
|
->attachMenuItem($item)
|
2016-01-12 19:27:39 +01:00
|
|
|
->attachProfileObject($object)
|
2016-12-11 18:38:06 +01:00
|
|
|
->setMenuItemOrder($order);
|
2016-01-12 19:27:39 +01:00
|
|
|
|
2016-02-06 21:48:01 +01:00
|
|
|
if (!$builtin->shouldEnableForObject($object)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-01-12 19:27:39 +01:00
|
|
|
$map[$builtin_key] = $builtin;
|
|
|
|
|
|
|
|
$order++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $map;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function validateNavigationMenuItem($item) {
|
|
|
|
if (!($item instanceof PHUIListItemView)) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
|
|
|
'Expected buildNavigationMenuItems() to return a list of '.
|
|
|
|
'PHUIListItemView objects, but got a surprise.'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-13 00:06:43 +01:00
|
|
|
public function getConfigureURI() {
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$mode = $this->getEditMode();
|
|
|
|
|
|
|
|
switch ($mode) {
|
|
|
|
case self::MODE_CUSTOM:
|
|
|
|
return $this->getItemURI('configure/custom/');
|
|
|
|
case self::MODE_GLOBAL:
|
|
|
|
return $this->getItemURI('configure/global/');
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
return $this->getItemURI('configure/');
|
2016-01-13 00:06:43 +01:00
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
private function buildItemReorderContent(array $items) {
|
2016-01-13 18:40:27 +01:00
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$object = $this->getProfileObject();
|
|
|
|
|
2017-01-27 04:42:04 +01:00
|
|
|
// If you're reordering global items, you need to be able to edit the
|
|
|
|
// object the menu appears on. If you're reordering custom items, you only
|
|
|
|
// need to be able to edit the custom object. Currently, the custom object
|
|
|
|
// is always the viewing user's own user object.
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$custom_phid = $this->getEditModeCustomPHID();
|
|
|
|
|
2017-01-27 04:42:04 +01:00
|
|
|
if (!$custom_phid) {
|
|
|
|
PhabricatorPolicyFilter::requireCapability(
|
|
|
|
$viewer,
|
|
|
|
$object,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
} else {
|
|
|
|
$policy_object = id(new PhabricatorObjectQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs(array($custom_phid))
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
if (!$policy_object) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
|
|
|
'Failed to load custom PHID "%s"!',
|
|
|
|
$custom_phid));
|
|
|
|
}
|
|
|
|
|
|
|
|
PhabricatorPolicyFilter::requireCapability(
|
|
|
|
$viewer,
|
|
|
|
$policy_object,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
}
|
2016-01-13 18:40:27 +01:00
|
|
|
|
|
|
|
$controller = $this->getController();
|
|
|
|
$request = $controller->getRequest();
|
|
|
|
|
|
|
|
$request->validateCSRF();
|
|
|
|
|
|
|
|
$order = $request->getStrList('order');
|
|
|
|
|
|
|
|
$by_builtin = array();
|
|
|
|
$by_id = array();
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
foreach ($items as $key => $item) {
|
|
|
|
$id = $item->getID();
|
2016-01-13 18:40:27 +01:00
|
|
|
if ($id) {
|
|
|
|
$by_id[$id] = $key;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$builtin_key = $item->getBuiltinKey();
|
2016-01-13 18:40:27 +01:00
|
|
|
if ($builtin_key) {
|
|
|
|
$by_builtin[$builtin_key] = $key;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$key_order = array();
|
|
|
|
foreach ($order as $order_item) {
|
|
|
|
if (isset($by_id[$order_item])) {
|
|
|
|
$key_order[] = $by_id[$order_item];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isset($by_builtin[$order_item])) {
|
|
|
|
$key_order[] = $by_builtin[$order_item];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$items = array_select_keys($items, $key_order) + $items;
|
2016-01-13 18:40:27 +01:00
|
|
|
|
|
|
|
$type_order =
|
2016-12-11 18:38:06 +01:00
|
|
|
PhabricatorProfileMenuItemConfigurationTransaction::TYPE_ORDER;
|
2016-01-13 18:40:27 +01:00
|
|
|
|
|
|
|
$order = 1;
|
2016-12-11 19:08:26 +01:00
|
|
|
foreach ($items as $item) {
|
2016-01-13 18:40:27 +01:00
|
|
|
$xactions = array();
|
|
|
|
|
2016-12-11 18:38:06 +01:00
|
|
|
$xactions[] = id(new PhabricatorProfileMenuItemConfigurationTransaction())
|
2016-01-13 18:40:27 +01:00
|
|
|
->setTransactionType($type_order)
|
|
|
|
->setNewValue($order);
|
|
|
|
|
2016-12-11 18:38:06 +01:00
|
|
|
$editor = id(new PhabricatorProfileMenuEditor())
|
2016-01-13 18:40:27 +01:00
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setActor($viewer)
|
|
|
|
->setContinueOnMissingFields(true)
|
|
|
|
->setContinueOnNoEffect(true)
|
2016-12-11 19:08:26 +01:00
|
|
|
->applyTransactions($item, $xactions);
|
2016-01-13 18:40:27 +01:00
|
|
|
|
|
|
|
$order++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI($this->getConfigureURI());
|
|
|
|
}
|
|
|
|
|
2017-02-03 18:20:17 +01:00
|
|
|
protected function buildItemViewContent(
|
Allow menu items to render their own content; make Dashboard items render on-page
Summary:
Ref T11957. When you click a dashboard item, it now sends you to `/<app>/item/view/123/`, which renders the proper crumbs, navigation, etc., with the dashboard as page content.
This works as you'd expect in Projects:
{F2508568}
It's sliiiightly odd in Favorites since we nuke the nav menu, but seems basically fine?
{F2508571}
Test Plan:
- Created a dashboard panel on a project.
- Clicked it, saw it render.
- Made it the default panel, viewed project default screen, saw dashboard.
- Disabled every panel I could, still saw reasonable behavior (this is silly anyway).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11957
Differential Revision: https://secure.phabricator.com/D17255
2017-01-26 21:14:02 +01:00
|
|
|
PhabricatorProfileMenuItemConfiguration $item) {
|
|
|
|
return $item->newPageContent();
|
|
|
|
}
|
2016-01-13 18:40:27 +01:00
|
|
|
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
private function getViewerEditModes() {
|
|
|
|
$modes = array();
|
|
|
|
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
if ($viewer->isLoggedIn() && $this->isMenuEnginePersonalizable()) {
|
|
|
|
$modes[] = self::MODE_CUSTOM;
|
|
|
|
}
|
|
|
|
|
|
|
|
$object = $this->getProfileObject();
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$object,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
|
|
if ($can_edit) {
|
|
|
|
$modes[] = self::MODE_GLOBAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $modes;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function isMenuEnginePersonalizable() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-02-02 16:37:53 +01:00
|
|
|
/**
|
|
|
|
* Does this engine support pinning items?
|
|
|
|
*
|
|
|
|
* Personalizable menus disable pinning by default since it creates a number
|
|
|
|
* of weird edge cases without providing many benefits for current menus.
|
|
|
|
*
|
|
|
|
* @return bool True if items may be pinned as default items.
|
|
|
|
*/
|
|
|
|
protected function isMenuEnginePinnable() {
|
|
|
|
return !$this->isMenuEnginePersonalizable();
|
|
|
|
}
|
|
|
|
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
private function buildMenuEditModeContent() {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
2017-02-17 11:10:15 +01:00
|
|
|
$modes = $this->getViewerEditModes();
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
if (!$modes) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($modes) == 1) {
|
|
|
|
$mode = head($modes);
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI($this->getItemURI("configure/{$mode}/"));
|
|
|
|
}
|
|
|
|
|
|
|
|
$menu = id(new PHUIObjectItemListView())
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
$modes = array_fuse($modes);
|
|
|
|
|
|
|
|
if (isset($modes['custom'])) {
|
|
|
|
$menu->addItem(
|
|
|
|
id(new PHUIObjectItemView())
|
|
|
|
->setHeader(pht('Personal Menu Items'))
|
|
|
|
->setHref($this->getItemURI('configure/custom/'))
|
|
|
|
->setImageURI($viewer->getProfileImageURI())
|
|
|
|
->addAttribute(pht('Edit the menu for your personal account.')));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($modes['global'])) {
|
|
|
|
$icon = id(new PHUIIconView())
|
|
|
|
->setIcon('fa-globe')
|
|
|
|
->setBackground('bg-blue');
|
|
|
|
|
|
|
|
$menu->addItem(
|
|
|
|
id(new PHUIObjectItemView())
|
|
|
|
->setHeader(pht('Global Menu Items'))
|
|
|
|
->setHref($this->getItemURI('configure/global/'))
|
|
|
|
->setImageIcon($icon)
|
|
|
|
->addAttribute(pht('Edit the global default menu for all users.')));
|
|
|
|
}
|
|
|
|
|
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
|
|
->setObjectList($menu);
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader(pht('Manage Menu'))
|
|
|
|
->setHeaderIcon('fa-list');
|
|
|
|
|
|
|
|
return id(new PHUITwoColumnView())
|
|
|
|
->setHeader($header)
|
|
|
|
->setFooter($box);
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
private function buildItemConfigureContent(array $items) {
|
2016-01-13 00:06:43 +01:00
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$object = $this->getProfileObject();
|
|
|
|
|
2017-01-18 04:15:09 +01:00
|
|
|
$filtered_groups = mgroup($items, 'getMenuItemKey');
|
|
|
|
foreach ($filtered_groups as $group) {
|
|
|
|
$first_item = head($group);
|
|
|
|
$first_item->willBuildNavigationItems($group);
|
|
|
|
}
|
|
|
|
|
2017-01-19 20:06:42 +01:00
|
|
|
// Users only need to be able to edit the object which this menu appears
|
|
|
|
// on if they're editing global menu items. For example, users do not need
|
|
|
|
// to be able to edit the Favorites application to add new items to the
|
|
|
|
// Favorites menu.
|
|
|
|
if (!$this->getCustomPHID()) {
|
|
|
|
PhabricatorPolicyFilter::requireCapability(
|
|
|
|
$viewer,
|
|
|
|
$object,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
}
|
2016-01-13 00:06:43 +01:00
|
|
|
|
2016-01-13 18:40:27 +01:00
|
|
|
$list_id = celerity_generate_unique_node_id();
|
|
|
|
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$mode = $this->getEditMode();
|
|
|
|
|
2016-01-13 18:40:27 +01:00
|
|
|
Javelin::initBehavior(
|
|
|
|
'reorder-profile-menu-items',
|
|
|
|
array(
|
|
|
|
'listID' => $list_id,
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
'orderURI' => $this->getItemURI("reorder/{$mode}/"),
|
2016-01-13 18:40:27 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
$list = id(new PHUIObjectItemListView())
|
2017-01-17 21:04:28 +01:00
|
|
|
->setID($list_id)
|
|
|
|
->setNoDataString(pht('This menu currently has no items.'));
|
2016-01-13 18:40:27 +01:00
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
foreach ($items as $item) {
|
|
|
|
$id = $item->getID();
|
|
|
|
$builtin_key = $item->getBuiltinKey();
|
2016-01-13 00:06:43 +01:00
|
|
|
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
2016-12-11 19:08:26 +01:00
|
|
|
$item,
|
2016-01-13 00:06:43 +01:00
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$view = id(new PHUIObjectItemView());
|
2016-01-13 00:06:43 +01:00
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$name = $item->getDisplayName();
|
|
|
|
$type = $item->getMenuItemTypeName();
|
2016-01-13 00:06:43 +01:00
|
|
|
if (!strlen(trim($name))) {
|
|
|
|
$name = pht('Untitled "%s" Item', $type);
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$view->setHeader($name);
|
|
|
|
$view->addAttribute($type);
|
2016-01-13 00:06:43 +01:00
|
|
|
|
|
|
|
if ($can_edit) {
|
2016-12-11 19:08:26 +01:00
|
|
|
$view
|
2016-01-13 18:40:27 +01:00
|
|
|
->setGrippable(true)
|
|
|
|
->addSigil('profile-menu-item')
|
|
|
|
->setMetadata(
|
|
|
|
array(
|
|
|
|
'key' => nonempty($id, $builtin_key),
|
|
|
|
));
|
|
|
|
|
2016-01-22 14:33:21 +01:00
|
|
|
if ($id) {
|
2016-12-11 19:08:26 +01:00
|
|
|
$default_uri = $this->getItemURI("default/{$id}/");
|
2016-01-22 14:33:21 +01:00
|
|
|
} else {
|
2016-12-11 19:08:26 +01:00
|
|
|
$default_uri = $this->getItemURI("default/{$builtin_key}/");
|
2016-01-22 14:33:21 +01:00
|
|
|
}
|
|
|
|
|
2017-02-02 16:37:53 +01:00
|
|
|
$default_text = null;
|
|
|
|
|
|
|
|
if ($this->isMenuEnginePinnable()) {
|
|
|
|
if ($item->isDefault()) {
|
|
|
|
$default_icon = 'fa-thumb-tack green';
|
|
|
|
$default_text = pht('Current Default');
|
|
|
|
} else if ($item->canMakeDefault()) {
|
|
|
|
$default_icon = 'fa-thumb-tack';
|
|
|
|
$default_text = pht('Make Default');
|
|
|
|
}
|
2016-01-22 14:33:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($default_text !== null) {
|
2016-12-11 19:08:26 +01:00
|
|
|
$view->addAction(
|
2016-01-22 14:33:21 +01:00
|
|
|
id(new PHUIListItemView())
|
|
|
|
->setHref($default_uri)
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setName($default_text)
|
|
|
|
->setIcon($default_icon));
|
|
|
|
}
|
|
|
|
|
2016-01-13 00:06:43 +01:00
|
|
|
if ($id) {
|
2016-12-11 19:08:26 +01:00
|
|
|
$view->setHref($this->getItemURI("edit/{$id}/"));
|
|
|
|
$hide_uri = $this->getItemURI("hide/{$id}/");
|
2016-01-13 00:06:43 +01:00
|
|
|
} else {
|
2016-12-11 19:08:26 +01:00
|
|
|
$view->setHref($this->getItemURI("builtin/{$builtin_key}/"));
|
|
|
|
$hide_uri = $this->getItemURI("hide/{$builtin_key}/");
|
2016-01-13 00:06:43 +01:00
|
|
|
}
|
2016-01-13 19:40:31 +01:00
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
if ($item->isDisabled()) {
|
2016-01-22 14:33:21 +01:00
|
|
|
$hide_icon = 'fa-plus';
|
2016-01-22 15:49:33 +01:00
|
|
|
$hide_text = pht('Enable');
|
2016-12-11 19:08:26 +01:00
|
|
|
} else if ($item->getBuiltinKey() !== null) {
|
2016-01-22 14:33:21 +01:00
|
|
|
$hide_icon = 'fa-times';
|
|
|
|
$hide_text = pht('Disable');
|
|
|
|
} else {
|
|
|
|
$hide_icon = 'fa-times';
|
|
|
|
$hide_text = pht('Delete');
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$can_disable = $item->canHideMenuItem();
|
2016-01-25 12:21:36 +01:00
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$view->addAction(
|
2016-01-13 19:40:31 +01:00
|
|
|
id(new PHUIListItemView())
|
|
|
|
->setHref($hide_uri)
|
|
|
|
->setWorkflow(true)
|
2016-01-25 12:21:36 +01:00
|
|
|
->setDisabled(!$can_disable)
|
2016-01-22 14:33:21 +01:00
|
|
|
->setName($hide_text)
|
|
|
|
->setIcon($hide_icon));
|
2016-01-13 19:40:31 +01:00
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
if ($item->isDisabled()) {
|
|
|
|
$view->setDisabled(true);
|
2016-01-13 00:06:43 +01:00
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$list->addItem($view);
|
2016-01-13 00:06:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$action_view = id(new PhabricatorActionListView())
|
|
|
|
->setUser($viewer);
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$item_types = PhabricatorProfileMenuItem::getAllMenuItems();
|
2016-12-12 17:35:22 +01:00
|
|
|
$object = $this->getProfileObject();
|
|
|
|
|
|
|
|
$action_list = id(new PhabricatorActionListView())
|
|
|
|
->setViewer($viewer);
|
2016-01-13 00:06:43 +01:00
|
|
|
|
2016-12-12 17:35:22 +01:00
|
|
|
$action_list->addAction(
|
2016-01-13 00:06:43 +01:00
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setLabel(true)
|
|
|
|
->setName(pht('Add New Menu Item...')));
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
foreach ($item_types as $item_type) {
|
|
|
|
if (!$item_type->canAddToObject($object)) {
|
2016-01-13 00:06:43 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$item_key = $item_type->getMenuItemKey();
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$edit_mode = $this->getEditMode();
|
2016-01-13 00:06:43 +01:00
|
|
|
|
2016-12-12 17:35:22 +01:00
|
|
|
$action_list->addAction(
|
2016-01-13 00:06:43 +01:00
|
|
|
id(new PhabricatorActionView())
|
2016-12-11 19:08:26 +01:00
|
|
|
->setIcon($item_type->getMenuItemTypeIcon())
|
|
|
|
->setName($item_type->getMenuItemTypeName())
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
->setHref($this->getItemURI("new/{$edit_mode}/{$item_key}/"))
|
2016-12-12 17:35:22 +01:00
|
|
|
->setWorkflow(true));
|
2016-01-13 00:06:43 +01:00
|
|
|
}
|
|
|
|
|
2016-12-12 17:35:22 +01:00
|
|
|
$action_list->addAction(
|
2016-01-13 00:06:43 +01:00
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setLabel(true)
|
|
|
|
->setName(pht('Documentation')));
|
|
|
|
|
2016-01-22 15:49:33 +01:00
|
|
|
$doc_link = PhabricatorEnv::getDoclink('Profile Menu User Guide');
|
|
|
|
$doc_name = pht('Profile Menu User Guide');
|
|
|
|
|
2016-12-12 17:35:22 +01:00
|
|
|
$action_list->addAction(
|
2016-01-13 00:06:43 +01:00
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setIcon('fa-book')
|
2016-01-22 15:49:33 +01:00
|
|
|
->setHref($doc_link)
|
|
|
|
->setName($doc_name));
|
2016-01-13 00:06:43 +01:00
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
2017-01-17 21:04:28 +01:00
|
|
|
->setHeader(pht('Menu Items'))
|
2016-12-12 17:35:22 +01:00
|
|
|
->setHeaderIcon('fa-list');
|
2016-01-13 00:06:43 +01:00
|
|
|
|
|
|
|
$box = id(new PHUIObjectBoxView())
|
2017-01-17 21:04:28 +01:00
|
|
|
->setHeaderText(pht('Current Menu Items'))
|
2016-12-12 17:35:22 +01:00
|
|
|
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
|
2016-01-13 00:06:43 +01:00
|
|
|
->setObjectList($list);
|
|
|
|
|
2016-12-12 17:35:22 +01:00
|
|
|
$panel = id(new PHUICurtainPanelView())
|
|
|
|
->appendChild($action_view);
|
|
|
|
|
|
|
|
$curtain = id(new PHUICurtainView())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->setActionList($action_list);
|
|
|
|
|
|
|
|
$view = id(new PHUITwoColumnView())
|
|
|
|
->setHeader($header)
|
|
|
|
->setCurtain($curtain)
|
|
|
|
->setMainColumn(
|
|
|
|
array(
|
|
|
|
$box,
|
|
|
|
));
|
|
|
|
|
|
|
|
return $view;
|
2016-01-13 00:06:43 +01:00
|
|
|
}
|
|
|
|
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
private function buildItemNewContent($item_key, $mode) {
|
2016-12-11 19:08:26 +01:00
|
|
|
$item_types = PhabricatorProfileMenuItem::getAllMenuItems();
|
|
|
|
$item_type = idx($item_types, $item_key);
|
|
|
|
if (!$item_type) {
|
2016-01-13 00:06:43 +01:00
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$object = $this->getProfileObject();
|
2016-12-11 19:08:26 +01:00
|
|
|
if (!$item_type->canAddToObject($object)) {
|
2016-01-13 00:06:43 +01:00
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$custom_phid = $this->getEditModeCustomPHID();
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
$configuration = PhabricatorProfileMenuItemConfiguration::initializeNewItem(
|
|
|
|
$object,
|
2017-01-10 20:20:26 +01:00
|
|
|
$item_type,
|
|
|
|
$custom_phid);
|
2016-01-13 00:06:43 +01:00
|
|
|
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
PhabricatorPolicyFilter::requireCapability(
|
|
|
|
$viewer,
|
|
|
|
$configuration,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
|
|
$controller = $this->getController();
|
|
|
|
|
2016-12-11 18:06:43 +01:00
|
|
|
return id(new PhabricatorProfileMenuEditEngine())
|
2016-12-11 18:00:44 +01:00
|
|
|
->setMenuEngine($this)
|
2016-01-13 00:06:43 +01:00
|
|
|
->setProfileObject($object)
|
2016-12-11 19:08:26 +01:00
|
|
|
->setNewMenuItemConfiguration($configuration)
|
2017-01-10 20:20:26 +01:00
|
|
|
->setCustomPHID($custom_phid)
|
2016-01-13 00:06:43 +01:00
|
|
|
->setController($controller)
|
|
|
|
->buildResponse();
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
private function buildItemEditContent() {
|
2016-01-13 00:06:43 +01:00
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$object = $this->getProfileObject();
|
|
|
|
$controller = $this->getController();
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$custom_phid = $this->getEditModeCustomPHID();
|
2016-01-13 00:06:43 +01:00
|
|
|
|
2016-12-11 18:06:43 +01:00
|
|
|
return id(new PhabricatorProfileMenuEditEngine())
|
2016-12-11 18:00:44 +01:00
|
|
|
->setMenuEngine($this)
|
2016-01-13 00:06:43 +01:00
|
|
|
->setProfileObject($object)
|
|
|
|
->setController($controller)
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
->setCustomPHID($custom_phid)
|
2016-01-13 00:06:43 +01:00
|
|
|
->buildResponse();
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
private function buildItemBuiltinContent(
|
2016-12-11 18:38:06 +01:00
|
|
|
PhabricatorProfileMenuItemConfiguration $configuration) {
|
2016-01-13 00:06:43 +01:00
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
// If this builtin item has already been persisted, redirect to the
|
2016-01-13 00:06:43 +01:00
|
|
|
// edit page.
|
|
|
|
$id = $configuration->getID();
|
|
|
|
if ($id) {
|
|
|
|
return id(new AphrontRedirectResponse())
|
2016-12-11 19:08:26 +01:00
|
|
|
->setURI($this->getItemURI("edit/{$id}/"));
|
2016-01-13 00:06:43 +01:00
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
// Otherwise, act like we're creating a new item, we're just starting
|
2016-01-13 00:06:43 +01:00
|
|
|
// with the builtin template.
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
PhabricatorPolicyFilter::requireCapability(
|
|
|
|
$viewer,
|
|
|
|
$configuration,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
|
|
$object = $this->getProfileObject();
|
|
|
|
$controller = $this->getController();
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$custom_phid = $this->getEditModeCustomPHID();
|
2016-01-13 00:06:43 +01:00
|
|
|
|
2016-12-11 18:06:43 +01:00
|
|
|
return id(new PhabricatorProfileMenuEditEngine())
|
2016-01-13 00:06:43 +01:00
|
|
|
->setIsBuiltin(true)
|
2016-12-11 18:00:44 +01:00
|
|
|
->setMenuEngine($this)
|
2016-01-13 00:06:43 +01:00
|
|
|
->setProfileObject($object)
|
2016-12-11 19:08:26 +01:00
|
|
|
->setNewMenuItemConfiguration($configuration)
|
2016-01-13 00:06:43 +01:00
|
|
|
->setController($controller)
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
->setCustomPHID($custom_phid)
|
2016-01-13 00:06:43 +01:00
|
|
|
->buildResponse();
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
private function buildItemHideContent(
|
2016-12-11 18:38:06 +01:00
|
|
|
PhabricatorProfileMenuItemConfiguration $configuration) {
|
2016-01-13 19:40:31 +01:00
|
|
|
|
|
|
|
$controller = $this->getController();
|
|
|
|
$request = $controller->getRequest();
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
PhabricatorPolicyFilter::requireCapability(
|
|
|
|
$viewer,
|
|
|
|
$configuration,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
2016-12-11 18:38:06 +01:00
|
|
|
if (!$configuration->canHideMenuItem()) {
|
2016-01-25 12:21:36 +01:00
|
|
|
return $controller->newDialog()
|
2016-12-11 19:08:26 +01:00
|
|
|
->setTitle(pht('Mandatory Item'))
|
2016-01-25 12:21:36 +01:00
|
|
|
->appendParagraph(
|
2016-12-11 19:08:26 +01:00
|
|
|
pht('This menu item is very important, and can not be disabled.'))
|
2016-01-25 12:21:36 +01:00
|
|
|
->addCancelButton($this->getConfigureURI());
|
|
|
|
}
|
|
|
|
|
2016-01-22 14:33:21 +01:00
|
|
|
if ($configuration->getBuiltinKey() === null) {
|
|
|
|
$new_value = null;
|
|
|
|
|
|
|
|
$title = pht('Delete Menu Item');
|
|
|
|
$body = pht('Delete this menu item?');
|
|
|
|
$button = pht('Delete Menu Item');
|
|
|
|
} else if ($configuration->isDisabled()) {
|
2016-12-11 18:38:06 +01:00
|
|
|
$new_value = PhabricatorProfileMenuItemConfiguration::VISIBILITY_VISIBLE;
|
2016-01-22 14:33:21 +01:00
|
|
|
|
|
|
|
$title = pht('Enable Menu Item');
|
|
|
|
$body = pht(
|
|
|
|
'Enable this menu item? It will appear in the menu again.');
|
|
|
|
$button = pht('Enable Menu Item');
|
|
|
|
} else {
|
2016-12-11 18:38:06 +01:00
|
|
|
$new_value = PhabricatorProfileMenuItemConfiguration::VISIBILITY_DISABLED;
|
2016-01-22 14:33:21 +01:00
|
|
|
|
|
|
|
$title = pht('Disable Menu Item');
|
|
|
|
$body = pht(
|
|
|
|
'Disable this menu item? It will no longer appear in the menu, but '.
|
|
|
|
'you can re-enable it later.');
|
|
|
|
$button = pht('Disable Menu Item');
|
|
|
|
}
|
|
|
|
|
2016-01-13 19:40:31 +01:00
|
|
|
$v_visibility = $configuration->getVisibility();
|
|
|
|
if ($request->isFormPost()) {
|
2016-01-22 14:33:21 +01:00
|
|
|
if ($new_value === null) {
|
|
|
|
$configuration->delete();
|
|
|
|
} else {
|
|
|
|
$type_visibility =
|
2016-12-11 18:38:06 +01:00
|
|
|
PhabricatorProfileMenuItemConfigurationTransaction::TYPE_VISIBILITY;
|
2016-01-22 14:33:21 +01:00
|
|
|
|
|
|
|
$xactions = array();
|
|
|
|
|
2016-12-11 18:38:06 +01:00
|
|
|
$xactions[] =
|
|
|
|
id(new PhabricatorProfileMenuItemConfigurationTransaction())
|
|
|
|
->setTransactionType($type_visibility)
|
|
|
|
->setNewValue($new_value);
|
2016-01-22 14:33:21 +01:00
|
|
|
|
2016-12-11 18:38:06 +01:00
|
|
|
$editor = id(new PhabricatorProfileMenuEditor())
|
2016-01-22 14:33:21 +01:00
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setActor($viewer)
|
|
|
|
->setContinueOnMissingFields(true)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->applyTransactions($configuration, $xactions);
|
|
|
|
}
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI($this->getConfigureURI());
|
|
|
|
}
|
|
|
|
|
|
|
|
return $controller->newDialog()
|
|
|
|
->setTitle($title)
|
|
|
|
->appendParagraph($body)
|
|
|
|
->addCancelButton($this->getConfigureURI())
|
|
|
|
->addSubmitButton($button);
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
private function buildItemDefaultContent(
|
2016-12-11 18:38:06 +01:00
|
|
|
PhabricatorProfileMenuItemConfiguration $configuration,
|
2016-12-11 19:08:26 +01:00
|
|
|
array $items) {
|
2016-01-22 14:33:21 +01:00
|
|
|
|
|
|
|
$controller = $this->getController();
|
|
|
|
$request = $controller->getRequest();
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
PhabricatorPolicyFilter::requireCapability(
|
|
|
|
$viewer,
|
|
|
|
$configuration,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
|
|
$done_uri = $this->getConfigureURI();
|
|
|
|
|
|
|
|
if (!$configuration->canMakeDefault()) {
|
|
|
|
return $controller->newDialog()
|
|
|
|
->setTitle(pht('Not Defaultable'))
|
|
|
|
->appendParagraph(
|
|
|
|
pht(
|
|
|
|
'This item can not be set as the default item. This is usually '.
|
|
|
|
'because the item has no page of its own, or links to an '.
|
|
|
|
'external page.'))
|
|
|
|
->addCancelButton($done_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($configuration->isDefault()) {
|
|
|
|
return $controller->newDialog()
|
|
|
|
->setTitle(pht('Already Default'))
|
|
|
|
->appendParagraph(
|
|
|
|
pht(
|
|
|
|
'This item is already set as the default item for this menu.'))
|
|
|
|
->addCancelButton($done_uri);
|
|
|
|
}
|
|
|
|
|
2016-01-22 16:36:56 +01:00
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$key = $configuration->getID();
|
|
|
|
if (!$key) {
|
|
|
|
$key = $configuration->getBuiltinKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->adjustDefault($key);
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI($done_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $controller->newDialog()
|
|
|
|
->setTitle(pht('Make Default'))
|
|
|
|
->appendParagraph(
|
|
|
|
pht(
|
|
|
|
'Set this item as the default for this menu? Users arriving on '.
|
|
|
|
'this page will be shown the content of this item by default.'))
|
|
|
|
->addCancelButton($done_uri)
|
|
|
|
->addSubmitButton(pht('Make Default'));
|
|
|
|
}
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
protected function newItem() {
|
2016-12-11 18:38:06 +01:00
|
|
|
return PhabricatorProfileMenuItemConfiguration::initializeNewBuiltin();
|
2016-01-22 16:36:56 +01:00
|
|
|
}
|
|
|
|
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
protected function newManageItem() {
|
|
|
|
return $this->newItem()
|
|
|
|
->setBuiltinKey(self::ITEM_MANAGE)
|
|
|
|
->setMenuItemKey(PhabricatorManageProfileMenuItem::MENUITEMKEY);
|
|
|
|
}
|
|
|
|
|
2016-01-22 16:36:56 +01:00
|
|
|
public function adjustDefault($key) {
|
|
|
|
$controller = $this->getController();
|
|
|
|
$request = $controller->getRequest();
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$items = $this->loadItems(self::MODE_COMBINED);
|
2016-01-22 16:36:56 +01:00
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
// To adjust the default item, we first change any existing items that
|
|
|
|
// are marked as defaults to "visible", then make the new default item
|
2016-01-22 16:36:56 +01:00
|
|
|
// the default.
|
|
|
|
|
|
|
|
$default = array();
|
|
|
|
$visible = array();
|
|
|
|
|
2016-12-11 19:08:26 +01:00
|
|
|
foreach ($items as $item) {
|
|
|
|
$builtin_key = $item->getBuiltinKey();
|
|
|
|
$id = $item->getID();
|
2016-01-22 16:36:56 +01:00
|
|
|
|
|
|
|
$is_target =
|
|
|
|
(($builtin_key !== null) && ($builtin_key === $key)) ||
|
2016-02-02 21:42:28 +01:00
|
|
|
(($id !== null) && ((int)$id === (int)$key));
|
2016-01-22 16:36:56 +01:00
|
|
|
|
|
|
|
if ($is_target) {
|
2016-12-11 19:08:26 +01:00
|
|
|
if (!$item->isDefault()) {
|
|
|
|
$default[] = $item;
|
2016-01-22 16:36:56 +01:00
|
|
|
}
|
|
|
|
} else {
|
2016-12-11 19:08:26 +01:00
|
|
|
if ($item->isDefault()) {
|
|
|
|
$visible[] = $item;
|
2016-01-22 16:36:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-22 14:33:21 +01:00
|
|
|
$type_visibility =
|
2016-12-11 18:38:06 +01:00
|
|
|
PhabricatorProfileMenuItemConfigurationTransaction::TYPE_VISIBILITY;
|
2016-01-22 14:33:21 +01:00
|
|
|
|
2016-12-11 18:38:06 +01:00
|
|
|
$v_visible = PhabricatorProfileMenuItemConfiguration::VISIBILITY_VISIBLE;
|
|
|
|
$v_default = PhabricatorProfileMenuItemConfiguration::VISIBILITY_DEFAULT;
|
2016-01-22 14:33:21 +01:00
|
|
|
|
2016-01-22 16:36:56 +01:00
|
|
|
$apply = array(
|
|
|
|
array($v_visible, $visible),
|
|
|
|
array($v_default, $default),
|
|
|
|
);
|
2016-01-22 14:33:21 +01:00
|
|
|
|
2016-01-22 16:36:56 +01:00
|
|
|
foreach ($apply as $group) {
|
2016-12-11 19:08:26 +01:00
|
|
|
list($value, $items) = $group;
|
|
|
|
foreach ($items as $item) {
|
2016-01-22 14:33:21 +01:00
|
|
|
$xactions = array();
|
2016-01-13 19:40:31 +01:00
|
|
|
|
2016-12-11 18:38:06 +01:00
|
|
|
$xactions[] =
|
|
|
|
id(new PhabricatorProfileMenuItemConfigurationTransaction())
|
|
|
|
->setTransactionType($type_visibility)
|
|
|
|
->setNewValue($value);
|
2016-01-22 14:33:21 +01:00
|
|
|
|
2016-12-11 18:38:06 +01:00
|
|
|
$editor = id(new PhabricatorProfileMenuEditor())
|
2016-01-22 14:33:21 +01:00
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setActor($viewer)
|
|
|
|
->setContinueOnMissingFields(true)
|
|
|
|
->setContinueOnNoEffect(true)
|
2016-12-11 19:08:26 +01:00
|
|
|
->applyTransactions($item, $xactions);
|
2016-01-22 14:33:21 +01:00
|
|
|
}
|
2016-01-13 19:40:31 +01:00
|
|
|
}
|
|
|
|
|
2016-01-22 16:36:56 +01:00
|
|
|
return $this;
|
2016-01-14 14:59:25 +01:00
|
|
|
}
|
|
|
|
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
private function arrangeItems(array $items, $mode) {
|
2017-01-17 21:46:05 +01:00
|
|
|
// Sort the items.
|
|
|
|
$items = msortv($items, 'getSortVector');
|
|
|
|
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
$object = $this->getProfileObject();
|
|
|
|
|
2017-01-17 21:46:05 +01:00
|
|
|
// If we have some global items and some custom items and are in "combined"
|
|
|
|
// mode, put a hard-coded divider item between them.
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
if ($mode == self::MODE_COMBINED) {
|
2017-01-17 21:46:05 +01:00
|
|
|
$list = array();
|
|
|
|
$seen_custom = false;
|
|
|
|
$seen_global = false;
|
|
|
|
foreach ($items as $item) {
|
|
|
|
if ($item->getCustomPHID()) {
|
|
|
|
$seen_custom = true;
|
|
|
|
} else {
|
|
|
|
if ($seen_custom && !$seen_global) {
|
|
|
|
$list[] = $this->newItem()
|
|
|
|
->setBuiltinKey(self::ITEM_CUSTOM_DIVIDER)
|
|
|
|
->setMenuItemKey(PhabricatorDividerProfileMenuItem::MENUITEMKEY)
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 19:48:03 +01:00
|
|
|
->attachProfileObject($object)
|
2017-01-17 21:46:05 +01:00
|
|
|
->attachMenuItem(
|
|
|
|
new PhabricatorDividerProfileMenuItem());
|
|
|
|
}
|
|
|
|
$seen_global = true;
|
|
|
|
}
|
|
|
|
$list[] = $item;
|
|
|
|
}
|
|
|
|
$items = $list;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Normalize keys since callers shouldn't rely on this array being
|
|
|
|
// partially keyed.
|
|
|
|
$items = array_values($items);
|
|
|
|
|
|
|
|
return $items;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-12 19:27:39 +01:00
|
|
|
}
|