1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 21:02:41 +01:00

AddCommentView

This commit is contained in:
epriestley 2011-01-30 11:02:22 -08:00
parent c55b1ed9bb
commit 5f32fb3283
7 changed files with 162 additions and 76 deletions

View file

@ -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',

View file

@ -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;
}
}
}

View file

@ -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(
'<div class="differential-primary-pane">'.
$revision_detail->render().
@ -87,6 +91,7 @@ class DifferentialRevisionViewController extends DifferentialController {
$diff_history->render().
$toc_view->render().
$changeset_view->render().
$comment_form->render().
'</div>',
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();

View file

@ -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');

View file

@ -0,0 +1,66 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class DifferentialAddCommentView extends AphrontView {
private $revision;
private $actions;
private $actionURI;
public function setRevision($revision) {
$this->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
'<div class="differential-panel">'.
'<h1>Add Comment</h1>'.
$form->render().
'</div>';
}
}

View file

@ -0,0 +1,17 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/differential/constants/action');
phutil_require_module('phabricator', 'view/base');
phutil_require_module('phabricator', 'view/form/base');
phutil_require_module('phabricator', 'view/form/control/submit');
phutil_require_module('phutil', 'utils');
phutil_require_source('DifferentialAddCommentView.php');

View file

@ -46,7 +46,7 @@ final class DifferentialRevisionCommentView extends AphrontView {
$author = $comment->getAuthorPHID();
$author = $this->handles[$author]->renderLink();
$verb = DifferentialAction::getActionVerb($comment->getAction());
$verb = DifferentialAction::getActionPastTenseVerb($comment->getAction());
$verb = phutil_escape_html($verb);
$content = $comment->getContent();