1
0
Fork 0
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:
epriestley 2014-07-17 15:49:11 -07:00
parent 7f0fb63c44
commit b8d604acaf
9 changed files with 40 additions and 9 deletions

View file

@ -25,8 +25,7 @@ final class DiffusionRepositoryDatasource
->setName($repo->getMonogram().' '.$repo->getName()) ->setName($repo->getMonogram().' '.$repo->getName())
->setURI('/diffusion/'.$repo->getCallsign().'/') ->setURI('/diffusion/'.$repo->getCallsign().'/')
->setPHID($repo->getPHID()) ->setPHID($repo->getPHID())
->setPriorityString($repo->getMonogram()) ->setPriorityString($repo->getMonogram());
->setIcon('fa-database bluegrey');
} }
return $results; return $results;

View file

@ -23,7 +23,6 @@ final class LegalpadDocumentDatasource
foreach ($documents as $document) { foreach ($documents as $document) {
$results[] = id(new PhabricatorTypeaheadResult()) $results[] = id(new PhabricatorTypeaheadResult())
->setPHID($document->getPHID()) ->setPHID($document->getPHID())
->setIcon('fa-file-text-o')
->setName($document->getMonogram().' '.$document->getTitle()); ->setName($document->getMonogram().' '.$document->getTitle());
} }

View file

@ -25,8 +25,7 @@ final class PhabricatorMacroDatasource
foreach ($macros as $macro) { foreach ($macros as $macro) {
$results[] = id(new PhabricatorTypeaheadResult()) $results[] = id(new PhabricatorTypeaheadResult())
->setPHID($macro->getPHID()) ->setPHID($macro->getPHID())
->setName($macro->getName()) ->setName($macro->getName());
->setIcon('fa-meh-o bluegrey');
} }
return $results; return $results;

View file

@ -12,6 +12,10 @@ final class PhabricatorMailingListPHIDTypeList extends PhabricatorPHIDType {
return pht('Mailing List'); return pht('Mailing List');
} }
public function getTypeIcon() {
return 'fa-envelope-o';
}
public function newObject() { public function newObject() {
return new PhabricatorMetaMTAMailingList(); return new PhabricatorMetaMTAMailingList();
} }

View file

@ -12,6 +12,10 @@ final class PhabricatorOwnersPHIDTypePackage extends PhabricatorPHIDType {
return pht('Owners Package'); return pht('Owners Package');
} }
public function getTypeIcon() {
return 'fa-list-alt';
}
public function newObject() { public function newObject() {
return new PhabricatorOwnersPackage(); return new PhabricatorOwnersPackage();
} }

View file

@ -23,7 +23,6 @@ final class PhabricatorOwnersPackageDatasource
foreach ($packages as $package) { foreach ($packages as $package) {
$results[] = id(new PhabricatorTypeaheadResult()) $results[] = id(new PhabricatorTypeaheadResult())
->setIcon('fa-list-alt bluegrey')
->setName($package->getName()) ->setName($package->getName())
->setURI('/owners/package/'.$package->getID().'/') ->setURI('/owners/package/'.$package->getID().'/')
->setPHID($package->getPHID()); ->setPHID($package->getPHID());

View file

@ -104,7 +104,6 @@ final class PhabricatorPeopleDatasource
->setURI('/p/'.$user->getUsername()) ->setURI('/p/'.$user->getUsername())
->setPHID($user->getPHID()) ->setPHID($user->getPHID())
->setPriorityString($user->getUsername()) ->setPriorityString($user->getUsername())
->setIcon('fa-user bluegrey')
->setPriorityType('user') ->setPriorityType('user')
->setClosed($closed); ->setClosed($closed);

View file

@ -32,7 +32,7 @@ final class PhabricatorProjectDatasource
->setDisplayType('Project') ->setDisplayType('Project')
->setURI('/tag/'.$proj->getPrimarySlug().'/') ->setURI('/tag/'.$proj->getPrimarySlug().'/')
->setPHID($proj->getPHID()) ->setPHID($proj->getPHID())
->setIcon($proj->getIcon()) ->setIcon($proj->getIcon().' bluegrey')
->setPriorityType('proj') ->setPriorityType('proj')
->setClosed($closed); ->setClosed($closed);

View file

@ -79,7 +79,7 @@ final class PhabricatorTypeaheadResult {
$this->displayType, $this->displayType,
$this->imageURI ? (string)$this->imageURI : null, $this->imageURI ? (string)$this->imageURI : null,
$this->priorityType, $this->priorityType,
$this->icon, ($this->icon === null) ? $this->getDefaultIcon() : $this->icon,
$this->closed, $this->closed,
$this->imageSprite ? (string)$this->imageSprite : null, $this->imageSprite ? (string)$this->imageSprite : null,
); );
@ -89,4 +89,32 @@ final class PhabricatorTypeaheadResult {
return $data; 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;
}
} }