1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Collapse comments in long threads.

This commit is contained in:
epriestley 2011-02-05 11:06:56 -08:00
parent 18c0515440
commit 53f2a433f7
6 changed files with 140 additions and 14 deletions

View file

@ -127,7 +127,7 @@ celerity_register_resource_map(array(
),
'differential-revision-comment-list-css' =>
array(
'uri' => '/res/a1c117db/rsrc/css/application/differential/revision-comment-list.css',
'uri' => '/res/afbc5f6f/rsrc/css/application/differential/revision-comment-list.css',
'type' => 'css',
'requires' =>
array(
@ -293,6 +293,16 @@ celerity_register_resource_map(array(
),
'disk' => '/rsrc/js/application/differential/behavior-populate.js',
),
'javelin-behavior-differential-show-all-comments' =>
array(
'uri' => '/res/625fea99/rsrc/js/application/differential/behavior-show-all-comments.js',
'type' => 'js',
'requires' =>
array(
0 => 'javelin-lib-dev',
),
'disk' => '/rsrc/js/application/differential/behavior-show-all-comments.js',
),
'javelin-behavior-differential-show-more' =>
array(
'uri' => '/res/ea998002/rsrc/js/application/differential/behavior-show-more.js',
@ -400,7 +410,7 @@ celerity_register_resource_map(array(
'uri' => '/res/pkg/20cc4391/core.pkg.css',
'type' => 'css',
),
'33e57258' =>
'f7362a6c' =>
array (
'name' => 'differential.pkg.css',
'symbols' =>
@ -414,7 +424,7 @@ celerity_register_resource_map(array(
6 => 'differential-revision-add-comment-css',
7 => 'differential-revision-comment-list-css',
),
'uri' => '/res/pkg/33e57258/differential.pkg.css',
'uri' => '/res/pkg/f7362a6c/differential.pkg.css',
'type' => 'css',
),
'30d594cf' =>
@ -447,14 +457,14 @@ celerity_register_resource_map(array(
'phabricator-directory-css' => '20cc4391',
'phabricator-remarkup-css' => '20cc4391',
'syntax-highlighting-css' => '20cc4391',
'differential-core-view-css' => '33e57258',
'differential-changeset-view-css' => '33e57258',
'differential-revision-detail-css' => '33e57258',
'differential-revision-history-css' => '33e57258',
'differential-table-of-contents-css' => '33e57258',
'differential-revision-comment-css' => '33e57258',
'differential-revision-add-comment-css' => '33e57258',
'differential-revision-comment-list-css' => '33e57258',
'differential-core-view-css' => 'f7362a6c',
'differential-changeset-view-css' => 'f7362a6c',
'differential-revision-detail-css' => 'f7362a6c',
'differential-revision-history-css' => 'f7362a6c',
'differential-table-of-contents-css' => 'f7362a6c',
'differential-revision-comment-css' => 'f7362a6c',
'differential-revision-add-comment-css' => 'f7362a6c',
'differential-revision-comment-list-css' => 'f7362a6c',
'javelin-behavior-differential-feedback-preview' => '30d594cf',
'javelin-behavior-differential-edit-inline-comments' => '30d594cf',
'javelin-behavior-differential-populate' => '30d594cf',

View file

@ -82,6 +82,7 @@ class DifferentialRevisionViewController extends DifferentialController {
$comment_view->setHandles($handles);
$comment_view->setInlineComments($inlines);
$comment_view->setChangesets($changesets);
$comment_view->setUser($request->getUser());
$diff_history = new DifferentialRevisionUpdateHistoryView();
$diff_history->setDiffs($diffs);

View file

@ -22,6 +22,7 @@ final class DifferentialRevisionCommentListView extends AphrontView {
private $handles;
private $inlines;
private $changesets;
private $user;
public function setComments(array $comments) {
$this->comments = $comments;
@ -43,6 +44,11 @@ final class DifferentialRevisionCommentListView extends AphrontView {
return $this;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function render() {
require_celerity_resource('differential-revision-comment-list-css');
@ -53,7 +59,7 @@ final class DifferentialRevisionCommentListView extends AphrontView {
$inlines = mgroup($this->inlines, 'getCommentID');
$comments = array();
$html = array();
foreach ($this->comments as $comment) {
$view = new DifferentialRevisionCommentView();
$view->setComment($comment);
@ -62,12 +68,94 @@ final class DifferentialRevisionCommentListView extends AphrontView {
$view->setInlineComments(idx($inlines, $comment->getID(), array()));
$view->setChangesets($this->changesets);
$comments[] = $view->render();
$html[] = $view->render();
}
$objs = array_reverse(array_values($this->comments));
$html = array_reverse(array_values($html));
$user = $this->user;
$last_comment = null;
// Find the most recent comment by the viewer.
foreach ($objs as $position => $comment) {
if ($user && ($comment->getAuthorPHID() == $user->getPHID())) {
if ($last_comment === null) {
$last_comment = $position;
} else if ($last_comment == $position - 1) {
// If the viewer made several comments in a row, show them all. This
// is a spaz rule for epriestley.
$last_comment = $position;
}
}
}
$header = array();
$hidden = array();
if ($last_comment !== null) {
foreach ($objs as $position => $comment) {
if (!$comment->getID()) {
// These are synthetic comments with summary/test plan information.
$header[] = $html[$position];
unset($html[$position]);
continue;
}
if ($position <= $last_comment) {
// Always show comments after the viewer's last comment.
continue;
}
if ($position < 3) {
// Always show the 3 most recent comments.
continue;
}
$hidden[] = $position;
}
}
if (count($hidden) <= 3) {
// Don't hide if there's not much to hide.
$hidden = array();
}
$header = array_reverse($header);
$hidden = array_select_keys($html, $hidden);
$visible = array_diff_key($html, $hidden);
$hidden = array_reverse($hidden);
$visible = array_reverse($visible);
if ($hidden) {
Javelin::initBehavior(
'differential-show-all-comments',
array(
'markup' => implode("\n", $hidden),
));
$hidden = javelin_render_tag(
'div',
array(
'sigil' => "differential-all-comments-container",
),
'<div class="differential-older-comments-are-hidden">'.
number_format(count($hidden)).' older comments are hidden. '.
javelin_render_tag(
'a',
array(
'href' => '#',
'mustcapture' => true,
'sigil' => 'differential-show-all-comments',
),
'Show all comments.').
'</div>');
} else {
$hidden = null;
}
return
'<div>'.
implode("\n", $comments).
implode("\n", $header).
$hidden.
implode("\n", $visible).
'</div>';
}
}

View file

@ -9,6 +9,8 @@
phutil_require_module('phabricator', 'applications/differential/parser/markup');
phutil_require_module('phabricator', 'applications/differential/view/revisioncomment');
phutil_require_module('phabricator', 'infrastructure/celerity/api');
phutil_require_module('phabricator', 'infrastructure/javelin/api');
phutil_require_module('phabricator', 'infrastructure/javelin/markup');
phutil_require_module('phabricator', 'view/base');
phutil_require_module('phutil', 'utils');

View file

@ -2,3 +2,10 @@
* @provides differential-revision-comment-list-css
*/
.differential-older-comments-are-hidden {
background: #f0f0f0;
border: 1px solid #d6d6d6;
text-align: center;
padding: 1em;
color: #666666;
}

View file

@ -0,0 +1,18 @@
/**
* @provides javelin-behavior-differential-show-all-comments
* @requires javelin-lib-dev
*/
JX.behavior('differential-show-all-comments', function(config) {
JX.Stratcom.listen(
'click',
'differential-show-all-comments',
function(e) {
JX.DOM.setContent(
e.getNode('differential-all-comments-container'),
JX.HTML(config.markup));
e.kill();
});
});