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

Moderize Slowvote

Summary: phts everywhere, crumbs, and mobile views.

Test Plan: Created Questions, Voted, tested Chrome and iOS, Looked at ALLCAPS

Reviewers: epriestley, btrahan

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4938
This commit is contained in:
Chad Little 2013-02-13 16:47:24 -08:00
parent 6ae4066d18
commit a05ee0d743
4 changed files with 144 additions and 84 deletions

View file

@ -5,10 +5,14 @@
*/
abstract class PhabricatorSlowvoteController extends PhabricatorController {
const VIEW_ALL = 'all';
const VIEW_CREATED = 'created';
const VIEW_VOTED = 'voted';
public function buildStandardPageResponse($view, array $data) {
$page = $this->buildStandardPageView();
$page->setApplicationName('Slowvote');
$page->setApplicationName(pht('Slowvote'));
$page->setBaseURI('/vote/');
$page->setTitle(idx($data, 'title'));
$page->setGlyph("\xE2\x9C\x94");
@ -19,4 +23,48 @@ abstract class PhabricatorSlowvoteController extends PhabricatorController {
return $response->setContent($page->render());
}
public function buildSideNavView($filter = null, $for_app = false) {
$views = $this->getViews();
$side_nav = new AphrontSideNavFilterView();
$side_nav->setBaseURI(new PhutilURI('/vote/view/'));
foreach ($views as $key => $name) {
$side_nav->addFilter($key, $name);
}
if ($filter) {
$side_nav->selectFilter($filter, null);
}
if ($for_app) {
$side_nav->addFilter('', pht('Create Question'),
$this->getApplicationURI('create/'));
}
return $side_nav;
}
public function buildApplicationMenu() {
return $this->buildSideNavView(null, true)->getMenu();
}
public function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$crumbs->addAction(
id(new PhabricatorMenuItemView())
->setName(pht('Create Question'))
->setHref($this->getApplicationURI('create/'))
->setIcon('create'));
return $crumbs;
}
public function getViews() {
return array(
self::VIEW_ALL => pht('All Slowvotes'),
self::VIEW_CREATED => pht('Created'),
self::VIEW_VOTED => pht('Voted In'),
);
}
}

View file

