mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 12:00:55 +01:00
Refactor SlowvoteList controller
Summary: No change in functionality, just splitting this method up a bit Test Plan: Loaded list and looked at all three views. Reviewed By: jungejason Reviewers: jungejason, codeblock, aran, tuomaspelkonen CC: aran, jungejason Differential Revision: 618
This commit is contained in:
parent
233a2055f1
commit
f8c541b819
1 changed files with 78 additions and 61 deletions
|
@ -34,35 +34,80 @@ class PhabricatorSlowvoteListController
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
|
|
||||||
$filters = array(
|
$views = array(
|
||||||
self::VIEW_ALL => 'All Slowvotes',
|
self::VIEW_ALL => 'All Slowvotes',
|
||||||
self::VIEW_CREATED => 'Created',
|
self::VIEW_CREATED => 'Created',
|
||||||
self::VIEW_VOTED => 'Voted In',
|
self::VIEW_VOTED => 'Voted In',
|
||||||
);
|
);
|
||||||
|
|
||||||
$view = isset($filters[$this->view])
|
$view = isset($views[$this->view])
|
||||||
? $this->view
|
? $this->view
|
||||||
: self::VIEW_ALL;
|
: self::VIEW_ALL;
|
||||||
|
|
||||||
$side_nav = new AphrontSideNavView();
|
$side_nav = $this->renderSideNav($views, $view);
|
||||||
foreach ($filters as $key => $name) {
|
|
||||||
$side_nav->addNavItem(
|
|
||||||
phutil_render_tag(
|
|
||||||
'a',
|
|
||||||
array(
|
|
||||||
'href' => '/vote/view/'.$key.'/',
|
|
||||||
'class' => ($view == $key) ? 'aphront-side-nav-selected' : null,
|
|
||||||
),
|
|
||||||
phutil_escape_html($name)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$poll = new PhabricatorSlowvotePoll();
|
|
||||||
$conn = $poll->establishConnection('r');
|
|
||||||
|
|
||||||
$pager = new AphrontPagerView();
|
$pager = new AphrontPagerView();
|
||||||
$pager->setOffset($request->getInt('page'));
|
$pager->setOffset($request->getInt('page'));
|
||||||
$pager->setURI($request->getRequestURI(), 'page');
|
$pager->setURI($request->getRequestURI(), 'page');
|
||||||
|
|
||||||
|
$polls = $this->loadPolls($pager, $view);
|
||||||
|
|
||||||
|
$phids = mpull($polls, 'getAuthorPHID');
|
||||||
|
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
|
||||||
|
|
||||||
|
$rows = array();
|
||||||
|
foreach ($polls as $poll) {
|
||||||
|
$rows[] = array(
|
||||||
|
$handles[$poll->getAuthorPHID()]->renderLink(),
|
||||||
|
phutil_render_tag(
|
||||||
|
'a',
|
||||||
|
array(
|
||||||
|
'href' => '/V'.$poll->getID(),
|
||||||
|
),
|
||||||
|
phutil_escape_html('V'.$poll->getID().' '.$poll->getQuestion())),
|
||||||
|
phabricator_date($poll->getDateCreated(), $user),
|
||||||
|
phabricator_time($poll->getDateCreated(), $user),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$table = new AphrontTableView($rows);
|
||||||
|
$table->setColumnClasses(
|
||||||
|
array(
|
||||||
|
'',
|
||||||
|
'pri wide',
|
||||||
|
'',
|
||||||
|
'right',
|
||||||
|
));
|
||||||
|
$table->setHeaders(
|
||||||
|
array(
|
||||||
|
'Author',
|
||||||
|
'Poll',
|
||||||
|
'Date',
|
||||||
|
'Time',
|
||||||
|
));
|
||||||
|
|
||||||
|
$panel = new AphrontPanelView();
|
||||||
|
$panel->setHeader($this->getTableHeader($view));
|
||||||
|
$panel->setCreateButton('Create Slowvote', '/vote/create/');
|
||||||
|
$panel->appendChild($table);
|
||||||
|
$panel->appendChild($pager);
|
||||||
|
|
||||||
|
$side_nav->appendChild($panel);
|
||||||
|
|
||||||
|
return $this->buildStandardPageResponse(
|
||||||
|
$side_nav,
|
||||||
|
array(
|
||||||
|
'title' => 'Slowvotes',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function loadPolls(AphrontPagerView $pager, $view) {
|
||||||
|
$request = $this->getRequest();
|
||||||
|
$user = $request->getUser();
|
||||||
|
|
||||||
|
$poll = new PhabricatorSlowvotePoll();
|
||||||
|
|
||||||
|
$conn = $poll->establishConnection('r');
|
||||||
$offset = $pager->getOffset();
|
$offset = $pager->getOffset();
|
||||||
$limit = $pager->getPageSize() + 1;
|
$limit = $pager->getPageSize() + 1;
|
||||||
|
|
||||||
|
@ -104,43 +149,28 @@ class PhabricatorSlowvoteListController
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $pager->sliceResults($data);
|
$data = $pager->sliceResults($data);
|
||||||
$polls = $poll->loadAllFromArray($data);
|
return $poll->loadAllFromArray($data);
|
||||||
|
}
|
||||||
|
|
||||||
$phids = mpull($polls, 'getAuthorPHID');
|
private function renderSideNav(array $views, $view) {
|
||||||
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
|
$side_nav = new AphrontSideNavView();
|
||||||
|
foreach ($views as $key => $name) {
|
||||||
$rows = array();
|
$side_nav->addNavItem(
|
||||||
foreach ($polls as $poll) {
|
|
||||||
$rows[] = array(
|
|
||||||
$handles[$poll->getAuthorPHID()]->renderLink(),
|
|
||||||
phutil_render_tag(
|
phutil_render_tag(
|
||||||
'a',
|
'a',
|
||||||
array(
|
array(
|
||||||
'href' => '/V'.$poll->getID(),
|
'href' => '/vote/view/'.$key.'/',
|
||||||
|
'class' => ($view == $key)
|
||||||
|
? 'aphront-side-nav-selected'
|
||||||
|
: null,
|
||||||
),
|
),
|
||||||
phutil_escape_html('V'.$poll->getID().' '.$poll->getQuestion())),
|
phutil_escape_html($name)));
|
||||||
phabricator_date($poll->getDateCreated(), $user),
|
}
|
||||||
phabricator_time($poll->getDateCreated(), $user),
|
return $side_nav;
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$table = new AphrontTableView($rows);
|
private function getTableHeader($view) {
|
||||||
$table->setColumnClasses(
|
static $headers = array(
|
||||||
array(
|
|
||||||
'',
|
|
||||||
'pri wide',
|
|
||||||
'',
|
|
||||||
'right',
|
|
||||||
));
|
|
||||||
$table->setHeaders(
|
|
||||||
array(
|
|
||||||
'Author',
|
|
||||||
'Poll',
|
|
||||||
'Date',
|
|
||||||
'Time',
|
|
||||||
));
|
|
||||||
|
|
||||||
$headers = array(
|
|
||||||
self::VIEW_ALL
|
self::VIEW_ALL
|
||||||
=> 'Slowvotes Not Yet Consumed by the Ravages of Time',
|
=> 'Slowvotes Not Yet Consumed by the Ravages of Time',
|
||||||
self::VIEW_CREATED
|
self::VIEW_CREATED
|
||||||
|
@ -148,20 +178,7 @@ class PhabricatorSlowvoteListController
|
||||||
self::VIEW_VOTED
|
self::VIEW_VOTED
|
||||||
=> 'Slowvotes Within Which You Express Your Mighty Opinion',
|
=> 'Slowvotes Within Which You Express Your Mighty Opinion',
|
||||||
);
|
);
|
||||||
|
return idx($headers, $view);
|
||||||
$panel = new AphrontPanelView();
|
|
||||||
$panel->setHeader(idx($headers, $view));
|
|
||||||
$panel->setCreateButton('Create Slowvote', '/vote/create/');
|
|
||||||
$panel->appendChild($table);
|
|
||||||
$panel->appendChild($pager);
|
|
||||||
|
|
||||||
$side_nav->appendChild($panel);
|
|
||||||
|
|
||||||
return $this->buildStandardPageResponse(
|
|
||||||
$side_nav,
|
|
||||||
array(
|
|
||||||
'title' => 'Slowvotes',
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue