Improve organization of Diffusion browse controllers
Summary:
Currently we have this:
- DiffusionController (abstract, has some random shared browse code)
- DiffusionBrowseController (concrete, Handles routing, directories, and search)
- DiffusionBrowseFileController (concrete, handles files)
Instead, do this:
- DiffusionController (no browse-related code)
- DiffusionBrowseController (abstract, shared browse code)
- DiffusionBrowseMainController (concrete, handles routing)
- DiffusionBrowseDirectoryController (concrete, handles directories)
- DiffusionBrowseFileController (concrete, handles files)
- DiffusionBrowseSearchController (concrete, handles search)
Feels a lot cleaner.
Test Plan: Looked at directories, searches, and files.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7045
2013-09-20 01:01:34 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DiffusionBrowseSearchController extends DiffusionBrowseController {
|
|
|
|
|
2015-01-09 22:29:08 +01:00
|
|
|
protected function processDiffusionRequest(AphrontRequest $request) {
|
Improve organization of Diffusion browse controllers
Summary:
Currently we have this:
- DiffusionController (abstract, has some random shared browse code)
- DiffusionBrowseController (concrete, Handles routing, directories, and search)
- DiffusionBrowseFileController (concrete, handles files)
Instead, do this:
- DiffusionController (no browse-related code)
- DiffusionBrowseController (abstract, shared browse code)
- DiffusionBrowseMainController (concrete, handles routing)
- DiffusionBrowseDirectoryController (concrete, handles directories)
- DiffusionBrowseFileController (concrete, handles files)
- DiffusionBrowseSearchController (concrete, handles search)
Feels a lot cleaner.
Test Plan: Looked at directories, searches, and files.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7045
2013-09-20 01:01:34 +02:00
|
|
|
$drequest = $this->diffusionRequest;
|
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
$actions = $this->buildActionView($drequest);
|
|
|
|
$properties = $this->buildPropertyView($drequest, $actions);
|
|
|
|
|
2013-09-29 00:55:38 +02:00
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($this->buildHeaderView($drequest))
|
2013-10-11 16:53:56 +02:00
|
|
|
->addPropertyList($properties);
|
2013-09-29 00:55:38 +02:00
|
|
|
|
Improve organization of Diffusion browse controllers
Summary:
Currently we have this:
- DiffusionController (abstract, has some random shared browse code)
- DiffusionBrowseController (concrete, Handles routing, directories, and search)
- DiffusionBrowseFileController (concrete, handles files)
Instead, do this:
- DiffusionController (no browse-related code)
- DiffusionBrowseController (abstract, shared browse code)
- DiffusionBrowseMainController (concrete, handles routing)
- DiffusionBrowseDirectoryController (concrete, handles directories)
- DiffusionBrowseFileController (concrete, handles files)
- DiffusionBrowseSearchController (concrete, handles search)
Feels a lot cleaner.
Test Plan: Looked at directories, searches, and files.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7045
2013-09-20 01:01:34 +02:00
|
|
|
$content = array();
|
|
|
|
|
2013-09-29 00:55:38 +02:00
|
|
|
$content[] = $object_box;
|
Improve organization of Diffusion browse controllers
Summary:
Currently we have this:
- DiffusionController (abstract, has some random shared browse code)
- DiffusionBrowseController (concrete, Handles routing, directories, and search)
- DiffusionBrowseFileController (concrete, handles files)
Instead, do this:
- DiffusionController (no browse-related code)
- DiffusionBrowseController (abstract, shared browse code)
- DiffusionBrowseMainController (concrete, handles routing)
- DiffusionBrowseDirectoryController (concrete, handles directories)
- DiffusionBrowseFileController (concrete, handles files)
- DiffusionBrowseSearchController (concrete, handles search)
Feels a lot cleaner.
Test Plan: Looked at directories, searches, and files.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7045
2013-09-20 01:01:34 +02:00
|
|
|
$content[] = $this->renderSearchForm($collapsed = false);
|
|
|
|
$content[] = $this->renderSearchResults();
|
|
|
|
|
|
|
|
$crumbs = $this->buildCrumbs(
|
|
|
|
array(
|
|
|
|
'branch' => true,
|
|
|
|
'path' => true,
|
|
|
|
'view' => 'browse',
|
|
|
|
));
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$content,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => array(
|
|
|
|
nonempty(basename($drequest->getPath()), '/'),
|
|
|
|
$drequest->getRepository()->getCallsign().' Repository',
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderSearchResults() {
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
$repository = $drequest->getRepository();
|
|
|
|
$results = array();
|
|
|
|
|
|
|
|
$limit = 100;
|
|
|
|
$page = $this->getRequest()->getInt('page', 0);
|
|
|
|
$pager = new AphrontPagerView();
|
|
|
|
$pager->setPageSize($limit);
|
|
|
|
$pager->setOffset($page);
|
|
|
|
$pager->setURI($this->getRequest()->getRequestURI(), 'page');
|
|
|
|
|
2014-02-01 20:48:28 +01:00
|
|
|
$search_mode = null;
|
|
|
|
|
Improve organization of Diffusion browse controllers
Summary:
Currently we have this:
- DiffusionController (abstract, has some random shared browse code)
- DiffusionBrowseController (concrete, Handles routing, directories, and search)
- DiffusionBrowseFileController (concrete, handles files)
Instead, do this:
- DiffusionController (no browse-related code)
- DiffusionBrowseController (abstract, shared browse code)
- DiffusionBrowseMainController (concrete, handles routing)
- DiffusionBrowseDirectoryController (concrete, handles directories)
- DiffusionBrowseFileController (concrete, handles files)
- DiffusionBrowseSearchController (concrete, handles search)
Feels a lot cleaner.
Test Plan: Looked at directories, searches, and files.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7045
2013-09-20 01:01:34 +02:00
|
|
|
try {
|
2014-02-01 20:48:28 +01:00
|
|
|
if (strlen($this->getRequest()->getStr('grep'))) {
|
|
|
|
$search_mode = 'grep';
|
|
|
|
$query_string = $this->getRequest()->getStr('grep');
|
2014-02-01 17:32:23 +01:00
|
|
|
$results = $this->callConduitWithDiffusionRequest(
|
|
|
|
'diffusion.searchquery',
|
|
|
|
array(
|
2014-02-01 20:48:28 +01:00
|
|
|
'grep' => $query_string,
|
2014-05-13 22:51:45 +02:00
|
|
|
'commit' => $drequest->getStableCommit(),
|
2014-02-01 17:32:23 +01:00
|
|
|
'path' => $drequest->getPath(),
|
|
|
|
'limit' => $limit + 1,
|
2014-02-01 20:48:28 +01:00
|
|
|
'offset' => $page,
|
|
|
|
));
|
2014-02-01 17:32:23 +01:00
|
|
|
} else { // Filename search.
|
2014-02-01 20:48:28 +01:00
|
|
|
$search_mode = 'find';
|
|
|
|
$query_string = $this->getRequest()->getStr('find');
|
|
|
|
$results = $this->callConduitWithDiffusionRequest(
|
2014-02-01 17:32:23 +01:00
|
|
|
'diffusion.querypaths',
|
|
|
|
array(
|
2014-02-01 20:48:28 +01:00
|
|
|
'pattern' => $query_string,
|
2014-05-13 22:51:45 +02:00
|
|
|
'commit' => $drequest->getStableCommit(),
|
2014-02-01 17:32:23 +01:00
|
|
|
'path' => $drequest->getPath(),
|
|
|
|
'limit' => $limit + 1,
|
2014-02-01 20:48:28 +01:00
|
|
|
'offset' => $page,
|
|
|
|
));
|
2014-02-01 17:32:23 +01:00
|
|
|
}
|
Improve organization of Diffusion browse controllers
Summary:
Currently we have this:
- DiffusionController (abstract, has some random shared browse code)
- DiffusionBrowseController (concrete, Handles routing, directories, and search)
- DiffusionBrowseFileController (concrete, handles files)
Instead, do this:
- DiffusionController (no browse-related code)
- DiffusionBrowseController (abstract, shared browse code)
- DiffusionBrowseMainController (concrete, handles routing)
- DiffusionBrowseDirectoryController (concrete, handles directories)
- DiffusionBrowseFileController (concrete, handles files)
- DiffusionBrowseSearchController (concrete, handles search)
Feels a lot cleaner.
Test Plan: Looked at directories, searches, and files.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7045
2013-09-20 01:01:34 +02:00
|
|
|
} catch (ConduitException $ex) {
|
|
|
|
$err = $ex->getErrorDescription();
|
|
|
|
if ($err != '') {
|
|
|
|
return id(new AphrontErrorView())
|
|
|
|
->setTitle(pht('Search Error'))
|
|
|
|
->appendChild($err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$results = $pager->sliceResults($results);
|
|
|
|
|
2014-02-01 20:48:28 +01:00
|
|
|
if ($search_mode == 'grep') {
|
|
|
|
$table = $this->renderGrepResults($results);
|
|
|
|
$header = pht(
|
|
|
|
'File content matching "%s" under "%s"',
|
|
|
|
$query_string,
|
|
|
|
nonempty($drequest->getPath(), '/'));
|
|
|
|
} else {
|
|
|
|
$table = $this->renderFindResults($results);
|
|
|
|
$header = pht(
|
|
|
|
'Paths matching "%s" under "%s"',
|
|
|
|
$query_string,
|
|
|
|
nonempty($drequest->getPath(), '/'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeaderText($header)
|
|
|
|
->appendChild($table);
|
|
|
|
|
|
|
|
$pager_box = id(new PHUIBoxView())
|
|
|
|
->addMargin(PHUI::MARGIN_LARGE)
|
|
|
|
->appendChild($pager);
|
|
|
|
|
|
|
|
return array($box, $pager_box);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderGrepResults(array $results) {
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
|
Improve organization of Diffusion browse controllers
Summary:
Currently we have this:
- DiffusionController (abstract, has some random shared browse code)
- DiffusionBrowseController (concrete, Handles routing, directories, and search)
- DiffusionBrowseFileController (concrete, handles files)
Instead, do this:
- DiffusionController (no browse-related code)
- DiffusionBrowseController (abstract, shared browse code)
- DiffusionBrowseMainController (concrete, handles routing)
- DiffusionBrowseDirectoryController (concrete, handles directories)
- DiffusionBrowseFileController (concrete, handles files)
- DiffusionBrowseSearchController (concrete, handles search)
Feels a lot cleaner.
Test Plan: Looked at directories, searches, and files.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7045
2013-09-20 01:01:34 +02:00
|
|
|
require_celerity_resource('syntax-highlighting-css');
|
|
|
|
|
|
|
|
// NOTE: This can be wrong because we may find the string inside the
|
|
|
|
// comment. But it's correct in most cases and highlighting the whole file
|
|
|
|
// would be too expensive.
|
|
|
|
$futures = array();
|
|
|
|
$engine = PhabricatorSyntaxHighlighter::newEngine();
|
|
|
|
foreach ($results as $result) {
|
|
|
|
list($path, $line, $string) = $result;
|
|
|
|
$futures["{$path}:{$line}"] = $engine->getHighlightFuture(
|
|
|
|
$engine->getLanguageFromFilename($path),
|
|
|
|
ltrim($string));
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2014-12-30 13:13:38 +01:00
|
|
|
id(new FutureIterator($futures))
|
|
|
|
->limit(8)
|
|
|
|
->resolveAll();
|
2014-09-09 22:49:56 +02:00
|
|
|
} catch (PhutilSyntaxHighlighterException $ex) {}
|
Improve organization of Diffusion browse controllers
Summary:
Currently we have this:
- DiffusionController (abstract, has some random shared browse code)
- DiffusionBrowseController (concrete, Handles routing, directories, and search)
- DiffusionBrowseFileController (concrete, handles files)
Instead, do this:
- DiffusionController (no browse-related code)
- DiffusionBrowseController (abstract, shared browse code)
- DiffusionBrowseMainController (concrete, handles routing)
- DiffusionBrowseDirectoryController (concrete, handles directories)
- DiffusionBrowseFileController (concrete, handles files)
- DiffusionBrowseSearchController (concrete, handles search)
Feels a lot cleaner.
Test Plan: Looked at directories, searches, and files.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7045
2013-09-20 01:01:34 +02:00
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
foreach ($results as $result) {
|
|
|
|
list($path, $line, $string) = $result;
|
|
|
|
|
|
|
|
$href = $drequest->generateURI(array(
|
|
|
|
'action' => 'browse',
|
|
|
|
'path' => $path,
|
|
|
|
'line' => $line,
|
|
|
|
));
|
|
|
|
|
|
|
|
try {
|
|
|
|
$string = $futures["{$path}:{$line}"]->resolve();
|
2014-09-09 22:49:56 +02:00
|
|
|
} catch (PhutilSyntaxHighlighterException $ex) {}
|
Improve organization of Diffusion browse controllers
Summary:
Currently we have this:
- DiffusionController (abstract, has some random shared browse code)
- DiffusionBrowseController (concrete, Handles routing, directories, and search)
- DiffusionBrowseFileController (concrete, handles files)
Instead, do this:
- DiffusionController (no browse-related code)
- DiffusionBrowseController (abstract, shared browse code)
- DiffusionBrowseMainController (concrete, handles routing)
- DiffusionBrowseDirectoryController (concrete, handles directories)
- DiffusionBrowseFileController (concrete, handles files)
- DiffusionBrowseSearchController (concrete, handles search)
Feels a lot cleaner.
Test Plan: Looked at directories, searches, and files.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7045
2013-09-20 01:01:34 +02:00
|
|
|
|
|
|
|
$string = phutil_tag(
|
|
|
|
'pre',
|
|
|
|
array('class' => 'PhabricatorMonospaced'),
|
|
|
|
$string);
|
|
|
|
|
|
|
|
$path = Filesystem::readablePath($path, $drequest->getPath());
|
|
|
|
|
|
|
|
$rows[] = array(
|
|
|
|
phutil_tag('a', array('href' => $href), $path),
|
|
|
|
$line,
|
|
|
|
$string,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$table = id(new AphrontTableView($rows))
|
|
|
|
->setClassName('remarkup-code')
|
|
|
|
->setHeaders(array(pht('Path'), pht('Line'), pht('String')))
|
|
|
|
->setColumnClasses(array('', 'n', 'wide'))
|
2014-02-01 20:48:28 +01:00
|
|
|
->setNoDataString(
|
|
|
|
pht(
|
|
|
|
'The pattern you searched for was not found in the content of any '.
|
|
|
|
'files.'));
|
Improve organization of Diffusion browse controllers
Summary:
Currently we have this:
- DiffusionController (abstract, has some random shared browse code)
- DiffusionBrowseController (concrete, Handles routing, directories, and search)
- DiffusionBrowseFileController (concrete, handles files)
Instead, do this:
- DiffusionController (no browse-related code)
- DiffusionBrowseController (abstract, shared browse code)
- DiffusionBrowseMainController (concrete, handles routing)
- DiffusionBrowseDirectoryController (concrete, handles directories)
- DiffusionBrowseFileController (concrete, handles files)
- DiffusionBrowseSearchController (concrete, handles search)
Feels a lot cleaner.
Test Plan: Looked at directories, searches, and files.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7045
2013-09-20 01:01:34 +02:00
|
|
|
|
2014-02-01 20:48:28 +01:00
|
|
|
return $table;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderFindResults(array $results) {
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
foreach ($results as $result) {
|
|
|
|
$href = $drequest->generateURI(array(
|
|
|
|
'action' => 'browse',
|
|
|
|
'path' => $result,
|
|
|
|
));
|
|
|
|
|
|
|
|
$readable = Filesystem::readablePath($result, $drequest->getPath());
|
|
|
|
|
|
|
|
$rows[] = array(
|
|
|
|
phutil_tag('a', array('href' => $href), $readable),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$table = id(new AphrontTableView($rows))
|
|
|
|
->setHeaders(array(pht('Path')))
|
|
|
|
->setColumnClasses(array('wide'))
|
|
|
|
->setNoDataString(
|
|
|
|
pht(
|
|
|
|
'The pattern you searched for did not match the names of any '.
|
|
|
|
'files.'));
|
|
|
|
|
|
|
|
return $table;
|
Improve organization of Diffusion browse controllers
Summary:
Currently we have this:
- DiffusionController (abstract, has some random shared browse code)
- DiffusionBrowseController (concrete, Handles routing, directories, and search)
- DiffusionBrowseFileController (concrete, handles files)
Instead, do this:
- DiffusionController (no browse-related code)
- DiffusionBrowseController (abstract, shared browse code)
- DiffusionBrowseMainController (concrete, handles routing)
- DiffusionBrowseDirectoryController (concrete, handles directories)
- DiffusionBrowseFileController (concrete, handles files)
- DiffusionBrowseSearchController (concrete, handles search)
Feels a lot cleaner.
Test Plan: Looked at directories, searches, and files.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7045
2013-09-20 01:01:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|