mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-18 21:02:41 +01:00
When all actions in a submenu are disabled, disable the submenu header
Summary: Fixes T11240. Also simplify things a little and share a bit more code. Test Plan: - Viewed revisions and tasks, opened submenu. - Viewed as a user without edit permission, saw the menus greyed out. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11240 Differential Revision: https://secure.phabricator.com/D16201
This commit is contained in:
parent
2a7545a452
commit
7574f8dcf5
5 changed files with 57 additions and 43 deletions
|
@ -527,22 +527,16 @@ final class DifferentialRevisionViewController extends DifferentialController {
|
|||
$viewer,
|
||||
$revision);
|
||||
|
||||
$parent_key = DifferentialRevisionHasParentRelationship::RELATIONSHIPKEY;
|
||||
$child_key = DifferentialRevisionHasChildRelationship::RELATIONSHIPKEY;
|
||||
$revision_actions = array(
|
||||
DifferentialRevisionHasParentRelationship::RELATIONSHIPKEY,
|
||||
DifferentialRevisionHasChildRelationship::RELATIONSHIPKEY,
|
||||
);
|
||||
|
||||
$revision_submenu = array();
|
||||
$revision_submenu = $relationship_list->newActionSubmenu($revision_actions)
|
||||
->setName(pht('Edit Related Revisions...'))
|
||||
->setIcon('fa-cog');
|
||||
|
||||
$revision_submenu[] = $relationship_list->getRelationship($parent_key)
|
||||
->newAction($revision);
|
||||
|
||||
$revision_submenu[] = $relationship_list->getRelationship($child_key)
|
||||
->newAction($revision);
|
||||
|
||||
$curtain->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setName(pht('Edit Related Revisions...'))
|
||||
->setIcon('fa-cog')
|
||||
->setSubmenu($revision_submenu));
|
||||
$curtain->addAction($revision_submenu);
|
||||
|
||||
$relationship_submenu = $relationship_list->newActionMenu();
|
||||
if ($relationship_submenu) {
|
||||
|
|
|
@ -199,28 +199,18 @@ final class ManiphestTaskDetailController extends ManiphestController {
|
|||
$viewer,
|
||||
$task);
|
||||
|
||||
$parent_key = ManiphestTaskHasParentRelationship::RELATIONSHIPKEY;
|
||||
$subtask_key = ManiphestTaskHasSubtaskRelationship::RELATIONSHIPKEY;
|
||||
$merge_key = ManiphestTaskMergeInRelationship::RELATIONSHIPKEY;
|
||||
$close_key = ManiphestTaskCloseAsDuplicateRelationship::RELATIONSHIPKEY;
|
||||
$submenu_actions = array(
|
||||
ManiphestTaskHasParentRelationship::RELATIONSHIPKEY,
|
||||
ManiphestTaskHasSubtaskRelationship::RELATIONSHIPKEY,
|
||||
ManiphestTaskMergeInRelationship::RELATIONSHIPKEY,
|
||||
ManiphestTaskCloseAsDuplicateRelationship::RELATIONSHIPKEY,
|
||||
);
|
||||
|
||||
$task_submenu[] = $relationship_list->getRelationship($parent_key)
|
||||
->newAction($task);
|
||||
$task_submenu = $relationship_list->newActionSubmenu($submenu_actions)
|
||||
->setName(pht('Edit Related Tasks...'))
|
||||
->setIcon('fa-anchor');
|
||||
|
||||
$task_submenu[] = $relationship_list->getRelationship($subtask_key)
|
||||
->newAction($task);
|
||||
|
||||
$task_submenu[] = $relationship_list->getRelationship($merge_key)
|
||||
->newAction($task);
|
||||
|
||||
$task_submenu[] = $relationship_list->getRelationship($close_key)
|
||||
->newAction($task);
|
||||
|
||||
$curtain->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setName(pht('Edit Related Tasks...'))
|
||||
->setIcon('fa-anchor')
|
||||
->setSubmenu($task_submenu));
|
||||
$curtain->addAction($task_submenu);
|
||||
|
||||
$relationship_submenu = $relationship_list->newActionMenu();
|
||||
if ($relationship_submenu) {
|
||||
|
|
|
@ -2,13 +2,6 @@
|
|||
|
||||
abstract class PhabricatorSearchBaseController extends PhabricatorController {
|
||||
|
||||
|
||||
const ACTION_ATTACH = 'attach';
|
||||
const ACTION_MERGE = 'merge';
|
||||
const ACTION_DEPENDENCIES = 'dependencies';
|
||||
const ACTION_BLOCKS = 'blocks';
|
||||
const ACTION_EDGE = 'edge';
|
||||
|
||||
protected function loadRelationshipObject() {
|
||||
$request = $this->getRequest();
|
||||
$viewer = $this->getViewer();
|
||||
|
|
|
@ -46,6 +46,26 @@ final class PhabricatorObjectRelationshipList extends Phobject {
|
|||
return $this->relationships;
|
||||
}
|
||||
|
||||
public function newActionSubmenu(array $keys) {
|
||||
$object = $this->getObject();
|
||||
|
||||
$actions = array();
|
||||
|
||||
foreach ($keys as $key) {
|
||||
$relationship = $this->getRelationship($key);
|
||||
if (!$relationship) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'No object relationship of type "%s" exists.',
|
||||
$key));
|
||||
}
|
||||
|
||||
$actions[$key] = $relationship->newAction($object);
|
||||
}
|
||||
|
||||
return $this->newMenuWithActions($actions);
|
||||
}
|
||||
|
||||
public function newActionMenu() {
|
||||
$relationships = $this->getRelationships();
|
||||
$object = $this->getObject();
|
||||
|
@ -65,9 +85,22 @@ final class PhabricatorObjectRelationshipList extends Phobject {
|
|||
|
||||
$actions = msort($actions, 'getName');
|
||||
|
||||
return id(new PhabricatorActionView())
|
||||
return $this->newMenuWithActions($actions)
|
||||
->setName(pht('Edit Related Objects...'))
|
||||
->setIcon('fa-link')
|
||||
->setIcon('fa-link');
|
||||
}
|
||||
|
||||
private function newMenuWithActions(array $actions) {
|
||||
$any_enabled = false;
|
||||
foreach ($actions as $action) {
|
||||
if (!$action->getDisabled()) {
|
||||
$any_enabled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return id(new PhabricatorActionView())
|
||||
->setDisabled(!$any_enabled)
|
||||
->setSubmenu($actions);
|
||||
}
|
||||
|
||||
|
|
|
@ -84,6 +84,10 @@ final class PhabricatorActionView extends AphrontView {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getDisabled() {
|
||||
return $this->disabled;
|
||||
}
|
||||
|
||||
public function setWorkflow($workflow) {
|
||||
$this->workflow = $workflow;
|
||||
return $this;
|
||||
|
|
Loading…
Reference in a new issue