1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-05 12:21:02 +01:00

Add Application Routes to Phame AppSearch queries

Summary: Fixes T9388, lays in basic ApplicationSearch.

Test Plan: Build a dashboard with Posts and Blogs, click on search icon, get sent to correct page.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T9388

Differential Revision: https://secure.phabricator.com/D14146
This commit is contained in:
Chad Little 2015-09-23 12:48:19 -07:00
parent 1f311d64c6
commit be9cc235b2
4 changed files with 55 additions and 146 deletions

View file

@ -42,6 +42,7 @@ final class PhabricatorPhameApplication extends PhabricatorApplication {
'live/(?P<id>[^/]+)/(?P<more>.*)' => 'PhameBlogLiveController', 'live/(?P<id>[^/]+)/(?P<more>.*)' => 'PhameBlogLiveController',
'post/' => array( 'post/' => array(
'(?:(?P<filter>draft|all)/)?' => 'PhamePostListController', '(?:(?P<filter>draft|all)/)?' => 'PhamePostListController',
'(?:query/(?P<queryKey>[^/]+)/)?' => 'PhamePostListController',
'blogger/(?P<bloggername>[\w\.-_]+)/' => 'PhamePostListController', 'blogger/(?P<bloggername>[\w\.-_]+)/' => 'PhamePostListController',
'delete/(?P<id>[^/]+)/' => 'PhamePostDeleteController', 'delete/(?P<id>[^/]+)/' => 'PhamePostDeleteController',
'edit/(?:(?P<id>[^/]+)/)?' => 'PhamePostEditController', 'edit/(?:(?P<id>[^/]+)/)?' => 'PhamePostEditController',
@ -56,6 +57,7 @@ final class PhabricatorPhameApplication extends PhabricatorApplication {
), ),
'blog/' => array( 'blog/' => array(
'(?:(?P<filter>user|all)/)?' => 'PhameBlogListController', '(?:(?P<filter>user|all)/)?' => 'PhameBlogListController',
'(?:query/(?P<queryKey>[^/]+)/)?' => 'PhameBlogListController',
'delete/(?P<id>[^/]+)/' => 'PhameBlogDeleteController', 'delete/(?P<id>[^/]+)/' => 'PhameBlogDeleteController',
'edit/(?P<id>[^/]+)/' => 'PhameBlogEditController', 'edit/(?P<id>[^/]+)/' => 'PhameBlogEditController',
'view/(?P<id>[^/]+)/' => 'PhameBlogViewController', 'view/(?P<id>[^/]+)/' => 'PhameBlogViewController',

View file

@ -2,86 +2,33 @@
final class PhameBlogListController extends PhameController { final class PhameBlogListController extends PhameController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getUser(); $query_key = $request->getURIData('queryKey');
$controller = id(new PhabricatorApplicationSearchController())
->setQueryKey($query_key)
->setSearchEngine(new PhameBlogSearchEngine())
->setNavigation($this->buildSideNavView());
$nav = $this->renderSideNavFilterView(null); return $this->delegateToController($controller);
$filter = $request->getURIData('filter');
$filter = $nav->selectFilter('blog/'.$filter, 'blog/user');
$query = id(new PhameBlogQuery())
->setViewer($user);
switch ($filter) {
case 'blog/all':
$title = pht('All Blogs');
$nodata = pht('No blogs have been created.');
break;
case 'blog/user':
$title = pht('Joinable Blogs');
$nodata = pht('There are no blogs you can contribute to.');
$query->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_JOIN,
));
break;
default:
throw new Exception(pht("Unknown filter '%s'!", $filter));
} }
$pager = id(new PHUIPagerView()) public function buildSideNavView() {
->setURI($request->getRequestURI(), 'offset') $viewer = $this->getRequest()->getUser();
->setOffset($request->getInt('offset'));
$blogs = $query->executeWithOffsetPager($pager); $nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
$blog_list = $this->renderBlogList($blogs, $user, $nodata); id(new PhameBlogSearchEngine())
$blog_list->setPager($pager); ->setViewer($viewer)
->addNavigationItems($nav->getMenu());
$box = id(new PHUIObjectBoxView()) $nav->selectFilter(null);
->setHeaderText($title)
->setObjectList($blog_list);
$crumbs = $this->buildApplicationCrumbs(); return $nav;
$crumbs->addTextCrumb($title, $this->getApplicationURI());
$nav->appendChild(
array(
$crumbs,
$box,
));
return $this->buildApplicationPage(
$nav,
array(
'title' => $title,
));
}
private function renderBlogList(
array $blogs,
PhabricatorUser $viewer,
$nodata) {
$view = new PHUIObjectItemListView();
$view->setNoDataString($nodata);
$view->setUser($viewer);
foreach ($blogs as $blog) {
$id = $blog->getID();
$item = id(new PHUIObjectItemView())
->setUser($viewer)
->setObject($blog)
->setHeader($blog->getName())
->setStatusIcon('fa-star')
->setHref($this->getApplicationURI("/blog/view/{$id}/"))
->addAttribute($blog->getSkin())
->addAttribute($blog->getDomain());
$view->addItem($item);
}
return $view;
} }
} }

