From b8d604acaf84e967ee764f13462d84594f67bfa7 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 17 Jul 2014 15:49:11 -0700 Subject: [PATCH] Make typeahead datasources default to PHID type icons Summary: Ref T4420. If a datasource does not specify an icon explicitly, check if the PHID type has a default, and use that. This leaves us with only Projects and some special stuff setting explicit icons, and reduces code duplication. Test Plan: Used typeahead to find all affected object types. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4420 Differential Revision: https://secure.phabricator.com/D9894 --- .../DiffusionRepositoryDatasource.php | 3 +- .../typeahead/LegalpadDocumentDatasource.php | 1 - .../typeahead/PhabricatorMacroDatasource.php | 3 +- .../PhabricatorMailingListPHIDTypeList.php | 4 +++ .../phid/PhabricatorOwnersPHIDTypePackage.php | 4 +++ .../PhabricatorOwnersPackageDatasource.php | 1 - .../typeahead/PhabricatorPeopleDatasource.php | 1 - .../PhabricatorProjectDatasource.php | 2 +- .../storage/PhabricatorTypeaheadResult.php | 30 ++++++++++++++++++- 9 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/applications/diffusion/typeahead/DiffusionRepositoryDatasource.php b/src/applications/diffusion/typeahead/DiffusionRepositoryDatasource.php index cdaa5f7c6c..3cbf202eb6 100644 --- a/src/applications/diffusion/typeahead/DiffusionRepositoryDatasource.php +++ b/src/applications/diffusion/typeahead/DiffusionRepositoryDatasource.php @@ -25,8 +25,7 @@ final class DiffusionRepositoryDatasource ->setName($repo->getMonogram().' '.$repo->getName()) ->setURI('/diffusion/'.$repo->getCallsign().'/') ->setPHID($repo->getPHID()) - ->setPriorityString($repo->getMonogram()) - ->setIcon('fa-database bluegrey'); + ->setPriorityString($repo->getMonogram()); } return $results; diff --git a/src/applications/legalpad/typeahead/LegalpadDocumentDatasource.php b/src/applications/legalpad/typeahead/LegalpadDocumentDatasource.php index e266dca640..ccb527dfa0 100644 --- a/src/applications/legalpad/typeahead/LegalpadDocumentDatasource.php +++ b/src/applications/legalpad/typeahead/LegalpadDocumentDatasource.php @@ -23,7 +23,6 @@ final class LegalpadDocumentDatasource foreach ($documents as $document) { $results[] = id(new PhabricatorTypeaheadResult()) ->setPHID($document->getPHID()) - ->setIcon('fa-file-text-o') ->setName($document->getMonogram().' '.$document->getTitle()); } diff --git a/src/applications/macro/typeahead/PhabricatorMacroDatasource.php b/src/applications/macro/typeahead/PhabricatorMacroDatasource.php index a6c84d9cce..6b7078b410 100644 --- a/src/applications/macro/typeahead/PhabricatorMacroDatasource.php +++ b/src/applications/macro/typeahead/PhabricatorMacroDatasource.php @@ -25,8 +25,7 @@ final class PhabricatorMacroDatasource foreach ($macros as $macro) { $results[] = id(new PhabricatorTypeaheadResult()) ->setPHID($macro->getPHID()) - ->setName($macro->getName()) - ->setIcon('fa-meh-o bluegrey'); + ->setName($macro->getName()); } return $results; diff --git a/src/applications/mailinglists/phid/PhabricatorMailingListPHIDTypeList.php b/src/applications/mailinglists/phid/PhabricatorMailingListPHIDTypeList.php index df814dfa3a..3371d2cf0f 100644 --- a/src/applications/mailinglists/phid/PhabricatorMailingListPHIDTypeList.php +++ b/src/applications/mailinglists/phid/PhabricatorMailingListPHIDTypeList.php @@ -12,6 +12,10 @@ final class PhabricatorMailingListPHIDTypeList extends PhabricatorPHIDType { return pht('Mailing List'); } + public function getTypeIcon() { + return 'fa-envelope-o'; + } + public function newObject() { return new PhabricatorMetaMTAMailingList(); } diff --git a/src/applications/owners/phid/PhabricatorOwnersPHIDTypePackage.php b/src/applications/owners/phid/PhabricatorOwnersPHIDTypePackage.php index b82b47a9ea..6aff840c22 100644 --- a/src/applications/owners/phid/PhabricatorOwnersPHIDTypePackage.php +++ b/src/applications/owners/phid/PhabricatorOwnersPHIDTypePackage.php @@ -12,6 +12,10 @@ final class PhabricatorOwnersPHIDTypePackage extends PhabricatorPHIDType { return pht('Owners Package'); } + public function getTypeIcon() { + return 'fa-list-alt'; + } + public function newObject() { return new PhabricatorOwnersPackage(); } diff --git a/src/applications/owners/typeahead/PhabricatorOwnersPackageDatasource.php b/src/applications/owners/typeahead/PhabricatorOwnersPackageDatasource.php index edbcf758ce..7d681bc2cc 100644 --- a/src/applications/owners/typeahead/PhabricatorOwnersPackageDatasource.php +++ b/src/applications/owners/typeahead/PhabricatorOwnersPackageDatasource.php @@ -23,7 +23,6 @@ final class PhabricatorOwnersPackageDatasource foreach ($packages as $package) { $results[] = id(new PhabricatorTypeaheadResult()) - ->setIcon('fa-list-alt bluegrey') ->setName($package->getName()) ->setURI('/owners/package/'.$package->getID().'/') ->setPHID($package->getPHID()); diff --git a/src/applications/people/typeahead/PhabricatorPeopleDatasource.php b/src/applications/people/typeahead/PhabricatorPeopleDatasource.php index 5b1a91d953..d0f9aa2d18 100644 --- a/src/applications/people/typeahead/PhabricatorPeopleDatasource.php +++ b/src/applications/people/typeahead/PhabricatorPeopleDatasource.php @@ -104,7 +104,6 @@ final class PhabricatorPeopleDatasource ->setURI('/p/'.$user->getUsername()) ->setPHID($user->getPHID()) ->setPriorityString($user->getUsername()) - ->setIcon('fa-user bluegrey') ->setPriorityType('user') ->setClosed($closed); diff --git a/src/applications/project/typeahead/PhabricatorProjectDatasource.php b/src/applications/project/typeahead/PhabricatorProjectDatasource.php index 8b2343132d..f9bba5c33f 100644 --- a/src/applications/project/typeahead/PhabricatorProjectDatasource.php +++ b/src/applications/project/typeahead/PhabricatorProjectDatasource.php @@ -32,7 +32,7 @@ final class PhabricatorProjectDatasource ->setDisplayType('Project') ->setURI('/tag/'.$proj->getPrimarySlug().'/') ->setPHID($proj->getPHID()) - ->setIcon($proj->getIcon()) + ->setIcon($proj->getIcon().' bluegrey') ->setPriorityType('proj') ->setClosed($closed); diff --git a/src/applications/typeahead/storage/PhabricatorTypeaheadResult.php b/src/applications/typeahead/storage/PhabricatorTypeaheadResult.php index ee4c8609fa..37aa314ce9 100644 --- a/src/applications/typeahead/storage/PhabricatorTypeaheadResult.php +++ b/src/applications/typeahead/storage/PhabricatorTypeaheadResult.php @@ -79,7 +79,7 @@ final class PhabricatorTypeaheadResult { $this->displayType, $this->imageURI ? (string)$this->imageURI : null, $this->priorityType, - $this->icon, + ($this->icon === null) ? $this->getDefaultIcon() : $this->icon, $this->closed, $this->imageSprite ? (string)$this->imageSprite : null, ); @@ -89,4 +89,32 @@ final class PhabricatorTypeaheadResult { return $data; } + /** + * If the datasource did not specify an icon explicitly, try to select a + * default based on PHID type. + */ + private function getDefaultIcon() { + static $icon_map; + if ($icon_map === null) { + $types = PhabricatorPHIDType::getAllTypes(); + + $map = array(); + foreach ($types as $type) { + $icon = $type->getTypeIcon(); + if ($icon !== null) { + $map[$type->getTypeConstant()] = "{$icon} bluegrey"; + } + } + + $icon_map = $map; + } + + $phid_type = phid_get_type($this->phid); + if (isset($icon_map[$phid_type])) { + return $icon_map[$phid_type]; + } + + return null; + } + }