1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-23 07:12:41 +01:00

Render Maniphest fields in an application-transactions-compatible way

Summary: Improves transaction rendering for custom fields and standard custom fields.

Test Plan: See screenshot.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D7054
This commit is contained in:
epriestley 2013-09-21 16:23:17 -07:00
parent b8cb6ddaa5
commit a82992e9a5
12 changed files with 217 additions and 39 deletions

View file

@ -735,6 +735,7 @@ phutil_register_library_map(array(
'ManiphestTransactionEditor' => 'applications/maniphest/editor/ManiphestTransactionEditor.php',
'ManiphestTransactionListView' => 'applications/maniphest/view/ManiphestTransactionListView.php',
'ManiphestTransactionPreviewController' => 'applications/maniphest/controller/ManiphestTransactionPreviewController.php',
'ManiphestTransactionPro' => 'applications/maniphest/storage/ManiphestTransactionPro.php',
'ManiphestTransactionSaveController' => 'applications/maniphest/controller/ManiphestTransactionSaveController.php',
'ManiphestTransactionType' => 'applications/maniphest/constants/ManiphestTransactionType.php',
'ManiphestView' => 'applications/maniphest/view/ManiphestView.php',
@ -2828,6 +2829,7 @@ phutil_register_library_map(array(
'ManiphestTransactionEditor' => 'PhabricatorEditor',
'ManiphestTransactionListView' => 'ManiphestView',
'ManiphestTransactionPreviewController' => 'ManiphestController',
'ManiphestTransactionPro' => 'PhabricatorApplicationTransaction',
'ManiphestTransactionSaveController' => 'ManiphestController',
'ManiphestTransactionType' => 'ManiphestConstants',
'ManiphestView' => 'AphrontView',

View file

@ -153,7 +153,7 @@ final class ManiphestTaskEditController extends ManiphestController {
$placeholder_editor,
PhabricatorTransactions::TYPE_CUSTOMFIELD,
array(
id(new PhabricatorUserTransaction())
id(new ManiphestTransactionPro())
->setOldValue($aux_old_value)
->setNewValue($aux_new_value),
));

View file

@ -28,23 +28,4 @@ abstract class ManiphestCustomField
return false;
}
// TODO: All of this is legacy junk.
public function renderTransactionEmailVerb(
ManiphestTransaction $transaction) {
return null;
}
public function renderTransactionDescription(
ManiphestTransaction $transaction) {
$old = $transaction->getOldValue();
$new = $transaction->getNewValue();
return pht(
'updated field %s from %s to %s',
$this->getFieldName(),
hsprintf('%s', $old),
hsprintf('%s', $new));
}
}

View file

@ -0,0 +1,19 @@
<?php
final class ManiphestTransactionPro
extends PhabricatorApplicationTransaction {
public function getApplicationName() {
return 'maniphest';
}
public function getApplicationTransactionType() {
return ManiphestPHIDTypeTask::TYPECONST;
}
public function getApplicationTransactionCommentObject() {
return null;
}
}

View file

@ -92,14 +92,22 @@ final class ManiphestTransactionDetailView extends ManiphestView {
$descs = array();
$comments = null;
foreach ($this->transactions as $transaction) {
list($verb, $desc, $classes) = $this->describeAction($transaction);
list($verb, $desc, $classes, $full) = $this->describeAction($transaction);
if ($full) {
$desc = $full;
} else {
if ($desc === null) {
continue;
} else {
$desc = $author.' '.$desc.'.';
}
}
if ($action === null) {
$action = $verb;
}
$desc = $author.' '.$desc.'.';
if ($with_date) {
// NOTE: This is going into a (potentially multi-recipient) email so
// we can't use a single user's timezone preferences. Use the server's
@ -155,7 +163,17 @@ final class ManiphestTransactionDetailView extends ManiphestView {
$more_classes = array();
$descs = array();
foreach ($transactions as $transaction) {
list($verb, $desc, $classes) = $this->describeAction($transaction);
list($verb, $desc, $classes, $full) = $this->describeAction($transaction);
if ($full) {
$descs[] = javelin_tag(
'div',
array(
'sigil' => 'maniphest-transaction-description',
),
$full);
continue;
}
if ($desc === null) {
continue;
}
@ -301,6 +319,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
private function describeAction($transaction) {
$verb = null;
$desc = null;
$full = null;
$classes = array();
$handles = $this->handles;
@ -525,11 +544,6 @@ final class ManiphestTransactionDetailView extends ManiphestView {
$aux_field = $this->getAuxiliaryField('std:maniphest:'.$aux_key);
}
$verb = null;
if ($aux_field) {
$verb = $aux_field->renderTransactionEmailVerb($transaction);
}
if ($verb === null) {
if ($old === null) {
$verb = "Set Field";
} else if ($new === null) {
@ -537,11 +551,17 @@ final class ManiphestTransactionDetailView extends ManiphestView {
} else {
$verb = "Updated Field";
}
}
$desc = null;
if ($aux_field) {
$desc = $aux_field->renderTransactionDescription($transaction);
$proxy_transaction = new ManiphestTransactionPro();
$proxy_transaction->setOldValue($transaction->getOldValue());
$proxy_transaction->setNewValue($transaction->getNewValue());
$proxy_transaction->setAuthorPHID($transaction->getAuthorPHID());
$proxy_transaction->setHandles($this->handles);
$full = $aux_field->getApplicationTransactionTitle(
$proxy_transaction);
} else {
$desc = 'updated a field';
}
@ -556,7 +576,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
// correctly right now.
$desc = phutil_safe_html($desc);
return array($verb, $desc, $classes);
return array($verb, $desc, $classes, $full);
}
private function renderFullSummary($transaction) {

View file

@ -873,6 +873,19 @@ abstract class PhabricatorCustomField {
return array();
}
public function getApplicationTransactionTitle(
PhabricatorApplicationTransaction $xaction) {
if ($this->proxy) {
return $this->proxy->getApplicationTransactionTitle(
$xaction);
}
$author_phid = $xaction->getAuthorPHID();
return pht(
'%s updated this object.',
$xaction->renderHandleLink($author_phid));
}
/* -( Edit View )---------------------------------------------------------- */

View file

@ -300,4 +300,32 @@ abstract class PhabricatorStandardCustomField
return !strlen($value);
}
public function getApplicationTransactionTitle(
PhabricatorApplicationTransaction $xaction) {
$author_phid = $xaction->getAuthorPHID();
$old = $xaction->getOldValue();
$new = $xaction->getNewValue();
if (!$old) {
return pht(
'%s set %s to %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName(),
$new);
} else if (!$new) {
return pht(
'%s removed %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName());
} else {
return pht(
'%s changed %s from %s to %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName(),
$old,
$new);
}
}
}

View file

@ -92,5 +92,24 @@ final class PhabricatorStandardCustomFieldBool
}
}
public function getApplicationTransactionTitle(
PhabricatorApplicationTransaction $xaction) {
$author_phid = $xaction->getAuthorPHID();
$old = $xaction->getOldValue();
$new = $xaction->getNewValue();
if ($new) {
return pht(
'%s checked %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName());
} else {
return pht(
'%s unchecked %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName());
}
}
}

View file

@ -74,4 +74,43 @@ final class PhabricatorStandardCustomFieldDate
// but don't provide a UI for searching. To do so, we need a reasonable date
// range control and the ability to add a range constraint.
public function getApplicationTransactionTitle(
PhabricatorApplicationTransaction $xaction) {
$author_phid = $xaction->getAuthorPHID();
$old = $xaction->getOldValue();
$new = $xaction->getNewValue();
$viewer = $this->getViewer();
$old_date = null;
if ($old) {
$old_date = phabricator_datetime($old, $viewer);
}
$new_date = null;
if ($new) {
$new_date = phabricator_datetime($new, $viewer);
}
if (!$old) {
return pht(
'%s set %s to %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName(),
$new_date);
} else if (!$new) {
return pht(
'%s removed %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName());
} else {
return pht(
'%s changed %s from %s to %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName(),
$old_date,
$new_date);
}
}
}

View file

@ -37,4 +37,17 @@ final class PhabricatorStandardCustomFieldRemarkup
$viewer);
}
public function getApplicationTransactionTitle(
PhabricatorApplicationTransaction $xaction) {
$author_phid = $xaction->getAuthorPHID();
// TODO: Expose fancy transactions.
return pht(
'%s edited %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName());
}
}

View file

@ -77,4 +77,35 @@ final class PhabricatorStandardCustomFieldSelect
return idx($this->getOptions(), $this->getFieldValue());
}
public function getApplicationTransactionTitle(
PhabricatorApplicationTransaction $xaction) {
$author_phid = $xaction->getAuthorPHID();
$old = $xaction->getOldValue();
$new = $xaction->getNewValue();
$old = idx($this->getOptions(), $old, $old);
$new = idx($this->getOptions(), $new, $new);
if (!$old) {
return pht(
'%s set %s to %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName(),
$new);
} else if (!$new) {
return pht(
'%s removed %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName());
} else {
return pht(
'%s changed %s from %s to %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName(),
$old,
$new);
}
}
}

View file

@ -50,4 +50,17 @@ final class PhabricatorStandardCustomFieldUsers
$form->appendChild($control);
}
public function getApplicationTransactionTitle(
PhabricatorApplicationTransaction $xaction) {
$author_phid = $xaction->getAuthorPHID();
// TODO: Show added/removed and render handles. We don't have handle
// surfacing or batching yet so this is a bit awkward right now.
return pht(
'%s updated %s.',
$xaction->renderHandleLink($author_phid),
$this->getFieldName());
}
}