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
This commit is contained in:
epriestley
2015-06-05 14:20:25 -07:00
parent 4f0d61436b
commit 1e4e121956
8 changed files with 125 additions and 52 deletions

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -0,0 +1,36 @@
<?php
final class PHUISpacesNamespaceContextView extends AphrontView {
private $object;
public function setObject($object) {
$this->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),
' | ',
));
}
}