1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-03 19:31:02 +01:00

Make most slowvote fields edit transactionally

Summary: No support for responses yet, since they're more complicated, but put everything else on the transactions plan. This also prepares polls for editability, shortly.

Test Plan: {F50205}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D6460
This commit is contained in:
epriestley 2013-07-15 10:50:38 -07:00
parent 184f2ba7a4
commit aa2e6d1e5a
6 changed files with 188 additions and 20 deletions

View file

@ -1529,8 +1529,8 @@ phutil_register_library_map(array(
'PhabricatorSlowvoteComment' => 'applications/slowvote/storage/PhabricatorSlowvoteComment.php', 'PhabricatorSlowvoteComment' => 'applications/slowvote/storage/PhabricatorSlowvoteComment.php',
'PhabricatorSlowvoteCommentController' => 'applications/slowvote/controller/PhabricatorSlowvoteCommentController.php', 'PhabricatorSlowvoteCommentController' => 'applications/slowvote/controller/PhabricatorSlowvoteCommentController.php',
'PhabricatorSlowvoteController' => 'applications/slowvote/controller/PhabricatorSlowvoteController.php', 'PhabricatorSlowvoteController' => 'applications/slowvote/controller/PhabricatorSlowvoteController.php',
'PhabricatorSlowvoteCreateController' => 'applications/slowvote/controller/PhabricatorSlowvoteCreateController.php',
'PhabricatorSlowvoteDAO' => 'applications/slowvote/storage/PhabricatorSlowvoteDAO.php', 'PhabricatorSlowvoteDAO' => 'applications/slowvote/storage/PhabricatorSlowvoteDAO.php',
'PhabricatorSlowvoteEditController' => 'applications/slowvote/controller/PhabricatorSlowvoteEditController.php',
'PhabricatorSlowvoteEditor' => 'applications/slowvote/editor/PhabricatorSlowvoteEditor.php', 'PhabricatorSlowvoteEditor' => 'applications/slowvote/editor/PhabricatorSlowvoteEditor.php',
'PhabricatorSlowvoteListController' => 'applications/slowvote/controller/PhabricatorSlowvoteListController.php', 'PhabricatorSlowvoteListController' => 'applications/slowvote/controller/PhabricatorSlowvoteListController.php',
'PhabricatorSlowvoteOption' => 'applications/slowvote/storage/PhabricatorSlowvoteOption.php', 'PhabricatorSlowvoteOption' => 'applications/slowvote/storage/PhabricatorSlowvoteOption.php',
@ -3490,8 +3490,8 @@ phutil_register_library_map(array(
'PhabricatorSlowvoteComment' => 'PhabricatorSlowvoteDAO', 'PhabricatorSlowvoteComment' => 'PhabricatorSlowvoteDAO',
'PhabricatorSlowvoteCommentController' => 'PhabricatorSlowvoteController', 'PhabricatorSlowvoteCommentController' => 'PhabricatorSlowvoteController',
'PhabricatorSlowvoteController' => 'PhabricatorController', 'PhabricatorSlowvoteController' => 'PhabricatorController',
'PhabricatorSlowvoteCreateController' => 'PhabricatorSlowvoteController',
'PhabricatorSlowvoteDAO' => 'PhabricatorLiskDAO', 'PhabricatorSlowvoteDAO' => 'PhabricatorLiskDAO',
'PhabricatorSlowvoteEditController' => 'PhabricatorSlowvoteController',
'PhabricatorSlowvoteEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorSlowvoteEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorSlowvoteListController' => 'PhabricatorSlowvoteListController' =>
array( array(
@ -3503,6 +3503,8 @@ phutil_register_library_map(array(
array( array(
0 => 'PhabricatorSlowvoteDAO', 0 => 'PhabricatorSlowvoteDAO',
1 => 'PhabricatorPolicyInterface', 1 => 'PhabricatorPolicyInterface',
2 => 'PhabricatorSubscribableInterface',
3 => 'PhabricatorTokenReceiverInterface',
), ),
'PhabricatorSlowvotePollController' => 'PhabricatorSlowvoteController', 'PhabricatorSlowvotePollController' => 'PhabricatorSlowvoteController',
'PhabricatorSlowvoteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorSlowvoteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',

View file

@ -42,7 +42,7 @@ final class PhabricatorApplicationSlowvote extends PhabricatorApplication {
'/vote/' => array( '/vote/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?' '(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhabricatorSlowvoteListController', => 'PhabricatorSlowvoteListController',
'create/' => 'PhabricatorSlowvoteCreateController', 'create/' => 'PhabricatorSlowvoteEditController',
'(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteVoteController', '(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteVoteController',
'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteCommentController', 'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteCommentController',
), ),

View file

@ -3,9 +3,15 @@
/** /**
* @group slowvote * @group slowvote
*/ */
final class PhabricatorSlowvoteCreateController final class PhabricatorSlowvoteEditController
extends PhabricatorSlowvoteController { extends PhabricatorSlowvoteController {
private $id;
public function willProcessRequest(array $data) {
$this->id = idx($data, 'id');
}
public function processRequest() { public function processRequest() {
$request = $this->getRequest(); $request = $this->getRequest();
@ -13,23 +19,31 @@ final class PhabricatorSlowvoteCreateController
$poll = new PhabricatorSlowvotePoll(); $poll = new PhabricatorSlowvotePoll();
$poll->setAuthorPHID($user->getPHID()); $poll->setAuthorPHID($user->getPHID());
$poll->setViewPolicy(PhabricatorPolicies::POLICY_USER);
$is_new = true;
$e_question = true; $e_question = true;
$e_response = true; $e_response = true;
$errors = array(); $errors = array();
$v_question = $poll->getQuestion();
$v_description = $poll->getDescription();
$v_responses = $poll->getResponseVisibility();
$v_shuffle = $poll->getShuffle();
$responses = $request->getArr('response'); $responses = $request->getArr('response');
if ($request->isFormPost()) { if ($request->isFormPost()) {
$poll->setQuestion($request->getStr('question')); $v_question = $request->getStr('question');
$poll->setResponseVisibility($request->getInt('response_visibility')); $v_description = $request->getStr('description');
$poll->setShuffle((int)$request->getBool('shuffle', false)); $v_responses = $request->getInt('responses');
$poll->setMethod($request->getInt('method')); $v_shuffle = (int)$request->getBool('shuffle');
$poll->setDescription(''); if ($is_new) {
$poll->setViewPolicy(PhabricatorPolicies::POLICY_USER); $poll->setMethod($request->getInt('method'));
}
if (!strlen($poll->getQuestion())) { if (!strlen($v_question)) {
$e_question = pht('Required'); $e_question = pht('Required');
$errors[] = pht('You must ask a poll question.'); $errors[] = pht('You must ask a poll question.');
} else { } else {
@ -44,7 +58,32 @@ final class PhabricatorSlowvoteCreateController
$e_response = null; $e_response = null;
} }
$xactions = array();
$template = id(new PhabricatorSlowvoteTransaction());
$xactions[] = id(clone $template)
->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_QUESTION)
->setNewValue($v_question);
$xactions[] = id(clone $template)
->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION)
->setNewValue($v_description);
$xactions[] = id(clone $template)
->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_RESPONSES)
->setNewValue($v_responses);
$xactions[] = id(clone $template)
->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_SHUFFLE)
->setNewValue($v_shuffle);
if (empty($errors)) { if (empty($errors)) {
$editor = id(new PhabricatorSlowvoteEditor())
->setActor($user)
->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request)
->applyTransactions($poll, $xactions);
$poll->save(); $poll->save();
foreach ($responses as $response) { foreach ($responses as $response) {
@ -84,8 +123,13 @@ final class PhabricatorSlowvoteCreateController
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT) ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)
->setLabel(pht('Question')) ->setLabel(pht('Question'))
->setName('question') ->setName('question')
->setValue($poll->getQuestion()) ->setValue($v_question)
->setError($e_question)); ->setError($e_question))
->appendChild(
id(new PhabricatorRemarkupControl())
->setLabel(pht('Description'))
->setName('description')
->setValue($v_description));
for ($ii = 0; $ii < 10; $ii++) { for ($ii = 0; $ii < 10; $ii++) {
$n = ($ii + 1); $n = ($ii + 1);
@ -127,8 +171,8 @@ final class PhabricatorSlowvoteCreateController
->appendChild( ->appendChild(
id(new AphrontFormSelectControl()) id(new AphrontFormSelectControl())
->setLabel(pht('Responses')) ->setLabel(pht('Responses'))
->setName('response_visibility') ->setName('responses')
->setValue($poll->getResponseVisibility()) ->setValue($v_responses)
->setOptions($response_type_options)) ->setOptions($response_type_options))
->appendChild( ->appendChild(
id(new AphrontFormCheckboxControl()) id(new AphrontFormCheckboxControl())
@ -137,7 +181,7 @@ final class PhabricatorSlowvoteCreateController
'shuffle', 'shuffle',
1, 1,
pht('Show choices in random order.'), pht('Show choices in random order.'),
$poll->getShuffle())) $v_shuffle))
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->setValue(pht('Create Slowvote')) ->setValue(pht('Create Slowvote'))

View file

@ -391,7 +391,7 @@ final class PhabricatorSlowvotePollController
$view->invokeWillRenderEvent(); $view->invokeWillRenderEvent();
if (strlen($poll->getDescription())) { if (strlen($poll->getDescription())) {
$view->addTextSection( $view->addTextContent(
$output = PhabricatorMarkupEngine::renderOneObject( $output = PhabricatorMarkupEngine::renderOneObject(
id(new PhabricatorMarkupOneOff())->setContent( id(new PhabricatorMarkupOneOff())->setContent(
$poll->getDescription()), $poll->getDescription()),

View file

@ -7,6 +7,12 @@ final class PhabricatorSlowvoteEditor
$types = parent::getTransactionTypes(); $types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_COMMENT; $types[] = PhabricatorTransactions::TYPE_COMMENT;
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorSlowvoteTransaction::TYPE_QUESTION;
$types[] = PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION;
$types[] = PhabricatorSlowvoteTransaction::TYPE_RESPONSES;
$types[] = PhabricatorSlowvoteTransaction::TYPE_SHUFFLE;
return $types; return $types;
} }
@ -16,6 +22,14 @@ final class PhabricatorSlowvoteEditor
PhabricatorApplicationTransaction $xaction) { PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case PhabricatorSlowvoteTransaction::TYPE_QUESTION:
return $object->getQuestion();
case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION:
return $object->getDescription();
case PhabricatorSlowvoteTransaction::TYPE_RESPONSES:
return $object->getResponseVisibility();
case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE:
return $object->getShuffle();
} }
} }
@ -24,6 +38,11 @@ final class PhabricatorSlowvoteEditor
PhabricatorApplicationTransaction $xaction) { PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case PhabricatorSlowvoteTransaction::TYPE_QUESTION:
case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION:
case PhabricatorSlowvoteTransaction::TYPE_RESPONSES:
case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE:
return $xaction->getNewValue();
} }
} }
@ -32,6 +51,18 @@ final class PhabricatorSlowvoteEditor
PhabricatorApplicationTransaction $xaction) { PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case PhabricatorSlowvoteTransaction::TYPE_QUESTION:
$object->setQuestion($xaction->getNewValue());
break;
case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION:
$object->setDescription($xaction->getNewValue());
break;
case PhabricatorSlowvoteTransaction::TYPE_RESPONSES:
$object->setResponseVisibility($xaction->getNewValue());
break;
case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE:
$object->setShuffle($xaction->getNewValue());
break;
} }
} }

View file

@ -3,9 +3,10 @@
final class PhabricatorSlowvoteTransaction final class PhabricatorSlowvoteTransaction
extends PhabricatorApplicationTransaction { extends PhabricatorApplicationTransaction {
const TYPE_NAME = 'vote:name'; const TYPE_QUESTION = 'vote:question';
const TYPE_DESCRIPTION = 'vote:description'; const TYPE_DESCRIPTION = 'vote:description';
const TYPE_OPTION = 'vote:option'; const TYPE_RESPONSES = 'vote:responses';
const TYPE_SHUFFLE = 'vote:shuffle';
public function getApplicationName() { public function getApplicationName() {
return 'slowvote'; return 'slowvote';
@ -23,5 +24,95 @@ final class PhabricatorSlowvoteTransaction
return pht('vote'); return pht('vote');
} }
public function shouldHide() {
$old = $this->getOldValue();
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION:
case PhabricatorSlowvoteTransaction::TYPE_RESPONSES:
case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE:
return ($old === null);
}
return parent::shouldHide();
}
public function getTitle() {
$author_phid = $this->getAuthorPHID();
$old = $this->getOldValue();
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case PhabricatorSlowvoteTransaction::TYPE_QUESTION:
if ($old === null) {
return pht(
'%s created this poll.',
$this->renderHandleLink($author_phid));
} else {
return pht(
'%s changed the poll question from "%s" to "%s".',
$this->renderHandleLink($author_phid),
$old,
$new);
}
break;
case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION:
return pht(
'%s updated the description for this poll.',
$this->renderHandleLink($author_phid));
case PhabricatorSlowvoteTransaction::TYPE_RESPONSES:
// TODO: This could be more detailed
return pht(
'%s changed who can see the responses.',
$this->renderHandleLink($author_phid));
case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE:
if ($new) {
return pht(
'%s made poll responses appear in a random order.',
$this->renderHandleLink($author_phid));
} else {
return pht(
'%s made poll responses appear in a fixed order.',
$this->renderHandleLink($author_phid));
}
break;
}
return parent::getTitle();
}
public function getIcon() {
$old = $this->getOldValue();
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case PhabricatorSlowvoteTransaction::TYPE_QUESTION:
case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION:
case PhabricatorSlowvoteTransaction::TYPE_RESPONSES:
case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE:
return 'edit';
}
return parent::getIcon();
}
public function getColor() {
$old = $this->getOldValue();
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case PhabricatorSlowvoteTransaction::TYPE_QUESTION:
case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION:
case PhabricatorSlowvoteTransaction::TYPE_RESPONSES:
case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE:
return PhabricatorTransactions::COLOR_BLUE;
}
return parent::getColor();
}
} }