1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-20 13:52:40 +01:00

Add Maniphest Hovercard event listener

Summary:
Refs T1048
badassery

Test Plan: Used in a future diff. Verified correct appearance of hovercard

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T1048

Differential Revision: https://secure.phabricator.com/D5544
This commit is contained in:
Anh Nhan Nguyen 2013-04-03 10:05:48 -07:00 committed by epriestley
parent 81389e79e7
commit b14883bc6e
4 changed files with 122 additions and 0 deletions

View file

@ -618,6 +618,7 @@ phutil_register_library_map(array(
'ManiphestDefaultTaskExtensions' => 'applications/maniphest/extensions/ManiphestDefaultTaskExtensions.php',
'ManiphestEdgeEventListener' => 'applications/maniphest/event/ManiphestEdgeEventListener.php',
'ManiphestExportController' => 'applications/maniphest/controller/ManiphestExportController.php',
'ManiphestHovercardEventListener' => 'applications/maniphest/event/ManiphestHovercardEventListener.php',
'ManiphestPeopleMenuEventListener' => 'applications/maniphest/event/ManiphestPeopleMenuEventListener.php',
'ManiphestRemarkupRule' => 'applications/maniphest/remarkup/ManiphestRemarkupRule.php',
'ManiphestReplyHandler' => 'applications/maniphest/ManiphestReplyHandler.php',
@ -2289,6 +2290,7 @@ phutil_register_library_map(array(
'ManiphestDefaultTaskExtensions' => 'ManiphestTaskExtensions',
'ManiphestEdgeEventListener' => 'PhutilEventListener',
'ManiphestExportController' => 'ManiphestController',
'ManiphestHovercardEventListener' => 'PhutilEventListener',
'ManiphestPeopleMenuEventListener' => 'PhutilEventListener',
'ManiphestRemarkupRule' => 'PhabricatorRemarkupRuleObject',
'ManiphestReplyHandler' => 'PhabricatorMailReplyHandler',

View file

@ -39,6 +39,7 @@ final class PhabricatorApplicationManiphest extends PhabricatorApplication {
public function getEventListeners() {
return array(
new ManiphestPeopleMenuEventListener(),
new ManiphestHovercardEventListener(),
);
}

View file

@ -0,0 +1,117 @@
<?php
final class ManiphestHovercardEventListener extends PhutilEventListener {
public function register() {
$this->listen(PhabricatorEventType::TYPE_UI_DIDRENDERHOVERCARD);
}
public function handleEvent(PhutilEvent $event) {
switch ($event->getType()) {
case PhabricatorEventType::TYPE_UI_DIDRENDERHOVERCARD:
$this->handleHovercardEvent($event);
break;
}
}
private function handleHovercardEvent(PhutilEvent $event) {
$viewer = $event->getUser();
$hovercard = $event->getValue('hovercard');
$handle = $event->getValue('handle');
$phid = $handle->getPHID();
$task = $event->getValue('object');
if (!($task instanceof ManiphestTask)) {
return;
}
// Fun with "Unbeta Pholio", hua hua
$e_dep_on = PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK;
$e_dep_by = PhabricatorEdgeConfig::TYPE_TASK_DEPENDED_ON_BY_TASK;
$edge_query = id(new PhabricatorEdgeQuery())
->withSourcePHIDs(array($phid))
->withEdgeTypes(
array(
$e_dep_on,
$e_dep_by,
));
$edges = idx($edge_query->execute(), $phid);
$edge_phids = $edge_query->getDestinationPHIDs();
$owner_phid = $task->getOwnerPHID();
$project_phids = $task->getProjectPHIDs();
$phids = array_filter(array_merge(
array($owner_phid),
$edge_phids,
$project_phids));
$viewer_handles = $this->loadHandles($phids, $viewer);
$hovercard->setTitle(pht('T%d', $task->getID()))
->setDetail($task->getTitle());
$owner = phutil_tag('em', array(), pht('None'));
if ($owner_phid) {
$owner = $viewer_handles[$owner_phid]->renderLink();
}
$hovercard->addField(pht('Assigned to'), $owner);
if ($project_phids) {
$hovercard->addField(pht('Projects'),
$this->renderHandlesForPHIDs($project_phids, $viewer_handles));
}
if ($edge_phids) {
$edge_types = array(
PhabricatorEdgeConfig::TYPE_TASK_DEPENDED_ON_BY_TASK
=> pht('Dependent Tasks'),
PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK
=> pht('Depends On'),
);
$max_count = 6;
foreach ($edge_types as $edge_type => $edge_name) {
if ($edges[$edge_type]) {
// TODO: This can be made more sophisticated. We still load all
// edges into memory. Only load the ones we need.
$edge_overflow = array();
if (count($edges[$edge_type]) > $max_count) {
$edges[$edge_type] = array_slice($edges[$edge_type], 0, 6, true);
$edge_overflow = ', ...';
}
$hovercard->addField(
$edge_name,
$this->renderHandlesForPHIDs(
array_keys($edges[$edge_type]),
$viewer_handles)
->appendHTML($edge_overflow));
}
}
}
$hovercard->addTag(ManiphestView::renderTagForTask($task));
$event->setValue('hovercard', $hovercard);
}
protected function loadHandles(array $phids, $viewer) {
return id(new PhabricatorObjectHandleData($phids))
->setViewer($viewer)
->loadHandles();
}
protected function renderHandlesForPHIDs(array $phids,
array $handles, $glue = ', ') {
$items = array();
foreach ($phids as $phid) {
$items[] = $handles[$phid]->renderLink();
}
return phutil_implode_html($glue, $items);
}
}

View file

@ -31,5 +31,7 @@ final class PhabricatorEventType extends PhutilEventType {
const TYPE_UI_DIDRENDEROBJECTS = 'ui.didRenderObjects';
const TYPE_UI_WILLRENDERPROPERTIES = 'ui.willRenderProperties';
const TYPE_UI_DIDRENDERHOVERCARD = 'ui.didRenderHovercard';
const TYPE_PEOPLE_DIDRENDERMENU = 'people.didRenderMenu';
}