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

Use responsive UI elements in Ponder list views

Summary:
Use the new `PhabricatorObjectItemListView` in Ponder so it works with the new UI. It will also get some features like flags "for free" in the future.

This removes the pager; I'll restore it in the next diff.

Test Plan: Looked at feed.

Reviewers: pieter, starruler

Reviewed By: pieter

CC: aran, chad

Maniphest Tasks: T1644

Differential Revision: https://secure.phabricator.com/D3507
This commit is contained in:
epriestley 2012-09-30 20:08:22 -07:00
parent 6b1c27eb0e
commit 9f09144117
4 changed files with 75 additions and 22 deletions

View file

@ -32,4 +32,24 @@ abstract class PonderController extends PhabricatorController {
return $response->setContent($page->render());
}
protected function buildSideNavView(PonderQuestion $question = null) {
$side_nav = new AphrontSideNavFilterView();
$side_nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
$side_nav->addLabel('Create');
$side_nav->addFilter('question/ask', 'Ask a Question');
$side_nav->addSpacer();
$side_nav->addLabel('Questions');
$side_nav->addFilter('feed', 'All Questions');
$side_nav->addSpacer();
$side_nav->addLabel('Profile');
$side_nav->addFilter('profile', 'User Profile');
return $side_nav;
}
}

View file

@ -39,40 +39,29 @@ final class PonderFeedController extends PonderController {
$this->answerOffset = $request->getInt('aoff');
$pages = array(
'feed' => 'Popular Questions',
'feed' => 'All Questions',
'profile' => 'User Profile',
);
$side_nav = new AphrontSideNavFilterView();
$side_nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
foreach ($pages as $name => $title) {
$side_nav->addFilter($name, $title);
}
$side_nav = $this->buildSideNavView();
$this->page = $side_nav->selectFilter($this->page, 'feed');
$title = $pages[$this->page];
switch ($this->page) {
case 'feed':
$data = PonderQuestionQuery::loadHottest(
$questions = PonderQuestionQuery::loadHottest(
$user,
$this->feedOffset,
self::FEED_PAGE_SIZE + 1);
$phids = array();
foreach ($data as $question) {
$phids[] = $question->getAuthorPHID();
}
$handles = $this->loadViewerHandles($phids);
$this->loadHandles(mpull($questions, 'getAuthorPHID'));
$view = $this->buildQuestionListView($questions);
$side_nav->appendChild(
id(new PonderQuestionFeedView())
->setUser($user)
->setData($data)
->setHandles($handles)
->setOffset($this->feedOffset)
->setPageSize(self::FEED_PAGE_SIZE)
->setURI(new PhutilURI("/ponder/feed/"), "off")
);
id(new PhabricatorHeaderView())->setHeader($title));
$side_nav->appendChild($view);
break;
case 'profile':
$questions = PonderQuestionQuery::loadByAuthor(
@ -107,11 +96,53 @@ final class PonderFeedController extends PonderController {
}
return $this->buildStandardPageResponse(
return $this->buildApplicationPage(
$side_nav,
array(
'title' => $pages[$this->page]
'device' => true,
'title' => $title,
));
}
private function buildQuestionListView(array $questions) {
assert_instances_of($questions, 'PonderQuestion');
$user = $this->getRequest()->getUser();
$view = new PhabricatorObjectItemListView();
$view->setNoDataString(pht('No matching questions.'));
foreach ($questions as $question) {
$item = new PhabricatorObjectItemView();
$item->setHeader('Q'.$question->getID().' '.$question->getTitle());
$item->setHref('/Q'.$question->getID());
$desc = $question->getContent();
if ($desc) {
$item->addDetail(
pht('Description'),
phutil_escape_html(phutil_utf8_shorten($desc, 128)));
}
$item->addDetail(
pht('Author'),
$this->getHandle($question->getAuthorPHID())->renderLink());
$item->addDetail(
pht('Votes'),
$question->getVoteCount());
$item->addDetail(
pht('Answers'),
$question->getAnswerCount());
$created = pht(
'Created %s',
phabricator_date($question->getDateCreated(), $user));
$item->addAttribute($created);
$view->addItem($item);
}
return $view;
}
}

View file

@ -63,6 +63,7 @@ final class PonderQuestionQuery extends PhabricatorOffsetPagedQuery {
->setOffset($offset)
->setLimit($count)
->orderByHottest(true)
->orderByNewest(true)
->execute();
}

View file

@ -20,6 +20,7 @@ final class PhabricatorObjectItemView extends AphrontView {
private $header;
private $href;
private $attributes = array();
private $details = array();
private $dates = array();