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 {
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$drequest = $this->diffusionRequest;
|
|
|
|
|
2013-09-29 00:55:38 +02:00
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($this->buildHeaderView($drequest))
|
Provide more structure to PHUIObjectBoxView
Summary:
Three changes here.
- Add `setActionList()`, and use that to set the action list.
- Add `setPropertyList()`, and use that to set the property list.
These will let us add some apropriate CSS so we can fix the border issue, and get rid of a bunch of goofy `.x + .y` selectors.
- Replace `addContent()` with `appendChild()`.
This is just a consistency thing; `AphrontView` already provides `appendChild()`, and `addContent()` did the same thing.
Test Plan:
- Viewed "All Config".
- Viewed a countdown.
- Viewed a revision (add comment, change list, table of contents, comment, local commits, open revisions affecting these files, update history).
- Viewed Diffusion (browse, change, history, repository, lint).
- Viewed Drydock (resource, lease).
- Viewed Files.
- Viewed Herald.
- Viewed Legalpad.
- Viewed macro (edit, edit audio, view).
- Viewed Maniphest.
- Viewed Applications.
- Viewed Paste.
- Viewed People.
- Viewed Phulux.
- Viewed Pholio.
- Viewed Phame (blog, post).
- Viewed Phortune (account, product).
- Viewed Ponder (questions, answers, comments).
- Viewed Releeph.
- Viewed Projects.
- Viewed Slowvote.
NOTE: Images in Files aren't on a black background anymore -- I assume that's on purpose?
NOTE: Some jankiness in Phortune, I'll clean that up when I get back to it. Not related to this diff.
Reviewers: chad
Reviewed By: chad
CC: aran
Differential Revision: https://secure.phabricator.com/D7174
2013-09-30 18:36:04 +02:00
|
|
|
->setActionList($this->buildActionView($drequest))
|
|
|
|
->setPropertyList($this->buildPropertyView($drequest));
|
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(
|
|
|
|
'device' => true,
|
|
|
|
'title' => array(
|
|
|
|
nonempty(basename($drequest->getPath()), '/'),
|
|
|
|
$drequest->getRepository()->getCallsign().' Repository',
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderSearchResults() {
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
$repository = $drequest->getRepository();
|
|
|
|
$results = array();
|
|
|
|
$no_data = pht('No results found.');
|
|
|
|
|
|
|
|
$limit = 100;
|
|
|
|
$page = $this->getRequest()->getInt('page', 0);
|
|
|
|
$pager = new AphrontPagerView();
|
|
|
|
$pager->setPageSize($limit);
|
|
|
|
$pager->setOffset($page);
|
|
|
|
$pager->setURI($this->getRequest()->getRequestURI(), 'page');
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
$results = $this->callConduitWithDiffusionRequest(
|
|
|
|
'diffusion.searchquery',
|
|
|
|
array(
|
|
|
|
'grep' => $this->getRequest()->getStr('grep'),
|
|
|
|
'stableCommitName' => $drequest->getStableCommitName(),
|
|
|
|
'path' => $drequest->getPath(),
|
|
|
|
'limit' => $limit + 1,
|
|
|
|
'offset' => $page));
|
|
|
|
|
|
|
|
} catch (ConduitException $ex) {
|
|
|
|
$err = $ex->getErrorDescription();
|
|
|
|
if ($err != '') {
|
|
|
|
return id(new AphrontErrorView())
|
|
|
|
->setTitle(pht('Search Error'))
|
|
|
|
->appendChild($err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$results = $pager->sliceResults($results);
|
|
|
|
|
|
|
|
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 {
|
|
|
|
Futures($futures)->limit(8)->resolveAll();
|
|
|
|
} catch (PhutilSyntaxHighlighterException $ex) {
|
|
|
|
}
|
|
|
|
|
|
|
|
$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();
|
|
|
|
} catch (PhutilSyntaxHighlighterException $ex) {
|
|
|
|
}
|
|
|
|
|
|
|
|
$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'))
|
|
|
|
->setNoDataString($no_data);
|
|
|
|
|
|
|
|
return id(new AphrontPanelView())
|
|
|
|
->setNoBackground(true)
|
|
|
|
->appendChild($table)
|
|
|
|
->appendChild($pager);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|