Clean up the Diffusion search UI a little bit

Summary:
Ref T156. @vlada recently implemented filename search in Diffusion, this cleans up the UI a little bit:

  - Instead of showing one search box with two different buttons, let the submit buttons appear to the right of the text boxes and separate the search modes.
  - Clean up the results a little bit (don't show columns which don't exist).

Test Plan: {F107260}

Reviewers: vlada, btrahan, chad

Reviewed By: chad

CC: vlada, chad, aran

Maniphest Tasks: T156

Differential Revision: https://secure.phabricator.com/D8125
This commit is contained in:
epriestley
2014-02-01 11:48:28 -08:00
parent 2d27324bef
commit bb633fb42a
8 changed files with 188 additions and 36 deletions

View File

@@ -8,38 +8,45 @@ abstract class DiffusionBrowseController extends DiffusionController {
protected function renderSearchForm($collapsed) {
$drequest = $this->getDiffusionRequest();
$forms = array();
$form = id(new AphrontFormView())
->setUser($this->getRequest()->getUser())
->setMethod('GET');
switch ($drequest->getRepository()->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$form->appendChild(pht('Search is not available in Subversion.'));
$forms[] = id(clone $form)
->appendChild(pht('Search is not available in Subversion.'));
break;
default:
$form
$forms[] = id(clone $form)
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Search Here'))
id(new AphrontFormTextWithSubmitControl())
->setLabel(pht('File Name'))
->setSubmitLabel(pht('Search File Names'))
->setName('find')
->setValue($this->getRequest()->getStr('find')));
$forms[] = id(clone $form)
->appendChild(
id(new AphrontFormTextWithSubmitControl())
->setLabel(pht('Pattern'))
->setSubmitLabel(pht('Grep File Content'))
->setName('grep')
->setValue($this->getRequest()->getStr('grep'))
->setCaption(pht('Enter a regular expression.')))
->appendChild(
id(new PHUIFormMultiSubmitControl())
->addButton('__ls__', pht('Search File Names'))
->addButton('__grep__', pht('Search File Content')));
->setValue($this->getRequest()->getStr('grep')));
break;
}
$filter = new AphrontListFilterView();
$filter->appendChild($form);
$filter->appendChild($forms);
if ($collapsed) {
$filter->setCollapsed(
pht('Show Search'),
pht('Hide Search'),
pht('Search for file content in this directory.'),
pht('Search for file names or content in this directory.'),
'#');
}

View File

@@ -9,8 +9,9 @@ final class DiffusionBrowseMainController extends DiffusionBrowseController {
// Figure out if we're browsing a directory, a file, or a search result
// list. Then delegate to the appropriate controller.
$search = $request->getStr('grep');
if (strlen($search)) {
$grep = $request->getStr('grep');
$find = $request->getStr('find');
if (strlen($grep) || strlen($find)) {
$controller = new DiffusionBrowseSearchController($request);
} else {
$results = DiffusionBrowseResultSet::newFromConduit(

View File

@@ -43,7 +43,6 @@ final class DiffusionBrowseSearchController extends DiffusionBrowseController {
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$results = array();
$no_data = pht('No results found.');
$limit = 100;
$page = $this->getRequest()->getInt('page', 0);
@@ -52,29 +51,33 @@ final class DiffusionBrowseSearchController extends DiffusionBrowseController {
$pager->setOffset($page);
$pager->setURI($this->getRequest()->getRequestURI(), 'page');
$search_mode = null;
try {
if ($this->getRequest()->getStr('__grep__')) {
if (strlen($this->getRequest()->getStr('grep'))) {
$search_mode = 'grep';
$query_string = $this->getRequest()->getStr('grep');
$results = $this->callConduitWithDiffusionRequest(
'diffusion.searchquery',
array(
'grep' => $this->getRequest()->getStr('grep'),
'grep' => $query_string,
'stableCommitName' => $drequest->getStableCommitName(),
'path' => $drequest->getPath(),
'limit' => $limit + 1,
'offset' => $page));
'offset' => $page,
));
} else { // Filename search.
$results_raw = $this->callConduitWithDiffusionRequest(
$search_mode = 'find';
$query_string = $this->getRequest()->getStr('find');
$results = $this->callConduitWithDiffusionRequest(
'diffusion.querypaths',
array(
'pattern' => $this->getRequest()->getStr('grep'),
'pattern' => $query_string,
'commit' => $drequest->getStableCommitName(),
'path' => $drequest->getPath(),
'limit' => $limit + 1,
'offset' => $page));
$results = [];
foreach ($results_raw as $result) {
$results[] = array($result, null, null);
}
'offset' => $page,
));
}
} catch (ConduitException $ex) {
$err = $ex->getErrorDescription();
@@ -87,6 +90,34 @@ final class DiffusionBrowseSearchController extends DiffusionBrowseController {
$results = $pager->sliceResults($results);
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();
require_celerity_resource('syntax-highlighting-css');
// NOTE: This can be wrong because we may find the string inside the
@@ -139,12 +170,40 @@ final class DiffusionBrowseSearchController extends DiffusionBrowseController {
->setClassName('remarkup-code')
->setHeaders(array(pht('Path'), pht('Line'), pht('String')))
->setColumnClasses(array('', 'n', 'wide'))
->setNoDataString($no_data);
->setNoDataString(
pht(
'The pattern you searched for was not found in the content of any '.
'files.'));
return id(new AphrontPanelView())
->setNoBackground(true)
->appendChild($table)
->appendChild($pager);
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;
}
}