diff --git a/src/applications/search/editor/PhabricatorProfilePanelEditor.php b/src/applications/search/editor/PhabricatorProfilePanelEditor.php index 09f51a1c36..ce4dbeb8f0 100644 --- a/src/applications/search/editor/PhabricatorProfilePanelEditor.php +++ b/src/applications/search/editor/PhabricatorProfilePanelEditor.php @@ -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; } diff --git a/src/applications/search/engine/PhabricatorProfilePanelEngine.php b/src/applications/search/engine/PhabricatorProfilePanelEngine.php index b74117a234..760665e5b2 100644 --- a/src/applications/search/engine/PhabricatorProfilePanelEngine.php +++ b/src/applications/search/engine/PhabricatorProfilePanelEngine.php @@ -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')); + } + } diff --git a/src/applications/search/storage/PhabricatorProfilePanelConfiguration.php b/src/applications/search/storage/PhabricatorProfilePanelConfiguration.php index 47489f1223..9ad16f6db9 100644 --- a/src/applications/search/storage/PhabricatorProfilePanelConfiguration.php +++ b/src/applications/search/storage/PhabricatorProfilePanelConfiguration.php @@ -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 )----------------------------------------- */ diff --git a/src/applications/search/storage/PhabricatorProfilePanelConfigurationTransaction.php b/src/applications/search/storage/PhabricatorProfilePanelConfigurationTransaction.php index 998e525bc9..28181cb217 100644 --- a/src/applications/search/storage/PhabricatorProfilePanelConfigurationTransaction.php +++ b/src/applications/search/storage/PhabricatorProfilePanelConfigurationTransaction.php @@ -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';