1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-23 03:59:25 +01:00

Introduce some convenience methods for handle rendering

Summary:
So I don't have to copy/paste everything again.

Used them at places I could find with my limited `grep` skills.

Test Plan: Visited hovercards, revision and tasks. No crashes.

Reviewers: epriestley, btrahan, chad

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5592
This commit is contained in:
Anh Nhan Nguyen 2013-04-05 17:01:35 -07:00 committed by epriestley
parent e1b8c9d261
commit 843d0bdcde
6 changed files with 54 additions and 29 deletions

View file

@ -3043,7 +3043,7 @@ celerity_register_resource_map(array(
),
'phabricator-hovercard' =>
array(
'uri' => '/res/a6eafd28/rsrc/js/application/core/Hovercard.js',
'uri' => '/res/345f3fca/rsrc/js/application/core/Hovercard.js',
'type' => 'js',
'requires' =>
array(

View file

@ -1720,6 +1720,8 @@ phutil_register_library_map(array(
'celerity_generate_unique_node_id' => 'infrastructure/celerity/api.php',
'celerity_get_resource_uri' => 'infrastructure/celerity/api.php',
'celerity_register_resource_map' => 'infrastructure/celerity/map.php',
'implode_handle_links' => 'applications/phid/handle/view/render.php',
'implode_selected_handle_links' => 'applications/phid/handle/view/render.php',
'javelin_render_tag' => 'infrastructure/javelin/markup.php',
'javelin_tag' => 'infrastructure/javelin/markup.php',
'phabricator_date' => 'view/viewutils.php',

View file

@ -278,12 +278,9 @@ abstract class PhabricatorController extends AphrontController {
throw new Exception("Unknown handle list style '{$style}'!");
}
$items = array();
foreach ($phids as $phid) {
$items[] = $this->getHandle($phid)->renderLink();
}
return phutil_implode_html($style_map[$style], $items);
return implode_selected_handle_links($style_map[$style],
$this->getLoadedHandles(),
$phids);
}
protected function buildApplicationMenu() {

View file

@ -277,13 +277,8 @@ abstract class DifferentialFieldSpecification {
return phutil_tag('em', array(), pht('None'));
}
$links = array();
foreach ($user_phids as $user_phid) {
$handle = $this->getHandle($user_phid);
$links[] = $handle->renderLink();
}
return phutil_implode_html(', ', $links);
return implode_selected_handle_links(', ',
$this->getLoadedHandles(), $user_phids);
}
@ -988,6 +983,14 @@ abstract class DifferentialFieldSpecification {
return $this->handles[$phid];
}
final protected function getLoadedHandles() {
if ($this->handles === null) {
throw new DifferentialFieldDataNotAvailableException($this);
}
return $this->handles;
}
/**
* Get the list of properties for a diff set by @{method:setManualDiff}.
*

View file

@ -60,7 +60,7 @@ final class ManiphestHovercardEventListener extends PhutilEventListener {
$hovercard->addField(pht('Assigned to'), $owner);
if ($project_phids) {
$hovercard->addField(pht('Projects'),
$this->renderHandlesForPHIDs($project_phids, $viewer_handles));
implode_selected_handle_links(', ', $viewer_handles, $project_phids));
}
if ($edge_phids) {
@ -84,9 +84,8 @@ final class ManiphestHovercardEventListener extends PhutilEventListener {
$hovercard->addField(
$edge_name,
$this->renderHandlesForPHIDs(
array_keys($edges[$edge_type]),
$viewer_handles)
implode_selected_handle_links(', ', $viewer_handles,
array_keys($edges[$edge_type]))
->appendHTML($edge_overflow));
}
}
@ -104,15 +103,4 @@ final class ManiphestHovercardEventListener extends PhutilEventListener {
->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

@ -0,0 +1,35 @@
<?php
/**
* Implodes a list of handles, rendering their links
*
* @group handle
* @return PhutilSafeHTML
*/
function implode_handle_links($glue, array $handles) {
$items = array();
foreach ($handles as $handle) {
$items[] = $handle->renderLink();
}
return phutil_implode_html($glue, $items);
}
/**
* Like @{function:implode_handle_links}Implodes selected handles from a pool of
* handles. Useful if you load handles for various phids, but only render a few
* of them at a time
*
* @group handle
* @return PhutilSafeHTML
*/
function implode_selected_handle_links($glue, array $handles, array $phids) {
$items = array();
foreach ($phids as $phid) {
$items[] = $handles[$phid]->renderLink();
}
return phutil_implode_html($glue, $items);
}