1
0
Fork 0
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:
epriestley 2016-01-13 10:40:31 -08:00
parent 1c5167dc74
commit 473693786b
4 changed files with 95 additions and 1 deletions

View file

@ -16,6 +16,7 @@ final class PhabricatorProfilePanelEditor
$types[] = PhabricatorProfilePanelConfigurationTransaction::TYPE_PROPERTY;
$types[] = PhabricatorProfilePanelConfigurationTransaction::TYPE_ORDER;
$types[] = PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY;
return $types;
}
@ -30,6 +31,8 @@ final class PhabricatorProfilePanelEditor
return $object->getPanelProperty($key, null);
case PhabricatorProfilePanelConfigurationTransaction::TYPE_ORDER:
return $object->getPanelOrder();
case PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY:
return $object->getVisibility();
}
}
@ -39,6 +42,7 @@ final class PhabricatorProfilePanelEditor
switch ($xaction->getTransactionType()) {
case PhabricatorProfilePanelConfigurationTransaction::TYPE_PROPERTY:
case PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY:
return $xaction->getNewValue();
case PhabricatorProfilePanelConfigurationTransaction::TYPE_ORDER:
return (int)$xaction->getNewValue();
@ -58,6 +62,9 @@ final class PhabricatorProfilePanelEditor
case PhabricatorProfilePanelConfigurationTransaction::TYPE_ORDER:
$object->setPanelOrder($xaction->getNewValue());
return;
case PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY:
$object->setVisibility($xaction->getNewValue());
return;
}
return parent::applyCustomInternalTransaction($object, $xaction);
@ -70,6 +77,7 @@ final class PhabricatorProfilePanelEditor
switch ($xaction->getTransactionType()) {
case PhabricatorProfilePanelConfigurationTransaction::TYPE_PROPERTY:
case PhabricatorProfilePanelConfigurationTransaction::TYPE_ORDER:
case PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY:
return;
}

View file

@ -53,7 +53,7 @@ final class PhabricatorProfilePanelEngine extends Phobject {
$panel_id_int = (int)$panel_id;
foreach ($panel_list as $panel) {
if ($panel_id_int) {
if ((int)$panel->getID() === $panel_id) {
if ((int)$panel->getID() === $panel_id_int) {
$selected_panel = $panel;
break;
}
@ -101,6 +101,9 @@ final class PhabricatorProfilePanelEngine extends Phobject {
case 'builtin':
$content = $this->buildPanelBuiltinContent($selected_panel);
break;
case 'hide':
$content = $this->buildPanelHideContent($selected_panel);
break;
case 'edit':
$content = $this->buildPanelEditContent();
break;
@ -134,6 +137,10 @@ final class PhabricatorProfilePanelEngine extends Phobject {
$panels = $this->getPanels();
foreach ($panels as $panel) {
if ($panel->isDisabled()) {
continue;
}
$items = $panel->buildNavigationMenuItems();
foreach ($items as $item) {
$this->validateNavigationMenuItem($item);
@ -435,9 +442,22 @@ final class PhabricatorProfilePanelEngine extends Phobject {
if ($id) {
$item->setHref($this->getPanelURI("edit/{$id}/"));
$hide_uri = $this->getPanelURI("hide/{$id}/");
} else {
$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);
@ -573,4 +593,58 @@ final class PhabricatorProfilePanelEngine extends Phobject {
->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'));
}
}

View file

@ -56,6 +56,13 @@ final class PhabricatorProfilePanelConfiguration
) + parent::getConfiguration();
}
public static function getVisibilityNameMap() {
return array(
self::VISIBILITY_VISIBLE => pht('Visible'),
self::VISIBILITY_DISABLED => pht('Disabled'),
);
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
PhabricatorProfilePanelPHIDType::TYPECONST);
@ -115,6 +122,10 @@ final class PhabricatorProfilePanelConfiguration
$this->getID());
}
public function isDisabled() {
return ($this->getVisibility() === self::VISIBILITY_DISABLED);
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */

View file

@ -5,6 +5,7 @@ final class PhabricatorProfilePanelConfigurationTransaction
const TYPE_PROPERTY = 'profilepanel.property';
const TYPE_ORDER = 'profilepanel.order';
const TYPE_VISIBILITY = 'profilepanel.visibility';
public function getApplicationName() {
return 'search';