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:
parent
184f2ba7a4
commit
aa2e6d1e5a
6 changed files with 188 additions and 20 deletions
|
@ -1529,8 +1529,8 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSlowvoteComment' => 'applications/slowvote/storage/PhabricatorSlowvoteComment.php',
|
||||
'PhabricatorSlowvoteCommentController' => 'applications/slowvote/controller/PhabricatorSlowvoteCommentController.php',
|
||||
'PhabricatorSlowvoteController' => 'applications/slowvote/controller/PhabricatorSlowvoteController.php',
|
||||
'PhabricatorSlowvoteCreateController' => 'applications/slowvote/controller/PhabricatorSlowvoteCreateController.php',
|
||||
'PhabricatorSlowvoteDAO' => 'applications/slowvote/storage/PhabricatorSlowvoteDAO.php',
|
||||
'PhabricatorSlowvoteEditController' => 'applications/slowvote/controller/PhabricatorSlowvoteEditController.php',
|
||||
'PhabricatorSlowvoteEditor' => 'applications/slowvote/editor/PhabricatorSlowvoteEditor.php',
|
||||
'PhabricatorSlowvoteListController' => 'applications/slowvote/controller/PhabricatorSlowvoteListController.php',
|
||||
'PhabricatorSlowvoteOption' => 'applications/slowvote/storage/PhabricatorSlowvoteOption.php',
|
||||
|
@ -3490,8 +3490,8 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSlowvoteComment' => 'PhabricatorSlowvoteDAO',
|
||||
'PhabricatorSlowvoteCommentController' => 'PhabricatorSlowvoteController',
|
||||
'PhabricatorSlowvoteController' => 'PhabricatorController',
|
||||
'PhabricatorSlowvoteCreateController' => 'PhabricatorSlowvoteController',
|
||||
'PhabricatorSlowvoteDAO' => 'PhabricatorLiskDAO',
|
||||
'PhabricatorSlowvoteEditController' => 'PhabricatorSlowvoteController',
|
||||
'PhabricatorSlowvoteEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'PhabricatorSlowvoteListController' =>
|
||||
array(
|
||||
|
@ -3503,6 +3503,8 @@ phutil_register_library_map(array(
|
|||
array(
|
||||
0 => 'PhabricatorSlowvoteDAO',
|
||||
1 => 'PhabricatorPolicyInterface',
|
||||
2 => 'PhabricatorSubscribableInterface',
|
||||
3 => 'PhabricatorTokenReceiverInterface',
|
||||
),
|
||||
'PhabricatorSlowvotePollController' => 'PhabricatorSlowvoteController',
|
||||
'PhabricatorSlowvoteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
|
|
|
@ -42,7 +42,7 @@ final class PhabricatorApplicationSlowvote extends PhabricatorApplication {
|
|||
'/vote/' => array(
|
||||
'(?:query/(?P<queryKey>[^/]+)/)?'
|
||||
=> 'PhabricatorSlowvoteListController',
|
||||
'create/' => 'PhabricatorSlowvoteCreateController',
|
||||
'create/' => 'PhabricatorSlowvoteEditController',
|
||||
'(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteVoteController',
|
||||
'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteCommentController',
|
||||
),
|
||||
|
|
|
@ -3,9 +3,15 @@
|
|||
/**
|
||||
* @group slowvote
|
||||
*/
|
||||
final class PhabricatorSlowvoteCreateController
|
||||
final class PhabricatorSlowvoteEditController
|
||||
extends PhabricatorSlowvoteController {
|
||||
|
||||
private $id;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->id = idx($data, 'id');
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
@ -13,23 +19,31 @@ final class PhabricatorSlowvoteCreateController
|
|||
|
||||
$poll = new PhabricatorSlowvotePoll();
|
||||
$poll->setAuthorPHID($user->getPHID());
|
||||
$poll->setViewPolicy(PhabricatorPolicies::POLICY_USER);
|
||||
|
||||
$is_new = true;
|
||||
|
||||
$e_question = true;
|
||||
$e_response = true;
|
||||
$errors = array();
|
||||
|
||||
$v_question = $poll->getQuestion();
|
||||
$v_description = $poll->getDescription();
|
||||
$v_responses = $poll->getResponseVisibility();
|
||||
$v_shuffle = $poll->getShuffle();
|
||||
|
||||
$responses = $request->getArr('response');
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
$poll->setQuestion($request->getStr('question'));
|
||||
$poll->setResponseVisibility($request->getInt('response_visibility'));
|
||||
$poll->setShuffle((int)$request->getBool('shuffle', false));
|
||||
$v_question = $request->getStr('question');
|
||||
$v_description = $request->getStr('description');
|
||||
$v_responses = $request->getInt('responses');
|
||||
$v_shuffle = (int)$request->getBool('shuffle');
|
||||
|
||||
if ($is_new) {
|
||||
$poll->setMethod($request->getInt('method'));
|
||||
}
|
||||
|
||||
$poll->setDescription('');
|
||||
$poll->setViewPolicy(PhabricatorPolicies::POLICY_USER);
|
||||
|
||||
if (!strlen($poll->getQuestion())) {
|
||||
if (!strlen($v_question)) {
|
||||
$e_question = pht('Required');
|
||||
$errors[] = pht('You must ask a poll question.');
|
||||
} else {
|
||||
|
@ -44,7 +58,32 @@ final class PhabricatorSlowvoteCreateController
|
|||
$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)) {
|
||||
$editor = id(new PhabricatorSlowvoteEditor())
|
||||
->setActor($user)
|
||||
->setContinueOnNoEffect(true)
|
||||
->setContentSourceFromRequest($request)
|
||||
->applyTransactions($poll, $xactions);
|
||||
|
||||
$poll->save();
|
||||
|
||||
foreach ($responses as $response) {
|
||||
|
@ -84,8 +123,13 @@ final class PhabricatorSlowvoteCreateController
|
|||
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)
|
||||
->setLabel(pht('Question'))
|
||||
->setName('question')
|
||||
->setValue($poll->getQuestion())
|
||||
->setError($e_question));
|
||||
->setValue($v_question)
|
||||
->setError($e_question))
|
||||
->appendChild(
|
||||
id(new PhabricatorRemarkupControl())
|
||||
->setLabel(pht('Description'))
|
||||
->setName('description')
|
||||
->setValue($v_description));
|
||||
|
||||
for ($ii = 0; $ii < 10; $ii++) {
|
||||
$n = ($ii + 1);
|
||||
|
@ -127,8 +171,8 @@ final class PhabricatorSlowvoteCreateController
|
|||
->appendChild(
|
||||
id(new AphrontFormSelectControl())
|
||||
->setLabel(pht('Responses'))
|
||||
->setName('response_visibility')
|
||||
->setValue($poll->getResponseVisibility())
|
||||
->setName('responses')
|
||||
->setValue($v_responses)
|
||||
->setOptions($response_type_options))
|
||||
->appendChild(
|
||||
id(new AphrontFormCheckboxControl())
|
||||
|
@ -137,7 +181,7 @@ final class PhabricatorSlowvoteCreateController
|
|||
'shuffle',
|
||||
1,
|
||||
pht('Show choices in random order.'),
|
||||
$poll->getShuffle()))
|
||||
$v_shuffle))
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue(pht('Create Slowvote'))
|
|
@ -391,7 +391,7 @@ final class PhabricatorSlowvotePollController
|
|||
$view->invokeWillRenderEvent();
|
||||
|
||||
if (strlen($poll->getDescription())) {
|
||||
$view->addTextSection(
|
||||
$view->addTextContent(
|
||||
$output = PhabricatorMarkupEngine::renderOneObject(
|
||||
id(new PhabricatorMarkupOneOff())->setContent(
|
||||
$poll->getDescription()),
|
||||
|
|
|
@ -7,6 +7,12 @@ final class PhabricatorSlowvoteEditor
|
|||
$types = parent::getTransactionTypes();
|
||||
|
||||
$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;
|
||||
}
|
||||
|
@ -16,6 +22,14 @@ final class PhabricatorSlowvoteEditor
|
|||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
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) {
|
||||
|
||||
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) {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,9 +3,10 @@
|
|||
final class PhabricatorSlowvoteTransaction
|
||||
extends PhabricatorApplicationTransaction {
|
||||
|
||||
const TYPE_NAME = 'vote:name';
|
||||
const TYPE_QUESTION = 'vote:question';
|
||||
const TYPE_DESCRIPTION = 'vote:description';
|
||||
const TYPE_OPTION = 'vote:option';
|
||||
const TYPE_RESPONSES = 'vote:responses';
|
||||
const TYPE_SHUFFLE = 'vote:shuffle';
|
||||
|
||||
public function getApplicationName() {
|
||||
return 'slowvote';
|
||||
|
@ -23,5 +24,95 @@ final class PhabricatorSlowvoteTransaction
|
|||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue