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

Make Ponder status changes transaction-oriented and improve rendering of transactions

Summary: Ref T3373. Use transactions for status changes.

Test Plan: {F52083}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3373

Differential Revision: https://secure.phabricator.com/D6609
This commit is contained in:
epriestley 2013-07-28 17:52:35 -07:00
parent 4be9ccaea8
commit d4b24a2c07
3 changed files with 128 additions and 7 deletions

View file

@ -12,7 +12,6 @@ final class PonderQuestionStatusController
} }
public function processRequest() { public function processRequest() {
$request = $this->getRequest(); $request = $this->getRequest();
$viewer = $request->getUser(); $viewer = $request->getUser();
@ -29,20 +28,27 @@ final class PonderQuestionStatusController
return new Aphront404Response(); return new Aphront404Response();
} }
// TODO: Use transactions.
switch ($this->status) { switch ($this->status) {
case 'open': case 'open':
$question->setStatus(PonderQuestionStatus::STATUS_OPEN); $status = PonderQuestionStatus::STATUS_OPEN;
break; break;
case 'close': case 'close':
$question->setStatus(PonderQuestionStatus::STATUS_CLOSED); $status = PonderQuestionStatus::STATUS_CLOSED;
break; break;
default: default:
return new Aphront400Response(); return new Aphront400Response();
} }
$question->save(); $xactions = array();
$xactions[] = id(new PonderQuestionTransaction())
->setTransactionType(PonderQuestionTransaction::TYPE_STATUS)
->setNewValue($status);
$editor = id(new PonderQuestionEditor())
->setActor($viewer)
->setContentSourceFromRequest($request);
$editor->applyTransactions($question, $xactions);
return id(new AphrontRedirectResponse())->setURI('/Q'.$question->getID()); return id(new AphrontRedirectResponse())->setURI('/Q'.$question->getID());
} }

View file

@ -45,6 +45,7 @@ final class PonderQuestionEditor
$types[] = PonderQuestionTransaction::TYPE_TITLE; $types[] = PonderQuestionTransaction::TYPE_TITLE;
$types[] = PonderQuestionTransaction::TYPE_CONTENT; $types[] = PonderQuestionTransaction::TYPE_CONTENT;
$types[] = PonderQuestionTransaction::TYPE_ANSWERS; $types[] = PonderQuestionTransaction::TYPE_ANSWERS;
$types[] = PonderQuestionTransaction::TYPE_STATUS;
return $types; return $types;
} }
@ -60,6 +61,8 @@ final class PonderQuestionEditor
return $object->getContent(); return $object->getContent();
case PonderQuestionTransaction::TYPE_ANSWERS: case PonderQuestionTransaction::TYPE_ANSWERS:
return mpull($object->getAnswers(), 'getPHID'); return mpull($object->getAnswers(), 'getPHID');
case PonderQuestionTransaction::TYPE_STATUS:
return $object->getStatus();
} }
} }
@ -70,6 +73,7 @@ final class PonderQuestionEditor
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case PonderQuestionTransaction::TYPE_TITLE: case PonderQuestionTransaction::TYPE_TITLE:
case PonderQuestionTransaction::TYPE_CONTENT: case PonderQuestionTransaction::TYPE_CONTENT:
case PonderQuestionTransaction::TYPE_STATUS:
return $xaction->getNewValue(); return $xaction->getNewValue();
case PonderQuestionTransaction::TYPE_ANSWERS: case PonderQuestionTransaction::TYPE_ANSWERS:
$raw_new_value = $xaction->getNewValue(); $raw_new_value = $xaction->getNewValue();
@ -101,6 +105,9 @@ final class PonderQuestionEditor
case PonderQuestionTransaction::TYPE_CONTENT: case PonderQuestionTransaction::TYPE_CONTENT:
$object->setContent($xaction->getNewValue()); $object->setContent($xaction->getNewValue());
break; break;
case PonderQuestionTransaction::TYPE_STATUS:
$object->setStatus($xaction->getNewValue());
break;
case PonderQuestionTransaction::TYPE_ANSWERS: case PonderQuestionTransaction::TYPE_ANSWERS:
$old = $xaction->getOldValue(); $old = $xaction->getOldValue();
$new = $xaction->getNewValue(); $new = $xaction->getNewValue();
@ -131,6 +138,7 @@ final class PonderQuestionEditor
switch ($type) { switch ($type) {
case PonderQuestionTransaction::TYPE_TITLE: case PonderQuestionTransaction::TYPE_TITLE:
case PonderQuestionTransaction::TYPE_CONTENT: case PonderQuestionTransaction::TYPE_CONTENT:
case PonderQuestionTransaction::TYPE_STATUS:
return $v; return $v;
} }
@ -139,6 +147,5 @@ final class PonderQuestionEditor
// TODO: Feed support // TODO: Feed support
// TODO: Mail support // TODO: Mail support
// TODO: Add/remove answers
} }

