mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-23 12:09:12 +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:
parent
e1b8c9d261
commit
843d0bdcde
6 changed files with 54 additions and 29 deletions
|
@ -3043,7 +3043,7 @@ celerity_register_resource_map(array(
|
||||||
),
|
),
|
||||||
'phabricator-hovercard' =>
|
'phabricator-hovercard' =>
|
||||||
array(
|
array(
|
||||||
'uri' => '/res/a6eafd28/rsrc/js/application/core/Hovercard.js',
|
'uri' => '/res/345f3fca/rsrc/js/application/core/Hovercard.js',
|
||||||
'type' => 'js',
|
'type' => 'js',
|
||||||
'requires' =>
|
'requires' =>
|
||||||
array(
|
array(
|
||||||
|
|
|
@ -1720,6 +1720,8 @@ phutil_register_library_map(array(
|
||||||
'celerity_generate_unique_node_id' => 'infrastructure/celerity/api.php',
|
'celerity_generate_unique_node_id' => 'infrastructure/celerity/api.php',
|
||||||
'celerity_get_resource_uri' => 'infrastructure/celerity/api.php',
|
'celerity_get_resource_uri' => 'infrastructure/celerity/api.php',
|
||||||
'celerity_register_resource_map' => 'infrastructure/celerity/map.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_render_tag' => 'infrastructure/javelin/markup.php',
|
||||||
'javelin_tag' => 'infrastructure/javelin/markup.php',
|
'javelin_tag' => 'infrastructure/javelin/markup.php',
|
||||||
'phabricator_date' => 'view/viewutils.php',
|
'phabricator_date' => 'view/viewutils.php',
|
||||||
|
|
|
@ -278,12 +278,9 @@ abstract class PhabricatorController extends AphrontController {
|
||||||
throw new Exception("Unknown handle list style '{$style}'!");
|
throw new Exception("Unknown handle list style '{$style}'!");
|
||||||
}
|
}
|
||||||
|
|
||||||
$items = array();
|
return implode_selected_handle_links($style_map[$style],
|
||||||
foreach ($phids as $phid) {
|
$this->getLoadedHandles(),
|
||||||
$items[] = $this->getHandle($phid)->renderLink();
|
$phids);
|
||||||
}
|
|
||||||
|
|
||||||
return phutil_implode_html($style_map[$style], $items);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildApplicationMenu() {
|
protected function buildApplicationMenu() {
|
||||||
|
|
|
@ -277,13 +277,8 @@ abstract class DifferentialFieldSpecification {
|
||||||
return phutil_tag('em', array(), pht('None'));
|
return phutil_tag('em', array(), pht('None'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$links = array();
|
return implode_selected_handle_links(', ',
|
||||||
foreach ($user_phids as $user_phid) {
|
$this->getLoadedHandles(), $user_phids);
|
||||||
$handle = $this->getHandle($user_phid);
|
|
||||||
$links[] = $handle->renderLink();
|
|
||||||
}
|
|
||||||
|
|
||||||
return phutil_implode_html(', ', $links);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -988,6 +983,14 @@ abstract class DifferentialFieldSpecification {
|
||||||
return $this->handles[$phid];
|
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}.
|
* Get the list of properties for a diff set by @{method:setManualDiff}.
|
||||||
*
|
*
|
||||||
|
|
|
@ -60,7 +60,7 @@ final class ManiphestHovercardEventListener extends PhutilEventListener {
|
||||||
$hovercard->addField(pht('Assigned to'), $owner);
|
$hovercard->addField(pht('Assigned to'), $owner);
|
||||||
if ($project_phids) {
|
if ($project_phids) {
|
||||||
$hovercard->addField(pht('Projects'),
|
$hovercard->addField(pht('Projects'),
|
||||||
$this->renderHandlesForPHIDs($project_phids, $viewer_handles));
|
implode_selected_handle_links(', ', $viewer_handles, $project_phids));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($edge_phids) {
|
if ($edge_phids) {
|
||||||
|
@ -84,9 +84,8 @@ final class ManiphestHovercardEventListener extends PhutilEventListener {
|
||||||
|
|
||||||
$hovercard->addField(
|
$hovercard->addField(
|
||||||
$edge_name,
|
$edge_name,
|
||||||
$this->renderHandlesForPHIDs(
|
implode_selected_handle_links(', ', $viewer_handles,
|
||||||
array_keys($edges[$edge_type]),
|
array_keys($edges[$edge_type]))
|
||||||
$viewer_handles)
|
|
||||||
->appendHTML($edge_overflow));
|
->appendHTML($edge_overflow));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,15 +103,4 @@ final class ManiphestHovercardEventListener extends PhutilEventListener {
|
||||||
->loadHandles();
|
->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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
35
src/applications/phid/handle/view/render.php
Normal file
35
src/applications/phid/handle/view/render.php
Normal 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);
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue