mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-03 19:31: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:
parent
1f311d64c6
commit
be9cc235b2
4 changed files with 55 additions and 146 deletions
|
@ -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',
|
||||||
|
|
|
@ -2,86 +2,33 @@
|
||||||
|
|
||||||
final class PhameBlogListController extends PhameController {
|
final class PhameBlogListController extends PhameController {
|
||||||
|
|
||||||
public function handleRequest(AphrontRequest $request) {
|
public function shouldAllowPublic() {
|
||||||
$user = $request->getUser();
|
return true;
|
||||||
|
|
||||||
$nav = $this->renderSideNavFilterView(null);
|
|
||||||
$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())
|
|
||||||
->setURI($request->getRequestURI(), 'offset')
|
|
||||||
->setOffset($request->getInt('offset'));
|
|
||||||
|
|
||||||
$blogs = $query->executeWithOffsetPager($pager);
|
|
||||||
|
|
||||||
$blog_list = $this->renderBlogList($blogs, $user, $nodata);
|
|
||||||
$blog_list->setPager($pager);
|
|
||||||
|
|
||||||
$box = id(new PHUIObjectBoxView())
|
|
||||||
->setHeaderText($title)
|
|
||||||
->setObjectList($blog_list);
|
|
||||||
|
|
||||||
$crumbs = $this->buildApplicationCrumbs();
|
|
||||||
$crumbs->addTextCrumb($title, $this->getApplicationURI());
|
|
||||||
|
|
||||||
$nav->appendChild(
|
|
||||||
array(
|
|
||||||
$crumbs,
|
|
||||||
$box,
|
|
||||||
));
|
|
||||||
|
|
||||||
return $this->buildApplicationPage(
|
|
||||||
$nav,
|
|
||||||
array(
|
|
||||||
'title' => $title,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderBlogList(
|
public function handleRequest(AphrontRequest $request) {
|
||||||
array $blogs,
|
$query_key = $request->getURIData('queryKey');
|
||||||
PhabricatorUser $viewer,
|
$controller = id(new PhabricatorApplicationSearchController())
|
||||||
$nodata) {
|
->setQueryKey($query_key)
|
||||||
|
->setSearchEngine(new PhameBlogSearchEngine())
|
||||||
|
->setNavigation($this->buildSideNavView());
|
||||||
|
|
||||||
$view = new PHUIObjectItemListView();
|
return $this->delegateToController($controller);
|
||||||
$view->setNoDataString($nodata);
|
}
|
||||||
$view->setUser($viewer);
|
|
||||||
foreach ($blogs as $blog) {
|
|
||||||
|
|
||||||
$id = $blog->getID();
|
public function buildSideNavView() {
|
||||||
$item = id(new PHUIObjectItemView())
|
$viewer = $this->getRequest()->getUser();
|
||||||
->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);
|
$nav = new AphrontSideNavFilterView();
|
||||||
}
|
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
||||||
|
|
||||||
return $view;
|
id(new PhameBlogSearchEngine())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->addNavigationItems($nav->getMenu());
|
||||||
|
|
||||||
|
$nav->selectFilter(null);
|
||||||
|
|
||||||
|
return $nav;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,78 +2,37 @@
|
||||||
|
|
||||||
final class PhamePostListController extends PhameController {
|
final class PhamePostListController extends PhameController {
|
||||||
|
|
||||||
public function handleRequest(AphrontRequest $request) {
|
public function shouldAllowPublic() {
|
||||||
$viewer = $request->getViewer();
|
return true;
|
||||||
$filter = $request->getURIData('filter');
|
|
||||||
$bloggername = $request->getURIData('bloggername');
|
|
||||||
|
|
||||||
$query = id(new PhamePostQuery())
|
|
||||||
->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()));
|
|
||||||
if ($blogger->getPHID() == $viewer->getPHID()) {
|
|
||||||
$nav->selectFilter('post');
|
|
||||||
$nodata = pht('You have not written any posts.');
|
|
||||||
} else {
|
|
||||||
$nodata = pht('%s has not written any posts.', $blogger);
|
|
||||||
}
|
|
||||||
$title = pht('Posts by %s', $blogger);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
case 'all':
|
|
||||||
$nodata = pht('There are no visible posts.');
|
|
||||||
$title = pht('Posts');
|
|
||||||
$nav->selectFilter('post/all');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$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,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function handleRequest(AphrontRequest $request) {
|
||||||
|
$query_key = $request->getURIData('queryKey');
|
||||||
|
$controller = id(new PhabricatorApplicationSearchController())
|
||||||
|
->setQueryKey($query_key)
|
||||||
|
->setSearchEngine(new PhamePostSearchEngine())
|
||||||
|
->setNavigation($this->buildSideNavView());
|
||||||
|
|
||||||
|
return $this->delegateToController($controller);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildSideNavView() {
|
||||||
|
$viewer = $this->getRequest()->getUser();
|
||||||
|
|
||||||
|
$nav = new AphrontSideNavFilterView();
|
||||||
|
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
||||||
|
|
||||||
|
id(new PhamePostSearchEngine())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->addNavigationItems($nav->getMenu());
|
||||||
|
|
||||||
|
$nav->addLabel(pht('Blogs'));
|
||||||
|
$nav->addFilter('blog/', pht('Manage Blogs'));
|
||||||
|
|
||||||
|
$nav->selectFilter(null);
|
||||||
|
|
||||||
|
return $nav;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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'),
|
||||||
|
|
Loading…
Reference in a new issue