From 9f0914411732c372efdb9a266bcd9b3fd7302b46 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 30 Sep 2012 20:08:22 -0700 Subject: [PATCH] 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 --- .../ponder/controller/PonderController.php | 20 +++++ .../controller/PonderFeedController.php | 75 +++++++++++++------ .../ponder/query/PonderQuestionQuery.php | 1 + src/view/layout/PhabricatorObjectItemView.php | 1 + 4 files changed, 75 insertions(+), 22 deletions(-) diff --git a/src/applications/ponder/controller/PonderController.php b/src/applications/ponder/controller/PonderController.php index 8e40b4a4c9..91def1f133 100644 --- a/src/applications/ponder/controller/PonderController.php +++ b/src/applications/ponder/controller/PonderController.php @@ -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; + } + } diff --git a/src/applications/ponder/controller/PonderFeedController.php b/src/applications/ponder/controller/PonderFeedController.php index 58724ecfff..2fe4cb2d30 100644 --- a/src/applications/ponder/controller/PonderFeedController.php +++ b/src/applications/ponder/controller/PonderFeedController.php @@ -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; + } + } diff --git a/src/applications/ponder/query/PonderQuestionQuery.php b/src/applications/ponder/query/PonderQuestionQuery.php index 0b587f0c3d..c93bf69c0e 100644 --- a/src/applications/ponder/query/PonderQuestionQuery.php +++ b/src/applications/ponder/query/PonderQuestionQuery.php @@ -63,6 +63,7 @@ final class PonderQuestionQuery extends PhabricatorOffsetPagedQuery { ->setOffset($offset) ->setLimit($count) ->orderByHottest(true) + ->orderByNewest(true) ->execute(); } diff --git a/src/view/layout/PhabricatorObjectItemView.php b/src/view/layout/PhabricatorObjectItemView.php index 58d057ef04..e15e10f7f3 100644 --- a/src/view/layout/PhabricatorObjectItemView.php +++ b/src/view/layout/PhabricatorObjectItemView.php @@ -20,6 +20,7 @@ final class PhabricatorObjectItemView extends AphrontView { private $header; private $href; + private $attributes = array(); private $details = array(); private $dates = array();