diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 8320ea298e..90768186e4 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -836,6 +836,7 @@ phutil_register_library_map(array( 'HeraldTranscriptGarbageCollector' => 'applications/herald/garbagecollector/HeraldTranscriptGarbageCollector.php', 'HeraldTranscriptListController' => 'applications/herald/controller/HeraldTranscriptListController.php', 'HeraldTranscriptQuery' => 'applications/herald/query/HeraldTranscriptQuery.php', + 'HeraldTranscriptSearchEngine' => 'applications/herald/query/HeraldTranscriptSearchEngine.php', 'HeraldTranscriptTestCase' => 'applications/herald/storage/__tests__/HeraldTranscriptTestCase.php', 'Javelin' => 'infrastructure/javelin/Javelin.php', 'JavelinReactorExample' => 'applications/uiexample/examples/JavelinReactorExample.php', @@ -3455,8 +3456,13 @@ phutil_register_library_map(array( ), 'HeraldTranscriptController' => 'HeraldController', 'HeraldTranscriptGarbageCollector' => 'PhabricatorGarbageCollector', - 'HeraldTranscriptListController' => 'HeraldController', + 'HeraldTranscriptListController' => + array( + 0 => 'HeraldController', + 1 => 'PhabricatorApplicationSearchResultsControllerInterface', + ), 'HeraldTranscriptQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'HeraldTranscriptSearchEngine' => 'PhabricatorApplicationSearchEngine', 'HeraldTranscriptTestCase' => 'PhabricatorTestCase', 'JavelinReactorExample' => 'PhabricatorUIExample', 'JavelinUIExample' => 'PhabricatorUIExample', diff --git a/src/applications/herald/application/PhabricatorApplicationHerald.php b/src/applications/herald/application/PhabricatorApplicationHerald.php index 4dfec83b6c..7ce1832994 100644 --- a/src/applications/herald/application/PhabricatorApplicationHerald.php +++ b/src/applications/herald/application/PhabricatorApplicationHerald.php @@ -47,10 +47,13 @@ final class PhabricatorApplicationHerald extends PhabricatorApplication { 'HeraldDisableController', 'history/(?:(?P[1-9]\d*)/)?' => 'HeraldRuleEditHistoryController', 'test/' => 'HeraldTestConsoleController', - 'transcript/' => 'HeraldTranscriptListController', - 'transcript/(?P[1-9]\d*)/(?:(?P\w+)/)?' + 'transcript/' => array( + '' => 'HeraldTranscriptListController', + '(?:query/(?P[^/]+)/)?' => 'HeraldTranscriptListController', + '(?P[1-9]\d*)/(?:(?P\w+)/)?' => 'HeraldTranscriptController', - ), + ) + ) ); } diff --git a/src/applications/herald/controller/HeraldTestConsoleController.php b/src/applications/herald/controller/HeraldTestConsoleController.php index 7ec11b9d19..58eae13c04 100644 --- a/src/applications/herald/controller/HeraldTestConsoleController.php +++ b/src/applications/herald/controller/HeraldTestConsoleController.php @@ -96,14 +96,16 @@ final class HeraldTestConsoleController extends HeraldController { ->setFormErrors($errors) ->setForm($form); + $nav = $this->buildSideNavView(); + $nav->selectFilter('test'); + $nav->appendChild($box); + $crumbs = id($this->buildApplicationCrumbs()) - ->addTextCrumb( - pht('Transcripts'), - $this->getApplicationURI('/transcript/')) ->addTextCrumb(pht('Test Console')); + $nav->setCrumbs($crumbs); return $this->buildApplicationPage( - $box, + $nav, array( 'title' => pht('Test Console'), 'device' => true, diff --git a/src/applications/herald/controller/HeraldTranscriptListController.php b/src/applications/herald/controller/HeraldTranscriptListController.php index 29004e0379..37399c3647 100644 --- a/src/applications/herald/controller/HeraldTranscriptListController.php +++ b/src/applications/herald/controller/HeraldTranscriptListController.php @@ -1,19 +1,59 @@ getRequest()->getUser(); + + $nav = new AphrontSideNavFilterView(); + $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); + + if ($for_app) { + $nav->addFilter('new', pht('Create Rule')); + } + + id(new HeraldTranscriptSearchEngine()) + ->setViewer($user) + ->addNavigationItems($nav->getMenu()); + + $nav->selectFilter(null); + + return $nav; + } + + public function buildApplicationCrumbs() { + $crumbs = parent::buildApplicationCrumbs(); + + $crumbs->addTextCrumb( + pht('Transcripts'), + $this->getApplicationURI('transcript/')); + return $crumbs; + } + + public function willProcessRequest(array $data) { + $this->queryKey = idx($data, 'queryKey'); + } public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); + $controller = id(new PhabricatorApplicationSearchController($request)) + ->setQueryKey($this->queryKey) + ->setSearchEngine(new HeraldTranscriptSearchEngine()) + ->setNavigation($this->buildSideNavView()); - $pager = new AphrontCursorPagerView(); - $pager->readFromRequest($request); + return $this->delegateToController($controller); + } - $transcripts = id(new HeraldTranscriptQuery()) - ->setViewer($user) - ->needPartialRecords(true) - ->executeWithCursorPager($pager); + + public function renderResultsList( + array $transcripts, + PhabricatorSavedQuery $query) { + assert_instances_of($transcripts, 'HeraldTranscript'); + + $viewer = $this->getRequest()->getUser(); // Render the table. $handles = array(); @@ -25,8 +65,8 @@ final class HeraldTranscriptListController extends HeraldController { $rows = array(); foreach ($transcripts as $xscript) { $rows[] = array( - phabricator_date($xscript->getTime(), $user), - phabricator_time($xscript->getTime(), $user), + phabricator_date($xscript->getTime(), $viewer), + phabricator_time($xscript->getTime(), $viewer), $handles[$xscript->getObjectPHID()]->renderLink(), $xscript->getDryRun() ? pht('Yes') : '', number_format((int)(1000 * $xscript->getDuration())).' ms', @@ -64,23 +104,10 @@ final class HeraldTranscriptListController extends HeraldController { $panel = new AphrontPanelView(); $panel->setHeader(pht('Herald Transcripts')); $panel->appendChild($table); - $panel->appendChild($pager); $panel->setNoBackground(); - $nav = $this->buildSideNavView(); - $nav->selectFilter('transcript'); - $nav->appendChild($panel); + return $panel; - $crumbs = id($this->buildApplicationCrumbs()) - ->addTextCrumb(pht('Transcripts')); - $nav->setCrumbs($crumbs); - - return $this->buildApplicationPage( - $nav, - array( - 'title' => pht('Herald Transcripts'), - 'device' => true, - )); } } diff --git a/src/applications/herald/query/HeraldTranscriptQuery.php b/src/applications/herald/query/HeraldTranscriptQuery.php index 258b2ea898..64b999a027 100644 --- a/src/applications/herald/query/HeraldTranscriptQuery.php +++ b/src/applications/herald/query/HeraldTranscriptQuery.php @@ -4,6 +4,7 @@ final class HeraldTranscriptQuery extends PhabricatorCursorPagedPolicyAwareQuery { private $ids; + private $objectPHIDs; private $needPartialRecords; public function withIDs(array $ids) { @@ -11,6 +12,11 @@ final class HeraldTranscriptQuery return $this; } + public function withObjectPHIDs(array $phids) { + $this->objectPHIDs = $phids; + return $this; + } + public function needPartialRecords($need_partial) { $this->needPartialRecords = $need_partial; return $this; @@ -89,6 +95,13 @@ final class HeraldTranscriptQuery $this->ids); } + if ($this->objectPHIDs) { + $where[] = qsprintf( + $conn_r, + 'objectPHID in (%Ls)', + $this->objectPHIDs); + } + $where[] = $this->buildPagingClause($conn_r); return $this->formatWhereClause($where); diff --git a/src/applications/herald/query/HeraldTranscriptSearchEngine.php b/src/applications/herald/query/HeraldTranscriptSearchEngine.php new file mode 100644 index 0000000000..4fa6667ced --- /dev/null +++ b/src/applications/herald/query/HeraldTranscriptSearchEngine.php @@ -0,0 +1,92 @@ +getStrList('objectMonograms'); + $saved->setParameter('objectMonograms', $object_monograms); + + $ids = $request->getStrList('ids'); + foreach ($ids as $key => $id) { + if (!$id || !is_numeric($id)) { + unset($ids[$key]); + } else { + $ids[$key] = $id; + } + } + $saved->setParameter('ids', $ids); + + return $saved; + } + + public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { + $query = id(new HeraldTranscriptQuery()); + + $object_monograms = $saved->getParameter('objectMonograms'); + if ($object_monograms) { + $objects = id(new PhabricatorObjectQuery()) + ->setViewer($this->requireViewer()) + ->withNames($object_monograms) + ->execute(); + $query->withObjectPHIDs(mpull($objects, 'getPHID')); + } + + $ids = $saved->getParameter('ids'); + if ($ids) { + $query->withIDs($ids); + } + + return $query; + } + + public function buildSearchForm( + AphrontFormView $form, + PhabricatorSavedQuery $saved) { + + $object_monograms = $saved->getParameter('objectMonograms', array()); + $ids = $saved->getParameter('ids', array()); + + $form + ->appendChild( + id(new AphrontFormTextControl()) + ->setName('objectMonograms') + ->setLabel(pht('Object Monograms')) + ->setValue(implode(', ', $object_monograms))) + ->appendChild( + id(new AphrontFormTextControl()) + ->setName('ids') + ->setLabel(pht('Transcript IDs')) + ->setValue(implode(', ', $ids))); + } + + protected function getURI($path) { + return '/herald/transcript/'.$path; + } + + public function getBuiltinQueryNames() { + $names = array(); + + $names['all'] = pht('All'); + + return $names; + } + + public function buildSavedQueryFromBuiltin($query_key) { + + $query = $this->newSavedQuery(); + $query->setQueryKey($query_key); + + $viewer_phid = $this->requireViewer()->getPHID(); + + switch ($query_key) { + case 'all': + return $query; + } + + return parent::buildSavedQueryFromBuiltin($query_key); + } + +} diff --git a/src/applications/search/controller/PhabricatorApplicationSearchController.php b/src/applications/search/controller/PhabricatorApplicationSearchController.php index 14fc701738..f326c71ddd 100644 --- a/src/applications/search/controller/PhabricatorApplicationSearchController.php +++ b/src/applications/search/controller/PhabricatorApplicationSearchController.php @@ -281,7 +281,7 @@ final class PhabricatorApplicationSearchController $crumbs = $parent ->buildApplicationCrumbs() - ->addTextCrumb(pht("Search")); + ->addTextCrumb($title); $nav->setCrumbs($crumbs);