mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 12:30:56 +01:00
Render "Show Context" blocks in unified view
Summary: Ref T2009. This basically copy/pastes them for now. Plans is: - Make this actually work all the way. - Add test coverage after D11970. - Move 2-up here after test coverage. Clicking the links does not work yet, because they use the 2-up renderer. I'll fix this in the next diff. Test Plan: Viewed diffs in unified, saw links to show more. Reviewers: btrahan Reviewed By: btrahan Subscribers: chad, epriestley Maniphest Tasks: T2009 Differential Revision: https://secure.phabricator.com/D11976
This commit is contained in:
parent
175a989e28
commit
06df75ebbd
4 changed files with 137 additions and 1 deletions
|
@ -439,4 +439,92 @@ abstract class DifferentialChangesetHTMLRenderer
|
|||
->setAllowReply($allow_reply);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build links which users can click to show more context in a changeset.
|
||||
*
|
||||
* @param int Beginning of the line range to build links for.
|
||||
* @param int Length of the line range to build links for.
|
||||
* @param int Total number of lines in the changeset.
|
||||
* @return markup Rendered links.
|
||||
*/
|
||||
protected function renderShowContextLinks($top, $len, $changeset_length) {
|
||||
$block_size = 20;
|
||||
$end = ($top + $len) - $block_size;
|
||||
|
||||
// If this is a large block, such that the "top" and "bottom" ranges are
|
||||
// non-overlapping, we'll provide options to show the top, bottom or entire
|
||||
// block. For smaller blocks, we only provide an option to show the entire
|
||||
// block, since it would be silly to show the bottom 20 lines of a 25-line
|
||||
// block.
|
||||
$is_large_block = ($len > ($block_size * 2));
|
||||
|
||||
$links = array();
|
||||
|
||||
if ($is_large_block) {
|
||||
$is_first_block = ($top == 0);
|
||||
if ($is_first_block) {
|
||||
$text = pht('Show First %d Line(s)', $block_size);
|
||||
} else {
|
||||
$text = pht("\xE2\x96\xB2 Show %d Line(s)", $block_size);
|
||||
}
|
||||
|
||||
$links[] = $this->renderShowContextLink(
|
||||
false,
|
||||
"{$top}-{$len}/{$top}-20",
|
||||
$text);
|
||||
}
|
||||
|
||||
$links[] = $this->renderShowContextLink(
|
||||
true,
|
||||
"{$top}-{$len}/{$top}-{$len}",
|
||||
pht('Show All %d Line(s)', $len));
|
||||
|
||||
if ($is_large_block) {
|
||||
$is_last_block = (($top + $len) >= $changeset_length);
|
||||
if ($is_last_block) {
|
||||
$text = pht('Show Last %d Line(s)', $block_size);
|
||||
} else {
|
||||
$text = pht("\xE2\x96\xBC Show %d Line(s)", $block_size);
|
||||
}
|
||||
|
||||
$links[] = $this->renderShowContextLink(
|
||||
false,
|
||||
"{$top}-{$len}/{$end}-20",
|
||||
$text);
|
||||
}
|
||||
|
||||
return phutil_implode_html(" \xE2\x80\xA2 ", $links);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build a link that shows more context in a changeset.
|
||||
*
|
||||
* See @{method:renderShowContextLinks}.
|
||||
*
|
||||
* @param bool Does this link show all context when clicked?
|
||||
* @param string Range specification for lines to show.
|
||||
* @param string Text of the link.
|
||||
* @return markup Rendered link.
|
||||
*/
|
||||
private function renderShowContextLink($is_all, $range, $text) {
|
||||
$reference = $this->getRenderingReference();
|
||||
|
||||
return javelin_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => '#',
|
||||
'mustcapture' => true,
|
||||
'sigil' => 'show-more',
|
||||
'meta' => array(
|
||||
'type' => ($is_all ? 'all' : null),
|
||||
'ref' => $reference,
|
||||
'range' => $range,
|
||||
),
|
||||
),
|
||||
$text);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -69,9 +69,28 @@ final class DifferentialChangesetOneUpRenderer
|
|||
break;
|
||||
case 'no-context':
|
||||
$out[] = hsprintf(
|
||||
'<tr><td class="show-more" colspan="3">%s</th></tr>',
|
||||
'<tr><td class="show-more" colspan="3">%s</td></tr>',
|
||||
pht('Context not available.'));
|
||||
break;
|
||||
case 'context':
|
||||
$top = $p['top'];
|
||||
$len = $p['len'];
|
||||
|
||||
$links = $this->renderShowContextLinks($top, $len, $rows);
|
||||
|
||||
$out[] = javelin_tag(
|
||||
'tr',
|
||||
array(
|
||||
'sigil' => 'context-target',
|
||||
),
|
||||
phutil_tag(
|
||||
'td',
|
||||
array(
|
||||
'class' => 'show-more',
|
||||
'colspan' => 3,
|
||||
),
|
||||
$links));
|
||||
break;
|
||||
default:
|
||||
$out[] = hsprintf('<tr><th /><th /><td>%s</td></tr>', $type);
|
||||
break;
|
||||
|
|
|
@ -84,6 +84,9 @@ final class DifferentialChangesetTwoUpRenderer
|
|||
// increments $ii by the entire size of the gap and then continues
|
||||
// the loop.
|
||||
$gap = array_pop($gaps);
|
||||
|
||||
// TODO: Move this to renderShowContextLinks() once that is stable.
|
||||
|
||||
$top = $gap[0];
|
||||
$len = $gap[1];
|
||||
|
||||
|
|
|
@ -941,6 +941,32 @@ final class PhabricatorUSEnglishTranslation
|
|||
'allowed domains will be able to register an account: %3$s',
|
||||
),
|
||||
),
|
||||
|
||||
'Show First %d Line(s)' => array(
|
||||
'Show First Line',
|
||||
'Show First %d Lines',
|
||||
),
|
||||
|
||||
"\xE2\x96\xB2 Show %d Line(s)" => array(
|
||||
"\xE2\x96\xB2 Show %d Line(s)",
|
||||
"\xE2\x96\xB2 Show %d Line(s)",
|
||||
),
|
||||
|
||||
'Show All %d Line(s)' => array(
|
||||
'Show Line',
|
||||
'Show All %d Lines',
|
||||
),
|
||||
|
||||
"\xE2\x96\xBC Show %d Line(s)" => array(
|
||||
"\xE2\x96\xBC Show Line",
|
||||
"\xE2\x96\xBC Show %d Lines",
|
||||
),
|
||||
|
||||
'Show Last %d Line(s)' => array(
|
||||
'Show Last Line',
|
||||
'Show Last %d Lines',
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue