From 5f32fb328333adafd4f616eb456310e213763a38 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 30 Jan 2011 11:02:22 -0800 Subject: [PATCH] AddCommentView --- src/__phutil_library_map__.php | 2 + .../constants/action/DifferentialAction.php | 21 ++- .../DifferentialRevisionViewController.php | 129 ++++++++---------- .../controller/revisionview/__init__.php | 1 + .../addcomment/DifferentialAddCommentView.php | 66 +++++++++ .../differential/view/addcomment/__init__.php | 17 +++ .../DifferentialRevisionCommentView.php | 2 +- 7 files changed, 162 insertions(+), 76 deletions(-) create mode 100644 src/applications/differential/view/addcomment/DifferentialAddCommentView.php create mode 100644 src/applications/differential/view/addcomment/__init__.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index cd8722d518..4831225f97 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -65,6 +65,7 @@ phutil_register_library_map(array( 'ConduitAPI_user_find_Method' => 'applications/conduit/method/user/find', 'ConduitException' => 'applications/conduit/protocol/exception', 'DifferentialAction' => 'applications/differential/constants/action', + 'DifferentialAddCommentView' => 'applications/differential/view/addcomment', 'DifferentialCCWelcomeMail' => 'applications/differential/mail/ccwelcome', 'DifferentialChangeType' => 'applications/differential/constants/changetype', 'DifferentialChangeset' => 'applications/differential/storage/changeset', @@ -224,6 +225,7 @@ phutil_register_library_map(array( 'ConduitAPI_differential_setdiffproperty_Method' => 'ConduitAPIMethod', 'ConduitAPI_file_upload_Method' => 'ConduitAPIMethod', 'ConduitAPI_user_find_Method' => 'ConduitAPIMethod', + 'DifferentialAddCommentView' => 'AphrontView', 'DifferentialCCWelcomeMail' => 'DifferentialReviewRequestMail', 'DifferentialChangeset' => 'DifferentialDAO', 'DifferentialChangesetDetailView' => 'AphrontView', diff --git a/src/applications/differential/constants/action/DifferentialAction.php b/src/applications/differential/constants/action/DifferentialAction.php index d89ba6d2bb..9d71fff450 100755 --- a/src/applications/differential/constants/action/DifferentialAction.php +++ b/src/applications/differential/constants/action/DifferentialAction.php @@ -32,7 +32,7 @@ final class DifferentialAction { const ACTION_CREATE = 'create'; const ACTION_ADDREVIEWERS = 'add_reviewers'; - public static function getActionVerb($action) { + public static function getActionPastTenseVerb($action) { static $verbs = array( self::ACTION_COMMENT => 'commented on', self::ACTION_ACCEPT => 'accepted', @@ -56,4 +56,23 @@ final class DifferentialAction { } } + public static function getActionVerb($action) { + static $verbs = array( + self::ACTION_COMMENT => 'Comment', + self::ACTION_ACCEPT => "Accept Revision \xE2\x9C\x94", + self::ACTION_REJECT => "Request Changes \xE2\x9C\x98", + self::ACTION_ABANDON => 'Abandon Revision', + self::ACTION_REQUEST => 'Request Review', + self::ACTION_RECLAIM => 'Reclaim Revision', + self::ACTION_RESIGN => 'Resign as Reviewer', + self::ACTION_ADDREVIEWERS => 'Add Reviewers', + ); + + if (!empty($verbs[$action])) { + return $verbs[$action]; + } else { + return 'brazenly '.$action; + } + } + } diff --git a/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php b/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php index 1b39d3fd43..ba28a982a5 100644 --- a/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php +++ b/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php @@ -80,6 +80,10 @@ class DifferentialRevisionViewController extends DifferentialController { $changeset_view = new DifferentialChangesetListView(); $changeset_view->setChangesets($changesets); + $comment_form = new DifferentialAddCommentView(); + $comment_form->setRevision($revision); + $comment_form->setActions($this->getRevisionCommentActions($revision)); + return $this->buildStandardPageResponse( '
'. $revision_detail->render(). @@ -87,6 +91,7 @@ class DifferentialRevisionViewController extends DifferentialController { $diff_history->render(). $toc_view->render(). $changeset_view->render(). + $comment_form->render(). '
', array( 'title' => $revision->getTitle(), @@ -210,10 +215,60 @@ class DifferentialRevisionViewController extends DifferentialController { return implode(', ', mpull($list, 'renderLink')); } + private function getRevisionCommentActions(DifferentialRevision $revision) { + + $actions = array( + DifferentialAction::ACTION_COMMENT => true, + ); + + $viewer_phid = $this->getRequest()->getUser()->getPHID(); + $viewer_is_owner = ($viewer_phid == $revision->getAuthorPHID()); + + if ($viewer_is_owner) { + switch ($revision->getStatus()) { + case DifferentialRevisionStatus::NEEDS_REVIEW: + $actions[DifferentialAction::ACTION_ABANDON] = true; + break; + case DifferentialRevisionStatus::NEEDS_REVISION: + case DifferentialRevisionStatus::ACCEPTED: + $actions[DifferentialAction::ACTION_ABANDON] = true; + $actions[DifferentialAction::ACTION_REQUEST] = true; + break; + case DifferentialRevisionStatus::COMMITTED: + break; + case DifferentialRevisionStatus::ABANDONED: + $actions[DifferentialAction::ACTION_RECLAIM] = true; + break; + } + } else { + switch ($revision->getStatus()) { + case DifferentialRevisionStatus::NEEDS_REVIEW: + $actions[DifferentialAction::ACTION_ACCEPT] = true; + $actions[DifferentialAction::ACTION_REJECT] = true; + break; + case DifferentialRevisionStatus::NEEDS_REVISION: + $actions[DifferentialAction::ACTION_ACCEPT] = true; + break; + case DifferentialRevisionStatus::ACCEPTED: + $actions[DifferentialAction::ACTION_REJECT] = true; + break; + case DifferentialRevisionStatus::COMMITTED: + case DifferentialRevisionStatus::ABANDONED: + break; + } + } + + $actions[DifferentialAction::ACTION_ADDREVIEWERS] = true; + + return array_keys($actions); + } + } /* + protected function getRevisionActions(DifferentialRevision $revision) { + $viewer_id = $this->getRequest()->getViewerContext()->getUserID(); $viewer_is_owner = ($viewer_id == $revision->getOwnerID()); $viewer_is_reviewer = @@ -1334,81 +1389,7 @@ class DifferentialRevisionViewController extends DifferentialController { return $inline_comments; } - protected function getRevisionActions(DifferentialRevision $revision) { - $actions = array( - 'none' => true, - ); - $viewer = $this->getRequest()->getViewerContext(); - - $viewer_is_owner = ($viewer->getUserID() == $revision->getOwnerID()); - if ($viewer_is_owner) { - switch ($revision->getStatus()) { - case DifferentialConstants::NEEDS_REVIEW: - $actions['abandon'] = true; - break; - case DifferentialConstants::NEEDS_REVISION: - $actions['abandon'] = true; - $actions['request_review'] = true; - break; - case DifferentialConstants::ACCEPTED: - $actions['abandon'] = true; - $actions['request_review'] = true; - break; - case DifferentialConstants::COMMITTED: - break; - case DifferentialConstants::ABANDONED: - $actions['reclaim'] = true; - break; - default: - throw new Exception('Unknown DifferentialRevision status.'); - } - } else { - switch ($revision->getStatus()) { - case DifferentialConstants::NEEDS_REVIEW: - $actions['accept'] = true; - $actions['reject'] = true; - break; - case DifferentialConstants::NEEDS_REVISION: - $actions['accept'] = true; - break; - case DifferentialConstants::ACCEPTED: - $actions['reject'] = true; - break; - case DifferentialConstants::COMMITTED: - break; - case DifferentialConstants::ABANDONED: - break; - default: - throw new Exception('Unknown DifferentialRevision status.'); - } - - if (in_array($viewer->getUserID(), $revision->getReviewers())) { - $actions['resign'] = true; - } - } - - // Put add reviewers at the bottom since it's rare relative to other - // actions, notably accept and reject - $actions['add_reviewers'] = true; - - static $action_names = array( - 'none' => 'Comment', - 'abandon' => 'Abandon Revision', - 'request_review' => 'Request Review', - 'reclaim' => 'Reclaim Revision', - 'accept' => "Accept Revision \xE2\x9C\x94", - 'reject' => "Request Changes \xE2\x9C\x98", - 'resign' => "Resign as Reviewer", - 'add_reviewers' => "Add Reviewers", - ); - - foreach ($actions as $key => $value) { - $actions[$key] = $action_names[$key]; - } - - return $actions; - } protected function getRevisionStatusDisplay(DifferentialRevision $revision) { $viewer_id = $this->getRequest()->getViewerContext()->getUserID(); diff --git a/src/applications/differential/controller/revisionview/__init__.php b/src/applications/differential/controller/revisionview/__init__.php index b8360feeee..04ea6dd3ac 100644 --- a/src/applications/differential/controller/revisionview/__init__.php +++ b/src/applications/differential/controller/revisionview/__init__.php @@ -12,6 +12,7 @@ phutil_require_module('phabricator', 'applications/differential/constants/revisi phutil_require_module('phabricator', 'applications/differential/controller/base'); phutil_require_module('phabricator', 'applications/differential/storage/comment'); phutil_require_module('phabricator', 'applications/differential/storage/revision'); +phutil_require_module('phabricator', 'applications/differential/view/addcomment'); phutil_require_module('phabricator', 'applications/differential/view/changesetlistview'); phutil_require_module('phabricator', 'applications/differential/view/difftableofcontents'); phutil_require_module('phabricator', 'applications/differential/view/revisioncommentlist'); diff --git a/src/applications/differential/view/addcomment/DifferentialAddCommentView.php b/src/applications/differential/view/addcomment/DifferentialAddCommentView.php new file mode 100644 index 0000000000..ec836065bc --- /dev/null +++ b/src/applications/differential/view/addcomment/DifferentialAddCommentView.php @@ -0,0 +1,66 @@ +revision = $revision; + return $this; + } + + public function setActions(array $actions) { + $this->actions = $actions; + return $this; + } + + public function setActionURI($uri) { + $this->actionURI = $uri; + } + + public function render() { + + $actions = array(); + foreach ($this->actions as $action) { + $actions[$action] = DifferentialAction::getActionVerb($action); + } + + $form = new AphrontFormView(); + $form + ->setAction($this->actionURI) + ->appendChild( + id(new AphrontFormSelectControl()) + ->setLabel('Action') + ->setOptions($actions)) + ->appendChild( + id(new AphrontFormTextAreaControl()) + ->setLabel('Comment')) + ->appendChild( + id(new AphrontFormSubmitControl()) + ->setValue('Comment')); + + return + '
'. + '

Add Comment

'. + $form->render(). + '
'; + } +} diff --git a/src/applications/differential/view/addcomment/__init__.php b/src/applications/differential/view/addcomment/__init__.php new file mode 100644 index 0000000000..67d21d5c5e --- /dev/null +++ b/src/applications/differential/view/addcomment/__init__.php @@ -0,0 +1,17 @@ +getAuthorPHID(); $author = $this->handles[$author]->renderLink(); - $verb = DifferentialAction::getActionVerb($comment->getAction()); + $verb = DifferentialAction::getActionPastTenseVerb($comment->getAction()); $verb = phutil_escape_html($verb); $content = $comment->getContent();