View file

@ -2,78 +2,37 @@
final class PhamePostListController extends PhameController { final class PhamePostListController extends PhameController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer(); $query_key = $request->getURIData('queryKey');
$filter = $request->getURIData('filter'); $controller = id(new PhabricatorApplicationSearchController())
$bloggername = $request->getURIData('bloggername'); ->setQueryKey($query_key)
->setSearchEngine(new PhamePostSearchEngine())
->setNavigation($this->buildSideNavView());
$query = id(new PhamePostQuery()) return $this->delegateToController($controller);
->setViewer($viewer);
$nav = $this->renderSideNavFilterView();
$nodata = null;
switch ($filter) {
case 'draft':
$query->withBloggerPHIDs(array($viewer->getPHID()));
$query->withVisibility(PhamePost::VISIBILITY_DRAFT);
$nodata = pht('You have no unpublished drafts.');
$title = pht('Unpublished Drafts');
$nav->selectFilter('post/draft');
break;
case 'blogger':
if ($bloggername) {
$blogger = id(new PhabricatorUser())->loadOneWhere(
'username = %s',
$bloggername);
if (!$blogger) {
return new Aphront404Response();
}
} else {
$blogger = $viewer;
} }
$query->withBloggerPHIDs(array($blogger->getPHID())); public function buildSideNavView() {
if ($blogger->getPHID() == $viewer->getPHID()) { $viewer = $this->getRequest()->getUser();
$nav->selectFilter('post');
$nodata = pht('You have not written any posts.'); $nav = new AphrontSideNavFilterView();
} else { $nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
$nodata = pht('%s has not written any posts.', $blogger);
} id(new PhamePostSearchEngine())
$title = pht('Posts by %s', $blogger); ->setViewer($viewer)
break; ->addNavigationItems($nav->getMenu());
default:
case 'all': $nav->addLabel(pht('Blogs'));
$nodata = pht('There are no visible posts.'); $nav->addFilter('blog/', pht('Manage Blogs'));
$title = pht('Posts');
$nav->selectFilter('post/all'); $nav->selectFilter(null);
break;
return $nav;
} }
$pager = id(new AphrontCursorPagerView())
->readFromRequest($request);
$posts = $query->executeWithCursorPager($pager);
$post_list = $this->renderPostList($posts, $viewer, $nodata);
$post_list = id(new PHUIObjectBoxView())
->setHeaderText($title)
->appendChild($post_list);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($title, $this->getApplicationURI());
$nav->appendChild(
array(
$crumbs,
$post_list,
));
return $this->buildApplicationPage(
$nav,
array(
'title' => $title,
));
}
} }

View file

@ -29,6 +29,7 @@ final class PhamePostSearchEngine
return array( return array(
id(new PhabricatorSearchSelectField()) id(new PhabricatorSearchSelectField())
->setKey('visibility') ->setKey('visibility')
->setLabel(pht('Visibility'))
->setOptions(array( ->setOptions(array(
'' => pht('All'), '' => pht('All'),
PhamePost::VISIBILITY_PUBLISHED => pht('Live'), PhamePost::VISIBILITY_PUBLISHED => pht('Live'),