1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-16 16:58:38 +01:00

Separate Slowvote poll status onto a dedicated object

Summary: Ref T13682. Prepares for use of API-friendly string constants rather than opaque integers.

Test Plan: Created and edited polls, opening and closing them. Grepped for affected methods.

Maniphest Tasks: T13682

Differential Revision: https://secure.phabricator.com/D21847
This commit is contained in:
epriestley 2022-05-26 10:35:38 -07:00
parent 03d3d1889d
commit c1887f0c1d
8 changed files with 102 additions and 15 deletions

View file

@ -5874,6 +5874,7 @@ phutil_register_library_map(array(
'SlowvoteEmbedView' => 'applications/slowvote/view/SlowvoteEmbedView.php',
'SlowvoteInfoConduitAPIMethod' => 'applications/slowvote/conduit/SlowvoteInfoConduitAPIMethod.php',
'SlowvotePollResponseVisibility' => 'applications/slowvote/constants/SlowvotePollResponseVisibility.php',
'SlowvotePollStatus' => 'applications/slowvote/constants/SlowvotePollStatus.php',
'SlowvotePollVotingMethod' => 'applications/slowvote/constants/SlowvotePollVotingMethod.php',
'SlowvoteRemarkupRule' => 'applications/slowvote/remarkup/SlowvoteRemarkupRule.php',
'SlowvoteSearchConduitAPIMethod' => 'applications/slowvote/conduit/SlowvoteSearchConduitAPIMethod.php',
@ -12778,6 +12779,7 @@ phutil_register_library_map(array(
'SlowvoteEmbedView' => 'AphrontView',
'SlowvoteInfoConduitAPIMethod' => 'SlowvoteConduitAPIMethod',
'SlowvotePollResponseVisibility' => 'Phobject',
'SlowvotePollStatus' => 'Phobject',
'SlowvotePollVotingMethod' => 'Phobject',
'SlowvoteRemarkupRule' => 'PhabricatorObjectRemarkupRule',
'SlowvoteSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',

View file

@ -0,0 +1,70 @@
<?php
final class SlowvotePollStatus
extends Phobject {
const STATUS_OPEN = 0;
const STATUS_CLOSED = 1;
private $key;
public static function newStatusObject($key) {
$object = new self();
$object->key = $key;
return $object;
}
public function getKey() {
return $this->key;
}
public static function getAll() {
$map = self::getMap();
$result = array();
foreach ($map as $key => $spec) {
$result[$key] = self::newStatusObject($key);
}
return $result;
}
public function getName() {
$name = $this->getProperty('name');
if ($name === null) {
$name = pht('Unknown ("%s")', $this->getKey());
}
return $name;
}
public function getHeaderTagIcon() {
return $this->getProperty('header.tag.icon');
}
public function getHeaderTagColor() {
return $this->getProperty('header.tag.color');
}
private function getProperty($key, $default = null) {
$spec = idx(self::getMap(), $this->getKey(), array());
return idx($spec, $key, $default);
}
private static function getMap() {
return array(
self::STATUS_OPEN => array(
'name' => pht('Open'),
'header.tag.icon' => 'fa-square-o',
'header.tag.color' => 'bluegrey',
),
self::STATUS_CLOSED => array(
'name' => pht('Closed'),
'header.tag.icon' => 'fa-ban',
'header.tag.color' => 'indigo',
),
);
}
}

View file

@ -23,10 +23,10 @@ final class PhabricatorSlowvoteCloseController
$close_uri = '/V'.$poll->getID();
if ($request->isFormPost()) {
if ($poll->getIsClosed()) {
$new_status = 0;
if ($poll->isClosed()) {
$new_status = SlowvotePollStatus::STATUS_OPEN;
} else {
$new_status = 1;
$new_status = SlowvotePollStatus::STATUS_CLOSED;
}
$xactions = array();
@ -46,7 +46,7 @@ final class PhabricatorSlowvoteCloseController
return id(new AphrontRedirectResponse())->setURI($close_uri);
}
if ($poll->getIsClosed()) {
if ($poll->isClosed()) {
$title = pht('Reopen Poll');
$content = pht('Are you sure you want to reopen the poll?');
$submit = pht('Reopen');

View file

@ -35,9 +35,11 @@ final class PhabricatorSlowvotePollController
));
}
$header_icon = $poll->getIsClosed() ? 'fa-ban' : 'fa-square-o';
$header_name = $poll->getIsClosed() ? pht('Closed') : pht('Open');
$header_color = $poll->getIsClosed() ? 'indigo' : 'bluegrey';
$status = $poll->getStatusObject();
$header_icon = $status->getHeaderTagIcon();
$header_color = $status->getHeaderTagColor();
$header_name = $status->getName();
$header = id(new PHUIHeaderView())
->setHeader($poll->getQuestion())
@ -50,7 +52,7 @@ final class PhabricatorSlowvotePollController
$subheader = $this->buildSubheaderView($poll);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb('V'.$poll->getID());
$crumbs->addTextCrumb($poll->getMonogram());
$crumbs->setBorder(true);
$timeline = $this->buildTransactionTimeline(
@ -71,7 +73,11 @@ final class PhabricatorSlowvotePollController
->setMainColumn($poll_content);
return $this->newPage()
->setTitle('V'.$poll->getID().' '.$poll->getQuestion())
->setTitle(
pht(
'%s %s',
$poll->getMonogram(),
$poll->getQuestion()))
->setCrumbs($crumbs)
->setPageObjectPHIDs(array($poll->getPHID()))
->appendChild($view);
@ -87,7 +93,7 @@ final class PhabricatorSlowvotePollController
$curtain = $this->newCurtainView($poll);
$is_closed = $poll->getIsClosed();
$is_closed = $poll->isClosed();
$close_poll_text = $is_closed ? pht('Reopen Poll') : pht('Close Poll');
$close_poll_icon = $is_closed ? 'fa-check' : 'fa-ban';

View file

@ -21,7 +21,7 @@ final class PhabricatorSlowvoteVoteController
return new Aphront404Response();
}
if ($poll->getIsClosed()) {
if ($poll->isClosed()) {
return new Aphront400Response();
}

View file

@ -142,7 +142,7 @@ final class PhabricatorSlowvoteSearchEngine
->setHref('/V'.$poll->getID())
->addIcon('none', $date_created);
if ($poll->getIsClosed()) {
if ($poll->isClosed()) {
$item->setStatusIcon('fa-ban grey');
$item->setDisabled(true);
} else {

View file

@ -20,7 +20,7 @@ final class PhabricatorSlowvotePoll
protected $shuffle = 0;
protected $method;
protected $viewPolicy;
protected $isClosed = 0;
protected $isClosed;
protected $spacePHID;
private $options = self::ATTACHABLE;
@ -43,6 +43,7 @@ final class PhabricatorSlowvotePoll
->setAuthorPHID($actor->getPHID())
->setViewPolicy($view_policy)
->setSpacePHID($actor->getDefaultSpacePHID())
->setIsClosed(SlowvotePollStatus::STATUS_OPEN)
->setMethod($default_method)
->setResponseVisibility($default_responses);
}
@ -67,6 +68,14 @@ final class PhabricatorSlowvotePoll
return PhabricatorSlowvotePollPHIDType::TYPECONST;
}
public function getStatusObject() {
return SlowvotePollStatus::newStatusObject($this->getIsClosed());
}
public function isClosed() {
return ($this->getIsClosed() == SlowvotePollStatus::STATUS_CLOSED);
}
public function getOptions() {
return $this->assertAttached($this->options);
}

View file

@ -95,7 +95,7 @@ final class SlowvoteEmbedView extends AphrontView {
),
$quip);
if ($poll->getIsClosed()) {
if ($poll->isClosed()) {
$submit = null;
} else {
$submit = phutil_tag(
@ -228,7 +228,7 @@ final class SlowvoteEmbedView extends AphrontView {
SlowvotePollVotingMethod::METHOD_APPROVAL => 'checkbox',
);
$closed = $this->getPoll()->getIsClosed();
$closed = $this->getPoll()->isClosed();
return phutil_tag(
'input',