@ -27,16 +27,16 @@ final class PhabricatorSlowvoteCreateController
$poll->setMethod($request->getInt('method'));
if (!strlen($poll->getQuestion())) {
$e_question = 'Required';
$errors[] = 'You must ask a poll question.';
$e_question = pht('Required');
$errors[] = pht('You must ask a poll question.');
} else {
$e_question = null;
}
$responses = array_filter($responses);
if (empty($responses)) {
$errors[] = 'You must offer at least one response.';
$e_response = 'Required';
$errors[] = pht('You must offer at least one response.');
$e_response = pht('Required');
} else {
$e_response = null;
}
@ -59,18 +59,26 @@ final class PhabricatorSlowvoteCreateController
$error_view = null;
if ($errors) {
$error_view = new AphrontErrorView();
$error_view->setTitle('Form Errors');
$error_view->setTitle(pht('Form Errors'));
$error_view->setErrors($errors);
}
$instructions =
phutil_tag(
'p',
array(
'class' => 'aphront-form-instructions',
),
pht('Resolve issues and build consensus through '.
'protracted deliberation.')
);
$form = id(new AphrontFormView())
->setUser($user)
->appendChild(hsprintf(
'<p class="aphront-form-instructions">Resolve issues and build '.
'consensus through protracted deliberation.</p>'))
->appendChild($instructions)
->appendChild(
id(new AphrontFormTextControl())
->setLabel('Question')
->setLabel(pht('Question'))
->setName('question')
->setValue($poll->getQuestion())
->setError($e_question));
@ -78,7 +86,7 @@ final class PhabricatorSlowvoteCreateController
for ($ii = 0; $ii < 10; $ii++) {
$n = ($ii + 1);
$response = id(new AphrontFormTextControl())
->setLabel("Response {$n}")
->setLabel(pht("Response %d", $n))
->setName('response[]')
->setValue(idx($responses, $ii, ''));
@ -90,57 +98,69 @@ final class PhabricatorSlowvoteCreateController
}
$poll_type_options = array(
PhabricatorSlowvotePoll::METHOD_PLURALITY => 'Plurality (Single Choice)',
PhabricatorSlowvotePoll::METHOD_APPROVAL => 'Approval (Multiple Choice)',
PhabricatorSlowvotePoll::METHOD_PLURALITY =>
pht('Plurality (Single Choice)'),
PhabricatorSlowvotePoll::METHOD_APPROVAL =>
pht('Approval (Multiple Choice)'),
);
$response_type_options = array(
PhabricatorSlowvotePoll::RESPONSES_VISIBLE
=> 'Allow anyone to see the responses',
=> pht('Allow anyone to see the responses'),
PhabricatorSlowvotePoll::RESPONSES_VOTERS
=> 'Require a vote to see the responses',
=> pht('Require a vote to see the responses'),
PhabricatorSlowvotePoll::RESPONSES_OWNER
=> 'Only I can see the responses',
=> pht('Only I can see the responses'),
);
$form
->appendChild(
id(new AphrontFormSelectControl())
->setLabel('Vote Type')
->setLabel(pht('Vote Type'))
->setName('method')
->setValue($poll->getMethod())
->setOptions($poll_type_options))
->appendChild(
id(new AphrontFormSelectControl())
->setLabel('Responses')
->setLabel(pht('Responses'))
->setName('response_visibility')
->setValue($poll->getResponseVisibility())
->setOptions($response_type_options))
->appendChild(
id(new AphrontFormCheckboxControl())
->setLabel('Shuffle')
->setLabel(pht('Shuffle'))
->addCheckbox(
'shuffle',
1,
'Show choices in random order',
pht('Show choices in random order'),
$poll->getShuffle()))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue('Create Slowvote')
->setValue(pht('Create Slowvote'))
->addCancelButton('/vote/'));
$panel = new AphrontPanelView();
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
$panel->setHeader('Create Slowvote');
$panel->setHeader(pht('Create Slowvote'));
$panel->setNoBackground();
$panel->appendChild($form);
return $this->buildStandardPageResponse(
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setName(pht('Create Slowvote'))
->setHref($this->getApplicationURI().'create/')
);
return $this->buildApplicationPage(
array(
$crumbs,
$error_view,
$panel,
),
array(
'title' => 'Create Slowvote',
'title' => pht('Create Slowvote'),
'device' => true,
));
}

View file

@ -8,12 +8,8 @@ final class PhabricatorSlowvoteListController
private $view;
const VIEW_ALL = 'all';
const VIEW_CREATED = 'created';
const VIEW_VOTED = 'voted';
public function willProcessRequest(array $data) {
$this->view = idx($data, 'view');
$this->view = idx($data, 'view', parent::VIEW_ALL);
}
public function processRequest() {
@ -21,17 +17,10 @@ final class PhabricatorSlowvoteListController
$request = $this->getRequest();
$user = $request->getUser();
$views = array(
self::VIEW_ALL => 'All Slowvotes',
self::VIEW_CREATED => 'Created',
self::VIEW_VOTED => 'Voted In',
);
$view = $this->view;
$views = $this->getViews();
$view = isset($views[$this->view])
? $this->view
: self::VIEW_ALL;
$side_nav = $this->renderSideNav($views, $view);
$side_nav = $this->buildSideNavView($view);
$pager = new AphrontPagerView();
$pager->setOffset($request->getInt('page'));
@ -69,25 +58,49 @@ final class PhabricatorSlowvoteListController
));
$table->setHeaders(
array(
'ID',
'Poll',
'Author',
'Date',
'Time',
pht('ID'),
pht('Poll'),
pht('Author'),
pht('Date'),
pht('Time'),
));
switch ($view) {
case self::VIEW_ALL:
$table_header =
pht('Slowvotes Not Yet Consumed by the Ravages of Time');
break;
case self::VIEW_CREATED:
$table_header =
pht('Slowvotes Birthed from Your Noblest of Great Minds');
break;
case self::VIEW_VOTED:
$table_header =
pht('Slowvotes Within Which You Express Your Mighty Opinion');
break;
}
$panel = new AphrontPanelView();
$panel->setHeader($this->getTableHeader($view));
$panel->setCreateButton('Create Slowvote', '/vote/create/');
$panel->setHeader($table_header);
$panel->setNoBackground();
$panel->appendChild($table);
$panel->appendChild($pager);
$side_nav->appendChild($panel);
return $this->buildStandardPageResponse(
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setName($views[$view])
->setHref($this->getApplicationURI())
);
$side_nav->setCrumbs($crumbs);
return $this->buildApplicationPage(
$side_nav,
array(
'title' => 'Slowvotes',
'title' => pht('Slowvotes'),
'device' => true,
));
}
@ -142,26 +155,4 @@ final class PhabricatorSlowvoteListController
return $poll->loadAllFromArray($data);
}
private function renderSideNav(array $views, $view) {
$side_nav = new AphrontSideNavFilterView();
$side_nav->setBaseURI(new PhutilURI('/vote/view/'));
foreach ($views as $key => $name) {
$side_nav->addFilter($key, $name);
}
$side_nav->selectFilter($view, null);
return $side_nav;
}
private function getTableHeader($view) {
static $headers = array(
self::VIEW_ALL
=> 'Slowvotes Not Yet Consumed by the Ravages of Time',
self::VIEW_CREATED
=> 'Slowvotes Birthed from Your Noblest of Great Minds',
self::VIEW_VOTED
=> 'Slowvotes Within Which You Express Your Mighty Opinion',
);
return idx($headers, $view);
}
}

