mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-19 03:01:11 +01:00
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
This commit is contained in:
parent
7f0fb63c44
commit
b8d604acaf
9 changed files with 40 additions and 9 deletions
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue