mirror of
https://we.phorge.it/source/phorge.git
synced 2025-03-29 04:28:12 +01:00
Summary: Ref T3718. Remove `bulkLoad()` and header-view rendering wrappers. Test Plan: Viewed a request, looked the same. `grep`'d for stuff. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T3718 Differential Revision: https://secure.phabricator.com/D8809
143 lines
3.4 KiB
PHP
143 lines
3.4 KiB
PHP
<?php
|
|
|
|
final class ReleephIntentFieldSpecification
|
|
extends ReleephFieldSpecification {
|
|
|
|
public function getFieldKey() {
|
|
return 'intent';
|
|
}
|
|
|
|
public function getName() {
|
|
return 'Intent';
|
|
}
|
|
|
|
public function renderPropertyViewValue(array $handles) {
|
|
$pull = $this->getReleephRequest();
|
|
|
|
$intents = $pull->getUserIntents();
|
|
$product = $this->getReleephProject();
|
|
|
|
if (!$intents) {
|
|
return null;
|
|
}
|
|
|
|
$user_phids = array_keys($intents);
|
|
if ($user_phids) {
|
|
$handles = id(new PhabricatorHandleQuery())
|
|
->withPHIDs($user_phids)
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
->execute();
|
|
} else {
|
|
$handles = array();
|
|
}
|
|
|
|
$pushers = array();
|
|
$others = array();
|
|
|
|
foreach ($intents as $phid => $intent) {
|
|
if ($product->isAuthoritativePHID($phid)) {
|
|
$pushers[$phid] = $intent;
|
|
} else {
|
|
$others[$phid] = $intent;
|
|
}
|
|
}
|
|
|
|
$intents = $pushers + $others;
|
|
|
|
$view = id(new PHUIStatusListView());
|
|
foreach ($intents as $phid => $intent) {
|
|
switch ($intent) {
|
|
case ReleephRequest::INTENT_WANT:
|
|
$icon = 'accept-green';
|
|
$label = pht('Want');
|
|
break;
|
|
case ReleephRequest::INTENT_PASS:
|
|
$icon = 'reject-red';
|
|
$label = pht('Pass');
|
|
break;
|
|
default:
|
|
$icon = 'question';
|
|
$label = pht('Unknown Intent (%s)', $intent);
|
|
break;
|
|
}
|
|
|
|
$target = $handles[$phid]->renderLink();
|
|
if ($product->isAuthoritativePHID($phid)) {
|
|
$target = phutil_tag('strong', array(), $target);
|
|
}
|
|
|
|
$view->addItem(
|
|
id(new PHUIStatusItemView())
|
|
->setIcon($icon, $label)
|
|
->setTarget($target));
|
|
}
|
|
|
|
return $view;
|
|
}
|
|
|
|
public function shouldAppearOnCommitMessage() {
|
|
return true;
|
|
}
|
|
|
|
public function shouldAppearOnRevertMessage() {
|
|
return true;
|
|
}
|
|
|
|
public function renderLabelForCommitMessage() {
|
|
return "Approved By";
|
|
}
|
|
|
|
public function renderLabelForRevertMessage() {
|
|
return "Rejected By";
|
|
}
|
|
|
|
public function renderValueForCommitMessage() {
|
|
return $this->renderIntentsForCommitMessage(ReleephRequest::INTENT_WANT);
|
|
}
|
|
|
|
public function renderValueForRevertMessage() {
|
|
return $this->renderIntentsForCommitMessage(ReleephRequest::INTENT_PASS);
|
|
}
|
|
|
|
private function renderIntentsForCommitMessage($print_intent) {
|
|
$intents = $this->getReleephRequest()->getUserIntents();
|
|
|
|
$requestor = $this->getReleephRequest()->getRequestUserPHID();
|
|
$pusher_phids = $this->getReleephProject()->getPushers();
|
|
|
|
$phids = array_unique($pusher_phids + array_keys($intents));
|
|
$handles = id(new PhabricatorHandleQuery())
|
|
->setViewer($this->getUser())
|
|
->withPHIDs($phids)
|
|
->execute();
|
|
|
|
$tokens = array();
|
|
foreach ($phids as $phid) {
|
|
$intent = idx($intents, $phid);
|
|
if ($intent == $print_intent) {
|
|
$name = $handles[$phid]->getName();
|
|
$is_pusher = in_array($phid, $pusher_phids);
|
|
$is_requestor = $phid == $requestor;
|
|
|
|
if ($is_pusher) {
|
|
if ($is_requestor) {
|
|
$token = "{$name} (pusher and requestor)";
|
|
} else {
|
|
$token = "{$name} (pusher)";
|
|
}
|
|
} else {
|
|
if ($is_requestor) {
|
|
$token = "{$name} (requestor)";
|
|
} else {
|
|
$token = $name;
|
|
}
|
|
}
|
|
|
|
$tokens[] = $token;
|
|
}
|
|
}
|
|
|
|
return implode(', ', $tokens);
|
|
}
|
|
|
|
}
|