Make jump nav use object name queries
Summary: Cleans up jump nav so it doesn't hard code a bunch of application behaviors. It still hard-codes a few, but few//er//? Test Plan: Jumped to stuff like `D12`, `d`, `@dog`, `p admins only`, etc. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D7196
This commit is contained in:
parent
901bdda6b1
commit
691e73b576
|
@ -76,10 +76,11 @@ final class PhabricatorDirectoryMainController
|
||||||
|
|
||||||
private function buildJumpResponse() {
|
private function buildJumpResponse() {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
$jump = $request->getStr('jump');
|
$jump = $request->getStr('jump');
|
||||||
|
|
||||||
$response = PhabricatorJumpNavHandler::jumpPostResponse($jump);
|
$response = PhabricatorJumpNavHandler::getJumpResponse(
|
||||||
|
$request->getUser(),
|
||||||
|
$jump);
|
||||||
|
|
||||||
if ($response) {
|
if ($response) {
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,9 @@ final class PhabricatorSearchController
|
||||||
$pref_jump = PhabricatorUserPreferences::PREFERENCE_SEARCHBAR_JUMP;
|
$pref_jump = PhabricatorUserPreferences::PREFERENCE_SEARCHBAR_JUMP;
|
||||||
if ($request->getStr('jump') != 'no' &&
|
if ($request->getStr('jump') != 'no' &&
|
||||||
$user && $user->loadPreferences()->getPreference($pref_jump, 1)) {
|
$user && $user->loadPreferences()->getPreference($pref_jump, 1)) {
|
||||||
$response = PhabricatorJumpNavHandler::jumpPostResponse($query_str);
|
$response = PhabricatorJumpNavHandler::getJumpResponse(
|
||||||
|
$user,
|
||||||
|
$query_str);
|
||||||
} else {
|
} else {
|
||||||
$response = null;
|
$response = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class PhabricatorJumpNavHandler {
|
final class PhabricatorJumpNavHandler {
|
||||||
public static function jumpPostResponse($jump) {
|
|
||||||
|
public static function getJumpResponse(PhabricatorUser $viewer, $jump) {
|
||||||
$jump = trim($jump);
|
$jump = trim($jump);
|
||||||
$help_href = PhabricatorEnv::getDocLink(
|
$help_href = PhabricatorEnv::getDocLink('article/Jump_Nav_User_Guide.html');
|
||||||
'article/Jump_Nav_User_Guide.html');
|
|
||||||
|
|
||||||
$patterns = array(
|
$patterns = array(
|
||||||
'/^help/i' => 'uri:'.$help_href,
|
'/^help/i' => 'uri:'.$help_href,
|
||||||
|
@ -15,18 +15,14 @@ final class PhabricatorJumpNavHandler {
|
||||||
'/^t$/i' => 'uri:/maniphest/',
|
'/^t$/i' => 'uri:/maniphest/',
|
||||||
'/^p$/i' => 'uri:/project/',
|
'/^p$/i' => 'uri:/project/',
|
||||||
'/^u$/i' => 'uri:/people/',
|
'/^u$/i' => 'uri:/people/',
|
||||||
'/^r([A-Z]+)$/' => 'repository',
|
|
||||||
'/^r([A-Z]+)(\S+)$/' => 'commit',
|
|
||||||
'/^d(\d+)$/i' => 'revision',
|
|
||||||
'/^t(\d+)$/i' => 'task',
|
|
||||||
'/^p(\d+)$/i' => 'paste',
|
|
||||||
'/^p\s+(.+)$/i' => 'project',
|
'/^p\s+(.+)$/i' => 'project',
|
||||||
|
'/^#(.+)$/i' => 'project',
|
||||||
'/^u\s+(\S+)$/i' => 'user',
|
'/^u\s+(\S+)$/i' => 'user',
|
||||||
|
'/^@(.+)$/i' => 'user',
|
||||||
'/^task:\s*(.+)/i' => 'create-task',
|
'/^task:\s*(.+)/i' => 'create-task',
|
||||||
'/^(?:s|symbol)\s+(\S+)/i' => 'find-symbol',
|
'/^(?:s|symbol)\s+(\S+)/i' => 'find-symbol',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
foreach ($patterns as $pattern => $effect) {
|
foreach ($patterns as $pattern => $effect) {
|
||||||
$matches = null;
|
$matches = null;
|
||||||
if (preg_match($pattern, $jump, $matches)) {
|
if (preg_match($pattern, $jump, $matches)) {
|
||||||
|
@ -35,24 +31,9 @@ final class PhabricatorJumpNavHandler {
|
||||||
->setURI(substr($effect, 4));
|
->setURI(substr($effect, 4));
|
||||||
} else {
|
} else {
|
||||||
switch ($effect) {
|
switch ($effect) {
|
||||||
case 'repository':
|
|
||||||
return id(new AphrontRedirectResponse())
|
|
||||||
->setURI('/diffusion/'.$matches[1].'/');
|
|
||||||
case 'commit':
|
|
||||||
return id(new AphrontRedirectResponse())
|
|
||||||
->setURI('/'.$matches[0]);
|
|
||||||
case 'revision':
|
|
||||||
return id(new AphrontRedirectResponse())
|
|
||||||
->setURI('/D'.$matches[1]);
|
|
||||||
case 'task':
|
|
||||||
return id(new AphrontRedirectResponse())
|
|
||||||
->setURI('/T'.$matches[1]);
|
|
||||||
case 'user':
|
case 'user':
|
||||||
return id(new AphrontRedirectResponse())
|
return id(new AphrontRedirectResponse())
|
||||||
->setURI('/p/'.$matches[1].'/');
|
->setURI('/p/'.$matches[1].'/');
|
||||||
case 'paste':
|
|
||||||
return id(new AphrontRedirectResponse())
|
|
||||||
->setURI('/P'.$matches[1]);
|
|
||||||
case 'project':
|
case 'project':
|
||||||
$project = self::findCloselyNamedProject($matches[1]);
|
$project = self::findCloselyNamedProject($matches[1]);
|
||||||
if ($project) {
|
if ($project) {
|
||||||
|
@ -83,6 +64,21 @@ final class PhabricatorJumpNavHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If none of the patterns matched, look for an object by name.
|
||||||
|
$objects = id(new PhabricatorObjectQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withNames(array($jump))
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
if (count($objects) == 1) {
|
||||||
|
$handle = id(new PhabricatorHandleQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withPHIDs(mpull($objects, 'getPHID'))
|
||||||
|
->executeOne();
|
||||||
|
|
||||||
|
return id(new AphrontRedirectResponse())->setURI($handle->getURI());
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue