Add a SublimeText-style repository typeahead
Summary:
Allows you to quickly search for files within a repository. Roughly:
- We build a big tree of everything and ship it to the client.
- The client implements a bunch of Sublime-ish magic to find paths.
Test Plan: {F154007}
Reviewers: chad, btrahan
Reviewed By: btrahan
Subscribers: epriestley, zeeg
Differential Revision: https://secure.phabricator.com/D9087
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
final class DiffusionPathTreeController extends DiffusionController {
|
||||
|
||||
public function processRequest() {
|
||||
$drequest = $this->getDiffusionRequest();
|
||||
|
||||
if (!$drequest->getRepository()->canUsePathTree()) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$paths = $this->callConduitWithDiffusionRequest(
|
||||
'diffusion.querypaths',
|
||||
array(
|
||||
'path' => $drequest->getPath(),
|
||||
'commit' => $drequest->getCommit(),
|
||||
));
|
||||
|
||||
$tree = array();
|
||||
foreach ($paths as $path) {
|
||||
$parts = preg_split('((?<=/))', $path);
|
||||
$cursor = &$tree;
|
||||
foreach ($parts as $part) {
|
||||
if (!is_array($cursor)) {
|
||||
$cursor = array();
|
||||
}
|
||||
if (!isset($cursor[$part])) {
|
||||
$cursor[$part] = 1;
|
||||
}
|
||||
$cursor = &$cursor[$part];
|
||||
}
|
||||
}
|
||||
|
||||
return id(new AphrontAjaxResponse())->setContent(array('tree' => $tree));
|
||||
}
|
||||
}
|
||||
@@ -366,9 +366,9 @@ final class DiffusionRepositoryController extends DiffusionController {
|
||||
$button->setTag('a');
|
||||
$button->setIcon($icon);
|
||||
$button->setHref($drequest->generateURI(
|
||||
array(
|
||||
'action' => 'tags',
|
||||
)));
|
||||
array(
|
||||
'action' => 'tags',
|
||||
)));
|
||||
|
||||
$header->addActionLink($button);
|
||||
|
||||
@@ -529,6 +529,33 @@ final class DiffusionRepositoryController extends DiffusionController {
|
||||
|
||||
$header->addActionLink($button);
|
||||
$browse_panel->setHeader($header);
|
||||
|
||||
if ($repository->canUsePathTree()) {
|
||||
Javelin::initBehavior(
|
||||
'diffusion-locate-file',
|
||||
array(
|
||||
'controlID' => 'locate-control',
|
||||
'inputID' => 'locate-input',
|
||||
'browseBaseURI' => (string)$drequest->generateURI(
|
||||
array(
|
||||
'action' => 'browse',
|
||||
)),
|
||||
'uri' => (string)$drequest->generateURI(
|
||||
array(
|
||||
'action' => 'pathtree',
|
||||
)),
|
||||
));
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setUser($viewer)
|
||||
->appendChild(
|
||||
id(new AphrontFormTypeaheadControl())
|
||||
->setHardpointID('locate-control')
|
||||
->setID('locate-input')
|
||||
->setLabel(pht('Locate File')));
|
||||
$browse_panel->appendChild($form->buildLayoutView());
|
||||
}
|
||||
|
||||
$browse_panel->appendChild($browse_table);
|
||||
|
||||
return $browse_panel;
|
||||
|
||||
Reference in New Issue
Block a user