diff --git a/src/applications/search/editor/PhabricatorProfilePanelEditor.php b/src/applications/search/editor/PhabricatorProfilePanelEditor.php --- a/src/applications/search/editor/PhabricatorProfilePanelEditor.php +++ b/src/applications/search/editor/PhabricatorProfilePanelEditor.php @@ -16,6 +16,7 @@ $types[] = PhabricatorProfilePanelConfigurationTransaction::TYPE_PROPERTY; $types[] = PhabricatorProfilePanelConfigurationTransaction::TYPE_ORDER; + $types[] = PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY; return $types; } @@ -30,6 +31,8 @@ return $object->getPanelProperty($key, null); case PhabricatorProfilePanelConfigurationTransaction::TYPE_ORDER: return $object->getPanelOrder(); + case PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY: + return $object->getVisibility(); } } @@ -39,6 +42,7 @@ 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 @@ 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 @@ 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 --- a/src/applications/search/engine/PhabricatorProfilePanelEngine.php +++ b/src/applications/search/engine/PhabricatorProfilePanelEngine.php @@ -53,7 +53,7 @@ $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 @@ 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 @@ $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 @@ 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 @@ ->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 --- a/src/applications/search/storage/PhabricatorProfilePanelConfiguration.php +++ b/src/applications/search/storage/PhabricatorProfilePanelConfiguration.php @@ -56,6 +56,13 @@ ) + 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 @@ $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 --- a/src/applications/search/storage/PhabricatorProfilePanelConfigurationTransaction.php +++ b/src/applications/search/storage/PhabricatorProfilePanelConfigurationTransaction.php @@ -5,6 +5,7 @@ const TYPE_PROPERTY = 'profilepanel.property'; const TYPE_ORDER = 'profilepanel.order'; + const TYPE_VISIBILITY = 'profilepanel.visibility'; public function getApplicationName() { return 'search';