From 5f46a61e6d514131dc77fd47cc81a03d959638c4 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 24 Feb 2012 14:14:39 -0800 Subject: [PATCH] Show audit comments on the Diffusion commit view Summary: We already allow you to create comments, but we don't show them on the commit page. After style / view unification this is easy; show comments on the commit page. Test Plan: Made comments on a commit using the audit too, saw them show up in Diffusion. Reviewers: btrahan, jungejason Reviewed By: btrahan CC: aran, epriestley Maniphest Tasks: T904 Differential Revision: https://secure.phabricator.com/D1687 --- src/__celerity_resource_map__.php | 48 +++---- src/__phutil_library_map__.php | 4 + .../PhabricatorAuditActionConstants.php | 10 +- .../commit/DiffusionCommitController.php | 18 +++ .../diffusion/controller/commit/__init__.php | 2 + .../view/comment/DiffusionCommentView.php | 132 ++++++++++++++++++ .../diffusion/view/comment/__init__.php | 17 +++ .../commentlist/DiffusionCommentListView.php | 70 ++++++++++ .../diffusion/view/commentlist/__init__.php | 15 ++ .../markup/engine/PhabricatorMarkupEngine.php | 5 + .../css/application/diffusion/commit-view.css | 12 ++ 11 files changed, 304 insertions(+), 29 deletions(-) create mode 100644 src/applications/diffusion/view/comment/DiffusionCommentView.php create mode 100644 src/applications/diffusion/view/comment/__init__.php create mode 100644 src/applications/diffusion/view/commentlist/DiffusionCommentListView.php create mode 100644 src/applications/diffusion/view/commentlist/__init__.php diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index 8fb5b990ea..a2bca84377 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -258,7 +258,7 @@ celerity_register_resource_map(array( ), 'diffusion-commit-view-css' => array( - 'uri' => '/res/bc39d876/rsrc/css/application/diffusion/commit-view.css', + 'uri' => '/res/d486f79a/rsrc/css/application/diffusion/commit-view.css', 'type' => 'css', 'requires' => array( @@ -1614,6 +1614,17 @@ celerity_register_resource_map(array( ), 'disk' => '/rsrc/css/application/slowvote/slowvote.css', ), + 0 => + array( + 'uri' => '/res/b6096fdd/rsrc/js/javelin/lib/__tests__/URI.js', + 'type' => 'js', + 'requires' => + array( + 0 => 'javelin-uri', + 1 => 'javelin-php-serializer', + ), + 'disk' => '/rsrc/js/javelin/lib/__tests__/URI.js', + ), 'phabricator-standard-page-view' => array( 'uri' => '/res/7e09bbfc/rsrc/css/application/base/standard-page-view.css', @@ -1625,7 +1636,7 @@ celerity_register_resource_map(array( ), 'phabricator-transaction-view-css' => array( - 'uri' => '/res/97f9e8f2/rsrc/css/aphront/transaction.css', + 'uri' => '/res/731959fb/rsrc/css/aphront/transaction.css', 'type' => 'css', 'requires' => array( @@ -1837,30 +1848,9 @@ celerity_register_resource_map(array( ), 'disk' => '/rsrc/css/core/syntax.css', ), - 0 => - array( - 'uri' => '/res/b6096fdd/rsrc/js/javelin/lib/__tests__/URI.js', - 'type' => 'js', - 'requires' => - array( - 0 => 'javelin-uri', - 1 => 'javelin-php-serializer', - ), - 'disk' => '/rsrc/js/javelin/lib/__tests__/URI.js', - ), ), array( 'packages' => array( - '03ef179e' => - array( - 'name' => 'diffusion.pkg.css', - 'symbols' => - array( - 0 => 'diffusion-commit-view-css', - ), - 'uri' => '/res/pkg/03ef179e/diffusion.pkg.css', - 'type' => 'css', - ), '080edee4' => array( 'name' => 'typeahead.pkg.js', @@ -1914,6 +1904,16 @@ celerity_register_resource_map(array( 'uri' => '/res/pkg/4fbae2af/javelin.pkg.js', 'type' => 'js', ), + '61f9d480' => + array( + 'name' => 'diffusion.pkg.css', + 'symbols' => + array( + 0 => 'diffusion-commit-view-css', + ), + 'uri' => '/res/pkg/61f9d480/diffusion.pkg.css', + 'type' => 'css', + ), '6a6def05' => array( 'name' => 'core.pkg.css', @@ -2006,7 +2006,7 @@ celerity_register_resource_map(array( 'differential-revision-detail-css' => '8152415f', 'differential-revision-history-css' => '8152415f', 'differential-table-of-contents-css' => '8152415f', - 'diffusion-commit-view-css' => '03ef179e', + 'diffusion-commit-view-css' => '61f9d480', 'javelin-behavior' => '4fbae2af', 'javelin-behavior-aphront-basic-tokenizer' => '080edee4', 'javelin-behavior-aphront-drag-and-drop' => 'c8aaade8', diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 3eaa17191a..08be8c8886 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -279,6 +279,8 @@ phutil_register_library_map(array( 'DiffusionBrowseQuery' => 'applications/diffusion/query/browse/base', 'DiffusionBrowseTableView' => 'applications/diffusion/view/browsetable', 'DiffusionChangeController' => 'applications/diffusion/controller/change', + 'DiffusionCommentListView' => 'applications/diffusion/view/commentlist', + 'DiffusionCommentView' => 'applications/diffusion/view/comment', 'DiffusionCommitChangeTableView' => 'applications/diffusion/view/commitchangetable', 'DiffusionCommitController' => 'applications/diffusion/controller/commit', 'DiffusionCommitListController' => 'applications/diffusion/controller/commitlist', @@ -1100,6 +1102,8 @@ phutil_register_library_map(array( 'DiffusionBrowseFileController' => 'DiffusionController', 'DiffusionBrowseTableView' => 'DiffusionView', 'DiffusionChangeController' => 'DiffusionController', + 'DiffusionCommentListView' => 'AphrontView', + 'DiffusionCommentView' => 'AphrontView', 'DiffusionCommitChangeTableView' => 'DiffusionView', 'DiffusionCommitController' => 'DiffusionController', 'DiffusionCommitListController' => 'DiffusionController', diff --git a/src/applications/audit/constants/action/PhabricatorAuditActionConstants.php b/src/applications/audit/constants/action/PhabricatorAuditActionConstants.php index 3b948ad6c6..f02f417efd 100644 --- a/src/applications/audit/constants/action/PhabricatorAuditActionConstants.php +++ b/src/applications/audit/constants/action/PhabricatorAuditActionConstants.php @@ -1,7 +1,7 @@ 'Have Concern', - self::ACCEPT => 'Accept', + self::COMMENT => 'Comment', + self::CONCERN => 'Raise Concern', + self::ACCEPT => 'Accept', ); return $map; diff --git a/src/applications/diffusion/controller/commit/DiffusionCommitController.php b/src/applications/diffusion/controller/commit/DiffusionCommitController.php index 57b4d55628..c56d3fa1a5 100644 --- a/src/applications/diffusion/controller/commit/DiffusionCommitController.php +++ b/src/applications/diffusion/controller/commit/DiffusionCommitController.php @@ -87,6 +87,7 @@ class DiffusionCommitController extends DiffusionController { } $content[] = $this->buildAuditTable($commit); + $content[] = $this->buildComments($commit); $change_query = DiffusionPathChangeQuery::newFromDiffusionRequest( $drequest); @@ -311,4 +312,21 @@ class DiffusionCommitController extends DiffusionController { return $panel; } + private function buildComments($commit) { + $user = $this->getRequest()->getUser(); + $comments = id(new PhabricatorAuditComment())->loadAllWhere( + 'targetPHID = %s ORDER BY dateCreated ASC', + $commit->getPHID()); + + $view = new DiffusionCommentListView(); + $view->setUser($user); + $view->setComments($comments); + + $phids = $view->getRequiredHandlePHIDs(); + $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); + $view->setHandles($handles); + + return $view; + } + } diff --git a/src/applications/diffusion/controller/commit/__init__.php b/src/applications/diffusion/controller/commit/__init__.php index 080864da29..0495458be8 100644 --- a/src/applications/diffusion/controller/commit/__init__.php +++ b/src/applications/diffusion/controller/commit/__init__.php @@ -7,6 +7,7 @@ phutil_require_module('phabricator', 'applications/audit/query/audit'); +phutil_require_module('phabricator', 'applications/audit/storage/auditcomment'); phutil_require_module('phabricator', 'applications/audit/view/list'); phutil_require_module('phabricator', 'applications/differential/constants/changetype'); phutil_require_module('phabricator', 'applications/differential/view/changesetlistview'); @@ -14,6 +15,7 @@ phutil_require_module('phabricator', 'applications/diffusion/controller/base'); phutil_require_module('phabricator', 'applications/diffusion/data/pathchange'); phutil_require_module('phabricator', 'applications/diffusion/query/contains/base'); phutil_require_module('phabricator', 'applications/diffusion/query/pathchange/base'); +phutil_require_module('phabricator', 'applications/diffusion/view/commentlist'); phutil_require_module('phabricator', 'applications/diffusion/view/commitchangetable'); phutil_require_module('phabricator', 'applications/markup/engine'); phutil_require_module('phabricator', 'applications/phid/handle/data'); diff --git a/src/applications/diffusion/view/comment/DiffusionCommentView.php b/src/applications/diffusion/view/comment/DiffusionCommentView.php new file mode 100644 index 0000000000..e9b19b30fa --- /dev/null +++ b/src/applications/diffusion/view/comment/DiffusionCommentView.php @@ -0,0 +1,132 @@ +user = $user; + return $this; + } + + public function setComment(PhabricatorAuditComment $comment) { + $this->comment = $comment; + return $this; + } + + public function setCommentNumber($comment_number) { + $this->commentNumber = $comment_number; + return $this; + } + + public function setHandles(array $handles) { + $this->handles = $handles; + return $this; + } + + private function getHandle($phid) { + if (empty($this->handles[$phid])) { + throw new Exception("Unloaded handle '{$phid}'!"); + } + return $this->handles[$phid]; + } + + public function render() { + $comment = $this->comment; + $author = $this->getHandle($comment->getActorPHID()); + $author_link = $author->renderLink(); + + $actions = $this->renderActions(); + $content = $this->renderContent(); + $classes = $this->renderClasses(); + + $xaction_view = id(new PhabricatorTransactionView()) + ->setUser($this->user) + ->setImageURI($author->getImageURI()) + ->setActions($actions) + ->setAnchor('comment-'.$this->commentNumber, '#'.$this->commentNumber) + ->setEpoch($comment->getDateCreated()) + ->appendChild($content); + + foreach ($classes as $class) { + $xaction_view->addClass($class); + } + + return $xaction_view; + } + + private function renderActions() { + $comment = $this->comment; + $author = $this->getHandle($comment->getActorPHID()); + $author_link = $author->renderLink(); + + $actions = array(); + switch ($comment->getAction()) { + case PhabricatorAuditActionConstants::ACCEPT: + $actions[] = "{$author_link} accepted this commit."; + break; + case PhabricatorAuditActionConstants::CONCERN: + $actions[] = "{$author_link} raised concerns with this commit."; + break; + case PhabricatorAuditActionConstants::COMMENT: + default: + $actions[] = "{$author_link} commented on this commit."; + break; + } + + foreach ($actions as $key => $action) { + $actions[$key] = '
'.$action.'
'; + } + + return $actions; + } + + private function renderContent() { + $comment = $this->comment; + + $engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine(); + return + '
'. + $engine->markupText($comment->getContent()). + '
'; + } + + private function renderClasses() { + $comment = $this->comment; + + $classes = array(); + switch ($comment->getAction()) { + case PhabricatorAuditActionConstants::ACCEPT: + $classes[] = 'audit-accept'; + break; + case PhabricatorAuditActionConstants::CONCERN: + $classes[] = 'audit-concern'; + break; + } + + return $classes; + } + + + + +} diff --git a/src/applications/diffusion/view/comment/__init__.php b/src/applications/diffusion/view/comment/__init__.php new file mode 100644 index 0000000000..a0ab7a62c1 --- /dev/null +++ b/src/applications/diffusion/view/comment/__init__.php @@ -0,0 +1,17 @@ +user = $user; + return $this; + } + + public function setComments(array $comments) { + $this->comments = $comments; + return $this; + } + + public function getRequiredHandlePHIDs() { + $phids = array(); + foreach ($this->comments as $comment) { + $phids[$comment->getActorPHID()] = true; + } + return array_keys($phids); + } + + public function setHandles(array $handles) { + $this->handles = $handles; + return $this; + } + + + public function render() { + + $num = 1; + + $comments = array(); + foreach ($this->comments as $comment) { + $view = id(new DiffusionCommentView()) + ->setComment($comment) + ->setCommentNumber($num) + ->setHandles($this->handles) + ->setUser($this->user); + + $comments[] = $view->render(); + ++$num; + } + + return + '
'. + $this->renderSingleView($comments). + '
'; + } + +} diff --git a/src/applications/diffusion/view/commentlist/__init__.php b/src/applications/diffusion/view/commentlist/__init__.php new file mode 100644 index 0000000000..740dae8035 --- /dev/null +++ b/src/applications/diffusion/view/commentlist/__init__.php @@ -0,0 +1,15 @@ +