From 1e4e121956e7877af24f6e47d8bdb0571fb57f3f Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 5 Jun 2015 14:20:25 -0700 Subject: [PATCH] Put Spaces on Hovercards and ObjectItemLists Summary: Ref T8449. Test Plan: {F474186} {F474187} Reviewers: btrahan Reviewed By: btrahan Subscribers: chad, epriestley Maniphest Tasks: T8449 Differential Revision: https://secure.phabricator.com/D13173 --- src/__phutil_library_map__.php | 2 + .../PhabricatorSearchHovercardController.php | 23 ++++++---- .../query/PhabricatorSpacesNamespaceQuery.php | 29 ++++++++++++ .../view/PHUISpacesNamespaceContextView.php | 36 +++++++++++++++ src/view/phui/PHUIHeaderView.php | 45 +++---------------- src/view/phui/PHUIObjectItemListView.php | 6 +++ src/view/phui/PHUIObjectItemView.php | 13 +++++- .../hovercard/PhabricatorHovercardView.php | 23 ++++++++-- 8 files changed, 125 insertions(+), 52 deletions(-) create mode 100644 src/applications/spaces/view/PHUISpacesNamespaceContextView.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 20d6e988f5..756bbfcbd2 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1228,6 +1228,7 @@ phutil_register_library_map(array( 'PHUIPropertyListExample' => 'applications/uiexample/examples/PHUIPropertyListExample.php', 'PHUIPropertyListView' => 'view/phui/PHUIPropertyListView.php', 'PHUIRemarkupPreviewPanel' => 'view/phui/PHUIRemarkupPreviewPanel.php', + 'PHUISpacesNamespaceContextView' => 'applications/spaces/view/PHUISpacesNamespaceContextView.php', 'PHUIStatusItemView' => 'view/phui/PHUIStatusItemView.php', 'PHUIStatusListView' => 'view/phui/PHUIStatusListView.php', 'PHUITagExample' => 'applications/uiexample/examples/PHUITagExample.php', @@ -4589,6 +4590,7 @@ phutil_register_library_map(array( 'PHUIPropertyListExample' => 'PhabricatorUIExample', 'PHUIPropertyListView' => 'AphrontView', 'PHUIRemarkupPreviewPanel' => 'AphrontTagView', + 'PHUISpacesNamespaceContextView' => 'AphrontView', 'PHUIStatusItemView' => 'AphrontTagView', 'PHUIStatusListView' => 'AphrontTagView', 'PHUITagExample' => 'PhabricatorUIExample', diff --git a/src/applications/search/controller/PhabricatorSearchHovercardController.php b/src/applications/search/controller/PhabricatorSearchHovercardController.php index 06422f9e79..a05a2392b5 100644 --- a/src/applications/search/controller/PhabricatorSearchHovercardController.php +++ b/src/applications/search/controller/PhabricatorSearchHovercardController.php @@ -7,18 +7,17 @@ final class PhabricatorSearchHovercardController return true; } - public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $viewer = $this->getViewer(); $phids = $request->getArr('phids'); $handles = id(new PhabricatorHandleQuery()) - ->setViewer($user) + ->setViewer($viewer) ->withPHIDs($phids) ->execute(); $objects = id(new PhabricatorObjectQuery()) - ->setViewer($user) + ->setViewer($viewer) ->withPHIDs($phids) ->execute(); @@ -26,9 +25,15 @@ final class PhabricatorSearchHovercardController foreach ($phids as $phid) { $handle = $handles[$phid]; + $object = $objects[$phid]; - $hovercard = new PhabricatorHovercardView(); - $hovercard->setObjectHandle($handle); + $hovercard = id(new PhabricatorHovercardView()) + ->setUser($viewer) + ->setObjectHandle($handle); + + if ($object) { + $hovercard->setObject($object); + } // Send it to the other side of the world, thanks to PhutilEventEngine $event = new PhabricatorEvent( @@ -36,9 +41,9 @@ final class PhabricatorSearchHovercardController array( 'hovercard' => $hovercard, 'handle' => $handle, - 'object' => idx($objects, $phid), + 'object' => $object, )); - $event->setUser($user); + $event->setUser($viewer); PhutilEventEngine::dispatchEvent($event); $cards[$phid] = $hovercard; diff --git a/src/applications/spaces/query/PhabricatorSpacesNamespaceQuery.php b/src/applications/spaces/query/PhabricatorSpacesNamespaceQuery.php index 6280136de4..ac02c306e7 100644 --- a/src/applications/spaces/query/PhabricatorSpacesNamespaceQuery.php +++ b/src/applications/spaces/query/PhabricatorSpacesNamespaceQuery.php @@ -145,4 +145,33 @@ final class PhabricatorSpacesNamespaceQuery return $result; } + /** + * Get the Space PHID for an object, if one exists. + * + * This is intended to simplify performing a bunch of redundant checks; you + * can intentionally pass any value in (including `null`). + * + * @param wild + * @return phid|null + */ + public static function getObjectSpacePHID($object) { + if (!$object) { + return null; + } + + if (!($object instanceof PhabricatorSpacesInterface)) { + return null; + } + + $space_phid = $object->getSpacePHID(); + if ($space_phid === null) { + $default_space = self::getDefaultSpace(); + if ($default_space) { + $space_phid = $default_space->getPHID(); + } + } + + return $space_phid; + } + } diff --git a/src/applications/spaces/view/PHUISpacesNamespaceContextView.php b/src/applications/spaces/view/PHUISpacesNamespaceContextView.php new file mode 100644 index 0000000000..ed28f53349 --- /dev/null +++ b/src/applications/spaces/view/PHUISpacesNamespaceContextView.php @@ -0,0 +1,36 @@ +object = $object; + return $this; + } + + public function getObject() { + return $this->object; + } + + public function render() { + $object = $this->getObject(); + + $space_phid = PhabricatorSpacesNamespaceQuery::getObjectSpacePHID($object); + if (!$space_phid) { + return null; + } + + $viewer = $this->getUser(); + return phutil_tag( + 'span', + array( + 'class' => 'spaces-name', + ), + array( + $viewer->renderHandle($space_phid), + ' | ', + )); + } + +} diff --git a/src/view/phui/PHUIHeaderView.php b/src/view/phui/PHUIHeaderView.php index 62842001a7..29aa2d07df 100644 --- a/src/view/phui/PHUIHeaderView.php +++ b/src/view/phui/PHUIHeaderView.php @@ -172,9 +172,14 @@ final class PHUIHeaderView extends AphrontTagView { ' '); } - $header = array(); + $viewer = $this->getUser(); - $header[] = $this->renderObjectSpaceInformation(); + $header = array(); + if ($viewer) { + $header[] = id(new PHUISpacesNamespaceContextView()) + ->setUser($viewer) + ->setObject($this->policyObject); + } if ($this->objectName) { $header[] = array( @@ -297,40 +302,4 @@ final class PHUIHeaderView extends AphrontTagView { return array($icon, $link); } - private function renderObjectSpaceInformation() { - $viewer = $this->getUser(); - - $object = $this->policyObject; - if (!$object) { - return; - } - - if (!($object instanceof PhabricatorSpacesInterface)) { - return; - } - - $space_phid = $object->getSpacePHID(); - if ($space_phid === null) { - $default_space = PhabricatorSpacesNamespaceQuery::getDefaultSpace(); - if ($default_space) { - $space_phid = $default_space->getPHID(); - } - } - - if ($space_phid === null) { - return; - } - - return phutil_tag( - 'span', - array( - 'class' => 'spaces-name', - ), - array( - $viewer->renderHandle($space_phid), - ' | ', - )); - } - - } diff --git a/src/view/phui/PHUIObjectItemListView.php b/src/view/phui/PHUIObjectItemListView.php index 108a2d6500..1bd5e3b23b 100644 --- a/src/view/phui/PHUIObjectItemListView.php +++ b/src/view/phui/PHUIObjectItemListView.php @@ -90,6 +90,7 @@ final class PHUIObjectItemListView extends AphrontTagView { } protected function getTagContent() { + $viewer = $this->getUser(); require_celerity_resource('phui-object-item-list-view-css'); $header = null; @@ -103,6 +104,11 @@ final class PHUIObjectItemListView extends AphrontTagView { } if ($this->items) { + if ($viewer) { + foreach ($this->items as $item) { + $item->setUser($viewer); + } + } $items = $this->items; } else if ($this->allowEmptyList) { $items = null; diff --git a/src/view/phui/PHUIObjectItemView.php b/src/view/phui/PHUIObjectItemView.php index 812fa993c2..6b530303a1 100644 --- a/src/view/phui/PHUIObjectItemView.php +++ b/src/view/phui/PHUIObjectItemView.php @@ -323,12 +323,21 @@ final class PHUIObjectItemView extends AphrontTagView { } protected function getTagContent() { + $viewer = $this->getUser(); + $content_classes = array(); $content_classes[] = 'phui-object-item-content'; - $header_name = null; + $header_name = array(); + + if ($viewer) { + $header_name[] = id(new PHUISpacesNamespaceContextView()) + ->setUser($viewer) + ->setObject($this->object); + } + if ($this->objectName) { - $header_name = array( + $header_name[] = array( phutil_tag( 'span', array( diff --git a/src/view/widget/hovercard/PhabricatorHovercardView.php b/src/view/widget/hovercard/PhabricatorHovercardView.php index e342feccee..3c938f3e61 100644 --- a/src/view/widget/hovercard/PhabricatorHovercardView.php +++ b/src/view/widget/hovercard/PhabricatorHovercardView.php @@ -10,6 +10,7 @@ final class PhabricatorHovercardView extends AphrontView { * @var PhabricatorObjectHandle */ private $handle; + private $object; private $title = array(); private $detail; @@ -23,6 +24,15 @@ final class PhabricatorHovercardView extends AphrontView { return $this; } + public function setObject($object) { + $this->object = $object; + return $this; + } + + public function getObject() { + return $this->object; + } + public function setTitle($title) { $this->title = $title; return $this; @@ -65,13 +75,20 @@ final class PhabricatorHovercardView extends AphrontView { throw new PhutilInvalidStateException('setObjectHandle'); } + $viewer = $this->getUser(); $handle = $this->handle; require_celerity_resource('phabricator-hovercard-view-css'); - $title = pht('%s: %s', - $handle->getTypeName(), - $this->title ? $this->title : $handle->getName()); + $title = array( + id(new PHUISpacesNamespaceContextView()) + ->setUser($viewer) + ->setObject($this->getObject()), + pht( + '%s: %s', + $handle->getTypeName(), + $this->title ? $this->title : $handle->getName()), + ); $header = new PHUIActionHeaderView(); $header->setHeaderColor($this->color);