mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 12:00:55 +01:00
Allow profile menu items to be disabled
Summary: Ref T10054. I made this a dropdown (currently: "Visible" or "Disabled") since I imagine we //miiiight// want to add a "Hidden, but click 'More' to reveal" state or do other special stuff in this vein. Not 100% sold on that but seemed within the realm of plausibility. Test Plan: {F1060759} Reviewers: chad Reviewed By: chad Maniphest Tasks: T10054 Differential Revision: https://secure.phabricator.com/D15012
This commit is contained in:
parent
1c5167dc74
commit
473693786b
4 changed files with 95 additions and 1 deletions
|
@ -16,6 +16,7 @@ final class PhabricatorProfilePanelEditor
|
||||||
|
|
||||||
$types[] = PhabricatorProfilePanelConfigurationTransaction::TYPE_PROPERTY;
|
$types[] = PhabricatorProfilePanelConfigurationTransaction::TYPE_PROPERTY;
|
||||||
$types[] = PhabricatorProfilePanelConfigurationTransaction::TYPE_ORDER;
|
$types[] = PhabricatorProfilePanelConfigurationTransaction::TYPE_ORDER;
|
||||||
|
$types[] = PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY;
|
||||||
|
|
||||||
return $types;
|
return $types;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +31,8 @@ final class PhabricatorProfilePanelEditor
|
||||||
return $object->getPanelProperty($key, null);
|
return $object->getPanelProperty($key, null);
|
||||||
case PhabricatorProfilePanelConfigurationTransaction::TYPE_ORDER:
|
case PhabricatorProfilePanelConfigurationTransaction::TYPE_ORDER:
|
||||||
return $object->getPanelOrder();
|
return $object->getPanelOrder();
|
||||||
|
case PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY:
|
||||||
|
return $object->getVisibility();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +42,7 @@ final class PhabricatorProfilePanelEditor
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
switch ($xaction->getTransactionType()) {
|
||||||
case PhabricatorProfilePanelConfigurationTransaction::TYPE_PROPERTY:
|
case PhabricatorProfilePanelConfigurationTransaction::TYPE_PROPERTY:
|
||||||
|
case PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY:
|
||||||
return $xaction->getNewValue();
|
return $xaction->getNewValue();
|
||||||
case PhabricatorProfilePanelConfigurationTransaction::TYPE_ORDER:
|
case PhabricatorProfilePanelConfigurationTransaction::TYPE_ORDER:
|
||||||
return (int)$xaction->getNewValue();
|
return (int)$xaction->getNewValue();
|
||||||
|
@ -58,6 +62,9 @@ final class PhabricatorProfilePanelEditor
|
||||||
case PhabricatorProfilePanelConfigurationTransaction::TYPE_ORDER:
|
case PhabricatorProfilePanelConfigurationTransaction::TYPE_ORDER:
|
||||||
$object->setPanelOrder($xaction->getNewValue());
|
$object->setPanelOrder($xaction->getNewValue());
|
||||||
return;
|
return;
|
||||||
|
case PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY:
|
||||||
|
$object->setVisibility($xaction->getNewValue());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::applyCustomInternalTransaction($object, $xaction);
|
return parent::applyCustomInternalTransaction($object, $xaction);
|
||||||
|
@ -70,6 +77,7 @@ final class PhabricatorProfilePanelEditor
|
||||||
switch ($xaction->getTransactionType()) {
|
switch ($xaction->getTransactionType()) {
|
||||||
case PhabricatorProfilePanelConfigurationTransaction::TYPE_PROPERTY:
|
case PhabricatorProfilePanelConfigurationTransaction::TYPE_PROPERTY:
|
||||||
case PhabricatorProfilePanelConfigurationTransaction::TYPE_ORDER:
|
case PhabricatorProfilePanelConfigurationTransaction::TYPE_ORDER:
|
||||||
|
case PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ final class PhabricatorProfilePanelEngine extends Phobject {
|
||||||
$panel_id_int = (int)$panel_id;
|
$panel_id_int = (int)$panel_id;
|
||||||
foreach ($panel_list as $panel) {
|
foreach ($panel_list as $panel) {
|
||||||
if ($panel_id_int) {
|
if ($panel_id_int) {
|
||||||
if ((int)$panel->getID() === $panel_id) {
|
if ((int)$panel->getID() === $panel_id_int) {
|
||||||
$selected_panel = $panel;
|
$selected_panel = $panel;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -101,6 +101,9 @@ final class PhabricatorProfilePanelEngine extends Phobject {
|
||||||
case 'builtin':
|
case 'builtin':
|
||||||
$content = $this->buildPanelBuiltinContent($selected_panel);
|
$content = $this->buildPanelBuiltinContent($selected_panel);
|
||||||
break;
|
break;
|
||||||
|
case 'hide':
|
||||||
|
$content = $this->buildPanelHideContent($selected_panel);
|
||||||
|
break;
|
||||||
case 'edit':
|
case 'edit':
|
||||||
$content = $this->buildPanelEditContent();
|
$content = $this->buildPanelEditContent();
|
||||||
break;
|
break;
|
||||||
|
@ -134,6 +137,10 @@ final class PhabricatorProfilePanelEngine extends Phobject {
|
||||||
$panels = $this->getPanels();
|
$panels = $this->getPanels();
|
||||||
|
|
||||||
foreach ($panels as $panel) {
|
foreach ($panels as $panel) {
|
||||||
|
if ($panel->isDisabled()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$items = $panel->buildNavigationMenuItems();
|
$items = $panel->buildNavigationMenuItems();
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
$this->validateNavigationMenuItem($item);
|
$this->validateNavigationMenuItem($item);
|
||||||
|
@ -435,9 +442,22 @@ final class PhabricatorProfilePanelEngine extends Phobject {
|
||||||
|
|
||||||
if ($id) {
|
if ($id) {
|
||||||
$item->setHref($this->getPanelURI("edit/{$id}/"));
|
$item->setHref($this->getPanelURI("edit/{$id}/"));
|
||||||
|
$hide_uri = $this->getPanelURI("hide/{$id}/");
|
||||||
} else {
|
} else {
|
||||||
$item->setHref($this->getPanelURI("builtin/{$builtin_key}/"));
|
$item->setHref($this->getPanelURI("builtin/{$builtin_key}/"));
|
||||||
|
$hide_uri = $this->getPanelURI("hide/{$builtin_key}/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$item->addAction(
|
||||||
|
id(new PHUIListItemView())
|
||||||
|
->setHref($hide_uri)
|
||||||
|
->setWorkflow(true)
|
||||||
|
->setIcon(pht('fa-eye')));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($panel->isDisabled()) {
|
||||||
|
$item->setDisabled(true);
|
||||||
|
$item->addIcon('fa-times grey', pht('Disabled'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$list->addItem($item);
|
$list->addItem($item);
|
||||||
|
@ -573,4 +593,58 @@ final class PhabricatorProfilePanelEngine extends Phobject {
|
||||||
->buildResponse();
|
->buildResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function buildPanelHideContent(
|
||||||
|
PhabricatorProfilePanelConfiguration $configuration) {
|
||||||
|
|
||||||
|
$controller = $this->getController();
|
||||||
|
$request = $controller->getRequest();
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
|
PhabricatorPolicyFilter::requireCapability(
|
||||||
|
$viewer,
|
||||||
|
$configuration,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT);
|
||||||
|
|
||||||
|
$v_visibility = $configuration->getVisibility();
|
||||||
|
if ($request->isFormPost()) {
|
||||||
|
$v_visibility = $request->getStr('visibility');
|
||||||
|
|
||||||
|
$type_visibility =
|
||||||
|
PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY;
|
||||||
|
|
||||||
|
$xactions = array();
|
||||||
|
|
||||||
|
$xactions[] = id(new PhabricatorProfilePanelConfigurationTransaction())
|
||||||
|
->setTransactionType($type_visibility)
|
||||||
|
->setNewValue($v_visibility);
|
||||||
|
|
||||||
|
$editor = id(new PhabricatorProfilePanelEditor())
|
||||||
|
->setContentSourceFromRequest($request)
|
||||||
|
->setActor($viewer)
|
||||||
|
->setContinueOnMissingFields(true)
|
||||||
|
->setContinueOnNoEffect(true)
|
||||||
|
->applyTransactions($configuration, $xactions);
|
||||||
|
|
||||||
|
return id(new AphrontRedirectResponse())
|
||||||
|
->setURI($this->getConfigureURI());
|
||||||
|
}
|
||||||
|
|
||||||
|
$map = PhabricatorProfilePanelConfiguration::getVisibilityNameMap();
|
||||||
|
|
||||||
|
$form = id(new AphrontFormView())
|
||||||
|
->setUser($viewer)
|
||||||
|
->appendControl(
|
||||||
|
id(new AphrontFormSelectControl())
|
||||||
|
->setName('visibility')
|
||||||
|
->setLabel(pht('Visibility'))
|
||||||
|
->setValue($v_visibility)
|
||||||
|
->setOptions($map));
|
||||||
|
|
||||||
|
return $controller->newDialog()
|
||||||
|
->setTitle(pht('Change Item Visibility'))
|
||||||
|
->appendForm($form)
|
||||||
|
->addCancelButton($this->getConfigureURI())
|
||||||
|
->addSubmitButton(pht('Save Changes'));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,13 @@ final class PhabricatorProfilePanelConfiguration
|
||||||
) + parent::getConfiguration();
|
) + parent::getConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getVisibilityNameMap() {
|
||||||
|
return array(
|
||||||
|
self::VISIBILITY_VISIBLE => pht('Visible'),
|
||||||
|
self::VISIBILITY_DISABLED => pht('Disabled'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function generatePHID() {
|
public function generatePHID() {
|
||||||
return PhabricatorPHID::generateNewPHID(
|
return PhabricatorPHID::generateNewPHID(
|
||||||
PhabricatorProfilePanelPHIDType::TYPECONST);
|
PhabricatorProfilePanelPHIDType::TYPECONST);
|
||||||
|
@ -115,6 +122,10 @@ final class PhabricatorProfilePanelConfiguration
|
||||||
$this->getID());
|
$this->getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isDisabled() {
|
||||||
|
return ($this->getVisibility() === self::VISIBILITY_DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ final class PhabricatorProfilePanelConfigurationTransaction
|
||||||
|
|
||||||
const TYPE_PROPERTY = 'profilepanel.property';
|
const TYPE_PROPERTY = 'profilepanel.property';
|
||||||
const TYPE_ORDER = 'profilepanel.order';
|
const TYPE_ORDER = 'profilepanel.order';
|
||||||
|
const TYPE_VISIBILITY = 'profilepanel.visibility';
|
||||||
|
|
||||||
public function getApplicationName() {
|
public function getApplicationName() {
|
||||||
return 'search';
|
return 'search';
|
||||||
|
|
Loading…
Reference in a new issue