From fc4e23c50f0a1e4366aea269017827b43f7762bf Mon Sep 17 00:00:00 2001 From: David Fisher Date: Mon, 20 Feb 2012 10:22:52 -0800 Subject: [PATCH] Added Additional Fuctionality to Jump Nav: Jump to users, projects, symbols, or create new tasks Summary: see title Test Plan: Tested jump nav and found the correct urls were being loaded. Old functionality was not effected. Reviewers: epriestley, btrahan Reviewed By: epriestley CC: ddfisher, allenjohnashton, kpark517, aran, epriestley Differential Revision: https://secure.phabricator.com/D1642 --- src/__phutil_library_map__.php | 1 + .../PhabricatorDirectoryMainController.php | 33 ++++++++++--- .../directory/controller/main/__init__.php | 1 + .../util/PhabricatorProjectQueryUtil.php | 46 +++++++++++++++++++ .../project/query/util/__init__.php | 14 ++++++ src/docs/userguide/jump.diviner | 9 +++- 6 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 src/applications/project/query/util/PhabricatorProjectQueryUtil.php create mode 100644 src/applications/project/query/util/__init__.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index e83581e17c..e5c35c6903 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -668,6 +668,7 @@ phutil_register_library_map(array( 'PhabricatorProjectProfileController' => 'applications/project/controller/profile', 'PhabricatorProjectProfileEditController' => 'applications/project/controller/profileedit', 'PhabricatorProjectQuery' => 'applications/project/query/project', + 'PhabricatorProjectQueryUtil' => 'applications/project/query/util', 'PhabricatorProjectStatus' => 'applications/project/constants/status', 'PhabricatorProjectSubproject' => 'applications/project/storage/subproject', 'PhabricatorProjectTransaction' => 'applications/project/storage/transaction', diff --git a/src/applications/directory/controller/main/PhabricatorDirectoryMainController.php b/src/applications/directory/controller/main/PhabricatorDirectoryMainController.php index 819f2f7f2d..706872b427 100644 --- a/src/applications/directory/controller/main/PhabricatorDirectoryMainController.php +++ b/src/applications/directory/controller/main/PhabricatorDirectoryMainController.php @@ -109,17 +109,16 @@ class PhabricatorDirectoryMainController '/^d$/i' => 'uri:/differential/', '/^r$/i' => 'uri:/diffusion/', '/^t$/i' => 'uri:/maniphest/', + '/^p$/i' => 'uri:/project/', + '/^u$/i' => 'uri:/people/', '/r([A-Z]+)$/' => 'repository', '/r([A-Z]+)(\S+)$/' => 'commit', '/^d(\d+)$/i' => 'revision', '/^t(\d+)$/i' => 'task', - - // TODO: '/^p$/i' => 'uri:/projects/', - // TODO: '/^u$/i' => 'uri:/people/', - // TODO: '/^p\s+(\S+)$/i' => 'project', - // TODO: '/^u\s+(\S+)$/i' => 'user', - // TODO: '/^task:\s+(\S+)/i' => 'create-task', - // TODO: '/^(?:s|symbol)\s+(\S+)/i' => 'find-symbol', + '/^p\s+(.+)$/i' => 'project', + '/^u\s+(\S+)$/i' => 'user', + '/^task:\s*(.+)/i' => 'create-task', + '/^(?:s|symbol)\s+(\S+)/i' => 'find-symbol', ); @@ -143,6 +142,26 @@ class PhabricatorDirectoryMainController case 'task': return id(new AphrontRedirectResponse()) ->setURI('/T'.$matches[1]); + case 'user': + return id(new AphrontRedirectResponse()) + ->setURI('/p/'.$matches[1].'/'); + case 'project': + $project = PhabricatorProjectQueryUtil + ::findCloselyNamedProject($matches[1]); + if ($project) { + return id(new AphrontRedirectResponse()) + ->setURI('/project/view/'.$project->getID().'/'); + } else { + $jump = $matches[1]; + } + break; + case 'find-symbol': + return id(new AphrontRedirectResponse()) + ->setURI('/diffusion/symbol/'.$matches[1].'/?jump=true'); + case 'create-task': + return id(new AphrontRedirectResponse()) + ->setURI('/maniphest/task/create/?title=' + .phutil_escape_uri($matches[1])); default: throw new Exception("Unknown jump effect '{$effect}'!"); } diff --git a/src/applications/directory/controller/main/__init__.php b/src/applications/directory/controller/main/__init__.php index 8f12294a0e..2f9726df2c 100644 --- a/src/applications/directory/controller/main/__init__.php +++ b/src/applications/directory/controller/main/__init__.php @@ -18,6 +18,7 @@ phutil_require_module('phabricator', 'applications/maniphest/query'); phutil_require_module('phabricator', 'applications/maniphest/view/tasklist'); phutil_require_module('phabricator', 'applications/phid/handle/data'); phutil_require_module('phabricator', 'applications/project/query/project'); +phutil_require_module('phabricator', 'applications/project/query/util'); phutil_require_module('phabricator', 'applications/search/storage/query'); phutil_require_module('phabricator', 'infrastructure/celerity/api'); phutil_require_module('phabricator', 'infrastructure/env'); diff --git a/src/applications/project/query/util/PhabricatorProjectQueryUtil.php b/src/applications/project/query/util/PhabricatorProjectQueryUtil.php new file mode 100644 index 0000000000..f07ebea7b5 --- /dev/null +++ b/src/applications/project/query/util/PhabricatorProjectQueryUtil.php @@ -0,0 +1,46 @@ +loadOneWhere( + 'name = %s', + name); + if ($project) { + return $project; + } else { // no exact match, try a fuzzy match + $projects = id(new PhabricatorProject())->loadAllWhere( + 'name LIKE %~', + $name); + if ($projects) { + $min_name_length = PHP_INT_MAX; + $best_project = null; + foreach ($projects as $project) { + $name_length = strlen($project->getName()); + if ($name_length <= $min_name_length) { + $min_name_length = $name_length; + $best_project = $project; + } + } + return $best_project; + } else { + return null; + } + } + } +} diff --git a/src/applications/project/query/util/__init__.php b/src/applications/project/query/util/__init__.php new file mode 100644 index 0000000000..4685a31eb8 --- /dev/null +++ b/src/applications/project/query/util/__init__.php @@ -0,0 +1,14 @@ +