View file

@ -6,6 +6,7 @@ final class PonderQuestionTransaction
const TYPE_TITLE = 'ponder.question:question'; const TYPE_TITLE = 'ponder.question:question';
const TYPE_CONTENT = 'ponder.question:content'; const TYPE_CONTENT = 'ponder.question:content';
const TYPE_ANSWERS = 'ponder.question:answer'; const TYPE_ANSWERS = 'ponder.question:answer';
const TYPE_STATUS = 'ponder.question:status';
public function getApplicationName() { public function getApplicationName() {
return 'ponder'; return 'ponder';
@ -27,6 +28,113 @@ final class PonderQuestionTransaction
return pht('question'); return pht('question');
} }
public function getTitle() {
$author_phid = $this->getAuthorPHID();
$old = $this->getOldValue();
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case self::TYPE_TITLE:
if ($old === null) {
return pht(
'%s created this question.',
$this->renderHandleLink($author_phid));
} else {
return pht(
'%s edited the question title from "%s" to "%s".',
$this->renderHandleLink($author_phid),
$old,
$new);
}
case self::TYPE_CONTENT:
return pht(
'%s edited the question description.',
$this->renderHandleLink($author_phid));
case self::TYPE_ANSWERS:
// TODO: This could be richer.
return pht(
'%s added an answer.',
$this->renderHandleLink($author_phid));
case self::TYPE_STATUS:
switch ($new) {
case PonderQuestionStatus::STATUS_OPEN:
return pht(
'%s reopened this question.',
$this->renderHandleLink($author_phid));
case PonderQuestionStatus::STATUS_CLOSED:
return pht(
'%s closed this question.',
$this->renderHandleLink($author_phid));
}
}
return parent::getTitle();
}
public function getIcon() {
$old = $this->getOldValue();
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case self::TYPE_TITLE:
case self::TYPE_CONTENT:
return 'edit';
case self::TYPE_STATUS:
switch ($new) {
case PonderQuestionStatus::STATUS_OPEN:
return 'enable';
case PonderQuestionStatus::STATUS_CLOSED:
return 'disable';
}
case self::TYPE_ANSWERS:
return 'new';
}
return parent::getIcon();
}
public function getColor() {
$old = $this->getOldValue();
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case self::TYPE_TITLE:
case self::TYPE_CONTENT:
return PhabricatorTransactions::COLOR_BLUE;
case self::TYPE_ANSWERS:
return PhabricatorTransactions::COLOR_GREEN;
case self::TYPE_STATUS:
switch ($new) {
case PonderQuestionStatus::STATUS_OPEN:
return PhabricatorTransactions::COLOR_GREEN;
case PonderQuestionStatus::STATUS_CLOSED:
return PhabricatorTransactions::COLOR_BLACK;
}
}
}
public function hasChangeDetails() {
switch ($this->getTransactionType()) {
case self::TYPE_CONTENT:
return true;
}
return parent::hasChangeDetails();
}
public function renderChangeDetails(PhabricatorUser $viewer) {
$old = $this->getOldValue();
$new = $this->getNewValue();
$view = id(new PhabricatorApplicationTransactionTextDiffDetailView())
->setUser($viewer)
->setOldText($old)
->setNewText($new);
return $view->render();
}
} }