From e407b2311e813a618ba1704d83a51c6a55ee2bfe Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 3 Apr 2011 22:23:31 -0700 Subject: [PATCH] Typeahead, handle and herald integration for packages. --- .../controller/rule/HeraldRuleController.php | 5 ++-- .../constants/PhabricatorPHIDConstants.php | 1 + .../data/PhabricatorObjectHandleData.php | 22 ++++++++++++++ ...torTypeaheadCommonDatasourceController.php | 30 +++++++++++++++++++ .../typeahead/controller/common/__init__.php | 2 ++ 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/applications/herald/controller/rule/HeraldRuleController.php b/src/applications/herald/controller/rule/HeraldRuleController.php index 1ddfe5b9e4..f48fd43105 100644 --- a/src/applications/herald/controller/rule/HeraldRuleController.php +++ b/src/applications/herald/controller/rule/HeraldRuleController.php @@ -445,10 +445,11 @@ class HeraldRuleController extends HeraldController { 'source' => array( 'email' => '/typeahead/common/mailable/', 'user' => '/typeahead/common/users/', - 'repository' => '/typeahead/common/repository/', + 'repository' => '/typeahead/common/repositories/', + 'package' => '/typeahead/common/packages/', + /* 'tag' => '/datasource/tag/', - 'package' => '/datasource/package/', */ ), 'markup' => $template, diff --git a/src/applications/phid/constants/PhabricatorPHIDConstants.php b/src/applications/phid/constants/PhabricatorPHIDConstants.php index f3e3867a8d..9dbb381c82 100644 --- a/src/applications/phid/constants/PhabricatorPHIDConstants.php +++ b/src/applications/phid/constants/PhabricatorPHIDConstants.php @@ -28,6 +28,7 @@ final class PhabricatorPHIDConstants { const PHID_TYPE_MAGIC = '!!!!'; const PHID_TYPE_REPO = 'REPO'; const PHID_TYPE_CMIT = 'CMIT'; + const PHID_TYPE_OPKG = 'OPKG'; public static function getTypes() { return array( diff --git a/src/applications/phid/handle/data/PhabricatorObjectHandleData.php b/src/applications/phid/handle/data/PhabricatorObjectHandleData.php index cc395d316e..d6e489e372 100644 --- a/src/applications/phid/handle/data/PhabricatorObjectHandleData.php +++ b/src/applications/phid/handle/data/PhabricatorObjectHandleData.php @@ -223,6 +223,28 @@ class PhabricatorObjectHandleData { $handles[$phid] = $handle; } break; + case PhabricatorPHIDConstants::PHID_TYPE_OPKG: + $class = 'PhabricatorOwnersPackage'; + PhutilSymbolLoader::loadClass($class); + $object = newv($class, array()); + + $packages = $object->loadAllWhere('phid in (%Ls)', $phids); + $packages = mpull($packages, null, 'getPHID'); + + foreach ($phids as $phid) { + $handle = new PhabricatorObjectHandle(); + $handle->setPHID($phid); + $handle->setType($type); + if (empty($packages[$phid])) { + $handle->setName('Unknown Package'); + } else { + $package = $packages[$phid]; + $handle->setName($package->getName()); + $handle->setURI('/owners/package/'.$package->getID().'/'); + } + $handles[$phid] = $handle; + } + break; default: $loader = null; if (isset($external_loaders[$type])) { diff --git a/src/applications/typeahead/controller/common/PhabricatorTypeaheadCommonDatasourceController.php b/src/applications/typeahead/controller/common/PhabricatorTypeaheadCommonDatasourceController.php index 98c2ed37ba..fbb1ad808f 100644 --- a/src/applications/typeahead/controller/common/PhabricatorTypeaheadCommonDatasourceController.php +++ b/src/applications/typeahead/controller/common/PhabricatorTypeaheadCommonDatasourceController.php @@ -28,6 +28,8 @@ class PhabricatorTypeaheadCommonDatasourceController $need_users = false; $need_lists = false; $need_projs = false; + $need_repos = false; + $need_packages = false; $need_upforgrabs = false; switch ($this->type) { case 'searchowner': @@ -43,6 +45,12 @@ class PhabricatorTypeaheadCommonDatasourceController case 'projects': $need_projs = true; break; + case 'repositories': + $need_repos = true; + break; + case 'packages': + $need_packages = true; + break; } $data = array(); @@ -88,6 +96,28 @@ class PhabricatorTypeaheadCommonDatasourceController } } + if ($need_repos) { + $repos = id(new PhabricatorRepository())->loadAll(); + foreach ($repos as $repo) { + $data[] = array( + 'r'.$repo->getCallsign().' ('.$repo->getName().')', + '/diffusion/'.$repo->getCallsign().'/', + $repo->getPHID(), + ); + } + } + + if ($need_packages) { + $packages = id(new PhabricatorOwnersPackage())->loadAll(); + foreach ($packages as $package) { + $data[] = array( + $package->getName(), + '/owners/package/'.$package->getID().'/', + $package->getPHID(), + ); + } + } + return id(new AphrontAjaxResponse()) ->setContent($data); } diff --git a/src/applications/typeahead/controller/common/__init__.php b/src/applications/typeahead/controller/common/__init__.php index cd491a9f15..9e27c3e96f 100644 --- a/src/applications/typeahead/controller/common/__init__.php +++ b/src/applications/typeahead/controller/common/__init__.php @@ -8,8 +8,10 @@ phutil_require_module('phabricator', 'aphront/response/ajax'); phutil_require_module('phabricator', 'applications/metamta/storage/mailinglist'); +phutil_require_module('phabricator', 'applications/owners/storage/package'); phutil_require_module('phabricator', 'applications/people/storage/user'); phutil_require_module('phabricator', 'applications/project/storage/project'); +phutil_require_module('phabricator', 'applications/repository/storage/repository'); phutil_require_module('phabricator', 'applications/typeahead/controller/base'); phutil_require_module('phutil', 'utils');