Use ApplicationSearch in Pholio
Summary: Ref T2637. Ref T2625. Convert Pholio to use ApplicationSearch. Test Plan: Viewed mocks, changed filters. Verified edit page works and no longer has a weird side nav on it. Reviewers: btrahan, chad Reviewed By: btrahan CC: aran Maniphest Tasks: T2625, T2637 Differential Revision: https://secure.phabricator.com/D6530
This commit is contained in:
@@ -1751,6 +1751,7 @@ phutil_register_library_map(array(
|
|||||||
'PholioMockListController' => 'applications/pholio/controller/PholioMockListController.php',
|
'PholioMockListController' => 'applications/pholio/controller/PholioMockListController.php',
|
||||||
'PholioMockMailReceiver' => 'applications/pholio/mail/PholioMockMailReceiver.php',
|
'PholioMockMailReceiver' => 'applications/pholio/mail/PholioMockMailReceiver.php',
|
||||||
'PholioMockQuery' => 'applications/pholio/query/PholioMockQuery.php',
|
'PholioMockQuery' => 'applications/pholio/query/PholioMockQuery.php',
|
||||||
|
'PholioMockSearchEngine' => 'applications/pholio/query/PholioMockSearchEngine.php',
|
||||||
'PholioMockViewController' => 'applications/pholio/controller/PholioMockViewController.php',
|
'PholioMockViewController' => 'applications/pholio/controller/PholioMockViewController.php',
|
||||||
'PholioPHIDTypeMock' => 'applications/pholio/phid/PholioPHIDTypeMock.php',
|
'PholioPHIDTypeMock' => 'applications/pholio/phid/PholioPHIDTypeMock.php',
|
||||||
'PholioRemarkupRule' => 'applications/pholio/remarkup/PholioRemarkupRule.php',
|
'PholioRemarkupRule' => 'applications/pholio/remarkup/PholioRemarkupRule.php',
|
||||||
@@ -3787,9 +3788,14 @@ phutil_register_library_map(array(
|
|||||||
'PholioMockEditor' => 'PhabricatorApplicationTransactionEditor',
|
'PholioMockEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||||
'PholioMockEmbedView' => 'AphrontView',
|
'PholioMockEmbedView' => 'AphrontView',
|
||||||
'PholioMockImagesView' => 'AphrontView',
|
'PholioMockImagesView' => 'AphrontView',
|
||||||
'PholioMockListController' => 'PholioController',
|
'PholioMockListController' =>
|
||||||
|
array(
|
||||||
|
0 => 'PholioController',
|
||||||
|
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
|
||||||
|
),
|
||||||
'PholioMockMailReceiver' => 'PhabricatorObjectMailReceiver',
|
'PholioMockMailReceiver' => 'PhabricatorObjectMailReceiver',
|
||||||
'PholioMockQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PholioMockQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
|
'PholioMockSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
'PholioMockViewController' => 'PholioController',
|
'PholioMockViewController' => 'PholioController',
|
||||||
'PholioPHIDTypeMock' => 'PhabricatorPHIDType',
|
'PholioPHIDTypeMock' => 'PhabricatorPHIDType',
|
||||||
'PholioRemarkupRule' => 'PhabricatorRemarkupRuleObject',
|
'PholioRemarkupRule' => 'PhabricatorRemarkupRuleObject',
|
||||||
|
|||||||
@@ -44,8 +44,7 @@ final class PhabricatorApplicationPholio extends PhabricatorApplication {
|
|||||||
return array(
|
return array(
|
||||||
'/M(?P<id>[1-9]\d*)(?:/(?P<imageID>\d+)/)?' => 'PholioMockViewController',
|
'/M(?P<id>[1-9]\d*)(?:/(?P<imageID>\d+)/)?' => 'PholioMockViewController',
|
||||||
'/pholio/' => array(
|
'/pholio/' => array(
|
||||||
'' => 'PholioMockListController',
|
'(?:query/(?P<queryKey>[^/]+)/)?' => 'PholioMockListController',
|
||||||
'view/(?P<view>\w+)/' => 'PholioMockListController',
|
|
||||||
'new/' => 'PholioMockEditController',
|
'new/' => 'PholioMockEditController',
|
||||||
'edit/(?P<id>\d+)/' => 'PholioMockEditController',
|
'edit/(?P<id>\d+)/' => 'PholioMockEditController',
|
||||||
'comment/(?P<id>\d+)/' => 'PholioMockCommentController',
|
'comment/(?P<id>\d+)/' => 'PholioMockCommentController',
|
||||||
|
|||||||
@@ -5,18 +5,22 @@
|
|||||||
*/
|
*/
|
||||||
abstract class PholioController extends PhabricatorController {
|
abstract class PholioController extends PhabricatorController {
|
||||||
|
|
||||||
public function buildSideNav($filter = null, $for_app = false) {
|
public function buildSideNavView($for_app = false) {
|
||||||
|
$user = $this->getRequest()->getUser();
|
||||||
|
|
||||||
$nav = new AphrontSideNavFilterView();
|
$nav = new AphrontSideNavFilterView();
|
||||||
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
||||||
|
|
||||||
$nav->addLabel('Mocks');
|
id(new PholioMockSearchEngine())
|
||||||
$nav->addFilter('view/all', pht('All Mocks'));
|
->setViewer($user)
|
||||||
$nav->addFilter('view/my', pht('My Mocks'));
|
->addNavigationItems($nav->getMenu());
|
||||||
|
|
||||||
if ($for_app) {
|
if ($for_app) {
|
||||||
$nav->addFilter('new/', pht('Create Mock'));
|
$nav->addFilter('new/', pht('Create Mock'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$nav->selectFilter(null);
|
||||||
|
|
||||||
return $nav;
|
return $nav;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +37,7 @@ abstract class PholioController extends PhabricatorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function buildApplicationMenu() {
|
public function buildApplicationMenu() {
|
||||||
return $this->buildSideNav(null, true)->getMenu();
|
return $this->buildSideNavView(true)->getMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ final class PholioMockEditController extends PholioController {
|
|||||||
->setError($e_images))
|
->setError($e_images))
|
||||||
->appendChild($submit);
|
->appendChild($submit);
|
||||||
|
|
||||||
$crumbs = $this->buildApplicationCrumbs($this->buildSideNav());
|
$crumbs = $this->buildApplicationCrumbs();
|
||||||
$crumbs->addCrumb(
|
$crumbs->addCrumb(
|
||||||
id(new PhabricatorCrumbView())
|
id(new PhabricatorCrumbView())
|
||||||
->setName($title)
|
->setName($title)
|
||||||
@@ -289,12 +289,8 @@ final class PholioMockEditController extends PholioController {
|
|||||||
$form,
|
$form,
|
||||||
);
|
);
|
||||||
|
|
||||||
$nav = $this->buildSideNav();
|
|
||||||
$nav->selectFilter(null);
|
|
||||||
$nav->appendChild($content);
|
|
||||||
|
|
||||||
return $this->buildApplicationPage(
|
return $this->buildApplicationPage(
|
||||||
$nav,
|
$content,
|
||||||
array(
|
array(
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
'device' => true,
|
'device' => true,
|
||||||
|
|||||||
@@ -1,45 +1,35 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
final class PholioMockListController
|
||||||
* @group pholio
|
extends PholioController
|
||||||
*/
|
implements PhabricatorApplicationSearchResultsControllerInterface {
|
||||||
final class PholioMockListController extends PholioController {
|
|
||||||
|
|
||||||
private $view;
|
private $queryKey;
|
||||||
|
|
||||||
|
public function shouldAllowPublic() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public function willProcessRequest(array $data) {
|
public function willProcessRequest(array $data) {
|
||||||
$this->view = idx($data, 'view');
|
$this->queryKey = idx($data, 'queryKey');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function processRequest() {
|
public function processRequest() {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$controller = id(new PhabricatorApplicationSearchController($request))
|
||||||
$viewer_phid = $user->getPHID();
|
->setQueryKey($this->queryKey)
|
||||||
|
->setSearchEngine(new PholioMockSearchEngine())
|
||||||
|
->setNavigation($this->buildSideNavView());
|
||||||
|
|
||||||
$query = id(new PholioMockQuery())
|
return $this->delegateToController($controller);
|
||||||
->setViewer($user)
|
}
|
||||||
->needCoverFiles(true)
|
|
||||||
->needImages(true)
|
|
||||||
->needTokenCounts(true);
|
|
||||||
|
|
||||||
$nav = $this->buildSideNav();
|
public function renderResultsList(
|
||||||
$filter = $nav->selectFilter('view/'.$this->view, 'view/all');
|
array $mocks,
|
||||||
|
PhabricatorSavedQuery $query) {
|
||||||
|
assert_instances_of($mocks, 'PholioMock');
|
||||||
|
|
||||||
switch ($filter) {
|
$viewer = $this->getRequest()->getUser();
|
||||||
case 'view/all':
|
|
||||||
default:
|
|
||||||
$title = pht('All Mocks');
|
|
||||||
break;
|
|
||||||
case 'view/my':
|
|
||||||
$title = pht('My Mocks');
|
|
||||||
$query->withAuthorPHIDs(array($viewer_phid));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$pager = new AphrontCursorPagerView();
|
|
||||||
$pager->readFromRequest($request);
|
|
||||||
|
|
||||||
$mocks = $query->executeWithCursorPager($pager);
|
|
||||||
|
|
||||||
$author_phids = array();
|
$author_phids = array();
|
||||||
foreach ($mocks as $mock) {
|
foreach ($mocks as $mock) {
|
||||||
@@ -47,47 +37,27 @@ final class PholioMockListController extends PholioController {
|
|||||||
}
|
}
|
||||||
$this->loadHandles($author_phids);
|
$this->loadHandles($author_phids);
|
||||||
|
|
||||||
|
|
||||||
$board = new PhabricatorPinboardView();
|
$board = new PhabricatorPinboardView();
|
||||||
foreach ($mocks as $mock) {
|
foreach ($mocks as $mock) {
|
||||||
$item = new PhabricatorPinboardItemView();
|
$item = id(new PhabricatorPinboardItemView())
|
||||||
$item->setHeader('M'.$mock->getID().' '.$mock->getName())
|
->setHeader('M'.$mock->getID().' '.$mock->getName())
|
||||||
->setURI('/M'.$mock->getID())
|
->setURI('/M'.$mock->getID())
|
||||||
->setImageURI($mock->getCoverFile()->getThumb280x210URI())
|
->setImageURI($mock->getCoverFile()->getThumb280x210URI())
|
||||||
->setImageSize(280, 210)
|
->setImageSize(280, 210)
|
||||||
->addIconCount('image', count($mock->getImages()))
|
->addIconCount('image', count($mock->getImages()))
|
||||||
->addIconCount('like', $mock->getTokenCount());
|
->addIconCount('like', $mock->getTokenCount());
|
||||||
|
|
||||||
if ($mock->getAuthorPHID()) {
|
if ($mock->getAuthorPHID()) {
|
||||||
$author_handle = $this->getHandle($mock->getAuthorPHID());
|
$author_handle = $this->getHandle($mock->getAuthorPHID());
|
||||||
$datetime = phabricator_date($mock->getDateCreated(), $user);
|
$datetime = phabricator_date($mock->getDateCreated(), $viewer);
|
||||||
$item->appendChild(
|
$item->appendChild(
|
||||||
pht('By %s on %s', $author_handle->renderLink(), $datetime));
|
pht('By %s on %s', $author_handle->renderLink(), $datetime));
|
||||||
}
|
}
|
||||||
|
|
||||||
$board->addItem($item);
|
$board->addItem($item);
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = array(
|
return $board;
|
||||||
$board,
|
|
||||||
$pager,
|
|
||||||
);
|
|
||||||
|
|
||||||
$nav->appendChild($content);
|
|
||||||
|
|
||||||
$crumbs = $this->buildApplicationCrumbs($this->buildSideNav());
|
|
||||||
$crumbs->addCrumb(
|
|
||||||
id(new PhabricatorCrumbView())
|
|
||||||
->setName($title)
|
|
||||||
->setHref($this->getApplicationURI()));
|
|
||||||
$nav->setCrumbs($crumbs);
|
|
||||||
|
|
||||||
return $this->buildApplicationPage(
|
|
||||||
$nav,
|
|
||||||
array(
|
|
||||||
'title' => $title,
|
|
||||||
'device' => true,
|
|
||||||
'dust' => true,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ final class PholioMockViewController extends PholioController {
|
|||||||
|
|
||||||
$add_comment = $this->buildAddCommentView($mock, $comment_form_id);
|
$add_comment = $this->buildAddCommentView($mock, $comment_form_id);
|
||||||
|
|
||||||
$crumbs = $this->buildApplicationCrumbs($this->buildSideNav());
|
$crumbs = $this->buildApplicationCrumbs();
|
||||||
$crumbs->setActionList($actions);
|
$crumbs->setActionList($actions);
|
||||||
$crumbs->addCrumb(
|
$crumbs->addCrumb(
|
||||||
id(new PhabricatorCrumbView())
|
id(new PhabricatorCrumbView())
|
||||||
|
|||||||
78
src/applications/pholio/query/PholioMockSearchEngine.php
Normal file
78
src/applications/pholio/query/PholioMockSearchEngine.php
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
final class PholioMockSearchEngine
|
||||||
|
extends PhabricatorApplicationSearchEngine {
|
||||||
|
|
||||||
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||||
|
$saved = new PhabricatorSavedQuery();
|
||||||
|
$saved->setParameter(
|
||||||
|
'authorPHIDs',
|
||||||
|
array_values($request->getArr('authors')));
|
||||||
|
|
||||||
|
return $saved;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||||
|
$query = id(new PholioMockQuery())
|
||||||
|
->needCoverFiles(true)
|
||||||
|
->needImages(true)
|
||||||
|
->needTokenCounts(true)
|
||||||
|
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()));
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildSearchForm(
|
||||||
|
AphrontFormView $form,
|
||||||
|
PhabricatorSavedQuery $saved_query) {
|
||||||
|
|
||||||
|
$phids = $saved_query->getParameter('authorPHIDs', array());
|
||||||
|
$handles = id(new PhabricatorObjectHandleData($phids))
|
||||||
|
->setViewer($this->requireViewer())
|
||||||
|
->loadHandles();
|
||||||
|
$author_tokens = mpull($handles, 'getFullName', 'getPHID');
|
||||||
|
|
||||||
|
$form
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormTokenizerControl())
|
||||||
|
->setDatasource('/typeahead/common/users/')
|
||||||
|
->setName('authors')
|
||||||
|
->setLabel(pht('Authors'))
|
||||||
|
->setValue($author_tokens));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getURI($path) {
|
||||||
|
return '/pholio/'.$path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBuiltinQueryNames() {
|
||||||
|
$names = array(
|
||||||
|
'all' => pht('All Mocks'),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($this->requireViewer()->isLoggedIn()) {
|
||||||
|
$names['authored'] = pht('Authored');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $names;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildSavedQueryFromBuiltin($query_key) {
|
||||||
|
|
||||||
|
$query = $this->newSavedQuery();
|
||||||
|
$query->setQueryKey($query_key);
|
||||||
|
|
||||||
|
switch ($query_key) {
|
||||||
|
case 'all':
|
||||||
|
return $query;
|
||||||
|
case 'authored':
|
||||||
|
return $query->setParameter(
|
||||||
|
'authorPHIDs',
|
||||||
|
array($this->requireViewer()->getPHID()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user