View file

@ -147,13 +147,13 @@ final class PhabricatorSlowvotePollController
if ($viewer_choices) {
$instructions =
'Your vote has been recorded... but there is still ample time to '.
pht('Your vote has been recorded... but there is still ample time to '.
'rethink your position. Have you thoroughly considered all possible '.
'eventualities?';
'eventualities?');
} else {
$instructions =
'This is a weighty matter indeed. Consider your choices with the '.
'greatest of care.';
pht('This is a weighty matter indeed. Consider your choices with the '.
'greatest of care.');
}
$form = id(new AphrontFormView())
@ -163,31 +163,32 @@ final class PhabricatorSlowvotePollController
$instructions))
->appendChild(
id(new AphrontFormMarkupControl())
->setLabel('Vote')
->setLabel(pht('Vote'))
->setValue($option_markup))
->appendChild(
id(new AphrontFormTextAreaControl())
->setLabel('Comments')
->setLabel(pht('Comments'))
->setHeight(AphrontFormTextAreaControl::HEIGHT_SHORT)
->setName('comments')
->setValue($comment_text))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue('Cautiously Engage in Deliberations'));
->setValue(pht('Engage in Deliberations')));
$panel = new AphrontPanelView();
$panel->setHeader($poll->getQuestion());
$panel->setWidth(AphrontPanelView::WIDTH_WIDE);
$panel->setNoBackground();
$panel->appendChild($form);
$panel->appendChild(hsprintf('<br /><br />'));
$panel->appendChild($result_markup);
return $this->buildStandardPageResponse(
return $this->buildApplicationPage(
$panel,
array(
'title' => 'V'.$poll->getID().' '.$poll->getQuestion(),
'device' => true,
));
}
@ -372,13 +373,13 @@ final class PhabricatorSlowvotePollController
}
$result_markup = id(new AphrontFormLayoutView())
->appendChild(phutil_tag('h1', array(), 'Ongoing Deliberation'));
->appendChild(phutil_tag('h1', array(), pht('Ongoing Deliberation')));
if (!$can_see_responses) {
if ($need_vote) {
$reason = "You must vote to see the results.";
$reason = pht("You must vote to see the results.");
} else {
$reason = "The results are not public.";
$reason = pht("The results are not public.");
}
$result_markup
->appendChild(hsprintf(
@ -415,7 +416,7 @@ final class PhabricatorSlowvotePollController
)));
}
} else {
$user_markup = 'This option has failed to appeal to anyone.';
$user_markup = pht('This option has failed to appeal to anyone.');
}
$comment_markup = $this->renderComments(
@ -449,7 +450,7 @@ final class PhabricatorSlowvotePollController
$comments,
$handles);
$result_markup->appendChild(
phutil_tag('h1', array(), 'Motions Proposed for Consideration'));
phutil_tag('h1', array(), pht('Motions Proposed for Consideration')));
$result_markup->appendChild($comment_markup);
}