Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/view/DifferentialReviewersView.php
| <?php | <?php | ||||
| final class DifferentialReviewersView extends AphrontView { | final class DifferentialReviewersView extends AphrontView { | ||||
| private $reviewers; | private $reviewers; | ||||
| private $handles; | private $handles; | ||||
| private $diff; | private $diff; | ||||
| public function setReviewers(array $reviewers) { | public function setReviewers(array $reviewers) { | ||||
| assert_instances_of($reviewers, 'DifferentialReviewerProxy'); | assert_instances_of($reviewers, 'DifferentialReviewer'); | ||||
| $this->reviewers = $reviewers; | $this->reviewers = $reviewers; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function setHandles(array $handles) { | public function setHandles(array $handles) { | ||||
| assert_instances_of($handles, 'PhabricatorObjectHandle'); | assert_instances_of($handles, 'PhabricatorObjectHandle'); | ||||
| $this->handles = $handles; | $this->handles = $handles; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function setActiveDiff(DifferentialDiff $diff) { | public function setActiveDiff(DifferentialDiff $diff) { | ||||
| $this->diff = $diff; | $this->diff = $diff; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function render() { | public function render() { | ||||
| $viewer = $this->getUser(); | $viewer = $this->getUser(); | ||||
| $view = new PHUIStatusListView(); | $view = new PHUIStatusListView(); | ||||
| foreach ($this->reviewers as $reviewer) { | foreach ($this->reviewers as $reviewer) { | ||||
| $phid = $reviewer->getReviewerPHID(); | $phid = $reviewer->getReviewerPHID(); | ||||
| $handle = $this->handles[$phid]; | $handle = $this->handles[$phid]; | ||||
| // If we're missing either the diff or action information for the | $action_phid = $reviewer->getLastActionDiffPHID(); | ||||
| // reviewer, render information as current. | $is_current_action = $this->isCurrent($action_phid); | ||||
| $is_current = (!$this->diff) || | |||||
| (!$reviewer->getDiffID()) || | $comment_phid = $reviewer->getLastCommentDiffPHID(); | ||||
| ($this->diff->getID() == $reviewer->getDiffID()); | $is_current_comment = $this->isCurrent($comment_phid); | ||||
| $item = new PHUIStatusItemView(); | $item = new PHUIStatusItemView(); | ||||
| $item->setHighlighted($reviewer->hasAuthority($viewer)); | $item->setHighlighted($reviewer->hasAuthority($viewer)); | ||||
| switch ($reviewer->getStatus()) { | switch ($reviewer->getReviewerStatus()) { | ||||
| case DifferentialReviewerStatus::STATUS_ADDED: | case DifferentialReviewerStatus::STATUS_ADDED: | ||||
| if ($comment_phid) { | |||||
| if ($is_current_comment) { | |||||
| $item->setIcon( | |||||
| 'fa-comment', | |||||
| 'blue', | |||||
| pht('Commented')); | |||||
| } else { | |||||
| $item->setIcon( | |||||
| 'fa-comment-o', | |||||
| 'bluegrey', | |||||
| pht('Commented Previously')); | |||||
| } | |||||
| } else { | |||||
| $item->setIcon( | $item->setIcon( | ||||
| PHUIStatusItemView::ICON_OPEN, | PHUIStatusItemView::ICON_OPEN, | ||||
| 'bluegrey', | 'bluegrey', | ||||
| pht('Review Requested')); | pht('Review Requested')); | ||||
| } | |||||
| break; | break; | ||||
| case DifferentialReviewerStatus::STATUS_ACCEPTED: | case DifferentialReviewerStatus::STATUS_ACCEPTED: | ||||
| if ($is_current) { | if ($is_current_action) { | ||||
| $item->setIcon( | $item->setIcon( | ||||
| PHUIStatusItemView::ICON_ACCEPT, | PHUIStatusItemView::ICON_ACCEPT, | ||||
| 'green', | 'green', | ||||
| pht('Accepted')); | pht('Accepted')); | ||||
| } else { | } else { | ||||
| $item->setIcon( | $item->setIcon( | ||||
| PHUIStatusItemView::ICON_ACCEPT, | |||||
| 'bluegrey', | |||||
| pht('Accepted Prior Diff')); | |||||
| } | |||||
| break; | |||||
| case DifferentialReviewerStatus::STATUS_ACCEPTED_OLDER: | |||||
| $item->setIcon( | |||||
| 'fa-check-circle-o', | 'fa-check-circle-o', | ||||
| 'bluegrey', | 'bluegrey', | ||||
| pht('Accepted Prior Diff')); | pht('Accepted Prior Diff')); | ||||
| } | |||||
| break; | break; | ||||
| case DifferentialReviewerStatus::STATUS_REJECTED: | case DifferentialReviewerStatus::STATUS_REJECTED: | ||||
| if ($is_current) { | if ($is_current_action) { | ||||
| $item->setIcon( | $item->setIcon( | ||||
| PHUIStatusItemView::ICON_REJECT, | PHUIStatusItemView::ICON_REJECT, | ||||
| 'red', | 'red', | ||||
| pht('Requested Changes')); | pht('Requested Changes')); | ||||
| } else { | } else { | ||||
| $item->setIcon( | $item->setIcon( | ||||
| 'fa-times-circle-o', | 'fa-times-circle-o', | ||||
| 'bluegrey', | 'bluegrey', | ||||
| pht('Requested Changes to Prior Diff')); | pht('Requested Changes to Prior Diff')); | ||||
| } | } | ||||
| break; | break; | ||||
| case DifferentialReviewerStatus::STATUS_REJECTED_OLDER: | |||||
| $item->setIcon( | |||||
| 'fa-times-circle-o', | |||||
| 'bluegrey', | |||||
| pht('Rejected Prior Diff')); | |||||
| break; | |||||
| case DifferentialReviewerStatus::STATUS_COMMENTED: | |||||
| if ($is_current) { | |||||
| $item->setIcon( | |||||
| 'fa-question-circle', | |||||
| 'blue', | |||||
| pht('Commented')); | |||||
| } else { | |||||
| $item->setIcon( | |||||
| 'fa-question-circle-o', | |||||
| 'bluegrey', | |||||
| pht('Commented Previously')); | |||||
| } | |||||
| break; | |||||
| case DifferentialReviewerStatus::STATUS_BLOCKING: | case DifferentialReviewerStatus::STATUS_BLOCKING: | ||||
| $item->setIcon( | $item->setIcon( | ||||
| PHUIStatusItemView::ICON_MINUS, | PHUIStatusItemView::ICON_MINUS, | ||||
| 'red', | 'red', | ||||
| pht('Blocking Review')); | pht('Blocking Review')); | ||||
| break; | break; | ||||
| default: | default: | ||||
| $item->setIcon( | $item->setIcon( | ||||
| PHUIStatusItemView::ICON_QUESTION, | PHUIStatusItemView::ICON_QUESTION, | ||||
| 'bluegrey', | 'bluegrey', | ||||
| pht('%s?', $reviewer->getStatus())); | pht('%s?', $reviewer->getReviewerStatus())); | ||||
| break; | break; | ||||
| } | } | ||||
| $item->setTarget($handle->renderHovercardLink()); | $item->setTarget($handle->renderHovercardLink()); | ||||
| $view->addItem($item); | $view->addItem($item); | ||||
| } | } | ||||
| return $view; | return $view; | ||||
| } | } | ||||
| private function isCurrent($action_phid) { | |||||
| if (!$this->diff) { | |||||
| echo "A\n"; | |||||
| return true; | |||||
| } | |||||
| if (!$action_phid) { | |||||
| return true; | |||||
| } | |||||
| $diff_phid = $this->diff->getPHID(); | |||||
| if (!$diff_phid) { | |||||
| return true; | |||||
| } | |||||
| if ($diff_phid == $action_phid) { | |||||
| return true; | |||||
| } | |||||
| return false; | |||||
| } | |||||
| } | } | ||||